pax_global_header00006660000000000000000000000064127301436700014515gustar00rootroot0000000000000052 comment=8bd7b7b23715b6a329fd4e6b765a707d718d2b45 pycogent-1.9/000077500000000000000000000000001273014367000132165ustar00rootroot00000000000000pycogent-1.9/.gitignore000066400000000000000000000005171273014367000152110ustar00rootroot00000000000000*.py[cod] # C extensions *.so # Packages *.egg *.egg-info dist build eggs parts bin var sdist develop-eggs .installed.cfg lib lib64 # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox nosetests.xml tests/draw_results # Translations *.mo # Mr Developer .mr.developer.cfg .project .pydevproject # vi .*.swp pycogent-1.9/.hgignore000066400000000000000000000002331273014367000150170ustar00rootroot00000000000000syntax:glob .svn *.pyc *.pyo *.so *.o *.DS_Store *.tmproj *.rej *.orig *.wpr *.pdf _build/* build *htmlcov* *.idea draw_results *.coverage *egg-info* *.wpupycogent-1.9/ChangeLog000077500000000000000000000720261273014367000150020ustar00rootroot00000000000000********* Changelog ********* Cogent 1.5.3 - 1.9 ================== NOTE: There have been so many changes since the 1.5.3 release that it is not viable to list themn all! Suffice it to say, many new features added and many bugs have been squashed. The best way to see them is using either git or mercurial to examine the commit logs. Cogent 1.5.2 - 1.5.3 ==================== New Features ------------ * Added a withoutLostSpans() method to Feature objects in cogent.core.annotation. Useful after projecting features from one aligned sequence across to another. Implemented for ordinary Features and SimpleVariables but not xxy_list Variables. Changes ------- * Make Span.remapWith() a little clearer in cogent.core.location. * Tidy annotation remapping code in cogent.core.annotation and cogent.core.sequence so that new positions are only calculated once when slicing, projecting, or otherwise remapping parts of sequences. The old code was needlessly doing it twice. Bug Fixes --------- * Fixed bug in BLAT application controller (cogent.app.blat) which would drop some input sequences when running assign_dna_reads_to_protein_database. * Prevent negative widths from arising in cogent.draw.compatibility when alignment is too wide. Cogent 1.5.1 - 1.5.2 ==================== New Features ------------ * Added new mantel_test function to cogent.maths.stats.test that allows the type of significance test to be specified. This function is meant to replace the pre-existing mantel function. * Added new correlation_test function to cogent.maths.stats.test that computes the correlation (pearson or spearman) between two vectors, in addition to parametric and nonparametric tests of significance and confidence intervals. This function gives more control and information than the pre-existing correlation function. The spearman function is also a new addition. * Added new mc_t_two_sample function to cogent.maths.stats.test that performs a two-sample t-test and uses Monte Carlo permutations to determine nonparametric significance (similar to R's Deducer::perm.t.test). * Added guppy 1.1, pplacer 1.1, ParsInsert 1.04, usearch 5.2.32, rtax 0.981, raxml 7.3.0, BLAT 34, and BWA 0.6.2 application controllers. * Added new functions to cogent.maths.stats.rarefaction that provide alternative ways to perform rarefaction subsampling. * Added convenience wrappers assign_dna_reads_to_database, assign_dna_reads_to_protein_database, and assign_dna_reads_to_dna_database for BLAT, BWA, and usearch with consistent interface across all three. Changes ------- * Minimum matplotlib version now set to 1.1.0. * Minimum Vienna package version now set to 1.8.5. * The pearson function in cogent.maths.stats.test has more robust error-checking. * The mantel and mantel_test functions in cogent.maths.stats.test now check for symmetric, hollow distance matrices as input by default, with an option to disable these checks. * cogent.draw.distribution_plots now uses matplotlib proxy Artists for legend creation (this simplifies the code a bit). Added ability to set the size of plot figures through two new optional parameters to generate_box_plots and generate_comparative_plots. More robust checks have been put in place in case making room for labels fails (this now uses matplotlib 1.1.0's new tight_layout() functionality, but this can still fail in some cases). * cogent.app.raxml (version 7.0.3) is now deprecated and will be removed in 1.6.0. Please use cogent.app.raxml_v730 instead (version 7.3.0). * cogent.app.muscle (version 3.6) is now deprecated and will be removed in 1.6.0. Please use cogent.app.muscle_v38 instead (version 3.8). * Updated cogent.app.uclust to handle --stepwords and --w. Bug Fixes --------- * improve handling of reading frames from Ensembl * actually included the test_ensembl/test_metazoa.py file that was accidentally overlooked. * fixed small diff in postcript output from RNAfold * Deprecation and discontinued warnings are now not ignored by default. cogent.util.warning was ignored in Python 2.7 because it uses DeprecationWarnings. These warnings are temporarily forced to not be ignored. * Included test_app/test_formatdb.py and test_app/test_mothur.py files in alltests.py. * Fixed test_safe_md5 in tests.test_util.test_misc to no longer run an MD5 over a file in PyCogent (this caused the test to break when a new release went out because the MD5 changes due to the new version string). The test now writes a temporary file populated with fixed data and computes the MD5 from that. * Fixed data_file_links.html in the PyCogent documentation to correctly point to several data files that were previously unreachable. Cogent 1.5 - 1.5.1 ================== New Features ------------ * Alignments can now add sequences that are pairwise aligned to a sequence already present in the alignment. * Alignment.addSeqs has more flexibility with the specific order of sequences now controllable by the user. Thanks to Jan Kosinski for these two very useful patches! * Increased options for reading Table data from files: limit keyword; and, line based (as distinct from column-based) type-casting of delimited files. * Flexible parser for raw Greengenes 16S records * Add fast pairwise distance estimation for DNA/RNA sequences. Currently only Jukes-Cantor 1969 and Tamura-Nei 1993 distances are provided. A cookbook entry was added to building_phylogenies. * Added a PredefinedNucleotide substitution model class. This class uses Cython implementations for nucleotide models where analytical solutions are available. Substantial speedups are achieved. These implementations do not support obtaining the rate matrix. Use the older style implementation if you require that (toggled by the rate_matrix_required argument). * Added fit_function function. This allows to fit any model to a x and y dataset using simplex to reduce the error between the model and the data. * Added parsers for bowtie and for BLAT's PSL format * Table can now read/write gzipped files. * GeneticCode class has a getStopIndices method. Returns the index positions of stop codons in a sequence for a user specified translation frame. * Added LogDet metric to cogent.evolve.pairwise_distance. With able assistance from Yicheng Zhu. Thanks Yicheng! * Added jackknife code to cogent.maths.stats.jackknife. This can be used to measure confidence of an estimate from a single vector or a matrix. Thanks to Anuj Pahwa for help implementing this! * Added abundance-based Jaccard beta diversity index (Chao et. al., 2005) Changes ------- * python 2.6 is now the minimum required version * We have removed code authored by Ziheng Yang as it is not available under an open source license. We note a modest performance hit for nucleotide and dinucleotide models. Codon models are not affected. The PredefinedNucleotide models recently added are faster than the older approach that used Yang's code. * The PredefinedNucleotide models are now available via cogent.evolve.models. The old-style (slower) nucleotide models can be obtained by setting rate_matrix_required=True. * RichGenbankParser can now return WGS blocks Bug Fixes --------- * fixed bug that crept into doing consensus trees from tree collections. Thanks to Klara Verbyla for catching this one! * fixed a bug (#3170464) affecting obtaining sequences from non-chromosome level coordinate systems. Thanks to brandoninvergo for reporting and Hua Ying for the patch! * fixed a bug (#2987278) associated with missing unit tests for gbseq.py * fixed a bug (#2987264) associated with missing unit tests for paml_matrix.py * fixed a bug (#2987238) associated with missing unit tests for tinyseq.py Cogent 1.4.1 - 1.5 ================== New Features ------------ * major additions to Cookbook. Thanks to the many contributors (too many to list here)! * added AlleleFreqs attribute to ensembl Variation objects. * added getGeneByStableId method to genome objects. * added Introns attribute to Transcript objects and an Intron class. (Thanks to Hua Ying for this patch!) * added Mann-Whitney test and a Monte-Carlo version * exploratory and confirmatory period estimation techniques (suitable for symbolic and continuous data) * Information theoretic measures (AIC and BIC) added * drawing of trees with collapsed nodes * progress display indicator support for terminal and GUI apps * added parser for illumina HiSeq2000 and GAiix sequence files as cogent.parse.illumina_sequence.MinimalIlluminaSequenceParser. * added parser to FASTQ files, one of the output options for illumina's workflow, also added cookbook demo. * added functionality for parsing of SFF files without the Roche tools in cogent.parse.binary_sff Changes ------- * thousand fold performance improvement to nmds * >10-fold performance improvements to some Table operations Bug Fixes --------- * Fixed a Bug in cogent.core.alphabet that resulted in 4 tests err'ing out when using NumPy v1.4.1 * Sourceforge bugs 2987289, 2987277, 2987378, 2987272, 2987269 were addressed and fixed Cogent 1.4 - 1.4.1 ================== New Features ------------ * Simplified getting genetic variation from Ensembl and provide the protein location of nonsynonymous variants. * rate heterogeneity variants of pre-canned continuous time substitution models easier to define. * Added implementation of generalised neighbour joining. * New capabilities for examining genetic variants using Ensembl. * Phylogenetic methods that can return collections of trees do so as a TreeCollections object, which has writeToFile and getConsensusTree methods. * Added uclust application controller which currently supports uclust v1.1.579. Changes ------- * Major additions to Cookbook documentation courtesy of Tom Elliot. Thanks Tom! * Improvements to parallelisation. Bug Fixes --------- Cogent 1.3 - 1.4 ================ New Features ------------ * added support for manipulating and handling macromolecular structures. This includes a PDB file format parser, a hierarchical data structure to represent molecules. Various utilities to manipulate e.g. clean-up molecules, efficient surface area and proximity-contact calculation via cython. Expansion into unit-cells and crystal lattices is also possible. * added a KD-Tree class for fast nearest neighbor look-ups. Supports k-nearest neighbours and all neighbours within radius queries currently only in 3D. * added new tools for evaluating clustering stresses, goodness_of_fit. In cogent.cluster . * added a new clustering tool, procrustes analysis. In cogent.cluster . * phylo.distance.EstimateDistances class has a new argument, modify_lf. This allows the use the modify the likelihood function, possibly constraining parameters, freeing them, setting bounds, pre-optimising etc.. * cogent Table mods; added transposed and normalized methods while the summed method can now return column or row sums. * Added a new context dependent model class. The conditional nucleotide frequency weighted class has been demonstrated to be superior to the model forms of Goldman and Yang (1994) and Muse and Gaut (1994). The publication supporting this claim is In press at Mol Biol Evol, authored by Yap, Lindsay, Easteal and Huttley. * added new argument to LoadTable to facilitate speedier loading of large files. The static_column_types argument auto-generates a separator format parser with column conversion for numeric columns. * added BLAST XML parser + tests. * Add compatibility matrix module for determining reticulate evolution. * Added 'start' and 'order' options to the WLS and ML tree finding method .trex() These allow the search of tree-space to be constrained to start at a particular subtree and to proceed in a specified order of leaf additions. * Consensus tree of weighted trees from phylo.maximum_likelihood. * Add Alignment.withGapsFrom() aka mirrorGaps, mirrors the gaps into a provided alignment. * added ANOVA to maths.stats.test * LoadTable gets an optional argument (static_column_types) to simplify speedy loading of big files. Changes ------- * Python 2.4 is no longer supported. * NumPy 1.3 is now the minimum supported NumPy version. * zlib is now a dependency. * cogent.format.table.asReportlabTable is being discontinued in version 1.5. This is the last dependency on reportlab and removal will simplify installation. * the conditional nucleotide model (Yap et al 2009) will be made the default model form for context dependent models in version 1.5. * Change required MPI library from PyxMPI to mpi4py. * Move all of the cogent.draw.matplotlib.* modules up to cogent.draw.* * Substitute matplotlib for reportlab throughout cogent.draw * cogent.db.ensembl code updated to work with the latest Ensembl release (56) * motif prob pseudocount option, used for initial values of optimisable mprobs * The mlagan application controller has been removed. Bug Fixes --------- * Fix and test for two bugs in multiple alignment, One in the pairwise.py Hirschberg code and the other in indel_positions.py where gaps at the end were effectively taken to be deletions and never insertions, unlike gaps at the start. * fix #2811993 alignment getMotifProbs. allow_gap argument now has an effect. Cogent 1.2 - 1.3 ================ New Features ------------ * Python2.6 is now supported * added cogent.cluster.nmds, code to perform nonmetric multidimensional scaling. Not as fast as others (e.g.: R, MASS package, isoMDS) * Documentation ported to using the Sphinx documentation generator. * Major additions to documentation in doc/examples. * Added partial support for querying the Ensembl MySQL databases. This capacity has additional dependencies (MySQL-python and SQLAlchemy). This module should be considered alpha level code, (although it has worked reliably for some time in the hands of the developers). * Introduced a new substitution model family. This family has the same form as that originally described by Muse and Gaut (Mol Biol Evol, 11, 715-24). These models were applied in the article by Lindsay et al. (2008, Biol Direct, 3, 52). Model state defaults to the tuple weighted matrix (eg. the Goldman and Yang codon models). Selecting the nucleotide weighted matrix is done using the mprob_model argument. * Likelihood functions now have a getStatistics method. This returns cogent Table objects. Optional arguments are with_motif_probs and with_titles where the latter refers to the Table.Title attribute being set. * Added rna_struct formatter and rna_plot parser * A fast unifrac method implementation. * Added new methods on tree related objects: TreeNode.getNodesDict; TreeNode.reassignNames; PhyloNode.tipsWithinDistance; PhyloNode.totalDescendingBranchLength * Adopted Sphinx documentation system, added many new use cases, improved existing ones. * added setTablesFormat to likelihood function. This allows setting the spacing, display precision of the stats tables resulting from printing a likelihood function. * Added non-parametric multidimensional scaling (nmds) method. * Added a seperate app controller for FastTree v1.0 * new protein MolType, PROTEIN_WITH_STOP, that supports the stop codon new sequence objects, ProteinWithStopSequence and ModelProteinWithStopSequence to support the new MolType. * Support for Cython added. Changes ------- * reconstructAncestralSequences has been deprecated to reconstructAncestralSeqs. It will be removed in version 1.4. * updated parsers * TreeNode.getNewick is now iterative. For recursive, use TreeNode.getNewickRecursive. Both the iterative and recursive methods of getNewick now support the keyword 'escape_name'. DndParser now supports the keyword 'unescape_name'. DndParser unescape_name will now try to remove underscores (like underscore_unmunge). * Generalized MinimalRnaalifoldParser to parse structures and energies from RNAfold as well. * PhyloNode.tipToTipDistances can now work on a subset of tips by passing either a list of tip names or a list of tip nodes using the endpoints param. * deprecating reconstructAncestralSequences to deprecating reconstructAncestralSeqs. * updated app controller parameters for FastTree v1.1 * Allow and require a more recent version of Pyrex. * LoadTree is now a method of cogent.__init__ .. warning:: Pyrex is no longer the accepted way to develop extensions. Use `Cython `_ instead. Bug Fixes --------- * the alignment sample methods and xsample (randint had the wrong max argument) * Fixes the tests that no longer work with NCBI's API changes, and sticks a big warning for the unwary in the ncbi module pointing users to the "official" list of reported rettypes. Note that the rettypes changed recently and NCBI says they do not plan to support the old behavior. * The TreeNode operators cmp, contains, and any operator that relies on those methods will now only perform comparisons against the objects id. Prior behavior first checked the TreeNode's Name attribute and then object id if the Name was not present. This resulted in ambiguous behavior in certain situations. * Added type conversion to Mantel so it works on lists. * kendall tau fix, bug 2794469 * Table now raises a RuntimeError if provided malformed data. * Fixed silent type conversion in TreeNode, bug 2804431 * RangeNode is now properly passing kwargs to baseclass, bug 2804441 * DndParser was not producing correct trees in niche cases, bug 2798580 Cogent 1.1 - 1.2 ================ New Features ------------ * Code for performing molecular coevolution/covariation analyses on multiple sequence alignments, plus support files. (Described in J. Caporaso et al. BMC Evol Biol, 8(1):327, 2008.) * App controller for `CD-HIT `_ * A ParameterEnumerator object is now available in cogent.app.util. This method will iterate over a range of parameters, returning parameter dicts that can be used with the relevant app controller. * Sequence and alignment objects that inherit from Annotatable can now mask regions of sequence, returning new objects where the observed sequence characters in the regions spanned by the annotations are replaced by a mask character (mask_char). * Table.count method. Counts the number of rows satisfying some condition. * Format writer for stockholm and clustal formats. * App controllers for dotur, infernal, RNAplot, RNAalifold. Parsers for infernal and dotur. * Empirical nucleotide substitution matrix estimation code (Described in M. Oscamou et al. BMC Bioinformatics, 9(1):511, 2008) New Documentation ----------------- Usage examples (see doc/) were added for the following: * Querying NCBI * The motif module. * UPGMA clustering * For using the ParameterCombinations object and generating command lines * Coevolution modelling * Sequence annotation handling * Table manipulation * Principal components analysis (PCoA) * Genetic code objects * How to construct profiles, consensus seqs etc .. Changes ------- * PyCogent no longer relies on the Python math module. All math functions are now imported from numpy. The main motivator was to remove casting between numpy and Python types. Such as, a 'numpy.float64' variable unknowingly being converted to a Python 'float' type. * Tables.getDistinctValues now handles multiple columns. * Table.Header is now an immutable property of Tables. Use the withNewHeader method modifying Header labels. * The TreeNode comparison methods now only check against the objects ID Bug Fixes --------- * LoadTable was ignoring title argument for standard file read. * Fixed bug in Table.joined. When a join produces no result, now returns a Table with 0 rows. * Improved consistency of LoadTable with previous behaviour of cogent.Table * Added methods to detect large sequences/alphabets and handle counts from sequence triples correctly. * goldman_q_dna_pair() and goldman_q_rna_pair() now average the frequency matrix used. * reverse complement of annotations with disjoint spans correctly preserve order. * Fixed ambiguity in TreeNode comparison methods which resulted in the prune method incorrectly removing entire subtrees. Cogent 1.0.1 - 1.1 ================== New Features ------------ * Added functionality to cogent.util.unit_test.TestCase assertSameObj - use in place of 'assert a is b' assertNotSameObj - use in place of 'assert a is not b' assertIsPermutation - checks if observed is a permutation of items assertIsProb - checks whether a value(s) are probabilities assertIsBetween - use in place of 'assert a < obs < b' assertLessThan - use in place of 'assert obs < value' assertGreaterThan - use in place of 'assert obs > value' assertSimiliarFreqs - compares frequency distributions using a G-test assertSimiliarMeans - compares samples using a t-test _set_suite_pvalue - set a suite wide pvalue .. note:: both the similiarity assertions can have a pvalue specified in the testing module. This pvalue can be overwritten during alltests.py by calling TestCase._set_suite_pvalue(pvalue) .. note:: All of these new assert methods can take lists as well. For instance: obs = [1,2,3,4] value = 5 self.assertLessThan(obs, value) * Alignment constructor now checks for iterators (e.g. results from parsers) and lists() them -- this allows direct construction like Alignment(MinimalFastaParser(open(myfile.fasta))). Applies to both dense and sparse alignments, and SequenceCollections. * Parameterized LoadTree underscore stripping in node names, and turned it off by default. * new Table features and refactor Trivial edits of the code provided by Felix Schill for SQL-like table joining. Principally a unification of the different types of table joins (inner- and outer-join) between 2 tables, and porting of all testing code into test_table.rest. The method Table.joined provides the interface (see tests/test_table.rest for usage). * added a Table.count method simply counts the number of rows satisfying some condition. Method has the same args as for Table.filtered. * Functions for obtaining the rate matrix for 2 or 3 sequences using the Goldman method. Support for RNA and DNA. * Additions to clustalw and muscle app controllers muscle.py add_seqs_to_alignment align_two_alignments align_unaligned_seqs align_and_build_tree build_tree_from_alignment clustalw.py align_unaligned_seqs bootstrap_tree_from_alignment build_tree_from_alignment align_and_build_tree * App controllers for Clearcut, ClustalW, Mafft * Added midpoint rooting * Accept FloatingPointError as well as ZeroDivisionError to accommodate numpy. * Trees can now compare themselves to other trees using a couple of methods. subsets: compare based on fraction of subsets of labels defined by clades that are the same in the two trees. tip_to_tip: compare based on correlations of tip_to_tip distances. Both of these are fairly badly behaved statistically, so should always be compared to a distribution of values from random (e.g. label-permuted) trees using Monte Carlo. * Added ability to exclude non-shared taxa from subsets tree cmp method. * Added Zongzhi's combination and permutation implementations to transform.py. * Added some docs to UPGMA_cluster. * Added median in cogent.maths.stats.test Added because the numpy version does not support an axis parameter. This function now works like numpy functions (sum, mean, etc...) where you can specify axis. This function should be safe in place of numpy.median. Changes ------- * Many changes to the core objects, mainly for compatibility. Major changes in this update: - ModelSequence now inherits from SequenceI and supports the various Sequence methods (e.g. nucleic acids can reverse-complement, etc.). Type checking is still performed using strings (e.g. for ambiguous characters, etc.) and could be improved, but everything seems to work. Bug # 1851959. - ModelProteinSequence added. Bug # 1851961. - DenseAlignment and ModelSequence can now handle the '?' character, which is added to the Alphabet during install. Bug # 1851483. - Fixed a severe bug in moltype constructors that mutated the dict of ambiguous states after construction of each of the standard moltypes (for example, preventing re-instantiation of a similar moltype after the initial install: bug # 1851482. This would have been very confusing for anyone trying to experiment with custom MolTypes. - DenseAlignment now implements many methods of Alignment (some of which have actually been moved into SequenceCollection), e.g. getGappedSeq() as per bug # 1816573. * Added parameter to MageListFromString and MageGroupFromString. Can now handle 'on' as well as 'off'. * SequenceCollection, Alignment, etc. now check for duplicate seq labels and raise exception or strip duplicates as desired. Added unit test to cover this case. - SequenceCollection now also produces FASTA as default __str__ behavior like the other objects. - DenseAlignment now iterates over its mapped items, not the indices for those items, by default. This allows API compatibility with Alignment but is slow: it may be worth optimizing this for cases such as detecting ambiguous chars, as I have already implemented for gaps. * Updated std in cogent.maths.stats.test - std now takes an axis parameter like numpy functions (sum, mean,etc...). - also added in a docstring and tests. .. note:: cogent.maths.stats.test import sqrt from numpy instead of math in order to allow std to work on arrays. * Tree now uses iterative implementation of traverse(). .. warning:: If you **do** modify the tree while using traverse(), you will get undesired results. If you need to modify the tree, use traverse_recursive() instead. This only applies to the tree topology (e.g. if you are adding or deleting nodes, or moving nodes around; doesn't apply if you are changing branch lengths, etc.). The only two uses I found in Cogent where the tree is modified during iteration are in rna2d (some of the structure tree operations) and the prune() method. I have changed both to use traverse_recursive for now. However, there might be issues with other code. It might be worth figuring out how to make the iterative method do the right thing when the tree is modified -- suggestions are welcome provided they do not impose substantial performance penalties. * Made compatible with Python 2.4 * Changed dev status in setup call * Dropping comments indicating windows support Bug Fixes --------- * Fixed bug 1850981: UPGMA does not check diagonals. This bug was caused because the UPGMA algorithm picks the smallest distances between nodes at each step but should not ever pick something on the diagonal. To prevent a diagonal choice we set it to a large number, but sometimes, for very large matrices, the diagonal sometimes is chosen becuase the number decreases in value as the distances are averaged during node collapse. To prevent this error, the program now checks to make sure that the selected smallest_index is not on the diagonal. If it is, it reassigns the diagonal to the large number. * Fixed bug in gff.py attribute string parsing. If attribute string did not contain double quotes, find() returned -1, so the last character of the string was inadvertently omitted. * Fixed error in taxonomy convenience functions that failed to pass in the specified database. This used to be masked by ncbi's automatic conversion between protein and nucleotide ids, but apparently this conversion no longer operates in the tested cases. * fixed unittest methods Zongzhi noticed that assertFloatEqual would compare two against when a shape (4,0) array was compared against a shape (4,4) array. I added tests for assertFloatEqual, assertFloatEqualAbs, assertFloatEqualRel and assertEqual. The same bug was noticed in assertFloatEqualRel. They are now fixed. These fixes resulted in errors in maths.stats.test.std and correlation_matrix. The std function needed a work over, but the correlation_matrix was a fault in the test case itself. * fixed bug in reading tab-delimited tables failure when a record had a missing observation in the last field has been fixed. Line stripping of only line-feed characters is now done. * Fixed important bug in metric_scaling. numpy eig() produces eigenvector array that is the transpose of Numeric eig(). Therefore, any code that does not take this into account will produce results that are TOTALLY INCORRECT when fed to downstream analyses. Coordinates from this module prior to this patch are incorrect and are not to be trusted. * Fixed a typo in dialign test * tree __repr__ now more robust to non-str Name entries * seqsim.rangenode traverse now compatible /w base class. * Fixed line color bug in PR2 bias plots. * Added method to dump raw coords from dendrogram. * Fixed called to eigenvector when no pyrex * Fixed bug in nonrecursive postorder traversal if not root Cogent 1.0 - (9/8/2007) ======================= * Initial release pycogent-1.9/README000077500000000000000000000102411273014367000140770ustar00rootroot00000000000000The Readme ========== :Download: `From github `_ or follow the :ref:`quick-install` instructions. Dependencies ------------ The toolkit requires Python 2.5.1 or greater, and Numpy 1.3 or greater. Aside from these the dependencies below are optional and the code will work as is. A C compiler, however, will allow external C module's responsible for the likelihood and matrix exponentiation calculations to be compiled, resulting in significantly improved performance. .. _required: Required ^^^^^^^^ - Python_: the language the toolkit is primarily written in, and in which the user writes control scripts. - Numpy_: This is a python module used for speeding up matrix computations. It is available as source code for \*nix. - zlib_: This is a compression library which is available for all platforms and comes pre-installed on most too. If, by chance, your platform doesn't have this installed then download the source from the zlib_ site and follow the install instructions, or refer to the instructions for `compiling matplotlib`_. .. note:: On some linux platforms (like Ubuntu), you must specifically install a ``python-dev`` package so that the Python_ header files required for building some external dependencies are available. Optional ^^^^^^^^ - C compiler: This is standard on most \*nix platforms. On Macos X this is available for free in the Developer tools which, if you don't already have them, can be obtained from Apple_. - Matplotlib_: used to plot several kinds of graphs related to codon usage. For installation, see these instructions for `compiling matplotlib`_. - Cython_: This module is only necessary if you are a developer who wants to modify the \*.pyx files. - mpi4py_: Message Passing Interface interface, required for parallel computation. - SQLAlchemy_ and a mysql connector such as `PyMySQL `_: These are required for the Ensembl querying code. See the :ref:`quick-install` approach for how these can be grabbed using the ``all`` option.. Installation ------------ See the :ref:`quick-install`. Testing ------- ``PyCogent/tests`` contains all the tests. You can most readily run the tests using the ``PyCogent/run_tests`` shell script. This is done by typing: .. code-block:: guess $ sh run_tests which will automatically build extensions in place, set up the PYTHONPATH and run ``PyCogent/tests/alltests.py``. Note that if certain optional applications are not installed this will be indicated in the output as "can't find" or "not installed". A "`.`" will be printed to screen for each test and if they all pass, you'll see output like: .. code-block:: guess Ran 3299 tests in 58.128s OK Tips for usage -------------- A good IDE can greatly simplify writing control scripts. Features such as code completion and definition look-up are extremely useful. For a complete list of `editors go here`_. To get help on attributes of an object in python, use .. code-block:: python >>> dir(myalign) to list the attributes of ``myalign`` or .. code-block:: python >>> help(myalign.writeToFile) to figure out how to use the ``myalign.writeToFile`` method. Also note that the directory structure of the package is similar to the import statements required to use a module -- to see the contents of ``alignment.py`` or ``sequence.py`` you need to look in the directory ``cogent/core`` path, to use the classes in those files you specify ``cogent.core`` for importing. .. _Python: http://www.python.org .. _Cython: http://www.cython.org/ .. _Numpy: http://numpy.scipy.org/ .. _Matplotlib: http://matplotlib.sourceforge.net .. _Apple: http://www.apple.com .. _Pyrex: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ .. _`editors go here`: http://www.python.org/cgi-bin/moinmoin/PythonEditors .. _mpi4py: http://code.google.com/p/mpi4py .. _`restructured text`: http://docutils.sourceforge.net/rst.html .. _gcc: http://gcc.gnu.org/ .. _SQLAlchemy: http://www.sqlalchemy.org .. _`mysql-connector-python`: https://pypi.python.org/pypi/mysql-connector-python .. _zlib: http://www.zlib.net/ .. _`compiling matplotlib`: http://sourceforge.net/projects/pycogent/forums/forum/651121/topic/5635916 pycogent-1.9/README.md000066400000000000000000000010561273014367000144770ustar00rootroot00000000000000PyCogent: A toolkit for making sense from sequence ================================================== The official PyCogent source code repository. For details on PyCogent, see http://www.pycogent.org/. PyCogent includes connectors to remote databases, built-in generalized probabilistic techniques for working with biological sequences, and controllers for 3rd party applications. For PyCogent news and announcements, including notification of new releases, you can subscribe to the [PyCogent News and Announcements Blog](http://pycogent.wordpress.com). pycogent-1.9/cogent/000077500000000000000000000000001273014367000144755ustar00rootroot00000000000000pycogent-1.9/cogent/__init__.py000066400000000000000000000236541273014367000166200ustar00rootroot00000000000000"""The most commonly used constructors are available from this toplevel module. The rest are in the subpackages: phylo, evolve, maths, draw, parse and format.""" import sys, os, re, cPickle import numpy __author__ = "" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Gavin Huttley", "Rob Knight", "Peter Maxwell", "Jeremy Widmann", "Catherine Lozupone", "Matthew Wakefield", "Edward Lang", "Greg Caporaso", "Mike Robeson", "Micah Hamady", "Sandra Smit", "Zongzhi Liu", "Andrew Butterfield", "Amanda Birmingham", "Brett Easton", "Hua Ying", "Jason Carnes", "Raymond Sammut", "Helen Lindsay", "Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Gavin Huttley" __email__ = "gavin.huttley@anu.edu.au" __status__ = "Production" #SUPPORT2425 if sys.version_info < (2, 6): py_version = ".".join([str(n) for n in sys.version_info]) raise RuntimeError("Python-2.6 or greater is required, Python-%s used." % py_version) numpy_version = re.split("[^\d]", numpy.__version__) numpy_version_info = tuple([int(i) for i in numpy_version if i.isdigit()]) if numpy_version_info < (1, 3): raise RuntimeError("Numpy-1.3 is required, %s found." % numpy_version) version = __version__ version_info = tuple([int(v) for v in version.split(".") if v.isdigit()]) from cogent.util.table import Table as _Table from cogent.parse.table import load_delimited, autogen_reader from cogent.core.tree import TreeBuilder, TreeError from cogent.parse.tree_xml import parse_string as tree_xml_parse_string from cogent.parse.newick import parse_string as newick_parse_string from cogent.core.alignment import SequenceCollection from cogent.core.alignment import Alignment from cogent.parse.sequence import FromFilenameParser from cogent.parse.structure import FromFilenameStructureParser #note that moltype has to be imported last, because it sets the moltype in #the objects created by the other modules. from cogent.core.moltype import ASCII, DNA, RNA, PROTEIN, STANDARD_CODON, \ CodonAlphabet def Sequence(moltype=None, seq=None, name=None, filename=None, format=None): if seq is None: for (a_name, a_seq) in FromFilenameParser(filename, format): if seq is None: seq = a_seq if name is None: name = a_name else: raise ValueError("Multiple sequences in '%s'" % filename) if moltype is not None: seq = moltype.makeSequence(seq) elif not hasattr(seq, 'MolType'): seq = ASCII.makeSequence(seq) if name is not None: seq.Name = name return seq def LoadSeqs(filename=None, format=None, data=None, moltype=None, name=None, aligned=True, label_to_name=None, parser_kw={}, constructor_kw={}, **kw): """Initialize an alignment or collection of sequences. Arguments: - filename: name of the sequence file - format: format of the sequence file - data: optional explicit provision of sequences - moltype: the MolType, eg DNA, PROTEIN - aligned: set True if sequences are already aligned and have the same length, results in an Alignment object. If False, a SequenceCollection instance is returned instead. If callable, will use as a constructor (e.g. can pass in DenseAlignment or CodonAlignment). - label_to_name: function for converting original name into another name. Default behavior is to preserve the original FASTA label and comment. To remove all FASTA label comments, and pass in only the label, pass in: label_to_name=lambda x: x.split()[0] To look up names in a dict, pass in: label_to_name = lambda x: d.get(x, default_name) ...where d is a dict that's in scope, and default_name is what you want to assign any sequence that isn't in the dict. If format is None, will attempt to infer format from the filename suffix. If label_to_name is None, will attempt to infer correct conversion from the format. """ if filename is None: assert data is not None assert format is None assert not kw, kw else: assert data is None, (filename, data) data = list(FromFilenameParser(filename, format, **parser_kw)) # the following is a temp hack until we have the load API sorted out. if aligned: #if callable, call it -- expect either f(data) or bool if hasattr(aligned, '__call__'): return aligned(data=data, MolType=moltype, Name=name, label_to_name=label_to_name, **constructor_kw) else: #was not callable, but wasn't False return Alignment(data=data, MolType=moltype, Name=name, label_to_name=label_to_name, **constructor_kw) else: #generic case: return SequenceCollection return SequenceCollection(data, MolType=moltype, Name=name, label_to_name=label_to_name, **constructor_kw) def LoadStructure(filename, format=None, parser_kw={}): """Initialize a Structure from data contained in filename. Arguments: - filename: name of the filename to create structure from. - format: the optional file format extension. - parser_kw: optional keyword arguments for the parser.""" # currently there is no support for string-input assert filename is not None, 'No filename given.' return FromFilenameStructureParser(filename, format, **parser_kw) def LoadTable(filename=None, sep=',', reader=None, header=None, rows=None, row_order=None, digits=4, space=4, title='', missing_data='', max_width = 1e100, row_ids=False, legend='', column_templates=None, dtype=None, static_column_types=False, limit=None, **kwargs): """ Arguments: - filename: path to file containing a pickled table - sep: the delimiting character between columns - reader: a parser for reading filename. This approach assumes the first row returned by the reader will be the header row. - static_column_types: if True, and reader is None, identifies columns with a numeric data type (int, float) from the first non-header row. This assumes all subsequent entries in that column are of the same type. Default is False. - header: column headings - rows: a 2D dict, list or tuple. If a dict, it must have column headings as top level keys, and common row labels as keys in each column. - row_order: the order in which rows will be pulled from the twoDdict - digits: floating point resolution - space: number of spaces between columns or a string - title: as implied - missing_data: character assigned if a row has no entry for a column - max_width: maximum column width for printing - row_ids: if True, the 0'th column is used as row identifiers and keys for slicing. - legend: table legend - column_templates: dict of column headings: string format templates or a function that will handle the formatting. - dtype: optional numpy array typecode. - limit: exits after this many lines. Only applied for non pickled data file types. """ # if filename is not None and not (reader or static_column_types): if filename[filename.rfind(".")+1:] == 'pickle': f = file(filename, 'U') loaded_table = cPickle.load(f) f.close() return _Table(**loaded_table) sep = sep or kwargs.pop('delimiter', None) header, rows, loaded_title, legend = load_delimited(filename, delimiter = sep, limit=limit, **kwargs) title = title or loaded_title elif filename and (reader or static_column_types): f = file(filename, "r") if not reader: reader = autogen_reader(f, sep, limit=limit, with_title=kwargs.get('with_title', False)) rows = [row for row in reader(f)] f.close() header = rows.pop(0) table = _Table(header=header, rows=rows, digits=digits, row_order=row_order, title=title, dtype=dtype, column_templates=column_templates, space=space, missing_data=missing_data, max_width=max_width, row_ids=row_ids, legend=legend) return table def LoadTree(filename=None, treestring=None, tip_names=None, format=None, \ underscore_unmunge=False): """Constructor for tree. Arguments, use only one of: - filename: a file containing a newick or xml formatted tree. - treestring: a newick or xml formatted tree string. - tip_names: a list of tip names. Note: underscore_unmunging is turned off by default, although it is part of the Newick format. Set underscore_unmunge to True to replace underscores with spaces in all names read. """ if filename: assert not (treestring or tip_names) treestring = open(filename).read() if format is None and filename.endswith('.xml'): format = "xml" if treestring: assert not tip_names if format is None and treestring.startswith('<'): format = "xml" if format == "xml": parser = tree_xml_parse_string else: parser = newick_parse_string tree_builder = TreeBuilder().createEdge #FIXME: More general strategy for underscore_unmunge if parser is newick_parse_string: tree = parser(treestring, tree_builder, \ underscore_unmunge=underscore_unmunge) else: tree = parser(treestring, tree_builder) if not tree.NameLoaded: tree.Name = 'root' elif tip_names: tree_builder = TreeBuilder().createEdge tips = [tree_builder([], tip_name, {}) for tip_name in tip_names] tree = tree_builder(tips, 'root', {}) else: raise TreeError, 'filename or treestring not specified' return tree pycogent-1.9/cogent/align/000077500000000000000000000000001273014367000155675ustar00rootroot00000000000000pycogent-1.9/cogent/align/__init__.py000066400000000000000000000012171273014367000177010ustar00rootroot00000000000000#!/usr/bin/env python from align import make_dna_scoring_dict, _align_pairwise, \ classic_align_pairwise, local_pairwise, global_pairwise __all__ = ['algorithm', 'align', 'dp_calculation', 'indel_model', 'indel_positions', 'pairwise', 'partial_order_graph', 'progressive', 'pycompare', 'traceback'] __author__ = "" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Peter Maxwell", "Jeremy Widmann", "Gavin Huttley", "Rob Knight"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Gavin Huttley" __email__ = "gavin.huttley@anu.edu.au" __status__ = "Production" pycogent-1.9/cogent/align/_compare.c000066400000000000000000002642101273014367000175250ustar00rootroot00000000000000/* Generated by Cython 0.16 on Fri Sep 14 13:38:21 2012 */ #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 < 0x02040000 #error Cython requires Python 2.4+. #else #include /* For offsetof */ #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 #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_CPYTHON 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #endif #if CYTHON_COMPILING_IN_PYPY #define __Pyx_PyCFunction_Call PyObject_Call #else #define __Pyx_PyCFunction_Call PyCFunction_Call #endif #if PY_VERSION_HEX < 0x02050000 typedef int Py_ssize_t; #define PY_SSIZE_T_MAX INT_MAX #define PY_SSIZE_T_MIN INT_MIN #define PY_FORMAT_SIZE_T "" #define PyInt_FromSsize_t(z) PyInt_FromLong(z) #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) #define PyNumber_Index(o) PyNumber_Int(o) #define PyIndex_Check(o) PyNumber_Check(o) #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) #define __PYX_BUILD_PY_SSIZE_T "i" #else #define __PYX_BUILD_PY_SSIZE_T "n" #endif #if PY_VERSION_HEX < 0x02060000 #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) #define PyVarObject_HEAD_INIT(type, size) \ PyObject_HEAD_INIT(type) size, #define PyType_Modified(t) typedef struct { void *buf; PyObject *obj; Py_ssize_t len; Py_ssize_t itemsize; int readonly; int ndim; char *format; Py_ssize_t *shape; Py_ssize_t *strides; Py_ssize_t *suboffsets; void *internal; } Py_buffer; #define PyBUF_SIMPLE 0 #define PyBUF_WRITABLE 0x0001 #define PyBUF_FORMAT 0x0004 #define PyBUF_ND 0x0008 #define PyBUF_STRIDES (0x0010 | PyBUF_ND) #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); typedef void (*releasebufferproc)(PyObject *, Py_buffer *); #endif #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, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #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) #endif #if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") #endif #if PY_MAJOR_VERSION >= 3 #define Py_TPFLAGS_CHECKTYPES 0 #define Py_TPFLAGS_HAVE_INDEX 0 #endif #if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) #define Py_TPFLAGS_HAVE_NEWBUFFER 0 #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_GET_LENGTH) #define CYTHON_PEP393_ENABLED 1 #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) #else #define CYTHON_PEP393_ENABLED 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])) #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 #endif #if PY_VERSION_HEX < 0x02060000 #define PyBytesObject PyStringObject #define PyBytes_Type PyString_Type #define PyBytes_Check PyString_Check #define PyBytes_CheckExact PyString_CheckExact #define PyBytes_FromString PyString_FromString #define PyBytes_FromStringAndSize PyString_FromStringAndSize #define PyBytes_FromFormat PyString_FromFormat #define PyBytes_DecodeEscape PyString_DecodeEscape #define PyBytes_AsString PyString_AsString #define PyBytes_AsStringAndSize PyString_AsStringAndSize #define PyBytes_Size PyString_Size #define PyBytes_AS_STRING PyString_AS_STRING #define PyBytes_GET_SIZE PyString_GET_SIZE #define PyBytes_Repr PyString_Repr #define PyBytes_Concat PyString_Concat #define PyBytes_ConcatAndDel PyString_ConcatAndDel #endif #if PY_VERSION_HEX < 0x02060000 #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) #endif #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) #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 #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif #if PY_VERSION_HEX < 0x03020000 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) || (PY_VERSION_HEX >= 0x03010300) #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) #else #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) #endif #if PY_MAJOR_VERSION >= 3 #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) #endif #if PY_VERSION_HEX < 0x02050000 #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) #else #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) #endif #if PY_VERSION_HEX < 0x02050000 #define __Pyx_NAMESTR(n) ((char *)(n)) #define __Pyx_DOCSTR(n) ((char *)(n)) #else #define __Pyx_NAMESTR(n) (n) #define __Pyx_DOCSTR(n) (n) #endif #if PY_MAJOR_VERSION >= 3 #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 #ifndef __PYX_EXTERN_C #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" #else #define __PYX_EXTERN_C extern #endif #endif #if defined(WIN32) || defined(MS_WINDOWS) #define _USE_MATH_DEFINES #endif #include #define __PYX_HAVE__cogent__align___compare #define __PYX_HAVE_API__cogent__align___compare #ifdef _OPENMP #include #endif /* _OPENMP */ #ifdef PYREX_WITHOUT_ASSERTIONS #define CYTHON_WITHOUT_ASSERTIONS #endif /* inline attribute */ #ifndef CYTHON_INLINE #if 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 /* unused attribute */ #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 typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ /* Type Conversion Predeclarations */ #define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) #define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) #define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) #define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) #ifdef __GNUC__ /* Test for GCC > 2.95 */ #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else /* __GNUC__ > 2 ... */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ > 2 ... */ #else /* __GNUC__ */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ static PyObject *__pyx_m; static PyObject *__pyx_b; static PyObject *__pyx_empty_tuple; static PyObject *__pyx_empty_bytes; 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[] = { "_compare.pyx", }; /*--- Type declarations ---*/ #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); /*proto*/ #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 /* CYTHON_REFNANNY */ #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) 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); /*proto*/ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ const char* function_name); /*proto*/ #include static CYTHON_INLINE int __Pyx_mod_int(int, int); /* proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) { #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02040000 if (likely(PyList_CheckExact(L)) && likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) { Py_SIZE(L) -= 1; return PyList_GET_ITEM(L, PyList_GET_SIZE(L)); } #if PY_VERSION_HEX >= 0x02050000 else if (Py_TYPE(L) == (&PySet_Type)) { return PySet_Pop(L); } #endif #endif return PyObject_CallMethod(L, (char*)"pop", NULL); } static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); static int __Pyx_check_binary_version(void); typedef struct { int code_line; PyCodeObject* code_object; } __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); static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename); /*proto*/ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'cogent.align._compare' */ static int __pyx_f_6cogent_5align_8_compare_cmax(int, int); /*proto*/ static int __pyx_f_6cogent_5align_8_compare_cmin(int, int); /*proto*/ #define __Pyx_MODULE_NAME "cogent.align._compare" int __pyx_module_is_main_cogent__align___compare = 0; /* Implementation of 'cogent.align._compare' */ static PyObject *__pyx_pf_6cogent_5align_8_compare_segments_from_diagonal(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_seq1, char *__pyx_v_seq2, int __pyx_v_window, int __pyx_v_threshold, int __pyx_v_min_gap_length, int __pyx_v_diagonal); /* proto */ static char __pyx_k_1[] = "50x speedup for dotplots, but sequences must be strings and scoring is based on identity only\n"; static char __pyx_k_3[] = "('1', '5', '3-dev')"; static char __pyx_k_6[] = "segments_from_diagonal"; static char __pyx_k_7[] = "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/align/_compare.pyx"; static char __pyx_k_8[] = "cogent.align._compare"; static char __pyx_k__i[] = "i"; static char __pyx_k__j[] = "j"; static char __pyx_k__k[] = "k"; static char __pyx_k__i_hi[] = "i_hi"; static char __pyx_k__i_lo[] = "i_lo"; static char __pyx_k__len1[] = "len1"; static char __pyx_k__len2[] = "len2"; static char __pyx_k__seq1[] = "seq1"; static char __pyx_k__seq2[] = "seq2"; static char __pyx_k__score[] = "score"; static char __pyx_k__start[] = "start"; static char __pyx_k__result[] = "result"; static char __pyx_k__scores[] = "scores"; static char __pyx_k__window[] = "window"; static char __pyx_k____main__[] = "__main__"; static char __pyx_k____test__[] = "__test__"; static char __pyx_k__diagonal[] = "diagonal"; static char __pyx_k__was_high[] = "was_high"; static char __pyx_k__prior_end[] = "prior_end"; static char __pyx_k__threshold[] = "threshold"; static char __pyx_k__jumped_end[] = "jumped_end"; static char __pyx_k____version__[] = "__version__"; static char __pyx_k__version_info[] = "version_info"; static char __pyx_k__min_gap_length[] = "min_gap_length"; static PyObject *__pyx_kp_s_3; static PyObject *__pyx_n_s_6; static PyObject *__pyx_kp_s_7; static PyObject *__pyx_n_s_8; static PyObject *__pyx_n_s____main__; static PyObject *__pyx_n_s____test__; static PyObject *__pyx_n_s____version__; static PyObject *__pyx_n_s__diagonal; static PyObject *__pyx_n_s__i; static PyObject *__pyx_n_s__i_hi; static PyObject *__pyx_n_s__i_lo; static PyObject *__pyx_n_s__j; static PyObject *__pyx_n_s__jumped_end; static PyObject *__pyx_n_s__k; static PyObject *__pyx_n_s__len1; static PyObject *__pyx_n_s__len2; static PyObject *__pyx_n_s__min_gap_length; static PyObject *__pyx_n_s__prior_end; static PyObject *__pyx_n_s__result; static PyObject *__pyx_n_s__score; static PyObject *__pyx_n_s__scores; static PyObject *__pyx_n_s__seq1; static PyObject *__pyx_n_s__seq2; static PyObject *__pyx_n_s__start; static PyObject *__pyx_n_s__threshold; static PyObject *__pyx_n_s__version_info; static PyObject *__pyx_n_s__was_high; static PyObject *__pyx_n_s__window; static PyObject *__pyx_int_1; static PyObject *__pyx_int_3; static PyObject *__pyx_k_tuple_2; static PyObject *__pyx_k_tuple_4; static PyObject *__pyx_k_codeobj_5; /* "cogent/align/_compare.pyx":7 * __version__ = "('1', '5', '3-dev')" * * cdef int cmax(int a, int b): # <<<<<<<<<<<<<< * if a > b: * return a */ static int __pyx_f_6cogent_5align_8_compare_cmax(int __pyx_v_a, int __pyx_v_b) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("cmax", 0); /* "cogent/align/_compare.pyx":8 * * cdef int cmax(int a, int b): * if a > b: # <<<<<<<<<<<<<< * return a * else: */ __pyx_t_1 = (__pyx_v_a > __pyx_v_b); if (__pyx_t_1) { /* "cogent/align/_compare.pyx":9 * cdef int cmax(int a, int b): * if a > b: * return a # <<<<<<<<<<<<<< * else: * return b */ __pyx_r = __pyx_v_a; goto __pyx_L0; goto __pyx_L3; } /*else*/ { /* "cogent/align/_compare.pyx":11 * return a * else: * return b # <<<<<<<<<<<<<< * * cdef int cmin(int a, int b): */ __pyx_r = __pyx_v_b; goto __pyx_L0; } __pyx_L3:; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cogent/align/_compare.pyx":13 * return b * * cdef int cmin(int a, int b): # <<<<<<<<<<<<<< * if a < b: * return a */ static int __pyx_f_6cogent_5align_8_compare_cmin(int __pyx_v_a, int __pyx_v_b) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("cmin", 0); /* "cogent/align/_compare.pyx":14 * * cdef int cmin(int a, int b): * if a < b: # <<<<<<<<<<<<<< * return a * else: */ __pyx_t_1 = (__pyx_v_a < __pyx_v_b); if (__pyx_t_1) { /* "cogent/align/_compare.pyx":15 * cdef int cmin(int a, int b): * if a < b: * return a # <<<<<<<<<<<<<< * else: * return b */ __pyx_r = __pyx_v_a; goto __pyx_L0; goto __pyx_L3; } /*else*/ { /* "cogent/align/_compare.pyx":17 * return a * else: * return b # <<<<<<<<<<<<<< * * def segments_from_diagonal( */ __pyx_r = __pyx_v_b; goto __pyx_L0; } __pyx_L3:; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_6cogent_5align_8_compare_1segments_from_diagonal(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_6cogent_5align_8_compare_segments_from_diagonal[] = "List of ((x1,y1), (x2,y2)) for diagonal line segments scoring >= threshold/window"; static PyMethodDef __pyx_mdef_6cogent_5align_8_compare_1segments_from_diagonal = {__Pyx_NAMESTR("segments_from_diagonal"), (PyCFunction)__pyx_pw_6cogent_5align_8_compare_1segments_from_diagonal, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6cogent_5align_8_compare_segments_from_diagonal)}; static PyObject *__pyx_pw_6cogent_5align_8_compare_1segments_from_diagonal(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { char *__pyx_v_seq1; char *__pyx_v_seq2; int __pyx_v_window; int __pyx_v_threshold; int __pyx_v_min_gap_length; int __pyx_v_diagonal; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__seq1,&__pyx_n_s__seq2,&__pyx_n_s__window,&__pyx_n_s__threshold,&__pyx_n_s__min_gap_length,&__pyx_n_s__diagonal,0}; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("segments_from_diagonal (wrapper)", 0); __pyx_self = __pyx_self; { PyObject* values[6] = {0,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); case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__seq1); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__seq2); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("segments_from_diagonal", 1, 6, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__window); if (likely(values[2])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("segments_from_diagonal", 1, 6, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__threshold); if (likely(values[3])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("segments_from_diagonal", 1, 6, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__min_gap_length); if (likely(values[4])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("segments_from_diagonal", 1, 6, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 5: values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__diagonal); if (likely(values[5])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("segments_from_diagonal", 1, 6, 6, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "segments_from_diagonal") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { 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); 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_seq1 = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_seq1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_seq2 = PyBytes_AsString(values[1]); if (unlikely((!__pyx_v_seq2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_window = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_window == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_threshold = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_threshold == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_min_gap_length = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_min_gap_length == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_diagonal = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_diagonal == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("segments_from_diagonal", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("cogent.align._compare.segments_from_diagonal", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_6cogent_5align_8_compare_segments_from_diagonal(__pyx_self, __pyx_v_seq1, __pyx_v_seq2, __pyx_v_window, __pyx_v_threshold, __pyx_v_min_gap_length, __pyx_v_diagonal); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cogent/align/_compare.pyx":19 * return b * * def segments_from_diagonal( # <<<<<<<<<<<<<< * char seq1[], * char seq2[], */ static PyObject *__pyx_pf_6cogent_5align_8_compare_segments_from_diagonal(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_seq1, char *__pyx_v_seq2, int __pyx_v_window, int __pyx_v_threshold, int __pyx_v_min_gap_length, int __pyx_v_diagonal) { int __pyx_v_was_high; int __pyx_v_score; int __pyx_v_i; int __pyx_v_i_lo; int __pyx_v_i_hi; int __pyx_v_j; int __pyx_v_k; int __pyx_v_start; int __pyx_v_prior_end; int __pyx_v_len1; int __pyx_v_len2; int __pyx_v_scores[100]; PyObject *__pyx_v_result = NULL; CYTHON_UNUSED PyObject *__pyx_v_jumped_end = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations size_t __pyx_t_1; PyObject *__pyx_t_2 = NULL; 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)(PyObject *); int __pyx_t_9; int __pyx_t_10; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("segments_from_diagonal", 0); /* "cogent/align/_compare.pyx":31 * cdef int len1, len2 * cdef int scores[100] # yuk - use malloc? * assert window < 100 # <<<<<<<<<<<<<< * len1 = len(seq1) * len2 = len(seq2) */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!(__pyx_v_window < 100))) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif /* "cogent/align/_compare.pyx":32 * cdef int scores[100] # yuk - use malloc? * assert window < 100 * len1 = len(seq1) # <<<<<<<<<<<<<< * len2 = len(seq2) * result = [] */ __pyx_t_1 = strlen(__pyx_v_seq1); __pyx_v_len1 = __pyx_t_1; /* "cogent/align/_compare.pyx":33 * assert window < 100 * len1 = len(seq1) * len2 = len(seq2) # <<<<<<<<<<<<<< * result = [] * was_high = 0 */ __pyx_t_1 = strlen(__pyx_v_seq2); __pyx_v_len2 = __pyx_t_1; /* "cogent/align/_compare.pyx":34 * len1 = len(seq1) * len2 = len(seq2) * result = [] # <<<<<<<<<<<<<< * was_high = 0 * for i from 0 <= i < window: */ __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_v_result = __pyx_t_2; __pyx_t_2 = 0; /* "cogent/align/_compare.pyx":35 * len2 = len(seq2) * result = [] * was_high = 0 # <<<<<<<<<<<<<< * for i from 0 <= i < window: * scores[i] = 0 */ __pyx_v_was_high = 0; /* "cogent/align/_compare.pyx":36 * result = [] * was_high = 0 * for i from 0 <= i < window: # <<<<<<<<<<<<<< * scores[i] = 0 * score = 0 */ __pyx_t_3 = __pyx_v_window; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { /* "cogent/align/_compare.pyx":37 * was_high = 0 * for i from 0 <= i < window: * scores[i] = 0 # <<<<<<<<<<<<<< * score = 0 * i_lo = cmax(0, 0-diagonal) */ (__pyx_v_scores[__pyx_v_i]) = 0; } /* "cogent/align/_compare.pyx":38 * for i from 0 <= i < window: * scores[i] = 0 * score = 0 # <<<<<<<<<<<<<< * i_lo = cmax(0, 0-diagonal) * i_hi = cmin(len1, len2-diagonal) */ __pyx_v_score = 0; /* "cogent/align/_compare.pyx":39 * scores[i] = 0 * score = 0 * i_lo = cmax(0, 0-diagonal) # <<<<<<<<<<<<<< * i_hi = cmin(len1, len2-diagonal) * prior_end = 0 */ __pyx_v_i_lo = __pyx_f_6cogent_5align_8_compare_cmax(0, (0 - __pyx_v_diagonal)); /* "cogent/align/_compare.pyx":40 * score = 0 * i_lo = cmax(0, 0-diagonal) * i_hi = cmin(len1, len2-diagonal) # <<<<<<<<<<<<<< * prior_end = 0 * for i from i_lo <= i < i_hi: */ __pyx_v_i_hi = __pyx_f_6cogent_5align_8_compare_cmin(__pyx_v_len1, (__pyx_v_len2 - __pyx_v_diagonal)); /* "cogent/align/_compare.pyx":41 * i_lo = cmax(0, 0-diagonal) * i_hi = cmin(len1, len2-diagonal) * prior_end = 0 # <<<<<<<<<<<<<< * for i from i_lo <= i < i_hi: * j = i + diagonal */ __pyx_v_prior_end = 0; /* "cogent/align/_compare.pyx":42 * i_hi = cmin(len1, len2-diagonal) * prior_end = 0 * for i from i_lo <= i < i_hi: # <<<<<<<<<<<<<< * j = i + diagonal * k = i % window */ __pyx_t_3 = __pyx_v_i_hi; for (__pyx_v_i = __pyx_v_i_lo; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { /* "cogent/align/_compare.pyx":43 * prior_end = 0 * for i from i_lo <= i < i_hi: * j = i + diagonal # <<<<<<<<<<<<<< * k = i % window * score -= scores[k] */ __pyx_v_j = (__pyx_v_i + __pyx_v_diagonal); /* "cogent/align/_compare.pyx":44 * for i from i_lo <= i < i_hi: * j = i + diagonal * k = i % window # <<<<<<<<<<<<<< * score -= scores[k] * scores[k] = (seq1[i] == seq2[j]) */ if (unlikely(__pyx_v_window == 0)) { PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_v_k = __Pyx_mod_int(__pyx_v_i, __pyx_v_window); /* "cogent/align/_compare.pyx":45 * j = i + diagonal * k = i % window * score -= scores[k] # <<<<<<<<<<<<<< * scores[k] = (seq1[i] == seq2[j]) * score += scores[k] */ __pyx_v_score = (__pyx_v_score - (__pyx_v_scores[__pyx_v_k])); /* "cogent/align/_compare.pyx":46 * k = i % window * score -= scores[k] * scores[k] = (seq1[i] == seq2[j]) # <<<<<<<<<<<<<< * score += scores[k] * if score >= threshold: */ (__pyx_v_scores[__pyx_v_k]) = ((__pyx_v_seq1[__pyx_v_i]) == (__pyx_v_seq2[__pyx_v_j])); /* "cogent/align/_compare.pyx":47 * score -= scores[k] * scores[k] = (seq1[i] == seq2[j]) * score += scores[k] # <<<<<<<<<<<<<< * if score >= threshold: * if not was_high: */ __pyx_v_score = (__pyx_v_score + (__pyx_v_scores[__pyx_v_k])); /* "cogent/align/_compare.pyx":48 * scores[k] = (seq1[i] == seq2[j]) * score += scores[k] * if score >= threshold: # <<<<<<<<<<<<<< * if not was_high: * start = cmax(i_lo, i - window) */ __pyx_t_4 = (__pyx_v_score >= __pyx_v_threshold); if (__pyx_t_4) { /* "cogent/align/_compare.pyx":49 * score += scores[k] * if score >= threshold: * if not was_high: # <<<<<<<<<<<<<< * start = cmax(i_lo, i - window) * if min_gap_length and prior_end: */ __pyx_t_4 = (!__pyx_v_was_high); if (__pyx_t_4) { /* "cogent/align/_compare.pyx":50 * if score >= threshold: * if not was_high: * start = cmax(i_lo, i - window) # <<<<<<<<<<<<<< * if min_gap_length and prior_end: * if start < prior_end + min_gap_length: */ __pyx_v_start = __pyx_f_6cogent_5align_8_compare_cmax(__pyx_v_i_lo, (__pyx_v_i - __pyx_v_window)); /* "cogent/align/_compare.pyx":51 * if not was_high: * start = cmax(i_lo, i - window) * if min_gap_length and prior_end: # <<<<<<<<<<<<<< * if start < prior_end + min_gap_length: * (start, jumped_end) = result.pop() */ if (__pyx_v_min_gap_length) { __pyx_t_4 = __pyx_v_prior_end; } else { __pyx_t_4 = __pyx_v_min_gap_length; } if (__pyx_t_4) { /* "cogent/align/_compare.pyx":52 * start = cmax(i_lo, i - window) * if min_gap_length and prior_end: * if start < prior_end + min_gap_length: # <<<<<<<<<<<<<< * (start, jumped_end) = result.pop() * was_high = 1 */ __pyx_t_4 = (__pyx_v_start < (__pyx_v_prior_end + __pyx_v_min_gap_length)); if (__pyx_t_4) { /* "cogent/align/_compare.pyx":53 * if min_gap_length and prior_end: * if start < prior_end + min_gap_length: * (start, jumped_end) = result.pop() # <<<<<<<<<<<<<< * was_high = 1 * else: */ __pyx_t_2 = __Pyx_PyObject_Pop(((PyObject *)__pyx_v_result)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { PyObject* sequence = __pyx_t_2; if (likely(PyTuple_CheckExact(sequence))) { if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) { if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2); else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); } else { if (unlikely(PyList_GET_SIZE(sequence) != 2)) { if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2); else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_5 = PyList_GET_ITEM(sequence, 0); __pyx_t_6 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx_t_6); __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_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __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_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L11_unpacking_failed; __Pyx_GOTREF(__pyx_t_5); index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L11_unpacking_failed; __Pyx_GOTREF(__pyx_t_6); if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __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; if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L12_unpacking_done:; } __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_start = __pyx_t_9; __Pyx_XDECREF(__pyx_v_jumped_end); __pyx_v_jumped_end = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L10; } __pyx_L10:; goto __pyx_L9; } __pyx_L9:; /* "cogent/align/_compare.pyx":54 * if start < prior_end + min_gap_length: * (start, jumped_end) = result.pop() * was_high = 1 # <<<<<<<<<<<<<< * else: * if was_high: */ __pyx_v_was_high = 1; goto __pyx_L8; } __pyx_L8:; goto __pyx_L7; } /*else*/ { /* "cogent/align/_compare.pyx":56 * was_high = 1 * else: * if was_high: # <<<<<<<<<<<<<< * result.append((start, i)) * prior_end = i */ if (__pyx_v_was_high) { /* "cogent/align/_compare.pyx":57 * else: * if was_high: * result.append((start, i)) # <<<<<<<<<<<<<< * prior_end = i * was_high = 0 */ __pyx_t_2 = PyInt_FromLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_2 = 0; __pyx_t_6 = 0; __pyx_t_10 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_5)); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; /* "cogent/align/_compare.pyx":58 * if was_high: * result.append((start, i)) * prior_end = i # <<<<<<<<<<<<<< * was_high = 0 * if was_high: */ __pyx_v_prior_end = __pyx_v_i; /* "cogent/align/_compare.pyx":59 * result.append((start, i)) * prior_end = i * was_high = 0 # <<<<<<<<<<<<<< * if was_high: * result.append((start, i_hi)) */ __pyx_v_was_high = 0; goto __pyx_L13; } __pyx_L13:; } __pyx_L7:; } /* "cogent/align/_compare.pyx":60 * prior_end = i * was_high = 0 * if was_high: # <<<<<<<<<<<<<< * result.append((start, i_hi)) * return result */ if (__pyx_v_was_high) { /* "cogent/align/_compare.pyx":61 * was_high = 0 * if was_high: * result.append((start, i_hi)) # <<<<<<<<<<<<<< * return result */ __pyx_t_5 = PyInt_FromLong(__pyx_v_start); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = PyInt_FromLong(__pyx_v_i_hi); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_10 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; goto __pyx_L14; } __pyx_L14:; /* "cogent/align/_compare.pyx":62 * if was_high: * result.append((start, i_hi)) * return result # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0; __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_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("cogent.align._compare.segments_from_diagonal", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_result); __Pyx_XDECREF(__pyx_v_jumped_end); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef __pyx_moduledef = { PyModuleDef_HEAD_INIT, __Pyx_NAMESTR("_compare"), __Pyx_DOCSTR(__pyx_k_1), /* m_doc */ -1, /* m_size */ __pyx_methods /* m_methods */, NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, {&__pyx_n_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 1}, {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0}, {&__pyx_n_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 1}, {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, {&__pyx_n_s____version__, __pyx_k____version__, sizeof(__pyx_k____version__), 0, 0, 1, 1}, {&__pyx_n_s__diagonal, __pyx_k__diagonal, sizeof(__pyx_k__diagonal), 0, 0, 1, 1}, {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1}, {&__pyx_n_s__i_hi, __pyx_k__i_hi, sizeof(__pyx_k__i_hi), 0, 0, 1, 1}, {&__pyx_n_s__i_lo, __pyx_k__i_lo, sizeof(__pyx_k__i_lo), 0, 0, 1, 1}, {&__pyx_n_s__j, __pyx_k__j, sizeof(__pyx_k__j), 0, 0, 1, 1}, {&__pyx_n_s__jumped_end, __pyx_k__jumped_end, sizeof(__pyx_k__jumped_end), 0, 0, 1, 1}, {&__pyx_n_s__k, __pyx_k__k, sizeof(__pyx_k__k), 0, 0, 1, 1}, {&__pyx_n_s__len1, __pyx_k__len1, sizeof(__pyx_k__len1), 0, 0, 1, 1}, {&__pyx_n_s__len2, __pyx_k__len2, sizeof(__pyx_k__len2), 0, 0, 1, 1}, {&__pyx_n_s__min_gap_length, __pyx_k__min_gap_length, sizeof(__pyx_k__min_gap_length), 0, 0, 1, 1}, {&__pyx_n_s__prior_end, __pyx_k__prior_end, sizeof(__pyx_k__prior_end), 0, 0, 1, 1}, {&__pyx_n_s__result, __pyx_k__result, sizeof(__pyx_k__result), 0, 0, 1, 1}, {&__pyx_n_s__score, __pyx_k__score, sizeof(__pyx_k__score), 0, 0, 1, 1}, {&__pyx_n_s__scores, __pyx_k__scores, sizeof(__pyx_k__scores), 0, 0, 1, 1}, {&__pyx_n_s__seq1, __pyx_k__seq1, sizeof(__pyx_k__seq1), 0, 0, 1, 1}, {&__pyx_n_s__seq2, __pyx_k__seq2, sizeof(__pyx_k__seq2), 0, 0, 1, 1}, {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1}, {&__pyx_n_s__threshold, __pyx_k__threshold, sizeof(__pyx_k__threshold), 0, 0, 1, 1}, {&__pyx_n_s__version_info, __pyx_k__version_info, sizeof(__pyx_k__version_info), 0, 0, 1, 1}, {&__pyx_n_s__was_high, __pyx_k__was_high, sizeof(__pyx_k__was_high), 0, 0, 1, 1}, {&__pyx_n_s__window, __pyx_k__window, sizeof(__pyx_k__window), 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); /* "cogent/align/_compare.pyx":4 * """ * * version_info = (1, 3) # <<<<<<<<<<<<<< * __version__ = "('1', '5', '3-dev')" * */ __pyx_k_tuple_2 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_2); __Pyx_INCREF(__pyx_int_1); PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, __pyx_int_1); __Pyx_GIVEREF(__pyx_int_1); __Pyx_INCREF(__pyx_int_3); PyTuple_SET_ITEM(__pyx_k_tuple_2, 1, __pyx_int_3); __Pyx_GIVEREF(__pyx_int_3); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2)); /* "cogent/align/_compare.pyx":19 * return b * * def segments_from_diagonal( # <<<<<<<<<<<<<< * char seq1[], * char seq2[], */ __pyx_k_tuple_4 = PyTuple_New(20); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_4); __Pyx_INCREF(((PyObject *)__pyx_n_s__seq1)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_n_s__seq1)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__seq1)); __Pyx_INCREF(((PyObject *)__pyx_n_s__seq2)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 1, ((PyObject *)__pyx_n_s__seq2)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__seq2)); __Pyx_INCREF(((PyObject *)__pyx_n_s__window)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 2, ((PyObject *)__pyx_n_s__window)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__window)); __Pyx_INCREF(((PyObject *)__pyx_n_s__threshold)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 3, ((PyObject *)__pyx_n_s__threshold)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__threshold)); __Pyx_INCREF(((PyObject *)__pyx_n_s__min_gap_length)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 4, ((PyObject *)__pyx_n_s__min_gap_length)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__min_gap_length)); __Pyx_INCREF(((PyObject *)__pyx_n_s__diagonal)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 5, ((PyObject *)__pyx_n_s__diagonal)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__diagonal)); __Pyx_INCREF(((PyObject *)__pyx_n_s__was_high)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 6, ((PyObject *)__pyx_n_s__was_high)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__was_high)); __Pyx_INCREF(((PyObject *)__pyx_n_s__score)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 7, ((PyObject *)__pyx_n_s__score)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__score)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 8, ((PyObject *)__pyx_n_s__i)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i_lo)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 9, ((PyObject *)__pyx_n_s__i_lo)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_lo)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i_hi)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 10, ((PyObject *)__pyx_n_s__i_hi)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_hi)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 11, ((PyObject *)__pyx_n_s__j)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j)); __Pyx_INCREF(((PyObject *)__pyx_n_s__k)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 12, ((PyObject *)__pyx_n_s__k)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__k)); __Pyx_INCREF(((PyObject *)__pyx_n_s__start)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 13, ((PyObject *)__pyx_n_s__start)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start)); __Pyx_INCREF(((PyObject *)__pyx_n_s__prior_end)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 14, ((PyObject *)__pyx_n_s__prior_end)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__prior_end)); __Pyx_INCREF(((PyObject *)__pyx_n_s__len1)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 15, ((PyObject *)__pyx_n_s__len1)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__len1)); __Pyx_INCREF(((PyObject *)__pyx_n_s__len2)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 16, ((PyObject *)__pyx_n_s__len2)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__len2)); __Pyx_INCREF(((PyObject *)__pyx_n_s__scores)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 17, ((PyObject *)__pyx_n_s__scores)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__scores)); __Pyx_INCREF(((PyObject *)__pyx_n_s__result)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 18, ((PyObject *)__pyx_n_s__result)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__result)); __Pyx_INCREF(((PyObject *)__pyx_n_s__jumped_end)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 19, ((PyObject *)__pyx_n_s__jumped_end)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__jumped_end)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4)); __pyx_k_codeobj_5 = (PyObject*)__Pyx_PyCode_New(6, 0, 20, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_4, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_7, __pyx_n_s_6, 19, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; return 0; __pyx_L1_error:; return -1; } #if PY_MAJOR_VERSION < 3 PyMODINIT_FUNC init_compare(void); /*proto*/ PyMODINIT_FUNC init_compare(void) #else PyMODINIT_FUNC PyInit__compare(void); /*proto*/ PyMODINIT_FUNC PyInit__compare(void) #endif { PyObject *__pyx_t_1 = NULL; __Pyx_RefNannyDeclarations #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("PyMODINIT_FUNC PyInit__compare(void)", 0); if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #ifdef __Pyx_CyFunction_USED if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif #ifdef __Pyx_FusedFunction_USED if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif #ifdef __Pyx_Generator_USED if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __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 PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_compare"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_1), 0, PYTHON_API_VERSION); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #if PY_MAJOR_VERSION < 3 Py_INCREF(__pyx_m); #endif __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; /*--- Initialize various global constants etc. ---*/ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_module_is_main_cogent__align___compare) { if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; } /*--- Builtin init code ---*/ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Constants init code ---*/ if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Global init code ---*/ /*--- Variable export code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ /* "cogent/align/_compare.pyx":4 * """ * * version_info = (1, 3) # <<<<<<<<<<<<<< * __version__ = "('1', '5', '3-dev')" * */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__version_info, ((PyObject *)__pyx_k_tuple_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_compare.pyx":5 * * version_info = (1, 3) * __version__ = "('1', '5', '3-dev')" # <<<<<<<<<<<<<< * * cdef int cmax(int a, int b): */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____version__, ((PyObject *)__pyx_kp_s_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_compare.pyx":19 * return b * * def segments_from_diagonal( # <<<<<<<<<<<<<< * char seq1[], * char seq2[], */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6cogent_5align_8_compare_1segments_from_diagonal, NULL, __pyx_n_s_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s_6, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "cogent/align/_compare.pyx":1 * """50x speedup for dotplots, but sequences must be strings and scoring is based on identity only # <<<<<<<<<<<<<< * """ * */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); if (__pyx_m) { __Pyx_AddTraceback("init cogent.align._compare", __pyx_clineno, __pyx_lineno, __pyx_filename); Py_DECREF(__pyx_m); __pyx_m = 0; } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init cogent.align._compare"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); #if PY_MAJOR_VERSION < 3 return; #else return __pyx_m; #endif } /* Runtime support code */ #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 /* CYTHON_REFNANNY */ 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, "%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } 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_AS_STRING(kw_name)); #endif } 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; } else { #if PY_MAJOR_VERSION < 3 if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { #else if (unlikely(!PyUnicode_Check(key))) { #endif goto invalid_keyword_type; } else { for (name = first_kw_arg; *name; name++) { #if PY_MAJOR_VERSION >= 3 if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && PyUnicode_Compare(**name, key) == 0) break; #else if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && _PyString_Eq(**name, key)) break; #endif } if (*name) { values[name-argnames] = value; } else { for (name=argnames; name != first_kw_arg; name++) { if (**name == key) goto arg_passed_twice; #if PY_MAJOR_VERSION >= 3 if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; #else if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && _PyString_Eq(**name, key)) goto arg_passed_twice; #endif } if (kwds2) { if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; } else { goto invalid_keyword; } } } } } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, **name); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 "%s() got an unexpected keyword argument '%s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", function_name, key); #endif bad: return -1; } static CYTHON_INLINE int __Pyx_mod_int(int a, int b) { int r = a % b; r += ((r != 0) & ((r ^ b) < 0)) * b; return r; } static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, "need more than %"PY_FORMAT_SIZE_T"d value%s to unpack", index, (index == 1) ? "" : "s"); } static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { PyErr_Format(PyExc_ValueError, "too many values to unpack (expected %"PY_FORMAT_SIZE_T"d)", expected); } static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { if (unlikely(retval)) { Py_DECREF(retval); __Pyx_RaiseTooManyValuesError(expected); return -1; } else if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { PyErr_Clear(); return 0; } else { return -1; } } return 0; } static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { const unsigned char neg_one = (unsigned char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned char" : "value too large to convert to unsigned char"); } return (unsigned char)-1; } return (unsigned char)val; } return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { const unsigned short neg_one = (unsigned short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned short" : "value too large to convert to unsigned short"); } return (unsigned short)-1; } return (unsigned short)val; } return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { const unsigned int neg_one = (unsigned int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned int" : "value too large to convert to unsigned int"); } return (unsigned int)-1; } return (unsigned int)val; } return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { const char neg_one = (char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to char" : "value too large to convert to char"); } return (char)-1; } return (char)val; } return (char)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { const short neg_one = (short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to short" : "value too large to convert to short"); } return (short)-1; } return (short)val; } return (short)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { const int neg_one = (int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to int" : "value too large to convert to int"); } return (int)-1; } return (int)val; } return (int)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { const signed char neg_one = (signed char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed char" : "value too large to convert to signed char"); } return (signed char)-1; } return (signed char)val; } return (signed char)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { const signed short neg_one = (signed short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed short" : "value too large to convert to signed short"); } return (signed short)-1; } return (signed short)val; } return (signed short)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { const signed int neg_one = (signed int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed int" : "value too large to convert to signed int"); } return (signed int)-1; } return (signed int)val; } return (signed int)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { const int neg_one = (int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to int" : "value too large to convert to int"); } return (int)-1; } return (int)val; } return (int)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { const unsigned long neg_one = (unsigned long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned long"); return (unsigned long)-1; } return (unsigned long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned long"); return (unsigned long)-1; } return (unsigned long)PyLong_AsUnsignedLong(x); } else { return (unsigned long)PyLong_AsLong(x); } } else { unsigned long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (unsigned long)-1; val = __Pyx_PyInt_AsUnsignedLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG)-1; } return (unsigned PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG)-1; } return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); } else { return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); } } else { unsigned PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (unsigned PY_LONG_LONG)-1; val = __Pyx_PyInt_AsUnsignedLongLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { const long neg_one = (long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long)-1; } return (long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long)-1; } return (long)PyLong_AsUnsignedLong(x); } else { return (long)PyLong_AsLong(x); } } else { long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (long)-1; val = __Pyx_PyInt_AsLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to PY_LONG_LONG"); return (PY_LONG_LONG)-1; } return (PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to PY_LONG_LONG"); return (PY_LONG_LONG)-1; } return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); } else { return (PY_LONG_LONG)PyLong_AsLongLong(x); } } else { PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (PY_LONG_LONG)-1; val = __Pyx_PyInt_AsLongLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { const signed long neg_one = (signed long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed long"); return (signed long)-1; } return (signed long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed long"); return (signed long)-1; } return (signed long)PyLong_AsUnsignedLong(x); } else { return (signed long)PyLong_AsLong(x); } } else { signed long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (signed long)-1; val = __Pyx_PyInt_AsSignedLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed PY_LONG_LONG"); return (signed PY_LONG_LONG)-1; } return (signed PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed PY_LONG_LONG"); return (signed PY_LONG_LONG)-1; } return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); } else { return (signed PY_LONG_LONG)PyLong_AsLongLong(x); } } else { signed PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (signed PY_LONG_LONG)-1; val = __Pyx_PyInt_AsSignedLongLong(tmp); Py_DECREF(tmp); return val; } } 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); #if PY_VERSION_HEX < 0x02050000 return PyErr_Warn(NULL, message); #else return PyErr_WarnEx(NULL, message, 1); #endif } return 0; } 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) / 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, 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); } #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, /*int argcount,*/ 0, /*int kwonlyargcount,*/ 0, /*int nlocals,*/ 0, /*int stacksize,*/ 0, /*int flags,*/ __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, /*int firstlineno,*/ __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; PyObject *py_globals = 0; PyFrameObject *py_frame = 0; 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_globals = PyModule_GetDict(__pyx_m); if (!py_globals) goto bad; py_frame = PyFrame_New( PyThreadState_GET(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ py_globals, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; py_frame->f_lineno = py_line; PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_code); Py_XDECREF(py_frame); } 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 /* Python 3+ has unicode identifiers */ 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; ++t; } return 0; } /* Type Conversion Functions */ 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 CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { PyNumberMethods *m; const char *name = NULL; PyObject *res = NULL; #if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(x) || PyLong_Check(x)) #else if (PyLong_Check(x)) #endif return Py_INCREF(x), x; m = Py_TYPE(x)->tp_as_number; #if PY_VERSION_HEX < 0x03000000 if (m && m->nb_int) { name = "int"; res = PyNumber_Int(x); } else if (m && m->nb_long) { name = "long"; res = PyNumber_Long(x); } #else if (m && m->nb_int) { name = "int"; res = PyNumber_Long(x); } #endif if (res) { #if PY_VERSION_HEX < 0x03000000 if (!PyInt_Check(res) && !PyLong_Check(res)) { #else if (!PyLong_Check(res)) { #endif PyErr_Format(PyExc_TypeError, "__%s__ returned non-%s (type %.200s)", name, name, Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } } 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 = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); return ival; } static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { #if PY_VERSION_HEX < 0x02050000 if (ival <= LONG_MAX) return PyInt_FromLong((long)ival); else { unsigned char *bytes = (unsigned char *) &ival; int one = 1; int little = (int)*(unsigned char*)&one; return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); } #else return PyInt_FromSize_t(ival); #endif } static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { return (size_t)-1; } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { PyErr_SetString(PyExc_OverflowError, "value too large to convert to size_t"); return (size_t)-1; } return (size_t)val; } #endif /* Py_PYTHON_H */ pycogent-1.9/cogent/align/_compare.pyx000066400000000000000000000032451273014367000201220ustar00rootroot00000000000000"""50x speedup for dotplots, but sequences must be strings and scoring is based on identity only """ version_info = (1, 3) __version__ = "('1', '9')" cdef int cmax(int a, int b): if a > b: return a else: return b cdef int cmin(int a, int b): if a < b: return a else: return b def segments_from_diagonal( char seq1[], char seq2[], int window, int threshold, int min_gap_length, int diagonal): """List of ((x1,y1), (x2,y2)) for diagonal line segments scoring >= threshold/window""" cdef int was_high, score, i, i_lo, i_hi, j, k, start, prior_end cdef int len1, len2 cdef int scores[100] # yuk - use malloc? assert window < 100 len1 = len(seq1) len2 = len(seq2) result = [] was_high = 0 for i from 0 <= i < window: scores[i] = 0 score = 0 i_lo = cmax(0, 0-diagonal) i_hi = cmin(len1, len2-diagonal) prior_end = 0 for i from i_lo <= i < i_hi: j = i + diagonal k = i % window score -= scores[k] scores[k] = (seq1[i] == seq2[j]) score += scores[k] if score >= threshold: if not was_high: start = cmax(i_lo, i - window) if min_gap_length and prior_end: if start < prior_end + min_gap_length: (start, jumped_end) = result.pop() was_high = 1 else: if was_high: result.append((start, i)) prior_end = i was_high = 0 if was_high: result.append((start, i_hi)) return result pycogent-1.9/cogent/align/_pairwise_pogs.c000066400000000000000000030625221273014367000207570ustar00rootroot00000000000000/* Generated by Cython 0.17.1 on Sat Nov 3 13:26:59 2012 */ #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 < 0x02040000 #error Cython requires Python 2.4+. #else #include /* For offsetof */ #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 #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_CPYTHON 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #endif #if PY_VERSION_HEX < 0x02050000 typedef int Py_ssize_t; #define PY_SSIZE_T_MAX INT_MAX #define PY_SSIZE_T_MIN INT_MIN #define PY_FORMAT_SIZE_T "" #define CYTHON_FORMAT_SSIZE_T "" #define PyInt_FromSsize_t(z) PyInt_FromLong(z) #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ (PyErr_Format(PyExc_TypeError, \ "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ (PyObject*)0)) #define PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && !PyComplex_Check(o)) #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) #define __PYX_BUILD_PY_SSIZE_T "i" #else #define __PYX_BUILD_PY_SSIZE_T "n" #define CYTHON_FORMAT_SSIZE_T "z" #endif #if PY_VERSION_HEX < 0x02060000 #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) #define PyVarObject_HEAD_INIT(type, size) \ PyObject_HEAD_INIT(type) size, #define PyType_Modified(t) typedef struct { void *buf; PyObject *obj; Py_ssize_t len; Py_ssize_t itemsize; int readonly; int ndim; char *format; Py_ssize_t *shape; Py_ssize_t *strides; Py_ssize_t *suboffsets; void *internal; } Py_buffer; #define PyBUF_SIMPLE 0 #define PyBUF_WRITABLE 0x0001 #define PyBUF_FORMAT 0x0004 #define PyBUF_ND 0x0008 #define PyBUF_STRIDES (0x0010 | PyBUF_ND) #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); typedef void (*releasebufferproc)(PyObject *, Py_buffer *); #endif #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, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #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) #endif #if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") #endif #if PY_MAJOR_VERSION >= 3 #define Py_TPFLAGS_CHECKTYPES 0 #define Py_TPFLAGS_HAVE_INDEX 0 #endif #if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) #define Py_TPFLAGS_HAVE_NEWBUFFER 0 #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_READ(k, d, i) PyUnicode_READ(k, d, i) #else #define CYTHON_PEP393_ENABLED 0 #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_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i])) #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 #endif #if PY_VERSION_HEX < 0x02060000 #define PyBytesObject PyStringObject #define PyBytes_Type PyString_Type #define PyBytes_Check PyString_Check #define PyBytes_CheckExact PyString_CheckExact #define PyBytes_FromString PyString_FromString #define PyBytes_FromStringAndSize PyString_FromStringAndSize #define PyBytes_FromFormat PyString_FromFormat #define PyBytes_DecodeEscape PyString_DecodeEscape #define PyBytes_AsString PyString_AsString #define PyBytes_AsStringAndSize PyString_AsStringAndSize #define PyBytes_Size PyString_Size #define PyBytes_AS_STRING PyString_AS_STRING #define PyBytes_GET_SIZE PyString_GET_SIZE #define PyBytes_Repr PyString_Repr #define PyBytes_Concat PyString_Concat #define PyBytes_ConcatAndDel PyString_ConcatAndDel #endif #if PY_VERSION_HEX < 0x02060000 #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) #endif #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) #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 #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif #if PY_VERSION_HEX < 0x03020000 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) || (PY_VERSION_HEX >= 0x03010300) #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) #else #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) #endif #if PY_MAJOR_VERSION >= 3 #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) #endif #if PY_VERSION_HEX < 0x02050000 #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) #else #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) #endif #if PY_VERSION_HEX < 0x02050000 #define __Pyx_NAMESTR(n) ((char *)(n)) #define __Pyx_DOCSTR(n) ((char *)(n)) #else #define __Pyx_NAMESTR(n) (n) #define __Pyx_DOCSTR(n) (n) #endif #if PY_MAJOR_VERSION >= 3 #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 #ifndef __PYX_EXTERN_C #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" #else #define __PYX_EXTERN_C extern #endif #endif #if defined(WIN32) || defined(MS_WINDOWS) #define _USE_MATH_DEFINES #endif #include #define __PYX_HAVE__cogent__align___pairwise_pogs #define __PYX_HAVE_API__cogent__align___pairwise_pogs #include "limits.h" #include "math.h" #include "pythread.h" #include "string.h" #include "stdlib.h" #include "stdio.h" #include "pystate.h" #ifdef _OPENMP #include #endif /* _OPENMP */ #ifdef PYREX_WITHOUT_ASSERTIONS #define CYTHON_WITHOUT_ASSERTIONS #endif /* inline attribute */ #ifndef CYTHON_INLINE #if 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 /* unused attribute */ #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 typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ /* Type Conversion Predeclarations */ #define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) #define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) #define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) #define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); #if CYTHON_COMPILING_IN_CPYTHON #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)) #ifdef __GNUC__ /* Test for GCC > 2.95 */ #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else /* __GNUC__ > 2 ... */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ > 2 ... */ #else /* __GNUC__ */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ static PyObject *__pyx_m; static PyObject *__pyx_b; static PyObject *__pyx_empty_tuple; static PyObject *__pyx_empty_bytes; 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[] = { "numerical_pyrex.pyx", "_pairwise_pogs.pyx", "stringsource", }; struct __pyx_memoryview_obj; typedef struct { struct __pyx_memoryview_obj *memview; char *data; Py_ssize_t shape[8]; Py_ssize_t strides[8]; Py_ssize_t suboffsets[8]; } __Pyx_memviewslice; #define IS_UNSIGNED(type) (((type) -1) > 0) struct __Pyx_StructField_; #define __PYX_BUF_FLAGS_PACKED_STRUCT (1 << 0) typedef struct { const char* name; /* for error messages only */ struct __Pyx_StructField_* fields; size_t size; /* sizeof(type) */ size_t arraysize[8]; /* length of array in each dimension */ int ndim; char typegroup; /* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject, c_H_ar */ char is_unsigned; int flags; } __Pyx_TypeInfo; typedef struct __Pyx_StructField_ { __Pyx_TypeInfo* type; const char* name; size_t offset; } __Pyx_StructField; typedef struct { __Pyx_StructField* field; size_t parent_offset; } __Pyx_BufFmt_StackElem; typedef struct { __Pyx_StructField root; __Pyx_BufFmt_StackElem* head; size_t fmt_offset; size_t new_count, enc_count; size_t struct_alignment; int is_complex; char enc_type; char new_packmode; char enc_packmode; char is_valid_array; } __Pyx_BufFmt_Context; #include #ifndef CYTHON_ATOMICS #define CYTHON_ATOMICS 1 #endif #define __pyx_atomic_int_type int /* todo: Portland pgcc, maybe OS X's OSAtomicIncrement32, libatomic + autotools-like distutils support? Such a pain... */ #if CYTHON_ATOMICS && __GNUC__ >= 4 && (__GNUC_MINOR__ > 1 || \ (__GNUC_MINOR__ == 1 && __GNUC_PATHLEVEL >= 2)) #define __pyx_atomic_incr_aligned(value, lock) __sync_fetch_and_add(value, 1) #define __pyx_atomic_decr_aligned(value, lock) __sync_fetch_and_sub(value, 1) #ifdef __PYX_DEBUG_ATOMICS #warning "Using GNU atomics" #endif #elif CYTHON_ATOMICS && MSC_VER #include #define __pyx_atomic_int_type LONG #define __pyx_atomic_incr_aligned(value, lock) InterlockedIncrement(value) #define __pyx_atomic_decr_aligned(value, lock) InterlockedDecrement(value) #ifdef __PYX_DEBUG_ATOMICS #warning "Using MSVC atomics" #endif #elif CYTHON_ATOMICS && (defined(__ICC) || defined(__INTEL_COMPILER)) && 0 #define __pyx_atomic_incr_aligned(value, lock) _InterlockedIncrement(value) #define __pyx_atomic_decr_aligned(value, lock) _InterlockedDecrement(value) #ifdef __PYX_DEBUG_ATOMICS #warning "Using Intel atomics" #endif #else #undef CYTHON_ATOMICS #define CYTHON_ATOMICS 0 #ifdef __PYX_DEBUG_ATOMICS #warning "Not using atomics" #endif #endif typedef volatile __pyx_atomic_int_type __pyx_atomic_int; #if CYTHON_ATOMICS #define __pyx_add_acquisition_count(memview) \ __pyx_atomic_incr_aligned(__pyx_get_slice_count_pointer(memview), memview->lock) #define __pyx_sub_acquisition_count(memview) \ __pyx_atomic_decr_aligned(__pyx_get_slice_count_pointer(memview), memview->lock) #else #define __pyx_add_acquisition_count(memview) \ __pyx_add_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock) #define __pyx_sub_acquisition_count(memview) \ __pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock) #endif /*--- Type declarations ---*/ struct __pyx_memoryview_obj; struct __pyx_array_obj; struct __pyx_MemviewEnum_obj; struct __pyx_memoryviewslice_obj; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":31 * int * * ctypedef double[::1] Double1D # <<<<<<<<<<<<<< * ctypedef double[:, ::1] Double2D * ctypedef double[:, :, ::1] Double3D */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_pogs_Double1D; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":32 * * ctypedef double[::1] Double1D * ctypedef double[:, ::1] Double2D # <<<<<<<<<<<<<< * ctypedef double[:, :, ::1] Double3D * ctypedef long[::1] Long1D */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_pogs_Double2D; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":33 * ctypedef double[::1] Double1D * ctypedef double[:, ::1] Double2D * ctypedef double[:, :, ::1] Double3D # <<<<<<<<<<<<<< * ctypedef long[::1] Long1D * ctypedef long[:, ::1] Long2D */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_pogs_Double3D; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":34 * ctypedef double[:, ::1] Double2D * ctypedef double[:, :, ::1] Double3D * ctypedef long[::1] Long1D # <<<<<<<<<<<<<< * ctypedef long[:, ::1] Long2D * ctypedef long[:, :, ::1] Long3D */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":35 * ctypedef double[:, :, ::1] Double3D * ctypedef long[::1] Long1D * ctypedef long[:, ::1] Long2D # <<<<<<<<<<<<<< * ctypedef long[:, :, ::1] Long3D * */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_pogs_Long2D; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":36 * ctypedef long[::1] Long1D * ctypedef long[:, ::1] Long2D * ctypedef long[:, :, ::1] Long3D # <<<<<<<<<<<<<< * * */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_pogs_Long3D; /* "cogent/align/_pairwise_pogs.pyx":31 * return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) * * ctypedef unsigned char [:,:,::1] UChar3D # <<<<<<<<<<<<<< * * def calc_rows(Long1D plan, Long1D seq1_index, Long1D seq2_index, */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_pogs_UChar3D; /* "View.MemoryView":308 * * @cname('__pyx_memoryview') * cdef class memoryview(object): # <<<<<<<<<<<<<< * * cdef object obj */ struct __pyx_memoryview_obj { PyObject_HEAD struct __pyx_vtabstruct_memoryview *__pyx_vtab; PyObject *obj; PyObject *_size; PyObject *_array_interface; PyThread_type_lock lock; __pyx_atomic_int acquisition_count[2]; __pyx_atomic_int *acquisition_count_aligned_p; Py_buffer view; int flags; int dtype_is_object; __Pyx_TypeInfo *typeinfo; }; /* "View.MemoryView":96 * * @cname("__pyx_array") * cdef class array: # <<<<<<<<<<<<<< * * cdef: */ struct __pyx_array_obj { PyObject_HEAD char *data; Py_ssize_t len; char *format; int ndim; Py_ssize_t *_shape; Py_ssize_t *_strides; Py_ssize_t itemsize; PyObject *mode; PyObject *_format; void (*callback_free_data)(void *); int free_data; int dtype_is_object; }; /* "View.MemoryView":275 * * @cname('__pyx_MemviewEnum') * cdef class Enum(object): # <<<<<<<<<<<<<< * cdef object name * def __init__(self, name): */ struct __pyx_MemviewEnum_obj { PyObject_HEAD PyObject *name; }; /* "View.MemoryView":927 * * @cname('__pyx_memoryviewslice') * cdef class _memoryviewslice(memoryview): # <<<<<<<<<<<<<< * "Internal class for passing memoryview slices to Python" * */ struct __pyx_memoryviewslice_obj { struct __pyx_memoryview_obj __pyx_base; __Pyx_memviewslice from_slice; PyObject *from_object; PyObject *(*to_object_func)(char *); int (*to_dtype_func)(char *, PyObject *); }; /* "View.MemoryView":308 * * @cname('__pyx_memoryview') * cdef class memoryview(object): # <<<<<<<<<<<<<< * * cdef object obj */ struct __pyx_vtabstruct_memoryview { char *(*get_item_pointer)(struct __pyx_memoryview_obj *, PyObject *); PyObject *(*is_slice)(struct __pyx_memoryview_obj *, PyObject *); PyObject *(*setitem_slice_assignment)(struct __pyx_memoryview_obj *, PyObject *, PyObject *); PyObject *(*setitem_slice_assign_scalar)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *); PyObject *(*setitem_indexed)(struct __pyx_memoryview_obj *, PyObject *, PyObject *); PyObject *(*convert_item_to_object)(struct __pyx_memoryview_obj *, char *); PyObject *(*assign_item_from_object)(struct __pyx_memoryview_obj *, char *, PyObject *); }; static struct __pyx_vtabstruct_memoryview *__pyx_vtabptr_memoryview; /* "View.MemoryView":927 * * @cname('__pyx_memoryviewslice') * cdef class _memoryviewslice(memoryview): # <<<<<<<<<<<<<< * "Internal class for passing memoryview slices to Python" * */ struct __pyx_vtabstruct__memoryviewslice { struct __pyx_vtabstruct_memoryview __pyx_base; }; static struct __pyx_vtabstruct__memoryviewslice *__pyx_vtabptr__memoryviewslice; #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); /*proto*/ #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 /* CYTHON_REFNANNY */ #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) static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*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); /*proto*/ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ const char* function_name); /*proto*/ static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack); static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info); static int __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b); #define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d #define __Pyx_MEMVIEW_DIRECT 1 #define __Pyx_MEMVIEW_PTR 2 #define __Pyx_MEMVIEW_FULL 4 #define __Pyx_MEMVIEW_CONTIG 8 #define __Pyx_MEMVIEW_STRIDED 16 #define __Pyx_MEMVIEW_FOLLOW 32 #define __Pyx_IS_C_CONTIG 1 #define __Pyx_IS_F_CONTIG 2 static int __Pyx_ValidateAndInit_memviewslice( int *axes_specs, int c_or_f_flag, int buf_flags, int ndim, __Pyx_TypeInfo *dtype, __Pyx_BufFmt_StackElem stack[], __Pyx_memviewslice *memviewslice, PyObject *original_obj); static int __Pyx_init_memviewslice( struct __pyx_memoryview_obj *memview, int ndim, __Pyx_memviewslice *memviewslice, int memview_is_new_reference); static CYTHON_INLINE int __pyx_add_acquisition_count_locked(__pyx_atomic_int *acquisition_count, PyThread_type_lock lock); static CYTHON_INLINE int __pyx_sub_acquisition_count_locked(__pyx_atomic_int *acquisition_count, PyThread_type_lock lock); #define __pyx_get_slice_count_pointer(memview) (memview->acquisition_count_aligned_p) #define __pyx_get_slice_count(memview) (*__pyx_get_slice_count_pointer(memview)) #define __PYX_INC_MEMVIEW(slice, have_gil) __Pyx_INC_MEMVIEW(slice, have_gil, __LINE__) #define __PYX_XDEC_MEMVIEW(slice, have_gil) __Pyx_XDEC_MEMVIEW(slice, have_gil, __LINE__) static CYTHON_INLINE void __Pyx_INC_MEMVIEW(__Pyx_memviewslice *, int, int); static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *, int, int); static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact); /*proto*/ static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); /*proto*/ static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t, Py_ssize_t); /* proto */ #define UNARY_NEG_WOULD_OVERFLOW(x) (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) static int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/ static PyObject *get_memview(PyObject *__pyx_v_self); /*proto*/ static CYTHON_INLINE PyObject* __Pyx_decode_c_string( const char* cstring, Py_ssize_t start, Py_ssize_t stop, const char* encoding, const char* errors, PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)); #include static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; if (!j) return NULL; r = PyObject_GetItem(o, j); Py_DECREF(j); return r; } #define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_GetItemInt_List_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { #if CYTHON_COMPILING_IN_CPYTHON if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { PyObject *r = PyList_GET_ITEM(o, i); Py_INCREF(r); return r; } else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } #define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_GetItemInt_Tuple_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { #if CYTHON_COMPILING_IN_CPYTHON if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, i); Py_INCREF(r); return r; } else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } #define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_GetItemInt_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { #if CYTHON_COMPILING_IN_CPYTHON if (PyList_CheckExact(o)) { Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); if (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 = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, n); Py_INCREF(r); return r; } } else { /* inlined PySequence_GetItem() */ PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; if (likely(m && m->sq_item)) { if (unlikely(i < 0) && likely(m->sq_length)) { Py_ssize_t l = m->sq_length(o); if (unlikely(l < 0)) return NULL; i += l; } return m->sq_item(o, i); } } #else if (PySequence_Check(o)) { return PySequence_GetItem(o, i); } #endif return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } static int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ static PyObject *__pyx_memoryview_transpose(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview__get__base(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_shape(PyObject *__pyx_v_self); /*proto*/ #if CYTHON_COMPILING_IN_CPYTHON 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)) { 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 static PyObject *__pyx_memoryview_get_strides(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_suboffsets(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_ndim(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_itemsize(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_nbytes(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_size(PyObject *__pyx_v_self); /*proto*/ static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); #ifndef __PYX_FORCE_INIT_THREADS #define __PYX_FORCE_INIT_THREADS 0 #endif static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */ static PyObject *__pyx_memoryviewslice__get__base(PyObject *__pyx_v_self); /*proto*/ typedef struct { Py_ssize_t shape, strides, suboffsets; } __Pyx_Buf_DimInfo; typedef struct { size_t refcount; Py_buffer pybuffer; } __Pyx_Buffer; typedef struct { __Pyx_Buffer *rcbuffer; char *data; __Pyx_Buf_DimInfo diminfo[8]; } __Pyx_LocalBuf_ND; #if PY_MAJOR_VERSION < 3 static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags); static void __Pyx_ReleaseBuffer(Py_buffer *view); #else #define __Pyx_GetBuffer PyObject_GetBuffer #define __Pyx_ReleaseBuffer PyBuffer_Release #endif static Py_ssize_t __Pyx_zeros[] = {0, 0, 0, 0, 0, 0, 0, 0}; static Py_ssize_t __Pyx_minusones[] = {-1, -1, -1, -1, -1, -1, -1, -1}; static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dc_long(PyObject *); static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_dc_long(PyObject *); static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(PyObject *); static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_double(PyObject *); static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_unsigned_char(PyObject *); static int __pyx_memviewslice_is_contig(const __Pyx_memviewslice *mvs, char order, int ndim); static int __pyx_slices_overlap(__Pyx_memviewslice *slice1, __Pyx_memviewslice *slice2, int ndim, size_t itemsize); 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, int dtype_is_object); static CYTHON_INLINE PyObject *__pyx_capsule_create(void *p, const char *sig); static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_long(PyObject *); static void __Pyx_WriteUnraisable(const char *name, int clineno, int lineno, const char *filename); /*proto*/ static int __Pyx_check_binary_version(void); static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ typedef struct { int code_line; PyCodeObject* code_object; } __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); static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename); /*proto*/ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'cogent.align._pairwise_pogs' */ 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 double __pyx_v_6cogent_5align_14_pairwise_pogs_SCALE_STEP; static double __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_FLOAT_VALUE; static int __pyx_v_6cogent_5align_14_pairwise_pogs_MAX_XCOUNT; static long __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_SCALE; static long __pyx_v_6cogent_5align_14_pairwise_pogs_MAX_SCALE; static PyObject *generic = 0; static PyObject *strided = 0; static PyObject *indirect = 0; static PyObject *contiguous = 0; static PyObject *indirect_contiguous = 0; static int __pyx_fuse_0__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(PyObject *, Py_ssize_t, Py_ssize_t *); /*proto*/ static int __pyx_fuse_1__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(PyObject *, Py_ssize_t, long *); /*proto*/ static int __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(PyObject *, Py_ssize_t, int *); /*proto*/ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray1D(__Pyx_memviewslice, int *); /*proto*/ static int __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray2D(__Pyx_memviewslice, int *, int *); /*proto*/ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray2D(__Pyx_memviewslice, int *, int *); /*proto*/ static int __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray3D(__Pyx_memviewslice, int *, int *, int *); /*proto*/ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray3D(__Pyx_memviewslice, int *, int *, int *); /*proto*/ static int __pyx_fuse_2_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray3D(__Pyx_memviewslice, int *, int *, int *); /*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*/ static int __pyx_memoryview_check(PyObject *); /*proto*/ static PyObject *_unellipsify(PyObject *, int); /*proto*/ static PyObject *assert_direct_dimensions(Py_ssize_t *, int); /*proto*/ static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *, PyObject *); /*proto*/ static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int, int); /*proto*/ static char *__pyx_pybuffer_index(Py_buffer *, char *, Py_ssize_t, int); /*proto*/ static int __pyx_memslice_transpose(__Pyx_memviewslice *); /*proto*/ static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice, int, PyObject *(*)(char *), int (*)(char *, PyObject *), int); /*proto*/ static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *); /*proto*/ static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ static Py_ssize_t abs_py_ssize_t(Py_ssize_t); /*proto*/ static char __pyx_get_best_slice_order(__Pyx_memviewslice *, int); /*proto*/ static void _copy_strided_to_strided(char *, Py_ssize_t *, char *, Py_ssize_t *, Py_ssize_t *, Py_ssize_t *, int, size_t); /*proto*/ static void copy_strided_to_strided(__Pyx_memviewslice *, __Pyx_memviewslice *, int, size_t); /*proto*/ static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *, int); /*proto*/ static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *, Py_ssize_t *, Py_ssize_t, int, char); /*proto*/ static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *, __Pyx_memviewslice *, char, int); /*proto*/ static int __pyx_memoryview_err_extents(int, Py_ssize_t, Py_ssize_t); /*proto*/ static int __pyx_memoryview_err_dim(PyObject *, char *, int); /*proto*/ static int __pyx_memoryview_err(PyObject *, char *); /*proto*/ static int __pyx_memoryview_copy_contents(__Pyx_memviewslice, __Pyx_memviewslice, int, int, int); /*proto*/ static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *, int, int); /*proto*/ static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *, int, int, int); /*proto*/ static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/ static void __pyx_memoryview_refcount_objects_in_slice(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/ static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *, int, size_t, void *, int); /*proto*/ static void __pyx_memoryview__slice_assign_scalar(char *, Py_ssize_t *, Py_ssize_t *, int, size_t, void *); /*proto*/ static __Pyx_TypeInfo __Pyx_TypeInfo_long = { "long", NULL, sizeof(long), { 0 }, 0, IS_UNSIGNED(long) ? 'U' : 'I', IS_UNSIGNED(long), 0 }; static __Pyx_TypeInfo __Pyx_TypeInfo_double = { "double", NULL, sizeof(double), { 0 }, 0, 'R', 0, 0 }; static __Pyx_TypeInfo __Pyx_TypeInfo_unsigned_char = { "unsigned char", NULL, sizeof(unsigned char), { 0 }, 0, IS_UNSIGNED(unsigned char) ? 'U' : 'I', IS_UNSIGNED(unsigned char), 0 }; #define __Pyx_MODULE_NAME "cogent.align._pairwise_pogs" int __pyx_module_is_main_cogent__align___pairwise_pogs = 0; /* Implementation of 'cogent.align._pairwise_pogs' */ static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_ArithmeticError; static PyObject *__pyx_builtin_MemoryError; static PyObject *__pyx_builtin_enumerate; static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_Ellipsis; static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_xrange; static PyObject *__pyx_builtin_id; static PyObject *__pyx_builtin_IndexError; static PyObject *__pyx_pf_6cogent_5align_14_pairwise_pogs_fmpt(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_mantissa, PyObject *__pyx_v_exponent, PyObject *__pyx_v_msg); /* proto */ static PyObject *__pyx_pf_6cogent_5align_14_pairwise_pogs_2calc_rows(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_plan, __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_seq1_index, __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_seq2_index, int __pyx_v_i_low, int __pyx_v_i_high, int __pyx_v_j_low, int __pyx_v_j_high, PyObject *__pyx_v_preds, __pyx_t_6cogent_5align_14_pairwise_pogs_Long2D __pyx_v_state_directions, __pyx_t_6cogent_5align_14_pairwise_pogs_Double2D __pyx_v_T, __pyx_t_6cogent_5align_14_pairwise_pogs_Double2D __pyx_v_xgap_scores, __pyx_t_6cogent_5align_14_pairwise_pogs_Double2D __pyx_v_ygap_scores, __pyx_t_6cogent_5align_14_pairwise_pogs_Double3D __pyx_v_match_scores, PyObject *__pyx_v_rows, __pyx_t_6cogent_5align_14_pairwise_pogs_UChar3D __pyx_v_track, PyObject *__pyx_v_track_enc, int __pyx_v_viterbi, int __pyx_v_use_logs, int __pyx_v_local, int __pyx_v_use_scaling); /* proto */ static int __pyx_array_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_getbuffer_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_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self); /* proto */ static PyObject *get_memview_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_array_MemoryView_5array_6__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr); /* proto */ static PyObject *__pyx_array_MemoryView_5array_8__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item); /* proto */ static int __pyx_array_MemoryView_5array_10__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /* proto */ static int __pyx_MemviewEnum_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name); /* proto */ static PyObject *__pyx_MemviewEnum_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self); /* proto */ static int __pyx_memoryview_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object); /* proto */ static void __pyx_memoryview_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index); /* proto */ static int __pyx_memoryview_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /* proto */ static int __pyx_memoryview_getbuffer_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ static PyObject *__pyx_memoryview_transpose_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview__get__base_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_shape_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_strides_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_suboffsets_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_ndim_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_itemsize_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_nbytes_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_size_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static Py_ssize_t __pyx_memoryview_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static void __pyx_memoryviewslice_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryviewslice__get__base_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */ static char __pyx_k_1[] = "%s dimension is %s, expected %s"; static char __pyx_k_2[] = "%s dimension is %s, too big"; static char __pyx_k_3[] = "Array required, got None"; static char __pyx_k_10[] = ""; static char __pyx_k_11[] = "%s * SCALE_STEP ** %s %s"; static char __pyx_k_12[] = "transition is a negative probability"; static char __pyx_k_13[] = "product is a negative probability"; static char __pyx_k_14[] = "is unexpectedly large"; static char __pyx_k_15[] = "Empty shape tuple for cython.array"; static char __pyx_k_17[] = "itemsize <= 0 for cython.array"; static char __pyx_k_20[] = "unable to allocate shape or strides."; static char __pyx_k_22[] = "Invalid shape in axis %d: %d."; static char __pyx_k_23[] = "Invalid mode, expected 'c' or 'fortran', got %s"; static char __pyx_k_25[] = "unable to allocate array data."; static char __pyx_k_27[] = "Can only create a buffer that is contiguous in memory."; static char __pyx_k_29[] = "Unable to convert item to object"; static char __pyx_k_31[] = "Buffer view does not expose strides"; static char __pyx_k_33[] = ""; static char __pyx_k_34[] = ""; static char __pyx_k_37[] = "Cannot index with type '%s'"; static char __pyx_k_39[] = "Indirect dimensions not supported"; static char __pyx_k_41[] = "Index out of bounds (axis %d)"; static char __pyx_k_42[] = "Step may not be zero (axis %d)"; static char __pyx_k_43[] = "All dimensions preceding dimension %d must be indexed and not sliced"; static char __pyx_k_44[] = "Out of bounds on buffer access (axis %d)"; static char __pyx_k_45[] = "Cannot transpose memoryview with indirect dimensions"; static char __pyx_k_46[] = "got differing extents in dimension %d (got %d and %d)"; static char __pyx_k_47[] = "Dimension %d is not direct"; static char __pyx_k_48[] = "('1', '5', '3-dev')"; static char __pyx_k_52[] = "/Users/maxwell/Documents/Work/Cogent/cogent/align/_pairwise_pogs.pyx"; static char __pyx_k_53[] = "cogent.align._pairwise_pogs"; static char __pyx_k_54[] = "source_row_index_cache"; static char __pyx_k_55[] = "overall_max_mantissa"; static char __pyx_k_56[] = "overall_max_exponent"; static char __pyx_k_59[] = "getbuffer(obj, view, flags)"; static char __pyx_k_60[] = ""; static char __pyx_k_62[] = ""; static char __pyx_k_64[] = ""; static char __pyx_k_66[] = ""; static char __pyx_k_68[] = ""; static char __pyx_k__N[] = "N"; static char __pyx_k__O[] = "O"; static char __pyx_k__T[] = "T"; static char __pyx_k__a[] = "a"; static char __pyx_k__b[] = "b"; static char __pyx_k__c[] = "c"; static char __pyx_k__i[] = "i"; static char __pyx_k__j[] = "j"; static char __pyx_k__x[] = "x"; static char __pyx_k__y[] = "y"; static char __pyx_k__d4[] = "d4"; static char __pyx_k__dx[] = "dx"; static char __pyx_k__dy[] = "dy"; static char __pyx_k__id[] = "id"; static char __pyx_k__1st[] = "1st"; static char __pyx_k__2nd[] = "2nd"; static char __pyx_k__3rd[] = "3rd"; static char __pyx_k__bin[] = "bin"; static char __pyx_k__msg[] = "msg"; static char __pyx_k__obj[] = "obj"; static char __pyx_k__base[] = "base"; static char __pyx_k__fmpt[] = "fmpt"; static char __pyx_k__mode[] = "mode"; static char __pyx_k__name[] = "name"; static char __pyx_k__ndim[] = "ndim"; static char __pyx_k__pack[] = "pack"; static char __pyx_k__plan[] = "plan"; static char __pyx_k__pog1[] = "pog1"; static char __pyx_k__pog2[] = "pog2"; static char __pyx_k__rows[] = "rows"; static char __pyx_k__size[] = "size"; static char __pyx_k__step[] = "step"; static char __pyx_k__stop[] = "stop"; static char __pyx_k__ASCII[] = "ASCII"; static char __pyx_k__a_low[] = "a_low"; static char __pyx_k__b_low[] = "b_low"; static char __pyx_k__error[] = "error"; static char __pyx_k__flags[] = "flags"; static char __pyx_k__i_low[] = "i_low"; static char __pyx_k__j_low[] = "j_low"; static char __pyx_k__local[] = "local"; static char __pyx_k__max_x[] = "max_x"; static char __pyx_k__max_y[] = "max_y"; static char __pyx_k__preds[] = "preds"; static char __pyx_k__range[] = "range"; static char __pyx_k__score[] = "score"; static char __pyx_k__shape[] = "shape"; static char __pyx_k__start[] = "start"; static char __pyx_k__state[] = "state"; static char __pyx_k__track[] = "track"; static char __pyx_k__a_high[] = "a_high"; static char __pyx_k__b_high[] = "b_high"; static char __pyx_k__decode[] = "decode"; static char __pyx_k__encode[] = "encode"; static char __pyx_k__extend[] = "extend"; static char __pyx_k__format[] = "format"; static char __pyx_k__i_high[] = "i_high"; static char __pyx_k__j_high[] = "j_high"; static char __pyx_k__last_i[] = "last_i"; static char __pyx_k__last_j[] = "last_j"; static char __pyx_k__prev_i[] = "prev_i"; static char __pyx_k__prev_j[] = "prev_j"; static char __pyx_k__struct[] = "struct"; static char __pyx_k__unpack[] = "unpack"; static char __pyx_k__xrange[] = "xrange"; static char __pyx_k__a_count[] = "a_count"; static char __pyx_k__b_count[] = "b_count"; static char __pyx_k__d_score[] = "d_score"; static char __pyx_k__fortran[] = "fortran"; static char __pyx_k__memview[] = "memview"; static char __pyx_k__tcode_s[] = "tcode_s"; static char __pyx_k__tcode_x[] = "tcode_x"; static char __pyx_k__tcode_y[] = "tcode_y"; static char __pyx_k__viterbi[] = "viterbi"; static char __pyx_k__Ellipsis[] = "Ellipsis"; static char __pyx_k____main__[] = "__main__"; static char __pyx_k____name__[] = "__name__"; static char __pyx_k____test__[] = "__test__"; static char __pyx_k__exponent[] = "exponent"; static char __pyx_k__itemsize[] = "itemsize"; static char __pyx_k__mantissa[] = "mantissa"; static char __pyx_k__tmp_rows[] = "tmp_rows"; static char __pyx_k__use_logs[] = "use_logs"; static char __pyx_k__TypeError[] = "TypeError"; static char __pyx_k____class__[] = "__class__"; static char __pyx_k__bin_count[] = "bin_count"; static char __pyx_k__calc_rows[] = "calc_rows"; static char __pyx_k__enumerate[] = "enumerate"; static char __pyx_k__exponents[] = "exponents"; static char __pyx_k__i_sources[] = "i_sources"; static char __pyx_k__j_sources[] = "j_sources"; static char __pyx_k__mantissas[] = "mantissas"; static char __pyx_k__pointer_a[] = "pointer_a"; static char __pyx_k__pointer_b[] = "pointer_b"; static char __pyx_k__row_count[] = "row_count"; static char __pyx_k__track_enc[] = "track_enc"; static char __pyx_k__IndexError[] = "IndexError"; static char __pyx_k__ValueError[] = "ValueError"; static char __pyx_k__dest_state[] = "dest_state"; static char __pyx_k__impossible[] = "impossible"; static char __pyx_k__last_state[] = "last_state"; static char __pyx_k__prev_state[] = "prev_state"; static char __pyx_k__row_count1[] = "row_count1"; static char __pyx_k__row_length[] = "row_length"; static char __pyx_k__seq1_index[] = "seq1_index"; static char __pyx_k__seq2_index[] = "seq2_index"; static char __pyx_k__underflows[] = "underflows"; static char __pyx_k__MemoryError[] = "MemoryError"; static char __pyx_k____version__[] = "__version__"; static char __pyx_k__dest_states[] = "dest_states"; static char __pyx_k__partial_sum[] = "partial_sum"; static char __pyx_k__row_length1[] = "row_length1"; static char __pyx_k__use_scaling[] = "use_scaling"; static char __pyx_k__xgap_scores[] = "xgap_scores"; static char __pyx_k__ygap_scores[] = "ygap_scores"; static char __pyx_k__i_link_count[] = "i_link_count"; static char __pyx_k__j_link_count[] = "j_link_count"; static char __pyx_k__match_scores[] = "match_scores"; static char __pyx_k__max_exponent[] = "max_exponent"; static char __pyx_k__max_mantissa[] = "max_mantissa"; static char __pyx_k__version_info[] = "version_info"; static char __pyx_k__i_sources_end[] = "i_sources_end"; static char __pyx_k__j_sources_end[] = "j_sources_end"; static char __pyx_k__pointer_state[] = "pointer_state"; static char __pyx_k__min_prev_state[] = "min_prev_state"; static char __pyx_k__ArithmeticError[] = "ArithmeticError"; static char __pyx_k____pyx_getbuffer[] = "__pyx_getbuffer"; static char __pyx_k__allocate_buffer[] = "allocate_buffer"; static char __pyx_k__asCombinedArray[] = "asCombinedArray"; static char __pyx_k__dtype_is_object[] = "dtype_is_object"; static char __pyx_k__i_sources_start[] = "i_sources_start"; static char __pyx_k__j_sources_start[] = "j_sources_start"; static char __pyx_k__sub_partial_sum[] = "sub_partial_sum"; static char __pyx_k__source_row_index[] = "source_row_index"; static char __pyx_k__state_directions[] = "state_directions"; static char __pyx_k__current_row_index[] = "current_row_index"; static char __pyx_k__i_sources_offsets[] = "i_sources_offsets"; static char __pyx_k__j_sources_offsets[] = "j_sources_offsets"; static PyObject *__pyx_kp_s_1; static PyObject *__pyx_kp_s_10; static PyObject *__pyx_kp_s_11; static PyObject *__pyx_kp_s_12; static PyObject *__pyx_kp_s_13; static PyObject *__pyx_kp_s_14; static PyObject *__pyx_kp_s_15; static PyObject *__pyx_kp_s_17; static PyObject *__pyx_kp_s_2; static PyObject *__pyx_kp_s_20; static PyObject *__pyx_kp_s_22; static PyObject *__pyx_kp_s_23; static PyObject *__pyx_kp_s_25; static PyObject *__pyx_kp_s_27; static PyObject *__pyx_kp_s_29; static PyObject *__pyx_kp_s_3; static PyObject *__pyx_kp_s_31; static PyObject *__pyx_kp_s_33; static PyObject *__pyx_kp_s_34; static PyObject *__pyx_kp_s_37; static PyObject *__pyx_kp_s_39; static PyObject *__pyx_kp_s_44; static PyObject *__pyx_kp_s_46; static PyObject *__pyx_kp_s_48; static PyObject *__pyx_kp_s_52; static PyObject *__pyx_n_s_53; static PyObject *__pyx_n_s_54; static PyObject *__pyx_n_s_55; static PyObject *__pyx_n_s_56; static PyObject *__pyx_kp_s_60; static PyObject *__pyx_kp_s_62; static PyObject *__pyx_kp_s_64; static PyObject *__pyx_kp_s_66; static PyObject *__pyx_kp_s_68; static PyObject *__pyx_kp_s__1st; static PyObject *__pyx_kp_s__2nd; static PyObject *__pyx_kp_s__3rd; static PyObject *__pyx_n_s__ASCII; static PyObject *__pyx_n_s__ArithmeticError; static PyObject *__pyx_n_s__Ellipsis; static PyObject *__pyx_n_s__IndexError; static PyObject *__pyx_n_s__MemoryError; static PyObject *__pyx_n_s__N; static PyObject *__pyx_n_b__O; static PyObject *__pyx_n_s__T; static PyObject *__pyx_n_s__TypeError; static PyObject *__pyx_n_s__ValueError; static PyObject *__pyx_n_s____class__; static PyObject *__pyx_n_s____main__; static PyObject *__pyx_n_s____name__; static PyObject *__pyx_n_s____pyx_getbuffer; static PyObject *__pyx_n_s____test__; static PyObject *__pyx_n_s____version__; static PyObject *__pyx_n_s__a; static PyObject *__pyx_n_s__a_count; static PyObject *__pyx_n_s__a_high; static PyObject *__pyx_n_s__a_low; static PyObject *__pyx_n_s__allocate_buffer; static PyObject *__pyx_n_s__asCombinedArray; static PyObject *__pyx_n_s__b; static PyObject *__pyx_n_s__b_count; static PyObject *__pyx_n_s__b_high; static PyObject *__pyx_n_s__b_low; static PyObject *__pyx_n_s__base; static PyObject *__pyx_n_s__bin; static PyObject *__pyx_n_s__bin_count; static PyObject *__pyx_n_b__c; static PyObject *__pyx_n_s__c; static PyObject *__pyx_n_u__c; static PyObject *__pyx_n_s__calc_rows; static PyObject *__pyx_n_s__current_row_index; static PyObject *__pyx_n_s__d4; static PyObject *__pyx_n_s__d_score; static PyObject *__pyx_n_s__decode; static PyObject *__pyx_n_s__dest_state; static PyObject *__pyx_n_s__dest_states; static PyObject *__pyx_n_s__dtype_is_object; static PyObject *__pyx_n_s__dx; static PyObject *__pyx_n_s__dy; static PyObject *__pyx_n_s__encode; static PyObject *__pyx_n_s__enumerate; static PyObject *__pyx_n_s__error; static PyObject *__pyx_n_s__exponent; static PyObject *__pyx_n_s__exponents; static PyObject *__pyx_n_s__extend; static PyObject *__pyx_n_s__flags; static PyObject *__pyx_n_s__fmpt; static PyObject *__pyx_n_s__format; static PyObject *__pyx_n_b__fortran; static PyObject *__pyx_n_s__fortran; static PyObject *__pyx_n_s__i; static PyObject *__pyx_n_s__i_high; static PyObject *__pyx_n_s__i_link_count; static PyObject *__pyx_n_s__i_low; static PyObject *__pyx_n_s__i_sources; static PyObject *__pyx_n_s__i_sources_end; static PyObject *__pyx_n_s__i_sources_offsets; static PyObject *__pyx_n_s__i_sources_start; static PyObject *__pyx_n_s__id; static PyObject *__pyx_n_s__impossible; static PyObject *__pyx_n_s__itemsize; static PyObject *__pyx_n_s__j; static PyObject *__pyx_n_s__j_high; static PyObject *__pyx_n_s__j_link_count; static PyObject *__pyx_n_s__j_low; static PyObject *__pyx_n_s__j_sources; static PyObject *__pyx_n_s__j_sources_end; static PyObject *__pyx_n_s__j_sources_offsets; static PyObject *__pyx_n_s__j_sources_start; static PyObject *__pyx_n_s__last_i; static PyObject *__pyx_n_s__last_j; static PyObject *__pyx_n_s__last_state; static PyObject *__pyx_n_s__local; static PyObject *__pyx_n_s__mantissa; static PyObject *__pyx_n_s__mantissas; static PyObject *__pyx_n_s__match_scores; static PyObject *__pyx_n_s__max_exponent; static PyObject *__pyx_n_s__max_mantissa; static PyObject *__pyx_n_s__max_x; static PyObject *__pyx_n_s__max_y; static PyObject *__pyx_n_s__memview; static PyObject *__pyx_n_s__min_prev_state; static PyObject *__pyx_n_s__mode; static PyObject *__pyx_n_s__msg; static PyObject *__pyx_n_s__name; static PyObject *__pyx_n_s__ndim; static PyObject *__pyx_n_s__obj; static PyObject *__pyx_n_s__pack; static PyObject *__pyx_n_s__partial_sum; static PyObject *__pyx_n_s__plan; static PyObject *__pyx_n_s__pog1; static PyObject *__pyx_n_s__pog2; static PyObject *__pyx_n_s__pointer_a; static PyObject *__pyx_n_s__pointer_b; static PyObject *__pyx_n_s__pointer_state; static PyObject *__pyx_n_s__preds; static PyObject *__pyx_n_s__prev_i; static PyObject *__pyx_n_s__prev_j; static PyObject *__pyx_n_s__prev_state; static PyObject *__pyx_n_s__range; static PyObject *__pyx_n_s__row_count; static PyObject *__pyx_n_s__row_count1; static PyObject *__pyx_n_s__row_length; static PyObject *__pyx_n_s__row_length1; static PyObject *__pyx_n_s__rows; static PyObject *__pyx_n_s__score; static PyObject *__pyx_n_s__seq1_index; static PyObject *__pyx_n_s__seq2_index; static PyObject *__pyx_n_s__shape; static PyObject *__pyx_n_s__size; static PyObject *__pyx_n_s__source_row_index; static PyObject *__pyx_n_s__start; static PyObject *__pyx_n_s__state; static PyObject *__pyx_n_s__state_directions; static PyObject *__pyx_n_s__step; static PyObject *__pyx_n_s__stop; static PyObject *__pyx_n_s__struct; static PyObject *__pyx_n_s__sub_partial_sum; static PyObject *__pyx_n_s__tcode_s; static PyObject *__pyx_n_s__tcode_x; static PyObject *__pyx_n_s__tcode_y; static PyObject *__pyx_n_s__tmp_rows; static PyObject *__pyx_n_s__track; static PyObject *__pyx_n_s__track_enc; static PyObject *__pyx_n_s__underflows; static PyObject *__pyx_n_s__unpack; static PyObject *__pyx_n_s__use_logs; static PyObject *__pyx_n_s__use_scaling; static PyObject *__pyx_n_s__version_info; static PyObject *__pyx_n_s__viterbi; static PyObject *__pyx_n_s__x; static PyObject *__pyx_n_s__xgap_scores; static PyObject *__pyx_n_s__xrange; static PyObject *__pyx_n_s__y; static PyObject *__pyx_n_s__ygap_scores; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_int_2; static PyObject *__pyx_int_3; static PyObject *__pyx_int_neg_1; static PyObject *__pyx_k_tuple_4; static PyObject *__pyx_k_tuple_5; static PyObject *__pyx_k_tuple_6; static PyObject *__pyx_k_tuple_7; static PyObject *__pyx_k_tuple_8; static PyObject *__pyx_k_tuple_9; static PyObject *__pyx_k_tuple_16; static PyObject *__pyx_k_tuple_18; static PyObject *__pyx_k_tuple_19; static PyObject *__pyx_k_tuple_21; static PyObject *__pyx_k_tuple_24; static PyObject *__pyx_k_tuple_26; static PyObject *__pyx_k_tuple_28; static PyObject *__pyx_k_tuple_30; static PyObject *__pyx_k_tuple_32; static PyObject *__pyx_k_tuple_35; static PyObject *__pyx_k_tuple_36; static PyObject *__pyx_k_tuple_38; static PyObject *__pyx_k_tuple_40; static PyObject *__pyx_k_tuple_49; static PyObject *__pyx_k_tuple_50; static PyObject *__pyx_k_tuple_57; static PyObject *__pyx_k_tuple_61; static PyObject *__pyx_k_tuple_63; static PyObject *__pyx_k_tuple_65; static PyObject *__pyx_k_tuple_67; static PyObject *__pyx_k_tuple_69; static PyObject *__pyx_k_codeobj_51; static PyObject *__pyx_k_codeobj_58; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":39 * * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: # <<<<<<<<<<<<<< * if var[0] == 0: * # Length unspecified, take it from the provided array */ static int __pyx_fuse_0__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(PyObject *__pyx_v_dimension, Py_ssize_t __pyx_v_val, Py_ssize_t *__pyx_v_var) { 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_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_0checkDim", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":40 * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: * if var[0] == 0: # <<<<<<<<<<<<<< * # Length unspecified, take it from the provided array * if dim is int: */ __pyx_t_1 = ((__pyx_v_var[0]) == 0); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":51 * var[0] = val * else: * var[0] = val # <<<<<<<<<<<<<< * * elif var[0] != val: */ (__pyx_v_var[0]) = __pyx_v_val; goto __pyx_L3; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":53 * var[0] = val * * elif var[0] != val: # <<<<<<<<<<<<<< * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % */ __pyx_t_1 = ((__pyx_v_var[0]) != __pyx_v_val); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":56 * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % * (dimension, val, var[0])) # <<<<<<<<<<<<<< * else: * # Length matches what was expected */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyInt_FromSsize_t((__pyx_v_var[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_dimension); __Pyx_GIVEREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } /*else*/ { } __pyx_L3:; __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("cogent.align._pairwise_pogs.checkDim", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":39 * * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: # <<<<<<<<<<<<<< * if var[0] == 0: * # Length unspecified, take it from the provided array */ static int __pyx_fuse_1__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(PyObject *__pyx_v_dimension, Py_ssize_t __pyx_v_val, long *__pyx_v_var) { 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_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_1checkDim", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":40 * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: * if var[0] == 0: # <<<<<<<<<<<<<< * # Length unspecified, take it from the provided array * if dim is int: */ __pyx_t_1 = ((__pyx_v_var[0]) == 0); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":47 * var[0] = val * elif dim is long: * if val > LONG_MAX: # <<<<<<<<<<<<<< * raise ValueError("%s dimension is %s, too big" % (dimension, val)) * var[0] = val */ __pyx_t_1 = (__pyx_v_val > LONG_MAX); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":48 * elif dim is long: * if val > LONG_MAX: * raise ValueError("%s dimension is %s, too big" % (dimension, val)) # <<<<<<<<<<<<<< * var[0] = val * else: */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_dimension); __Pyx_GIVEREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":49 * if val > LONG_MAX: * raise ValueError("%s dimension is %s, too big" % (dimension, val)) * var[0] = val # <<<<<<<<<<<<<< * else: * var[0] = val */ (__pyx_v_var[0]) = ((long)__pyx_v_val); goto __pyx_L3; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":53 * var[0] = val * * elif var[0] != val: # <<<<<<<<<<<<<< * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % */ __pyx_t_1 = ((__pyx_v_var[0]) != __pyx_v_val); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":56 * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % * (dimension, val, var[0])) # <<<<<<<<<<<<<< * else: * # Length matches what was expected */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyInt_FromLong((__pyx_v_var[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_dimension); __Pyx_GIVEREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } /*else*/ { } __pyx_L3:; __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("cogent.align._pairwise_pogs.checkDim", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":39 * * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: # <<<<<<<<<<<<<< * if var[0] == 0: * # Length unspecified, take it from the provided array */ static int __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(PyObject *__pyx_v_dimension, Py_ssize_t __pyx_v_val, int *__pyx_v_var) { 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_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_2checkDim", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":40 * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: * if var[0] == 0: # <<<<<<<<<<<<<< * # Length unspecified, take it from the provided array * if dim is int: */ __pyx_t_1 = ((__pyx_v_var[0]) == 0); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":43 * # Length unspecified, take it from the provided array * if dim is int: * if val > INT_MAX: # <<<<<<<<<<<<<< * raise ValueError("%s dimension is %s, too big" % (dimension, val)) * var[0] = val */ __pyx_t_1 = (__pyx_v_val > INT_MAX); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":44 * if dim is int: * if val > INT_MAX: * raise ValueError("%s dimension is %s, too big" % (dimension, val)) # <<<<<<<<<<<<<< * var[0] = val * elif dim is long: */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_dimension); __Pyx_GIVEREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":45 * if val > INT_MAX: * raise ValueError("%s dimension is %s, too big" % (dimension, val)) * var[0] = val # <<<<<<<<<<<<<< * elif dim is long: * if val > LONG_MAX: */ (__pyx_v_var[0]) = ((int)__pyx_v_val); goto __pyx_L3; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":53 * var[0] = val * * elif var[0] != val: # <<<<<<<<<<<<<< * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % */ __pyx_t_1 = ((__pyx_v_var[0]) != __pyx_v_val); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":56 * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % * (dimension, val, var[0])) # <<<<<<<<<<<<<< * else: * # Length matches what was expected */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyInt_FromLong((__pyx_v_var[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_dimension); __Pyx_GIVEREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } /*else*/ { } __pyx_L3:; __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("cogent.align._pairwise_pogs.checkDim", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":62 * * * cdef int checkArray1D(num[::1] a, dim *x) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray1D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_1_2checkArray1D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":63 * * cdef int checkArray1D(num[::1] a, dim *x) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":64 * cdef int checkArray1D(num[::1] a, dim *x) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":65 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_pogs.checkArray1D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":67 * checkDim('1st', a.shape[0], x) * * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray2D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_0_2checkArray2D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":68 * * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":69 * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":70 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * checkDim('2nd', a.shape[1], y) * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":71 * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) # <<<<<<<<<<<<<< * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__2nd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[1]), __pyx_v_y); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_pogs.checkArray2D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":67 * checkDim('1st', a.shape[0], x) * * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray2D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_1_2checkArray2D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":68 * * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":69 * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":70 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * checkDim('2nd', a.shape[1], y) * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":71 * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) # <<<<<<<<<<<<<< * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__2nd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[1]), __pyx_v_y); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_pogs.checkArray2D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":73 * checkDim('2nd', a.shape[1], y) * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray3D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y, int *__pyx_v_z) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_0_2checkArray3D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":74 * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":75 * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":76 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":77 * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) # <<<<<<<<<<<<<< * checkDim('3rd', a.shape[2], z) * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__2nd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[1]), __pyx_v_y); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":78 * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) # <<<<<<<<<<<<<< * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__3rd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[2]), __pyx_v_z); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_pogs.checkArray3D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":73 * checkDim('2nd', a.shape[1], y) * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray3D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y, int *__pyx_v_z) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_1_2checkArray3D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":74 * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":75 * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":76 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":77 * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) # <<<<<<<<<<<<<< * checkDim('3rd', a.shape[2], z) * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__2nd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[1]), __pyx_v_y); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":78 * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) # <<<<<<<<<<<<<< * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__3rd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[2]), __pyx_v_z); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_pogs.checkArray3D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":73 * checkDim('2nd', a.shape[1], y) * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_2_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray3D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y, int *__pyx_v_z) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_2_2checkArray3D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":74 * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":75 * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":76 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":77 * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) # <<<<<<<<<<<<<< * checkDim('3rd', a.shape[2], z) * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__2nd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[1]), __pyx_v_y); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":78 * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) # <<<<<<<<<<<<<< * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__3rd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkDim(__pyx_t_2, (__pyx_v_a.shape[2]), __pyx_v_z); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_pogs.checkArray3D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_6cogent_5align_14_pairwise_pogs_1fmpt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_6cogent_5align_14_pairwise_pogs_1fmpt = {__Pyx_NAMESTR("fmpt"), (PyCFunction)__pyx_pw_6cogent_5align_14_pairwise_pogs_1fmpt, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}; static PyObject *__pyx_pw_6cogent_5align_14_pairwise_pogs_1fmpt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_mantissa = 0; PyObject *__pyx_v_exponent = 0; PyObject *__pyx_v_msg = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("fmpt (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__mantissa,&__pyx_n_s__exponent,&__pyx_n_s__msg,0}; PyObject* values[3] = {0,0,0}; values[2] = ((PyObject *)__pyx_kp_s_10); 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); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mantissa)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__exponent)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("fmpt", 0, 2, 3, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__msg); if (value) { values[2] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fmpt") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); 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_mantissa = values[0]; __pyx_v_exponent = values[1]; __pyx_v_msg = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("fmpt", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("cogent.align._pairwise_pogs.fmpt", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_6cogent_5align_14_pairwise_pogs_fmpt(__pyx_self, __pyx_v_mantissa, __pyx_v_exponent, __pyx_v_msg); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cogent/align/_pairwise_pogs.pyx":28 * MAX_SCALE = +10000 # or 0 if all numbers should be probabilities * * def fmpt(mantissa, exponent, msg=''): # <<<<<<<<<<<<<< * return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) * */ static PyObject *__pyx_pf_6cogent_5align_14_pairwise_pogs_fmpt(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_mantissa, PyObject *__pyx_v_exponent, PyObject *__pyx_v_msg) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("fmpt", 0); /* "cogent/align/_pairwise_pogs.pyx":29 * * def fmpt(mantissa, exponent, msg=''): * return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) # <<<<<<<<<<<<<< * * ctypedef unsigned char [:,:,::1] UChar3D */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_mantissa); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_mantissa); __Pyx_GIVEREF(__pyx_v_mantissa); __Pyx_INCREF(__pyx_v_exponent); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_exponent); __Pyx_GIVEREF(__pyx_v_exponent); __Pyx_INCREF(__pyx_v_msg); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_msg); __Pyx_GIVEREF(__pyx_v_msg); __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_r = ((PyObject *)__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L0; __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("cogent.align._pairwise_pogs.fmpt", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_6cogent_5align_14_pairwise_pogs_3calc_rows(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_6cogent_5align_14_pairwise_pogs_2calc_rows[] = "The ultimate in 2D Pyrex dynamic programming - Forward or Viterbi \n algorithm, with doubles or with slower but practically unoverflowable \n (double, long) GMP-like numbers. Viterbi is also available in the ever \n popular addition-of-logs version. All this with any possible pair HMM \n transition matrix.\n \n One time to use something faster than this is when the inputs are sequences\n rather than alignments. This code expects alignments (which can be single\n sequences) represented as POGs (ie: DAGs).\n \n Limitations\n - HMM states must be in a sensible order: M and X, then Y, then END.\n "; static PyMethodDef __pyx_mdef_6cogent_5align_14_pairwise_pogs_3calc_rows = {__Pyx_NAMESTR("calc_rows"), (PyCFunction)__pyx_pw_6cogent_5align_14_pairwise_pogs_3calc_rows, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6cogent_5align_14_pairwise_pogs_2calc_rows)}; static PyObject *__pyx_pw_6cogent_5align_14_pairwise_pogs_3calc_rows(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_plan = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_seq1_index = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_seq2_index = { 0, 0, { 0 }, { 0 }, { 0 } }; int __pyx_v_i_low; int __pyx_v_i_high; int __pyx_v_j_low; int __pyx_v_j_high; PyObject *__pyx_v_preds = 0; __pyx_t_6cogent_5align_14_pairwise_pogs_Long2D __pyx_v_state_directions = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Double2D __pyx_v_T = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Double2D __pyx_v_xgap_scores = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Double2D __pyx_v_ygap_scores = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Double3D __pyx_v_match_scores = { 0, 0, { 0 }, { 0 }, { 0 } }; PyObject *__pyx_v_rows = 0; __pyx_t_6cogent_5align_14_pairwise_pogs_UChar3D __pyx_v_track = { 0, 0, { 0 }, { 0 }, { 0 } }; PyObject *__pyx_v_track_enc = 0; int __pyx_v_viterbi; int __pyx_v_use_logs; int __pyx_v_local; int __pyx_v_use_scaling; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("calc_rows (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__plan,&__pyx_n_s__seq1_index,&__pyx_n_s__seq2_index,&__pyx_n_s__i_low,&__pyx_n_s__i_high,&__pyx_n_s__j_low,&__pyx_n_s__j_high,&__pyx_n_s__preds,&__pyx_n_s__state_directions,&__pyx_n_s__T,&__pyx_n_s__xgap_scores,&__pyx_n_s__ygap_scores,&__pyx_n_s__match_scores,&__pyx_n_s__rows,&__pyx_n_s__track,&__pyx_n_s__track_enc,&__pyx_n_s__viterbi,&__pyx_n_s__use_logs,&__pyx_n_s__local,&__pyx_n_s__use_scaling,0}; PyObject* values[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__plan)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__seq1_index)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__seq2_index)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i_low)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 3); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i_high)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 4); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__j_low)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 5); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 6: if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__j_high)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 6); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 7: if (likely((values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__preds)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 7); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 8: if (likely((values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__state_directions)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 8); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 9: if (likely((values[9] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 9); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 10: if (likely((values[10] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__xgap_scores)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 10); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 11: if (likely((values[11] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ygap_scores)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 11); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 12: if (likely((values[12] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__match_scores)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 12); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 13: if (likely((values[13] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__rows)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 13); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 14: if (likely((values[14] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__track)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 14); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 15: if (likely((values[15] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__track_enc)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 15); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 16: if (likely((values[16] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__viterbi)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 16); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 17: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_logs); if (value) { values[17] = value; kw_args--; } } case 18: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__local); if (value) { values[18] = value; kw_args--; } } case 19: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_scaling); if (value) { values[19] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "calc_rows") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); values[15] = PyTuple_GET_ITEM(__pyx_args, 15); values[14] = PyTuple_GET_ITEM(__pyx_args, 14); values[13] = PyTuple_GET_ITEM(__pyx_args, 13); values[12] = PyTuple_GET_ITEM(__pyx_args, 12); values[11] = PyTuple_GET_ITEM(__pyx_args, 11); values[10] = PyTuple_GET_ITEM(__pyx_args, 10); values[9] = PyTuple_GET_ITEM(__pyx_args, 9); values[8] = PyTuple_GET_ITEM(__pyx_args, 8); values[7] = PyTuple_GET_ITEM(__pyx_args, 7); values[6] = PyTuple_GET_ITEM(__pyx_args, 6); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[3] = PyTuple_GET_ITEM(__pyx_args, 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_plan = __Pyx_PyObject_to_MemoryviewSlice_dc_long(values[0]); if (unlikely(!__pyx_v_plan.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_seq1_index = __Pyx_PyObject_to_MemoryviewSlice_dc_long(values[1]); if (unlikely(!__pyx_v_seq1_index.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_seq2_index = __Pyx_PyObject_to_MemoryviewSlice_dc_long(values[2]); if (unlikely(!__pyx_v_seq2_index.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_i_low = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_i_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_i_high = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_i_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_j_low = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_j_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_j_high = __Pyx_PyInt_AsInt(values[6]); if (unlikely((__pyx_v_j_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_preds = values[7]; __pyx_v_state_directions = __Pyx_PyObject_to_MemoryviewSlice_d_dc_long(values[8]); if (unlikely(!__pyx_v_state_directions.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_T = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(values[9]); if (unlikely(!__pyx_v_T.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_xgap_scores = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(values[10]); if (unlikely(!__pyx_v_xgap_scores.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_ygap_scores = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(values[11]); if (unlikely(!__pyx_v_ygap_scores.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_match_scores = __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_double(values[12]); if (unlikely(!__pyx_v_match_scores.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_rows = values[13]; __pyx_v_track = __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_unsigned_char(values[14]); if (unlikely(!__pyx_v_track.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_track_enc = values[15]; __pyx_v_viterbi = __Pyx_PyInt_AsInt(values[16]); if (unlikely((__pyx_v_viterbi == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L3_error;} if (values[17]) { __pyx_v_use_logs = __Pyx_PyInt_AsInt(values[17]); if (unlikely((__pyx_v_use_logs == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { __pyx_v_use_logs = ((int)0); } if (values[18]) { __pyx_v_local = __Pyx_PyInt_AsInt(values[18]); if (unlikely((__pyx_v_local == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { /* "cogent/align/_pairwise_pogs.pyx":37 * Long2D state_directions, Double2D T, * Double2D xgap_scores, Double2D ygap_scores, Double3D match_scores, * rows, UChar3D track, track_enc, int viterbi, int use_logs=0, int local=False, # <<<<<<<<<<<<<< * int use_scaling=True): * */ __pyx_v_local = ((int)0); } if (values[19]) { __pyx_v_use_scaling = __Pyx_PyInt_AsInt(values[19]); if (unlikely((__pyx_v_use_scaling == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { /* "cogent/align/_pairwise_pogs.pyx":38 * Double2D xgap_scores, Double2D ygap_scores, Double3D match_scores, * rows, UChar3D track, track_enc, int viterbi, int use_logs=0, int local=False, * int use_scaling=True): # <<<<<<<<<<<<<< * * """The ultimate in 2D Pyrex dynamic programming - Forward or Viterbi */ __pyx_v_use_scaling = ((int)1); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("cogent.align._pairwise_pogs.calc_rows", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_6cogent_5align_14_pairwise_pogs_2calc_rows(__pyx_self, __pyx_v_plan, __pyx_v_seq1_index, __pyx_v_seq2_index, __pyx_v_i_low, __pyx_v_i_high, __pyx_v_j_low, __pyx_v_j_high, __pyx_v_preds, __pyx_v_state_directions, __pyx_v_T, __pyx_v_xgap_scores, __pyx_v_ygap_scores, __pyx_v_match_scores, __pyx_v_rows, __pyx_v_track, __pyx_v_track_enc, __pyx_v_viterbi, __pyx_v_use_logs, __pyx_v_local, __pyx_v_use_scaling); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cogent/align/_pairwise_pogs.pyx":33 * ctypedef unsigned char [:,:,::1] UChar3D * * def calc_rows(Long1D plan, Long1D seq1_index, Long1D seq2_index, # <<<<<<<<<<<<<< * int i_low, int i_high, int j_low, int j_high, preds, * Long2D state_directions, Double2D T, */ static PyObject *__pyx_pf_6cogent_5align_14_pairwise_pogs_2calc_rows(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_plan, __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_seq1_index, __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_seq2_index, int __pyx_v_i_low, int __pyx_v_i_high, int __pyx_v_j_low, int __pyx_v_j_high, PyObject *__pyx_v_preds, __pyx_t_6cogent_5align_14_pairwise_pogs_Long2D __pyx_v_state_directions, __pyx_t_6cogent_5align_14_pairwise_pogs_Double2D __pyx_v_T, __pyx_t_6cogent_5align_14_pairwise_pogs_Double2D __pyx_v_xgap_scores, __pyx_t_6cogent_5align_14_pairwise_pogs_Double2D __pyx_v_ygap_scores, __pyx_t_6cogent_5align_14_pairwise_pogs_Double3D __pyx_v_match_scores, PyObject *__pyx_v_rows, __pyx_t_6cogent_5align_14_pairwise_pogs_UChar3D __pyx_v_track, PyObject *__pyx_v_track_enc, int __pyx_v_viterbi, int __pyx_v_use_logs, int __pyx_v_local, int __pyx_v_use_scaling) { int __pyx_v_prev_i; int __pyx_v_prev_j; int __pyx_v_state; int __pyx_v_prev_state; int __pyx_v_min_prev_state; int __pyx_v_N; int __pyx_v_row_length; int __pyx_v_row_length1; int __pyx_v_row_count; int __pyx_v_row_count1; int __pyx_v_tmp_rows; int __pyx_v_a_count; int __pyx_v_a; int __pyx_v_b; int __pyx_v_a_low; int __pyx_v_a_high; int __pyx_v_b_low; int __pyx_v_b_high; int __pyx_v_dest_states; int __pyx_v_dest_state; int __pyx_v_d4; int __pyx_v_j; int __pyx_v_i; int __pyx_v_last_i; int __pyx_v_last_j; int __pyx_v_last_state; int __pyx_v_bin; int __pyx_v_x; int __pyx_v_y; int __pyx_v_bin_count; int __pyx_v_max_x; int __pyx_v_max_y; int __pyx_v_current_row_index; int __pyx_v_source_row_index; int __pyx_v_source_row_index_cache[256]; int __pyx_v_i_link_count; int __pyx_v_j_link_count; int __pyx_v_dx; int __pyx_v_dy; int __pyx_v_tcode_x; int __pyx_v_tcode_y; int __pyx_v_tcode_s; double __pyx_v_d_score; double __pyx_v_mantissa; double __pyx_v_partial_sum; double __pyx_v_sub_partial_sum; double __pyx_v_max_mantissa; double __pyx_v_overall_max_mantissa; long __pyx_v_exponent; long __pyx_v_max_exponent; long __pyx_v_overall_max_exponent; __pyx_t_6cogent_5align_14_pairwise_pogs_Double3D __pyx_v_mantissas = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Long3D __pyx_v_exponents = { 0, 0, { 0 }, { 0 }, { 0 } }; long __pyx_v_pointer_a; long __pyx_v_pointer_b; long __pyx_v_pointer_state; __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_i_sources = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_i_sources_offsets = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_j_sources = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_v_j_sources_offsets = { 0, 0, { 0 }, { 0 }, { 0 } }; long __pyx_v_i_sources_start; long __pyx_v_i_sources_end; long __pyx_v_j_sources_start; long __pyx_v_j_sources_end; PyObject *__pyx_v_pog1 = NULL; PyObject *__pyx_v_pog2 = NULL; double __pyx_v_impossible; double __pyx_v_score; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_t_4; long __pyx_t_5; 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; PyObject *(*__pyx_t_12)(PyObject *); PyObject *__pyx_t_13 = NULL; __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_t_14 = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Long1D __pyx_t_15 = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Double3D __pyx_t_16 = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_pogs_Long3D __pyx_t_17 = { 0, 0, { 0 }, { 0 }, { 0 } }; int __pyx_t_18; int __pyx_t_19; __pyx_t_6cogent_5align_14_pairwise_pogs_UChar3D __pyx_t_20 = { 0, 0, { 0 }, { 0 }, { 0 } }; int __pyx_t_21; int __pyx_t_22; long __pyx_t_23; int __pyx_t_24; double __pyx_t_25; Py_ssize_t __pyx_t_26; Py_ssize_t __pyx_t_27; int __pyx_t_28; Py_ssize_t __pyx_t_29; Py_ssize_t __pyx_t_30; int __pyx_t_31; Py_ssize_t __pyx_t_32; Py_ssize_t __pyx_t_33; int __pyx_t_34; Py_ssize_t __pyx_t_35; Py_ssize_t __pyx_t_36; int __pyx_t_37; int __pyx_t_38; long __pyx_t_39; int __pyx_t_40; int __pyx_t_41; Py_ssize_t __pyx_t_42; int __pyx_t_43; Py_ssize_t __pyx_t_44; int __pyx_t_45; Py_ssize_t __pyx_t_46; int __pyx_t_47; Py_ssize_t __pyx_t_48; int __pyx_t_49; int __pyx_t_50; long __pyx_t_51; int __pyx_t_52; int __pyx_t_53; int __pyx_t_54; int __pyx_t_55; int __pyx_t_56; int __pyx_t_57; int __pyx_t_58; int __pyx_t_59; int __pyx_t_60; int __pyx_t_61; int __pyx_t_62; long __pyx_t_63; int __pyx_t_64; int __pyx_t_65; int __pyx_t_66; int __pyx_t_67; int __pyx_t_68; int __pyx_t_69; int __pyx_t_70; int __pyx_t_71; int __pyx_t_72; int __pyx_t_73; int __pyx_t_74; int __pyx_t_75; int __pyx_t_76; int __pyx_t_77; int __pyx_t_78; int __pyx_t_79; int __pyx_t_80; int __pyx_t_81; int __pyx_t_82; int __pyx_t_83; int __pyx_t_84; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("calc_rows", 0); /* "cogent/align/_pairwise_pogs.pyx":77 * cdef long j_sources_start, j_sources_end * * assert not (use_logs and not viterbi) # <<<<<<<<<<<<<< * assert not (use_logs and use_scaling) * assert not (local and not viterbi) */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (__pyx_v_use_logs) { __pyx_t_1 = (!__pyx_v_viterbi); __pyx_t_2 = __pyx_t_1; } else { __pyx_t_2 = __pyx_v_use_logs; } if (unlikely(!(!__pyx_t_2))) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif /* "cogent/align/_pairwise_pogs.pyx":78 * * assert not (use_logs and not viterbi) * assert not (use_logs and use_scaling) # <<<<<<<<<<<<<< * assert not (local and not viterbi) * */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (__pyx_v_use_logs) { __pyx_t_2 = __pyx_v_use_scaling; } else { __pyx_t_2 = __pyx_v_use_logs; } if (unlikely(!(!__pyx_t_2))) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif /* "cogent/align/_pairwise_pogs.pyx":79 * assert not (use_logs and not viterbi) * assert not (use_logs and use_scaling) * assert not (local and not viterbi) # <<<<<<<<<<<<<< * * N = 0 */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (__pyx_v_local) { __pyx_t_2 = (!__pyx_v_viterbi); __pyx_t_1 = __pyx_t_2; } else { __pyx_t_1 = __pyx_v_local; } if (unlikely(!(!__pyx_t_1))) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif /* "cogent/align/_pairwise_pogs.pyx":81 * assert not (local and not viterbi) * * N = 0 # <<<<<<<<<<<<<< * checkArray2D(T, &N, &N) * row_length = 0 */ __pyx_v_N = 0; /* "cogent/align/_pairwise_pogs.pyx":82 * * N = 0 * checkArray2D(T, &N, &N) # <<<<<<<<<<<<<< * row_length = 0 * row_count = 0 */ __pyx_t_3 = __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray2D(__pyx_v_T, (&__pyx_v_N), (&__pyx_v_N)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":83 * N = 0 * checkArray2D(T, &N, &N) * row_length = 0 # <<<<<<<<<<<<<< * row_count = 0 * checkArray1D(plan, &row_count) */ __pyx_v_row_length = 0; /* "cogent/align/_pairwise_pogs.pyx":84 * checkArray2D(T, &N, &N) * row_length = 0 * row_count = 0 # <<<<<<<<<<<<<< * checkArray1D(plan, &row_count) * */ __pyx_v_row_count = 0; /* "cogent/align/_pairwise_pogs.pyx":85 * row_length = 0 * row_count = 0 * checkArray1D(plan, &row_count) # <<<<<<<<<<<<<< * * dest_states = 0 */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray1D(__pyx_v_plan, (&__pyx_v_row_count)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":87 * checkArray1D(plan, &row_count) * * dest_states = 0 # <<<<<<<<<<<<<< * d4 = 4 * # Array of (state, bin, dx, dy) tuples describing the HMM states. */ __pyx_v_dest_states = 0; /* "cogent/align/_pairwise_pogs.pyx":88 * * dest_states = 0 * d4 = 4 # <<<<<<<<<<<<<< * # Array of (state, bin, dx, dy) tuples describing the HMM states. * checkArray2D(state_directions, &dest_states, &d4) */ __pyx_v_d4 = 4; /* "cogent/align/_pairwise_pogs.pyx":90 * d4 = 4 * # Array of (state, bin, dx, dy) tuples describing the HMM states. * checkArray2D(state_directions, &dest_states, &d4) # <<<<<<<<<<<<<< * * checkArray1D(seq1_index, &row_count) */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray2D(__pyx_v_state_directions, (&__pyx_v_dest_states), (&__pyx_v_d4)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":92 * checkArray2D(state_directions, &dest_states, &d4) * * checkArray1D(seq1_index, &row_count) # <<<<<<<<<<<<<< * checkArray1D(seq2_index, &row_length) * */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray1D(__pyx_v_seq1_index, (&__pyx_v_row_count)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":93 * * checkArray1D(seq1_index, &row_count) * checkArray1D(seq2_index, &row_length) # <<<<<<<<<<<<<< * * max_x = max_y = bin_count = 0 */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray1D(__pyx_v_seq2_index, (&__pyx_v_row_length)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":95 * checkArray1D(seq2_index, &row_length) * * max_x = max_y = bin_count = 0 # <<<<<<<<<<<<<< * checkArray3D(match_scores, &bin_count, &max_x, &max_y) * checkArray2D(xgap_scores, &bin_count, &max_x) */ __pyx_v_max_x = 0; __pyx_v_max_y = 0; __pyx_v_bin_count = 0; /* "cogent/align/_pairwise_pogs.pyx":96 * * max_x = max_y = bin_count = 0 * checkArray3D(match_scores, &bin_count, &max_x, &max_y) # <<<<<<<<<<<<<< * checkArray2D(xgap_scores, &bin_count, &max_x) * checkArray2D(ygap_scores, &bin_count, &max_y) */ __pyx_t_3 = __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray3D(__pyx_v_match_scores, (&__pyx_v_bin_count), (&__pyx_v_max_x), (&__pyx_v_max_y)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":97 * max_x = max_y = bin_count = 0 * checkArray3D(match_scores, &bin_count, &max_x, &max_y) * checkArray2D(xgap_scores, &bin_count, &max_x) # <<<<<<<<<<<<<< * checkArray2D(ygap_scores, &bin_count, &max_y) * */ __pyx_t_3 = __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray2D(__pyx_v_xgap_scores, (&__pyx_v_bin_count), (&__pyx_v_max_x)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":98 * checkArray3D(match_scores, &bin_count, &max_x, &max_y) * checkArray2D(xgap_scores, &bin_count, &max_x) * checkArray2D(ygap_scores, &bin_count, &max_y) # <<<<<<<<<<<<<< * * for i from 0 <= i < row_count: */ __pyx_t_3 = __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray2D(__pyx_v_ygap_scores, (&__pyx_v_bin_count), (&__pyx_v_max_y)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":100 * checkArray2D(ygap_scores, &bin_count, &max_y) * * for i from 0 <= i < row_count: # <<<<<<<<<<<<<< * assert 0 <= seq1_index[i] < max_x * for j from 0 <= j < row_length: */ __pyx_t_3 = __pyx_v_row_count; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { /* "cogent/align/_pairwise_pogs.pyx":101 * * for i from 0 <= i < row_count: * assert 0 <= seq1_index[i] < max_x # <<<<<<<<<<<<<< * for j from 0 <= j < row_length: * assert 0 <= seq2_index[j] < max_y */ #ifndef CYTHON_WITHOUT_ASSERTIONS __pyx_t_4 = __pyx_v_i; __pyx_t_5 = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_seq1_index.data) + __pyx_t_4)) ))); __pyx_t_1 = (0 <= __pyx_t_5); if (__pyx_t_1) { __pyx_t_1 = (__pyx_t_5 < __pyx_v_max_x); } if (unlikely(!__pyx_t_1)) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif } /* "cogent/align/_pairwise_pogs.pyx":102 * for i from 0 <= i < row_count: * assert 0 <= seq1_index[i] < max_x * for j from 0 <= j < row_length: # <<<<<<<<<<<<<< * assert 0 <= seq2_index[j] < max_y * */ __pyx_t_3 = __pyx_v_row_length; for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { /* "cogent/align/_pairwise_pogs.pyx":103 * assert 0 <= seq1_index[i] < max_x * for j from 0 <= j < row_length: * assert 0 <= seq2_index[j] < max_y # <<<<<<<<<<<<<< * * assert j_low >= 0 and j_high > j_low and j_high <= row_length */ #ifndef CYTHON_WITHOUT_ASSERTIONS __pyx_t_6 = __pyx_v_j; __pyx_t_5 = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_seq2_index.data) + __pyx_t_6)) ))); __pyx_t_1 = (0 <= __pyx_t_5); if (__pyx_t_1) { __pyx_t_1 = (__pyx_t_5 < __pyx_v_max_y); } if (unlikely(!__pyx_t_1)) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif } /* "cogent/align/_pairwise_pogs.pyx":105 * assert 0 <= seq2_index[j] < max_y * * assert j_low >= 0 and j_high > j_low and j_high <= row_length # <<<<<<<<<<<<<< * * (pog1, pog2) = preds */ #ifndef CYTHON_WITHOUT_ASSERTIONS __pyx_t_1 = (__pyx_v_j_low >= 0); if (__pyx_t_1) { __pyx_t_2 = (__pyx_v_j_high > __pyx_v_j_low); if (__pyx_t_2) { __pyx_t_7 = (__pyx_v_j_high <= __pyx_v_row_length); __pyx_t_8 = __pyx_t_7; } else { __pyx_t_8 = __pyx_t_2; } __pyx_t_2 = __pyx_t_8; } else { __pyx_t_2 = __pyx_t_1; } if (unlikely(!__pyx_t_2)) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif /* "cogent/align/_pairwise_pogs.pyx":107 * assert j_low >= 0 and j_high > j_low and j_high <= row_length * * (pog1, pog2) = preds # <<<<<<<<<<<<<< * (j_sources, j_sources_offsets) = pog2.asCombinedArray() * j_link_count = 0 */ if ((likely(PyTuple_CheckExact(__pyx_v_preds))) || (PyList_CheckExact(__pyx_v_preds))) { PyObject* sequence = __pyx_v_preds; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_9 = PyList_GET_ITEM(sequence, 0); __pyx_t_10 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(__pyx_t_10); #else __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { Py_ssize_t index = -1; __pyx_t_11 = PyObject_GetIter(__pyx_v_preds); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __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_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L8_unpacking_done:; } __pyx_v_pog1 = __pyx_t_9; __pyx_t_9 = 0; __pyx_v_pog2 = __pyx_t_10; __pyx_t_10 = 0; /* "cogent/align/_pairwise_pogs.pyx":108 * * (pog1, pog2) = preds * (j_sources, j_sources_offsets) = pog2.asCombinedArray() # <<<<<<<<<<<<<< * j_link_count = 0 * checkArray1D(j_sources, &j_link_count) */ __pyx_t_10 = PyObject_GetAttr(__pyx_v_pog2, __pyx_n_s__asCombinedArray); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_9 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; if ((likely(PyTuple_CheckExact(__pyx_t_9))) || (PyList_CheckExact(__pyx_t_9))) { PyObject* sequence = __pyx_t_9; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if CYTHON_COMPILING_IN_CPYTHON 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_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } else { Py_ssize_t index = -1; __pyx_t_13 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_12 = Py_TYPE(__pyx_t_13)->tp_iternext; index = 0; __pyx_t_10 = __pyx_t_12(__pyx_t_13); if (unlikely(!__pyx_t_10)) goto __pyx_L9_unpacking_failed; __Pyx_GOTREF(__pyx_t_10); index = 1; __pyx_t_11 = __pyx_t_12(__pyx_t_13); if (unlikely(!__pyx_t_11)) goto __pyx_L9_unpacking_failed; __Pyx_GOTREF(__pyx_t_11); if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_13), 2) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_12 = NULL; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; goto __pyx_L10_unpacking_done; __pyx_L9_unpacking_failed:; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_12 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L10_unpacking_done:; } __pyx_t_14 = __Pyx_PyObject_to_MemoryviewSlice_dc_long(__pyx_t_10); if (unlikely(!__pyx_t_14.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_dc_long(__pyx_t_11); if (unlikely(!__pyx_t_15.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_v_j_sources = __pyx_t_14; __pyx_t_14.memview = NULL; __pyx_t_14.data = NULL; __pyx_v_j_sources_offsets = __pyx_t_15; __pyx_t_15.memview = NULL; __pyx_t_15.data = NULL; /* "cogent/align/_pairwise_pogs.pyx":109 * (pog1, pog2) = preds * (j_sources, j_sources_offsets) = pog2.asCombinedArray() * j_link_count = 0 # <<<<<<<<<<<<<< * checkArray1D(j_sources, &j_link_count) * row_length1 = row_length + 1 */ __pyx_v_j_link_count = 0; /* "cogent/align/_pairwise_pogs.pyx":110 * (j_sources, j_sources_offsets) = pog2.asCombinedArray() * j_link_count = 0 * checkArray1D(j_sources, &j_link_count) # <<<<<<<<<<<<<< * row_length1 = row_length + 1 * checkArray1D(j_sources_offsets, &row_length1) */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray1D(__pyx_v_j_sources, (&__pyx_v_j_link_count)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":111 * j_link_count = 0 * checkArray1D(j_sources, &j_link_count) * row_length1 = row_length + 1 # <<<<<<<<<<<<<< * checkArray1D(j_sources_offsets, &row_length1) * */ __pyx_v_row_length1 = (__pyx_v_row_length + 1); /* "cogent/align/_pairwise_pogs.pyx":112 * checkArray1D(j_sources, &j_link_count) * row_length1 = row_length + 1 * checkArray1D(j_sources_offsets, &row_length1) # <<<<<<<<<<<<<< * * (i_sources, i_sources_offsets) = pog1.asCombinedArray() */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray1D(__pyx_v_j_sources_offsets, (&__pyx_v_row_length1)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":114 * checkArray1D(j_sources_offsets, &row_length1) * * (i_sources, i_sources_offsets) = pog1.asCombinedArray() # <<<<<<<<<<<<<< * i_link_count = 0 * checkArray1D(i_sources, &i_link_count) */ __pyx_t_9 = PyObject_GetAttr(__pyx_v_pog1, __pyx_n_s__asCombinedArray); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_11 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) { PyObject* sequence = __pyx_t_11; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_9 = PyList_GET_ITEM(sequence, 0); __pyx_t_10 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(__pyx_t_10); #else __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } else { Py_ssize_t index = -1; __pyx_t_13 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_12 = Py_TYPE(__pyx_t_13)->tp_iternext; index = 0; __pyx_t_9 = __pyx_t_12(__pyx_t_13); if (unlikely(!__pyx_t_9)) goto __pyx_L11_unpacking_failed; __Pyx_GOTREF(__pyx_t_9); index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_13); if (unlikely(!__pyx_t_10)) goto __pyx_L11_unpacking_failed; __Pyx_GOTREF(__pyx_t_10); if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_13), 2) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_12 = NULL; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; goto __pyx_L12_unpacking_done; __pyx_L11_unpacking_failed:; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_12 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L12_unpacking_done:; } __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_dc_long(__pyx_t_9); if (unlikely(!__pyx_t_15.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_14 = __Pyx_PyObject_to_MemoryviewSlice_dc_long(__pyx_t_10); if (unlikely(!__pyx_t_14.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_v_i_sources = __pyx_t_15; __pyx_t_15.memview = NULL; __pyx_t_15.data = NULL; __pyx_v_i_sources_offsets = __pyx_t_14; __pyx_t_14.memview = NULL; __pyx_t_14.data = NULL; /* "cogent/align/_pairwise_pogs.pyx":115 * * (i_sources, i_sources_offsets) = pog1.asCombinedArray() * i_link_count = 0 # <<<<<<<<<<<<<< * checkArray1D(i_sources, &i_link_count) * row_count1 = row_count + 1 */ __pyx_v_i_link_count = 0; /* "cogent/align/_pairwise_pogs.pyx":116 * (i_sources, i_sources_offsets) = pog1.asCombinedArray() * i_link_count = 0 * checkArray1D(i_sources, &i_link_count) # <<<<<<<<<<<<<< * row_count1 = row_count + 1 * checkArray1D(i_sources_offsets, &row_count1) */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray1D(__pyx_v_i_sources, (&__pyx_v_i_link_count)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":117 * i_link_count = 0 * checkArray1D(i_sources, &i_link_count) * row_count1 = row_count + 1 # <<<<<<<<<<<<<< * checkArray1D(i_sources_offsets, &row_count1) * */ __pyx_v_row_count1 = (__pyx_v_row_count + 1); /* "cogent/align/_pairwise_pogs.pyx":118 * checkArray1D(i_sources, &i_link_count) * row_count1 = row_count + 1 * checkArray1D(i_sources_offsets, &row_count1) # <<<<<<<<<<<<<< * * (mantissas, exponents) = rows */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray1D(__pyx_v_i_sources_offsets, (&__pyx_v_row_count1)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":120 * checkArray1D(i_sources_offsets, &row_count1) * * (mantissas, exponents) = rows # <<<<<<<<<<<<<< * tmp_rows = 0 * checkArray3D(mantissas, &tmp_rows, &row_length, &N) */ if ((likely(PyTuple_CheckExact(__pyx_v_rows))) || (PyList_CheckExact(__pyx_v_rows))) { PyObject* sequence = __pyx_v_rows; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_11 = PyList_GET_ITEM(sequence, 0); __pyx_t_10 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(__pyx_t_10); #else __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { Py_ssize_t index = -1; __pyx_t_9 = PyObject_GetIter(__pyx_v_rows); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_12 = Py_TYPE(__pyx_t_9)->tp_iternext; index = 0; __pyx_t_11 = __pyx_t_12(__pyx_t_9); if (unlikely(!__pyx_t_11)) goto __pyx_L13_unpacking_failed; __Pyx_GOTREF(__pyx_t_11); index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_9); if (unlikely(!__pyx_t_10)) goto __pyx_L13_unpacking_failed; __Pyx_GOTREF(__pyx_t_10); if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_9), 2) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_12 = NULL; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L14_unpacking_done; __pyx_L13_unpacking_failed:; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_12 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L14_unpacking_done:; } __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_double(__pyx_t_11); if (unlikely(!__pyx_t_16.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_17 = __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_long(__pyx_t_10); if (unlikely(!__pyx_t_17.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_v_mantissas = __pyx_t_16; __pyx_t_16.memview = NULL; __pyx_t_16.data = NULL; __pyx_v_exponents = __pyx_t_17; __pyx_t_17.memview = NULL; __pyx_t_17.data = NULL; /* "cogent/align/_pairwise_pogs.pyx":121 * * (mantissas, exponents) = rows * tmp_rows = 0 # <<<<<<<<<<<<<< * checkArray3D(mantissas, &tmp_rows, &row_length, &N) * if use_scaling: */ __pyx_v_tmp_rows = 0; /* "cogent/align/_pairwise_pogs.pyx":122 * (mantissas, exponents) = rows * tmp_rows = 0 * checkArray3D(mantissas, &tmp_rows, &row_length, &N) # <<<<<<<<<<<<<< * if use_scaling: * checkArray3D(exponents, &tmp_rows, &row_length, &N) */ __pyx_t_3 = __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray3D(__pyx_v_mantissas, (&__pyx_v_tmp_rows), (&__pyx_v_row_length), (&__pyx_v_N)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":123 * tmp_rows = 0 * checkArray3D(mantissas, &tmp_rows, &row_length, &N) * if use_scaling: # <<<<<<<<<<<<<< * checkArray3D(exponents, &tmp_rows, &row_length, &N) * */ if (__pyx_v_use_scaling) { /* "cogent/align/_pairwise_pogs.pyx":124 * checkArray3D(mantissas, &tmp_rows, &row_length, &N) * if use_scaling: * checkArray3D(exponents, &tmp_rows, &row_length, &N) # <<<<<<<<<<<<<< * * cdef double impossible */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray3D(__pyx_v_exponents, (&__pyx_v_tmp_rows), (&__pyx_v_row_length), (&__pyx_v_N)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L15; } __pyx_L15:; /* "cogent/align/_pairwise_pogs.pyx":127 * * cdef double impossible * if use_logs: # <<<<<<<<<<<<<< * impossible = log(0.0) # -inf * else: */ if (__pyx_v_use_logs) { /* "cogent/align/_pairwise_pogs.pyx":128 * cdef double impossible * if use_logs: * impossible = log(0.0) # -inf # <<<<<<<<<<<<<< * else: * impossible = 0.0 */ __pyx_v_impossible = log(0.0); goto __pyx_L16; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":130 * impossible = log(0.0) # -inf * else: * impossible = 0.0 # <<<<<<<<<<<<<< * * if viterbi and track is not None and track_enc is not None: */ __pyx_v_impossible = 0.0; } __pyx_L16:; /* "cogent/align/_pairwise_pogs.pyx":132 * impossible = 0.0 * * if viterbi and track is not None and track_enc is not None: # <<<<<<<<<<<<<< * checkArray3D(track, &row_count, &row_length, &N) * (tcode_x, tcode_y, tcode_s) = track_enc */ if (__pyx_v_viterbi) { __pyx_t_2 = (((PyObject *) __pyx_v_track.memview) != Py_None); if (__pyx_t_2) { __pyx_t_1 = (__pyx_v_track_enc != Py_None); __pyx_t_8 = __pyx_t_1; } else { __pyx_t_8 = __pyx_t_2; } __pyx_t_2 = __pyx_t_8; } else { __pyx_t_2 = __pyx_v_viterbi; } if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":133 * * if viterbi and track is not None and track_enc is not None: * checkArray3D(track, &row_count, &row_length, &N) # <<<<<<<<<<<<<< * (tcode_x, tcode_y, tcode_s) = track_enc * else: */ __pyx_t_3 = __pyx_fuse_2_2__pyx_f_6cogent_5align_14_pairwise_pogs_checkArray3D(__pyx_v_track, (&__pyx_v_row_count), (&__pyx_v_row_length), (&__pyx_v_N)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":134 * if viterbi and track is not None and track_enc is not None: * checkArray3D(track, &row_count, &row_length, &N) * (tcode_x, tcode_y, tcode_s) = track_enc # <<<<<<<<<<<<<< * else: * track = None */ if ((likely(PyTuple_CheckExact(__pyx_v_track_enc))) || (PyList_CheckExact(__pyx_v_track_enc))) { PyObject* sequence = __pyx_v_track_enc; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 3)) { if (size > 3) __Pyx_RaiseTooManyValuesError(3); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); __pyx_t_9 = PyTuple_GET_ITEM(sequence, 2); } else { __pyx_t_10 = PyList_GET_ITEM(sequence, 0); __pyx_t_11 = PyList_GET_ITEM(sequence, 1); __pyx_t_9 = PyList_GET_ITEM(sequence, 2); } __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(__pyx_t_9); #else __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_9 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { Py_ssize_t index = -1; __pyx_t_13 = PyObject_GetIter(__pyx_v_track_enc); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_13); __pyx_t_12 = Py_TYPE(__pyx_t_13)->tp_iternext; index = 0; __pyx_t_10 = __pyx_t_12(__pyx_t_13); if (unlikely(!__pyx_t_10)) goto __pyx_L18_unpacking_failed; __Pyx_GOTREF(__pyx_t_10); index = 1; __pyx_t_11 = __pyx_t_12(__pyx_t_13); if (unlikely(!__pyx_t_11)) goto __pyx_L18_unpacking_failed; __Pyx_GOTREF(__pyx_t_11); index = 2; __pyx_t_9 = __pyx_t_12(__pyx_t_13); if (unlikely(!__pyx_t_9)) goto __pyx_L18_unpacking_failed; __Pyx_GOTREF(__pyx_t_9); if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_13), 3) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_12 = NULL; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; goto __pyx_L19_unpacking_done; __pyx_L18_unpacking_failed:; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_12 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L19_unpacking_done:; } __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_10); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_t_11); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_19 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_19 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_tcode_x = __pyx_t_3; __pyx_v_tcode_y = __pyx_t_18; __pyx_v_tcode_s = __pyx_t_19; goto __pyx_L17; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":136 * (tcode_x, tcode_y, tcode_s) = track_enc * else: * track = None # <<<<<<<<<<<<<< * tcode_x = tcode_y = tcode_s = 0 * */ __pyx_t_20 = __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_unsigned_char(Py_None); if (unlikely(!__pyx_t_20.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __PYX_XDEC_MEMVIEW(&__pyx_v_track, 1); __pyx_v_track = __pyx_t_20; __pyx_t_20.memview = NULL; __pyx_t_20.data = NULL; /* "cogent/align/_pairwise_pogs.pyx":137 * else: * track = None * tcode_x = tcode_y = tcode_s = 0 # <<<<<<<<<<<<<< * * # For local */ __pyx_v_tcode_x = 0; __pyx_v_tcode_y = 0; __pyx_v_tcode_s = 0; } __pyx_L17:; /* "cogent/align/_pairwise_pogs.pyx":140 * * # For local * overall_max_exponent = MIN_SCALE # <<<<<<<<<<<<<< * overall_max_mantissa = impossible * last_i = last_j = last_state = -1 */ __pyx_v_overall_max_exponent = __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_SCALE; /* "cogent/align/_pairwise_pogs.pyx":141 * # For local * overall_max_exponent = MIN_SCALE * overall_max_mantissa = impossible # <<<<<<<<<<<<<< * last_i = last_j = last_state = -1 * */ __pyx_v_overall_max_mantissa = __pyx_v_impossible; /* "cogent/align/_pairwise_pogs.pyx":142 * overall_max_exponent = MIN_SCALE * overall_max_mantissa = impossible * last_i = last_j = last_state = -1 # <<<<<<<<<<<<<< * * for i from i_low <= i < i_high: */ __pyx_v_last_i = -1; __pyx_v_last_j = -1; __pyx_v_last_state = -1; /* "cogent/align/_pairwise_pogs.pyx":144 * last_i = last_j = last_state = -1 * * for i from i_low <= i < i_high: # <<<<<<<<<<<<<< * x = seq1_index[i] * */ __pyx_t_19 = __pyx_v_i_high; for (__pyx_v_i = __pyx_v_i_low; __pyx_v_i < __pyx_t_19; __pyx_v_i++) { /* "cogent/align/_pairwise_pogs.pyx":145 * * for i from i_low <= i < i_high: * x = seq1_index[i] # <<<<<<<<<<<<<< * * if PyErr_CheckSignals(): */ __pyx_t_18 = __pyx_v_i; __pyx_v_x = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_seq1_index.data) + __pyx_t_18)) ))); /* "cogent/align/_pairwise_pogs.pyx":147 * x = seq1_index[i] * * if PyErr_CheckSignals(): # <<<<<<<<<<<<<< * raise PyErr_Occurred() * */ __pyx_t_3 = PyErr_CheckSignals(); if (__pyx_t_3) { /* "cogent/align/_pairwise_pogs.pyx":148 * * if PyErr_CheckSignals(): * raise PyErr_Occurred() # <<<<<<<<<<<<<< * * i_sources_start = i_sources_offsets[i] */ __pyx_t_9 = PyErr_Occurred(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[1]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L22; } __pyx_L22:; /* "cogent/align/_pairwise_pogs.pyx":150 * raise PyErr_Occurred() * * i_sources_start = i_sources_offsets[i] # <<<<<<<<<<<<<< * i_sources_end = i_sources_offsets[i+1] * */ __pyx_t_3 = __pyx_v_i; __pyx_v_i_sources_start = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_i_sources_offsets.data) + __pyx_t_3)) ))); /* "cogent/align/_pairwise_pogs.pyx":151 * * i_sources_start = i_sources_offsets[i] * i_sources_end = i_sources_offsets[i+1] # <<<<<<<<<<<<<< * * current_row_index = plan[i] */ __pyx_t_5 = (__pyx_v_i + 1); __pyx_v_i_sources_end = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_i_sources_offsets.data) + __pyx_t_5)) ))); /* "cogent/align/_pairwise_pogs.pyx":153 * i_sources_end = i_sources_offsets[i+1] * * current_row_index = plan[i] # <<<<<<<<<<<<<< * source_row_index_cache[0] = current_row_index * */ __pyx_t_21 = __pyx_v_i; __pyx_v_current_row_index = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_plan.data) + __pyx_t_21)) ))); /* "cogent/align/_pairwise_pogs.pyx":154 * * current_row_index = plan[i] * source_row_index_cache[0] = current_row_index # <<<<<<<<<<<<<< * * a_count = i_sources_end-i_sources_start */ (__pyx_v_source_row_index_cache[0]) = __pyx_v_current_row_index; /* "cogent/align/_pairwise_pogs.pyx":156 * source_row_index_cache[0] = current_row_index * * a_count = i_sources_end-i_sources_start # <<<<<<<<<<<<<< * for a from 0 <= a < a_count: * prev_i = i_sources[a+i_sources_start] */ __pyx_v_a_count = (__pyx_v_i_sources_end - __pyx_v_i_sources_start); /* "cogent/align/_pairwise_pogs.pyx":157 * * a_count = i_sources_end-i_sources_start * for a from 0 <= a < a_count: # <<<<<<<<<<<<<< * prev_i = i_sources[a+i_sources_start] * source_row_index_cache[a+1] = plan[prev_i] */ __pyx_t_22 = __pyx_v_a_count; for (__pyx_v_a = 0; __pyx_v_a < __pyx_t_22; __pyx_v_a++) { /* "cogent/align/_pairwise_pogs.pyx":158 * a_count = i_sources_end-i_sources_start * for a from 0 <= a < a_count: * prev_i = i_sources[a+i_sources_start] # <<<<<<<<<<<<<< * source_row_index_cache[a+1] = plan[prev_i] * */ __pyx_t_23 = (__pyx_v_a + __pyx_v_i_sources_start); __pyx_v_prev_i = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_i_sources.data) + __pyx_t_23)) ))); /* "cogent/align/_pairwise_pogs.pyx":159 * for a from 0 <= a < a_count: * prev_i = i_sources[a+i_sources_start] * source_row_index_cache[a+1] = plan[prev_i] # <<<<<<<<<<<<<< * * if i == 0: */ __pyx_t_24 = __pyx_v_prev_i; (__pyx_v_source_row_index_cache[(__pyx_v_a + 1)]) = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_plan.data) + __pyx_t_24)) ))); } /* "cogent/align/_pairwise_pogs.pyx":161 * source_row_index_cache[a+1] = plan[prev_i] * * if i == 0: # <<<<<<<<<<<<<< * mantissas[current_row_index, 0, 0] = (0.0 if use_logs else 1.0) * if use_scaling: */ __pyx_t_2 = (__pyx_v_i == 0); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":162 * * if i == 0: * mantissas[current_row_index, 0, 0] = (0.0 if use_logs else 1.0) # <<<<<<<<<<<<<< * if use_scaling: * exponents[current_row_index, 0, 0] = 0 */ if (__pyx_v_use_logs) { __pyx_t_25 = 0.0; } else { __pyx_t_25 = 1.0; } __pyx_t_22 = __pyx_v_current_row_index; __pyx_t_26 = 0; __pyx_t_27 = 0; *((double *) ( /* dim=2 */ ((char *) (((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_mantissas.data + __pyx_t_22 * __pyx_v_mantissas.strides[0]) ) + __pyx_t_26 * __pyx_v_mantissas.strides[1]) )) + __pyx_t_27)) )) = __pyx_t_25; /* "cogent/align/_pairwise_pogs.pyx":163 * if i == 0: * mantissas[current_row_index, 0, 0] = (0.0 if use_logs else 1.0) * if use_scaling: # <<<<<<<<<<<<<< * exponents[current_row_index, 0, 0] = 0 * else: */ if (__pyx_v_use_scaling) { /* "cogent/align/_pairwise_pogs.pyx":164 * mantissas[current_row_index, 0, 0] = (0.0 if use_logs else 1.0) * if use_scaling: * exponents[current_row_index, 0, 0] = 0 # <<<<<<<<<<<<<< * else: * mantissas[current_row_index, 0, 0] = impossible */ __pyx_t_28 = __pyx_v_current_row_index; __pyx_t_29 = 0; __pyx_t_30 = 0; *((long *) ( /* dim=2 */ ((char *) (((long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_exponents.data + __pyx_t_28 * __pyx_v_exponents.strides[0]) ) + __pyx_t_29 * __pyx_v_exponents.strides[1]) )) + __pyx_t_30)) )) = 0; goto __pyx_L26; } __pyx_L26:; goto __pyx_L25; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":166 * exponents[current_row_index, 0, 0] = 0 * else: * mantissas[current_row_index, 0, 0] = impossible # <<<<<<<<<<<<<< * if use_scaling: * exponents[current_row_index, 0, 0] = MIN_SCALE */ __pyx_t_31 = __pyx_v_current_row_index; __pyx_t_32 = 0; __pyx_t_33 = 0; *((double *) ( /* dim=2 */ ((char *) (((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_mantissas.data + __pyx_t_31 * __pyx_v_mantissas.strides[0]) ) + __pyx_t_32 * __pyx_v_mantissas.strides[1]) )) + __pyx_t_33)) )) = __pyx_v_impossible; /* "cogent/align/_pairwise_pogs.pyx":167 * else: * mantissas[current_row_index, 0, 0] = impossible * if use_scaling: # <<<<<<<<<<<<<< * exponents[current_row_index, 0, 0] = MIN_SCALE * */ if (__pyx_v_use_scaling) { /* "cogent/align/_pairwise_pogs.pyx":168 * mantissas[current_row_index, 0, 0] = impossible * if use_scaling: * exponents[current_row_index, 0, 0] = MIN_SCALE # <<<<<<<<<<<<<< * * j_sources_end = j_sources_offsets[j_low] */ __pyx_t_34 = __pyx_v_current_row_index; __pyx_t_35 = 0; __pyx_t_36 = 0; *((long *) ( /* dim=2 */ ((char *) (((long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_exponents.data + __pyx_t_34 * __pyx_v_exponents.strides[0]) ) + __pyx_t_35 * __pyx_v_exponents.strides[1]) )) + __pyx_t_36)) )) = __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_SCALE; goto __pyx_L27; } __pyx_L27:; } __pyx_L25:; /* "cogent/align/_pairwise_pogs.pyx":170 * exponents[current_row_index, 0, 0] = MIN_SCALE * * j_sources_end = j_sources_offsets[j_low] # <<<<<<<<<<<<<< * for j from j_low <= j < j_high: * j_sources_start = j_sources_end */ __pyx_t_37 = __pyx_v_j_low; __pyx_v_j_sources_end = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_j_sources_offsets.data) + __pyx_t_37)) ))); /* "cogent/align/_pairwise_pogs.pyx":171 * * j_sources_end = j_sources_offsets[j_low] * for j from j_low <= j < j_high: # <<<<<<<<<<<<<< * j_sources_start = j_sources_end * j_sources_end = j_sources_offsets[j+1] */ __pyx_t_38 = __pyx_v_j_high; for (__pyx_v_j = __pyx_v_j_low; __pyx_v_j < __pyx_t_38; __pyx_v_j++) { /* "cogent/align/_pairwise_pogs.pyx":172 * j_sources_end = j_sources_offsets[j_low] * for j from j_low <= j < j_high: * j_sources_start = j_sources_end # <<<<<<<<<<<<<< * j_sources_end = j_sources_offsets[j+1] * */ __pyx_v_j_sources_start = __pyx_v_j_sources_end; /* "cogent/align/_pairwise_pogs.pyx":173 * for j from j_low <= j < j_high: * j_sources_start = j_sources_end * j_sources_end = j_sources_offsets[j+1] # <<<<<<<<<<<<<< * * for dest_state from 0 <= dest_state < dest_states: */ __pyx_t_39 = (__pyx_v_j + 1); __pyx_v_j_sources_end = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_j_sources_offsets.data) + __pyx_t_39)) ))); /* "cogent/align/_pairwise_pogs.pyx":175 * j_sources_end = j_sources_offsets[j+1] * * for dest_state from 0 <= dest_state < dest_states: # <<<<<<<<<<<<<< * state = state_directions[dest_state, 0] * bin = state_directions[dest_state, 1] */ __pyx_t_40 = __pyx_v_dest_states; for (__pyx_v_dest_state = 0; __pyx_v_dest_state < __pyx_t_40; __pyx_v_dest_state++) { /* "cogent/align/_pairwise_pogs.pyx":176 * * for dest_state from 0 <= dest_state < dest_states: * state = state_directions[dest_state, 0] # <<<<<<<<<<<<<< * bin = state_directions[dest_state, 1] * dx = state_directions[dest_state, 2] */ __pyx_t_41 = __pyx_v_dest_state; __pyx_t_42 = 0; __pyx_v_state = (*((long *) ( /* dim=1 */ ((char *) (((long *) ( /* dim=0 */ (__pyx_v_state_directions.data + __pyx_t_41 * __pyx_v_state_directions.strides[0]) )) + __pyx_t_42)) ))); /* "cogent/align/_pairwise_pogs.pyx":177 * for dest_state from 0 <= dest_state < dest_states: * state = state_directions[dest_state, 0] * bin = state_directions[dest_state, 1] # <<<<<<<<<<<<<< * dx = state_directions[dest_state, 2] * dy = state_directions[dest_state, 3] */ __pyx_t_43 = __pyx_v_dest_state; __pyx_t_44 = 1; __pyx_v_bin = (*((long *) ( /* dim=1 */ ((char *) (((long *) ( /* dim=0 */ (__pyx_v_state_directions.data + __pyx_t_43 * __pyx_v_state_directions.strides[0]) )) + __pyx_t_44)) ))); /* "cogent/align/_pairwise_pogs.pyx":178 * state = state_directions[dest_state, 0] * bin = state_directions[dest_state, 1] * dx = state_directions[dest_state, 2] # <<<<<<<<<<<<<< * dy = state_directions[dest_state, 3] * */ __pyx_t_45 = __pyx_v_dest_state; __pyx_t_46 = 2; __pyx_v_dx = (*((long *) ( /* dim=1 */ ((char *) (((long *) ( /* dim=0 */ (__pyx_v_state_directions.data + __pyx_t_45 * __pyx_v_state_directions.strides[0]) )) + __pyx_t_46)) ))); /* "cogent/align/_pairwise_pogs.pyx":179 * bin = state_directions[dest_state, 1] * dx = state_directions[dest_state, 2] * dy = state_directions[dest_state, 3] # <<<<<<<<<<<<<< * * max_mantissa = impossible */ __pyx_t_47 = __pyx_v_dest_state; __pyx_t_48 = 3; __pyx_v_dy = (*((long *) ( /* dim=1 */ ((char *) (((long *) ( /* dim=0 */ (__pyx_v_state_directions.data + __pyx_t_47 * __pyx_v_state_directions.strides[0]) )) + __pyx_t_48)) ))); /* "cogent/align/_pairwise_pogs.pyx":181 * dy = state_directions[dest_state, 3] * * max_mantissa = impossible # <<<<<<<<<<<<<< * max_exponent = MIN_SCALE * partial_sum = 0.0 */ __pyx_v_max_mantissa = __pyx_v_impossible; /* "cogent/align/_pairwise_pogs.pyx":182 * * max_mantissa = impossible * max_exponent = MIN_SCALE # <<<<<<<<<<<<<< * partial_sum = 0.0 * pointer_state = N # ie ERROR */ __pyx_v_max_exponent = __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_SCALE; /* "cogent/align/_pairwise_pogs.pyx":183 * max_mantissa = impossible * max_exponent = MIN_SCALE * partial_sum = 0.0 # <<<<<<<<<<<<<< * pointer_state = N # ie ERROR * */ __pyx_v_partial_sum = 0.0; /* "cogent/align/_pairwise_pogs.pyx":184 * max_exponent = MIN_SCALE * partial_sum = 0.0 * pointer_state = N # ie ERROR # <<<<<<<<<<<<<< * * if dx: */ __pyx_v_pointer_state = __pyx_v_N; /* "cogent/align/_pairwise_pogs.pyx":186 * pointer_state = N # ie ERROR * * if dx: # <<<<<<<<<<<<<< * a_low = 1 * a_high = a_count + 1 */ if (__pyx_v_dx) { /* "cogent/align/_pairwise_pogs.pyx":187 * * if dx: * a_low = 1 # <<<<<<<<<<<<<< * a_high = a_count + 1 * else: */ __pyx_v_a_low = 1; /* "cogent/align/_pairwise_pogs.pyx":188 * if dx: * a_low = 1 * a_high = a_count + 1 # <<<<<<<<<<<<<< * else: * a_low = 0 */ __pyx_v_a_high = (__pyx_v_a_count + 1); goto __pyx_L32; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":190 * a_high = a_count + 1 * else: * a_low = 0 # <<<<<<<<<<<<<< * a_high = 1 * */ __pyx_v_a_low = 0; /* "cogent/align/_pairwise_pogs.pyx":191 * else: * a_low = 0 * a_high = 1 # <<<<<<<<<<<<<< * * if dy: */ __pyx_v_a_high = 1; } __pyx_L32:; /* "cogent/align/_pairwise_pogs.pyx":193 * a_high = 1 * * if dy: # <<<<<<<<<<<<<< * b_low = 1 * b_high = j_sources_end - j_sources_start + 1 */ if (__pyx_v_dy) { /* "cogent/align/_pairwise_pogs.pyx":194 * * if dy: * b_low = 1 # <<<<<<<<<<<<<< * b_high = j_sources_end - j_sources_start + 1 * else: */ __pyx_v_b_low = 1; /* "cogent/align/_pairwise_pogs.pyx":195 * if dy: * b_low = 1 * b_high = j_sources_end - j_sources_start + 1 # <<<<<<<<<<<<<< * else: * b_low = 0 */ __pyx_v_b_high = ((__pyx_v_j_sources_end - __pyx_v_j_sources_start) + 1); goto __pyx_L33; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":197 * b_high = j_sources_end - j_sources_start + 1 * else: * b_low = 0 # <<<<<<<<<<<<<< * b_high = 1 * */ __pyx_v_b_low = 0; /* "cogent/align/_pairwise_pogs.pyx":198 * else: * b_low = 0 * b_high = 1 # <<<<<<<<<<<<<< * * if use_scaling: */ __pyx_v_b_high = 1; } __pyx_L33:; /* "cogent/align/_pairwise_pogs.pyx":200 * b_high = 1 * * if use_scaling: # <<<<<<<<<<<<<< * sub_partial_sum = 0.0 * # keep these next 9 lines same as below */ if (__pyx_v_use_scaling) { /* "cogent/align/_pairwise_pogs.pyx":201 * * if use_scaling: * sub_partial_sum = 0.0 # <<<<<<<<<<<<<< * # keep these next 9 lines same as below * for a from a_low <= a < a_high: */ __pyx_v_sub_partial_sum = 0.0; /* "cogent/align/_pairwise_pogs.pyx":203 * sub_partial_sum = 0.0 * # keep these next 9 lines same as below * for a from a_low <= a < a_high: # <<<<<<<<<<<<<< * source_row_index = source_row_index_cache[a] * for b from b_low <= b < b_high: */ __pyx_t_49 = __pyx_v_a_high; for (__pyx_v_a = __pyx_v_a_low; __pyx_v_a < __pyx_t_49; __pyx_v_a++) { /* "cogent/align/_pairwise_pogs.pyx":204 * # keep these next 9 lines same as below * for a from a_low <= a < a_high: * source_row_index = source_row_index_cache[a] # <<<<<<<<<<<<<< * for b from b_low <= b < b_high: * if dy: */ __pyx_v_source_row_index = (__pyx_v_source_row_index_cache[__pyx_v_a]); /* "cogent/align/_pairwise_pogs.pyx":205 * for a from a_low <= a < a_high: * source_row_index = source_row_index_cache[a] * for b from b_low <= b < b_high: # <<<<<<<<<<<<<< * if dy: * prev_j = j_sources[b-1+j_sources_start] */ __pyx_t_50 = __pyx_v_b_high; for (__pyx_v_b = __pyx_v_b_low; __pyx_v_b < __pyx_t_50; __pyx_v_b++) { /* "cogent/align/_pairwise_pogs.pyx":206 * source_row_index = source_row_index_cache[a] * for b from b_low <= b < b_high: * if dy: # <<<<<<<<<<<<<< * prev_j = j_sources[b-1+j_sources_start] * else: */ if (__pyx_v_dy) { /* "cogent/align/_pairwise_pogs.pyx":207 * for b from b_low <= b < b_high: * if dy: * prev_j = j_sources[b-1+j_sources_start] # <<<<<<<<<<<<<< * else: * prev_j = j */ __pyx_t_51 = ((__pyx_v_b - 1) + __pyx_v_j_sources_start); __pyx_v_prev_j = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_j_sources.data) + __pyx_t_51)) ))); goto __pyx_L39; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":209 * prev_j = j_sources[b-1+j_sources_start] * else: * prev_j = j # <<<<<<<<<<<<<< * min_prev_state = (prev_j > 0) * for prev_state from min_prev_state <= prev_state < N: */ __pyx_v_prev_j = __pyx_v_j; } __pyx_L39:; /* "cogent/align/_pairwise_pogs.pyx":210 * else: * prev_j = j * min_prev_state = (prev_j > 0) # <<<<<<<<<<<<<< * for prev_state from min_prev_state <= prev_state < N: * exponent = exponents[source_row_index, prev_j, prev_state] */ __pyx_v_min_prev_state = (__pyx_v_prev_j > 0); /* "cogent/align/_pairwise_pogs.pyx":211 * prev_j = j * min_prev_state = (prev_j > 0) * for prev_state from min_prev_state <= prev_state < N: # <<<<<<<<<<<<<< * exponent = exponents[source_row_index, prev_j, prev_state] * if exponent == MIN_SCALE: */ __pyx_t_52 = __pyx_v_N; for (__pyx_v_prev_state = __pyx_v_min_prev_state; __pyx_v_prev_state < __pyx_t_52; __pyx_v_prev_state++) { /* "cogent/align/_pairwise_pogs.pyx":212 * min_prev_state = (prev_j > 0) * for prev_state from min_prev_state <= prev_state < N: * exponent = exponents[source_row_index, prev_j, prev_state] # <<<<<<<<<<<<<< * if exponent == MIN_SCALE: * continue */ __pyx_t_53 = __pyx_v_source_row_index; __pyx_t_54 = __pyx_v_prev_j; __pyx_t_55 = __pyx_v_prev_state; __pyx_v_exponent = (*((long *) ( /* dim=2 */ ((char *) (((long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_exponents.data + __pyx_t_53 * __pyx_v_exponents.strides[0]) ) + __pyx_t_54 * __pyx_v_exponents.strides[1]) )) + __pyx_t_55)) ))); /* "cogent/align/_pairwise_pogs.pyx":213 * for prev_state from min_prev_state <= prev_state < N: * exponent = exponents[source_row_index, prev_j, prev_state] * if exponent == MIN_SCALE: # <<<<<<<<<<<<<< * continue * */ __pyx_t_2 = (__pyx_v_exponent == __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_SCALE); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":214 * exponent = exponents[source_row_index, prev_j, prev_state] * if exponent == MIN_SCALE: * continue # <<<<<<<<<<<<<< * * mantissa = mantissas[source_row_index, prev_j, prev_state] */ goto __pyx_L40_continue; goto __pyx_L42; } __pyx_L42:; /* "cogent/align/_pairwise_pogs.pyx":216 * continue * * mantissa = mantissas[source_row_index, prev_j, prev_state] # <<<<<<<<<<<<<< * mantissa = mantissa * T[prev_state, state] * */ __pyx_t_56 = __pyx_v_source_row_index; __pyx_t_57 = __pyx_v_prev_j; __pyx_t_58 = __pyx_v_prev_state; __pyx_v_mantissa = (*((double *) ( /* dim=2 */ ((char *) (((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_mantissas.data + __pyx_t_56 * __pyx_v_mantissas.strides[0]) ) + __pyx_t_57 * __pyx_v_mantissas.strides[1]) )) + __pyx_t_58)) ))); /* "cogent/align/_pairwise_pogs.pyx":217 * * mantissa = mantissas[source_row_index, prev_j, prev_state] * mantissa = mantissa * T[prev_state, state] # <<<<<<<<<<<<<< * * if mantissa < MIN_FLOAT_VALUE: */ __pyx_t_59 = __pyx_v_prev_state; __pyx_t_60 = __pyx_v_state; __pyx_v_mantissa = (__pyx_v_mantissa * (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_T.data + __pyx_t_59 * __pyx_v_T.strides[0]) )) + __pyx_t_60)) )))); /* "cogent/align/_pairwise_pogs.pyx":219 * mantissa = mantissa * T[prev_state, state] * * if mantissa < MIN_FLOAT_VALUE: # <<<<<<<<<<<<<< * if mantissa == 0.0: * continue */ __pyx_t_2 = (__pyx_v_mantissa < __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_FLOAT_VALUE); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":220 * * if mantissa < MIN_FLOAT_VALUE: * if mantissa == 0.0: # <<<<<<<<<<<<<< * continue * if mantissa < 0.0: */ __pyx_t_2 = (__pyx_v_mantissa == 0.0); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":221 * if mantissa < MIN_FLOAT_VALUE: * if mantissa == 0.0: * continue # <<<<<<<<<<<<<< * if mantissa < 0.0: * if T[prev_state, state] < 0.0: */ goto __pyx_L40_continue; goto __pyx_L44; } __pyx_L44:; /* "cogent/align/_pairwise_pogs.pyx":222 * if mantissa == 0.0: * continue * if mantissa < 0.0: # <<<<<<<<<<<<<< * if T[prev_state, state] < 0.0: * raise ArithmeticError(fmpt(mantissa, exponent, */ __pyx_t_2 = (__pyx_v_mantissa < 0.0); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":223 * continue * if mantissa < 0.0: * if T[prev_state, state] < 0.0: # <<<<<<<<<<<<<< * raise ArithmeticError(fmpt(mantissa, exponent, * "transition is a negative probability")) */ __pyx_t_61 = __pyx_v_prev_state; __pyx_t_62 = __pyx_v_state; __pyx_t_2 = ((*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_T.data + __pyx_t_61 * __pyx_v_T.strides[0]) )) + __pyx_t_62)) ))) < 0.0); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":224 * if mantissa < 0.0: * if T[prev_state, state] < 0.0: * raise ArithmeticError(fmpt(mantissa, exponent, # <<<<<<<<<<<<<< * "transition is a negative probability")) * raise ArithmeticError(fmpt(mantissa, exponent, */ __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__fmpt); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_11 = PyFloat_FromDouble(__pyx_v_mantissa); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __pyx_t_10 = PyInt_FromLong(__pyx_v_exponent); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); __Pyx_INCREF(((PyObject *)__pyx_kp_s_12)); PyTuple_SET_ITEM(__pyx_t_13, 2, ((PyObject *)__pyx_kp_s_12)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_12)); __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_builtin_ArithmeticError, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; __Pyx_Raise(__pyx_t_10, 0, 0, 0); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L46; } __pyx_L46:; /* "cogent/align/_pairwise_pogs.pyx":226 * raise ArithmeticError(fmpt(mantissa, exponent, * "transition is a negative probability")) * raise ArithmeticError(fmpt(mantissa, exponent, # <<<<<<<<<<<<<< * "product is a negative probability")) * while mantissa < MIN_FLOAT_VALUE: */ __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__fmpt); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_13 = PyFloat_FromDouble(__pyx_v_mantissa); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_13); __pyx_t_9 = PyInt_FromLong(__pyx_v_exponent); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __Pyx_INCREF(((PyObject *)__pyx_kp_s_13)); PyTuple_SET_ITEM(__pyx_t_11, 2, ((PyObject *)__pyx_kp_s_13)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13)); __pyx_t_13 = 0; __pyx_t_9 = 0; __pyx_t_9 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_9 = PyObject_Call(__pyx_builtin_ArithmeticError, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; __Pyx_Raise(__pyx_t_9, 0, 0, 0); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L45; } __pyx_L45:; /* "cogent/align/_pairwise_pogs.pyx":228 * raise ArithmeticError(fmpt(mantissa, exponent, * "product is a negative probability")) * while mantissa < MIN_FLOAT_VALUE: # <<<<<<<<<<<<<< * mantissa *= SCALE_STEP * exponent += -1 */ while (1) { __pyx_t_2 = (__pyx_v_mantissa < __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_FLOAT_VALUE); if (!__pyx_t_2) break; /* "cogent/align/_pairwise_pogs.pyx":229 * "product is a negative probability")) * while mantissa < MIN_FLOAT_VALUE: * mantissa *= SCALE_STEP # <<<<<<<<<<<<<< * exponent += -1 * if exponent <= MIN_SCALE: */ __pyx_v_mantissa = (__pyx_v_mantissa * __pyx_v_6cogent_5align_14_pairwise_pogs_SCALE_STEP); /* "cogent/align/_pairwise_pogs.pyx":230 * while mantissa < MIN_FLOAT_VALUE: * mantissa *= SCALE_STEP * exponent += -1 # <<<<<<<<<<<<<< * if exponent <= MIN_SCALE: * raise ArithmeticError(fmpt(mantissa, exponent, */ __pyx_v_exponent = (__pyx_v_exponent + -1); /* "cogent/align/_pairwise_pogs.pyx":231 * mantissa *= SCALE_STEP * exponent += -1 * if exponent <= MIN_SCALE: # <<<<<<<<<<<<<< * raise ArithmeticError(fmpt(mantissa, exponent, * "underflows")) */ __pyx_t_2 = (__pyx_v_exponent <= __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_SCALE); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":232 * exponent += -1 * if exponent <= MIN_SCALE: * raise ArithmeticError(fmpt(mantissa, exponent, # <<<<<<<<<<<<<< * "underflows")) * */ __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__fmpt); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_11 = PyFloat_FromDouble(__pyx_v_mantissa); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __pyx_t_10 = PyInt_FromLong(__pyx_v_exponent); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); __Pyx_INCREF(((PyObject *)__pyx_n_s__underflows)); PyTuple_SET_ITEM(__pyx_t_13, 2, ((PyObject *)__pyx_n_s__underflows)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__underflows)); __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_builtin_ArithmeticError, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; __Pyx_Raise(__pyx_t_10, 0, 0, 0); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L49; } __pyx_L49:; } goto __pyx_L43; } /* "cogent/align/_pairwise_pogs.pyx":235 * "underflows")) * * elif mantissa > 1.0: # <<<<<<<<<<<<<< * mantissa *= MIN_FLOAT_VALUE * exponent += 1 */ __pyx_t_2 = (__pyx_v_mantissa > 1.0); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":236 * * elif mantissa > 1.0: * mantissa *= MIN_FLOAT_VALUE # <<<<<<<<<<<<<< * exponent += 1 * if exponent > MAX_SCALE: */ __pyx_v_mantissa = (__pyx_v_mantissa * __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_FLOAT_VALUE); /* "cogent/align/_pairwise_pogs.pyx":237 * elif mantissa > 1.0: * mantissa *= MIN_FLOAT_VALUE * exponent += 1 # <<<<<<<<<<<<<< * if exponent > MAX_SCALE: * raise ArithmeticError(fmpt(mantissa, exponent, */ __pyx_v_exponent = (__pyx_v_exponent + 1); /* "cogent/align/_pairwise_pogs.pyx":238 * mantissa *= MIN_FLOAT_VALUE * exponent += 1 * if exponent > MAX_SCALE: # <<<<<<<<<<<<<< * raise ArithmeticError(fmpt(mantissa, exponent, * "is unexpectedly large")) */ __pyx_t_2 = (__pyx_v_exponent > __pyx_v_6cogent_5align_14_pairwise_pogs_MAX_SCALE); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":239 * exponent += 1 * if exponent > MAX_SCALE: * raise ArithmeticError(fmpt(mantissa, exponent, # <<<<<<<<<<<<<< * "is unexpectedly large")) * */ __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__fmpt); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_13 = PyFloat_FromDouble(__pyx_v_mantissa); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_13); __pyx_t_9 = PyInt_FromLong(__pyx_v_exponent); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); PyTuple_SET_ITEM(__pyx_t_11, 2, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); __pyx_t_13 = 0; __pyx_t_9 = 0; __pyx_t_9 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_9 = PyObject_Call(__pyx_builtin_ArithmeticError, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; __Pyx_Raise(__pyx_t_9, 0, 0, 0); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L50; } __pyx_L50:; goto __pyx_L43; } __pyx_L43:; /* "cogent/align/_pairwise_pogs.pyx":242 * "is unexpectedly large")) * * if exponent > max_exponent: # <<<<<<<<<<<<<< * if exponent == max_exponent + 1: * sub_partial_sum = partial_sum */ __pyx_t_2 = (__pyx_v_exponent > __pyx_v_max_exponent); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":243 * * if exponent > max_exponent: * if exponent == max_exponent + 1: # <<<<<<<<<<<<<< * sub_partial_sum = partial_sum * else: */ __pyx_t_2 = (__pyx_v_exponent == (__pyx_v_max_exponent + 1)); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":244 * if exponent > max_exponent: * if exponent == max_exponent + 1: * sub_partial_sum = partial_sum # <<<<<<<<<<<<<< * else: * sub_partial_sum = 0.0 */ __pyx_v_sub_partial_sum = __pyx_v_partial_sum; goto __pyx_L52; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":246 * sub_partial_sum = partial_sum * else: * sub_partial_sum = 0.0 # <<<<<<<<<<<<<< * partial_sum = 0.0 * max_mantissa = 0.0 */ __pyx_v_sub_partial_sum = 0.0; } __pyx_L52:; /* "cogent/align/_pairwise_pogs.pyx":247 * else: * sub_partial_sum = 0.0 * partial_sum = 0.0 # <<<<<<<<<<<<<< * max_mantissa = 0.0 * max_exponent = exponent */ __pyx_v_partial_sum = 0.0; /* "cogent/align/_pairwise_pogs.pyx":248 * sub_partial_sum = 0.0 * partial_sum = 0.0 * max_mantissa = 0.0 # <<<<<<<<<<<<<< * max_exponent = exponent * */ __pyx_v_max_mantissa = 0.0; /* "cogent/align/_pairwise_pogs.pyx":249 * partial_sum = 0.0 * max_mantissa = 0.0 * max_exponent = exponent # <<<<<<<<<<<<<< * * if exponent == max_exponent: */ __pyx_v_max_exponent = __pyx_v_exponent; goto __pyx_L51; } __pyx_L51:; /* "cogent/align/_pairwise_pogs.pyx":251 * max_exponent = exponent * * if exponent == max_exponent: # <<<<<<<<<<<<<< * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: */ __pyx_t_2 = (__pyx_v_exponent == __pyx_v_max_exponent); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":252 * * if exponent == max_exponent: * partial_sum += mantissa # <<<<<<<<<<<<<< * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa */ __pyx_v_partial_sum = (__pyx_v_partial_sum + __pyx_v_mantissa); /* "cogent/align/_pairwise_pogs.pyx":253 * if exponent == max_exponent: * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: # <<<<<<<<<<<<<< * max_mantissa = mantissa * pointer_state = prev_state */ if (__pyx_v_viterbi) { __pyx_t_2 = (__pyx_v_mantissa > __pyx_v_max_mantissa); __pyx_t_8 = __pyx_t_2; } else { __pyx_t_8 = __pyx_v_viterbi; } if (__pyx_t_8) { /* "cogent/align/_pairwise_pogs.pyx":254 * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa # <<<<<<<<<<<<<< * pointer_state = prev_state * pointer_a = a */ __pyx_v_max_mantissa = __pyx_v_mantissa; /* "cogent/align/_pairwise_pogs.pyx":255 * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa * pointer_state = prev_state # <<<<<<<<<<<<<< * pointer_a = a * pointer_b = b */ __pyx_v_pointer_state = __pyx_v_prev_state; /* "cogent/align/_pairwise_pogs.pyx":256 * max_mantissa = mantissa * pointer_state = prev_state * pointer_a = a # <<<<<<<<<<<<<< * pointer_b = b * */ __pyx_v_pointer_a = __pyx_v_a; /* "cogent/align/_pairwise_pogs.pyx":257 * pointer_state = prev_state * pointer_a = a * pointer_b = b # <<<<<<<<<<<<<< * * elif exponent == max_exponent - 1: */ __pyx_v_pointer_b = __pyx_v_b; goto __pyx_L54; } __pyx_L54:; goto __pyx_L53; } /* "cogent/align/_pairwise_pogs.pyx":259 * pointer_b = b * * elif exponent == max_exponent - 1: # <<<<<<<<<<<<<< * sub_partial_sum += mantissa * */ __pyx_t_8 = (__pyx_v_exponent == (__pyx_v_max_exponent - 1)); if (__pyx_t_8) { /* "cogent/align/_pairwise_pogs.pyx":260 * * elif exponent == max_exponent - 1: * sub_partial_sum += mantissa # <<<<<<<<<<<<<< * * partial_sum += sub_partial_sum * MIN_FLOAT_VALUE */ __pyx_v_sub_partial_sum = (__pyx_v_sub_partial_sum + __pyx_v_mantissa); goto __pyx_L53; } __pyx_L53:; __pyx_L40_continue:; } /* "cogent/align/_pairwise_pogs.pyx":262 * sub_partial_sum += mantissa * * partial_sum += sub_partial_sum * MIN_FLOAT_VALUE # <<<<<<<<<<<<<< * else: * # keep these next 9 lines same as above */ __pyx_v_partial_sum = (__pyx_v_partial_sum + (__pyx_v_sub_partial_sum * __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_FLOAT_VALUE)); } } goto __pyx_L34; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":265 * else: * # keep these next 9 lines same as above * for a from a_low <= a < a_high: # <<<<<<<<<<<<<< * source_row_index = source_row_index_cache[a] * for b from b_low <= b < b_high: */ __pyx_t_49 = __pyx_v_a_high; for (__pyx_v_a = __pyx_v_a_low; __pyx_v_a < __pyx_t_49; __pyx_v_a++) { /* "cogent/align/_pairwise_pogs.pyx":266 * # keep these next 9 lines same as above * for a from a_low <= a < a_high: * source_row_index = source_row_index_cache[a] # <<<<<<<<<<<<<< * for b from b_low <= b < b_high: * if dy: */ __pyx_v_source_row_index = (__pyx_v_source_row_index_cache[__pyx_v_a]); /* "cogent/align/_pairwise_pogs.pyx":267 * for a from a_low <= a < a_high: * source_row_index = source_row_index_cache[a] * for b from b_low <= b < b_high: # <<<<<<<<<<<<<< * if dy: * prev_j = j_sources[b-1+j_sources_start] */ __pyx_t_50 = __pyx_v_b_high; for (__pyx_v_b = __pyx_v_b_low; __pyx_v_b < __pyx_t_50; __pyx_v_b++) { /* "cogent/align/_pairwise_pogs.pyx":268 * source_row_index = source_row_index_cache[a] * for b from b_low <= b < b_high: * if dy: # <<<<<<<<<<<<<< * prev_j = j_sources[b-1+j_sources_start] * else: */ if (__pyx_v_dy) { /* "cogent/align/_pairwise_pogs.pyx":269 * for b from b_low <= b < b_high: * if dy: * prev_j = j_sources[b-1+j_sources_start] # <<<<<<<<<<<<<< * else: * prev_j = j */ __pyx_t_63 = ((__pyx_v_b - 1) + __pyx_v_j_sources_start); __pyx_v_prev_j = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_j_sources.data) + __pyx_t_63)) ))); goto __pyx_L59; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":271 * prev_j = j_sources[b-1+j_sources_start] * else: * prev_j = j # <<<<<<<<<<<<<< * min_prev_state = (prev_j > 0) * for prev_state from min_prev_state <= prev_state < N: */ __pyx_v_prev_j = __pyx_v_j; } __pyx_L59:; /* "cogent/align/_pairwise_pogs.pyx":272 * else: * prev_j = j * min_prev_state = (prev_j > 0) # <<<<<<<<<<<<<< * for prev_state from min_prev_state <= prev_state < N: * mantissa = mantissas[source_row_index, prev_j, prev_state] */ __pyx_v_min_prev_state = (__pyx_v_prev_j > 0); /* "cogent/align/_pairwise_pogs.pyx":273 * prev_j = j * min_prev_state = (prev_j > 0) * for prev_state from min_prev_state <= prev_state < N: # <<<<<<<<<<<<<< * mantissa = mantissas[source_row_index, prev_j, prev_state] * if use_logs: */ __pyx_t_52 = __pyx_v_N; for (__pyx_v_prev_state = __pyx_v_min_prev_state; __pyx_v_prev_state < __pyx_t_52; __pyx_v_prev_state++) { /* "cogent/align/_pairwise_pogs.pyx":274 * min_prev_state = (prev_j > 0) * for prev_state from min_prev_state <= prev_state < N: * mantissa = mantissas[source_row_index, prev_j, prev_state] # <<<<<<<<<<<<<< * if use_logs: * mantissa = mantissa + T[prev_state, state] */ __pyx_t_64 = __pyx_v_source_row_index; __pyx_t_65 = __pyx_v_prev_j; __pyx_t_66 = __pyx_v_prev_state; __pyx_v_mantissa = (*((double *) ( /* dim=2 */ ((char *) (((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_mantissas.data + __pyx_t_64 * __pyx_v_mantissas.strides[0]) ) + __pyx_t_65 * __pyx_v_mantissas.strides[1]) )) + __pyx_t_66)) ))); /* "cogent/align/_pairwise_pogs.pyx":275 * for prev_state from min_prev_state <= prev_state < N: * mantissa = mantissas[source_row_index, prev_j, prev_state] * if use_logs: # <<<<<<<<<<<<<< * mantissa = mantissa + T[prev_state, state] * else: */ if (__pyx_v_use_logs) { /* "cogent/align/_pairwise_pogs.pyx":276 * mantissa = mantissas[source_row_index, prev_j, prev_state] * if use_logs: * mantissa = mantissa + T[prev_state, state] # <<<<<<<<<<<<<< * else: * mantissa = mantissa * T[prev_state, state] */ __pyx_t_67 = __pyx_v_prev_state; __pyx_t_68 = __pyx_v_state; __pyx_v_mantissa = (__pyx_v_mantissa + (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_T.data + __pyx_t_67 * __pyx_v_T.strides[0]) )) + __pyx_t_68)) )))); goto __pyx_L62; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":278 * mantissa = mantissa + T[prev_state, state] * else: * mantissa = mantissa * T[prev_state, state] # <<<<<<<<<<<<<< * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: */ __pyx_t_69 = __pyx_v_prev_state; __pyx_t_70 = __pyx_v_state; __pyx_v_mantissa = (__pyx_v_mantissa * (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_T.data + __pyx_t_69 * __pyx_v_T.strides[0]) )) + __pyx_t_70)) )))); /* "cogent/align/_pairwise_pogs.pyx":279 * else: * mantissa = mantissa * T[prev_state, state] * partial_sum += mantissa # <<<<<<<<<<<<<< * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa */ __pyx_v_partial_sum = (__pyx_v_partial_sum + __pyx_v_mantissa); } __pyx_L62:; /* "cogent/align/_pairwise_pogs.pyx":280 * mantissa = mantissa * T[prev_state, state] * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: # <<<<<<<<<<<<<< * max_mantissa = mantissa * pointer_state = prev_state */ if (__pyx_v_viterbi) { __pyx_t_8 = (__pyx_v_mantissa > __pyx_v_max_mantissa); __pyx_t_2 = __pyx_t_8; } else { __pyx_t_2 = __pyx_v_viterbi; } if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":281 * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa # <<<<<<<<<<<<<< * pointer_state = prev_state * pointer_a = a */ __pyx_v_max_mantissa = __pyx_v_mantissa; /* "cogent/align/_pairwise_pogs.pyx":282 * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa * pointer_state = prev_state # <<<<<<<<<<<<<< * pointer_a = a * pointer_b = b */ __pyx_v_pointer_state = __pyx_v_prev_state; /* "cogent/align/_pairwise_pogs.pyx":283 * max_mantissa = mantissa * pointer_state = prev_state * pointer_a = a # <<<<<<<<<<<<<< * pointer_b = b * */ __pyx_v_pointer_a = __pyx_v_a; /* "cogent/align/_pairwise_pogs.pyx":284 * pointer_state = prev_state * pointer_a = a * pointer_b = b # <<<<<<<<<<<<<< * * if viterbi: */ __pyx_v_pointer_b = __pyx_v_b; goto __pyx_L63; } __pyx_L63:; } } } } __pyx_L34:; /* "cogent/align/_pairwise_pogs.pyx":286 * pointer_b = b * * if viterbi: # <<<<<<<<<<<<<< * mantissa = max_mantissa * if track is not None: */ if (__pyx_v_viterbi) { /* "cogent/align/_pairwise_pogs.pyx":287 * * if viterbi: * mantissa = max_mantissa # <<<<<<<<<<<<<< * if track is not None: * track[i, j, state] = ( */ __pyx_v_mantissa = __pyx_v_max_mantissa; /* "cogent/align/_pairwise_pogs.pyx":288 * if viterbi: * mantissa = max_mantissa * if track is not None: # <<<<<<<<<<<<<< * track[i, j, state] = ( * (pointer_a << tcode_x) | */ __pyx_t_2 = (((PyObject *) __pyx_v_track.memview) != Py_None); if (__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":289 * mantissa = max_mantissa * if track is not None: * track[i, j, state] = ( # <<<<<<<<<<<<<< * (pointer_a << tcode_x) | * (pointer_b << tcode_y) | */ __pyx_t_49 = __pyx_v_i; __pyx_t_50 = __pyx_v_j; __pyx_t_52 = __pyx_v_state; *((unsigned char *) ( /* dim=2 */ ((char *) (((unsigned char *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_track.data + __pyx_t_49 * __pyx_v_track.strides[0]) ) + __pyx_t_50 * __pyx_v_track.strides[1]) )) + __pyx_t_52)) )) = (((__pyx_v_pointer_a << __pyx_v_tcode_x) | (__pyx_v_pointer_b << __pyx_v_tcode_y)) | (__pyx_v_pointer_state << __pyx_v_tcode_s)); goto __pyx_L65; } __pyx_L65:; goto __pyx_L64; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":294 * (pointer_state << tcode_s)) * else: * mantissa = partial_sum # <<<<<<<<<<<<<< * * if dy: */ __pyx_v_mantissa = __pyx_v_partial_sum; } __pyx_L64:; /* "cogent/align/_pairwise_pogs.pyx":296 * mantissa = partial_sum * * if dy: # <<<<<<<<<<<<<< * y = seq2_index[j] * if dx: */ if (__pyx_v_dy) { /* "cogent/align/_pairwise_pogs.pyx":297 * * if dy: * y = seq2_index[j] # <<<<<<<<<<<<<< * if dx: * d_score = match_scores[bin, x, y] */ __pyx_t_71 = __pyx_v_j; __pyx_v_y = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_seq2_index.data) + __pyx_t_71)) ))); /* "cogent/align/_pairwise_pogs.pyx":298 * if dy: * y = seq2_index[j] * if dx: # <<<<<<<<<<<<<< * d_score = match_scores[bin, x, y] * else: */ if (__pyx_v_dx) { /* "cogent/align/_pairwise_pogs.pyx":299 * y = seq2_index[j] * if dx: * d_score = match_scores[bin, x, y] # <<<<<<<<<<<<<< * else: * d_score = ygap_scores[bin, y] */ __pyx_t_72 = __pyx_v_bin; __pyx_t_73 = __pyx_v_x; __pyx_t_74 = __pyx_v_y; __pyx_v_d_score = (*((double *) ( /* dim=2 */ ((char *) (((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_match_scores.data + __pyx_t_72 * __pyx_v_match_scores.strides[0]) ) + __pyx_t_73 * __pyx_v_match_scores.strides[1]) )) + __pyx_t_74)) ))); goto __pyx_L67; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":301 * d_score = match_scores[bin, x, y] * else: * d_score = ygap_scores[bin, y] # <<<<<<<<<<<<<< * elif dx: * d_score = xgap_scores[bin, x] */ __pyx_t_75 = __pyx_v_bin; __pyx_t_76 = __pyx_v_y; __pyx_v_d_score = (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_ygap_scores.data + __pyx_t_75 * __pyx_v_ygap_scores.strides[0]) )) + __pyx_t_76)) ))); } __pyx_L67:; goto __pyx_L66; } /* "cogent/align/_pairwise_pogs.pyx":302 * else: * d_score = ygap_scores[bin, y] * elif dx: # <<<<<<<<<<<<<< * d_score = xgap_scores[bin, x] * elif use_logs: */ if (__pyx_v_dx) { /* "cogent/align/_pairwise_pogs.pyx":303 * d_score = ygap_scores[bin, y] * elif dx: * d_score = xgap_scores[bin, x] # <<<<<<<<<<<<<< * elif use_logs: * d_score = 0.0 */ __pyx_t_77 = __pyx_v_bin; __pyx_t_78 = __pyx_v_x; __pyx_v_d_score = (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_xgap_scores.data + __pyx_t_77 * __pyx_v_xgap_scores.strides[0]) )) + __pyx_t_78)) ))); goto __pyx_L66; } /* "cogent/align/_pairwise_pogs.pyx":304 * elif dx: * d_score = xgap_scores[bin, x] * elif use_logs: # <<<<<<<<<<<<<< * d_score = 0.0 * else: */ if (__pyx_v_use_logs) { /* "cogent/align/_pairwise_pogs.pyx":305 * d_score = xgap_scores[bin, x] * elif use_logs: * d_score = 0.0 # <<<<<<<<<<<<<< * else: * d_score = 1.0 */ __pyx_v_d_score = 0.0; goto __pyx_L66; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":307 * d_score = 0.0 * else: * d_score = 1.0 # <<<<<<<<<<<<<< * * if use_logs: */ __pyx_v_d_score = 1.0; } __pyx_L66:; /* "cogent/align/_pairwise_pogs.pyx":309 * d_score = 1.0 * * if use_logs: # <<<<<<<<<<<<<< * mantissa += d_score * else: */ if (__pyx_v_use_logs) { /* "cogent/align/_pairwise_pogs.pyx":310 * * if use_logs: * mantissa += d_score # <<<<<<<<<<<<<< * else: * mantissa *= d_score */ __pyx_v_mantissa = (__pyx_v_mantissa + __pyx_v_d_score); goto __pyx_L68; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":312 * mantissa += d_score * else: * mantissa *= d_score # <<<<<<<<<<<<<< * * mantissas[current_row_index, j, state] = mantissa */ __pyx_v_mantissa = (__pyx_v_mantissa * __pyx_v_d_score); } __pyx_L68:; /* "cogent/align/_pairwise_pogs.pyx":314 * mantissa *= d_score * * mantissas[current_row_index, j, state] = mantissa # <<<<<<<<<<<<<< * if use_scaling: * exponents[current_row_index, j, state] = max_exponent */ __pyx_t_79 = __pyx_v_current_row_index; __pyx_t_80 = __pyx_v_j; __pyx_t_81 = __pyx_v_state; *((double *) ( /* dim=2 */ ((char *) (((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_mantissas.data + __pyx_t_79 * __pyx_v_mantissas.strides[0]) ) + __pyx_t_80 * __pyx_v_mantissas.strides[1]) )) + __pyx_t_81)) )) = __pyx_v_mantissa; /* "cogent/align/_pairwise_pogs.pyx":315 * * mantissas[current_row_index, j, state] = mantissa * if use_scaling: # <<<<<<<<<<<<<< * exponents[current_row_index, j, state] = max_exponent * */ if (__pyx_v_use_scaling) { /* "cogent/align/_pairwise_pogs.pyx":316 * mantissas[current_row_index, j, state] = mantissa * if use_scaling: * exponents[current_row_index, j, state] = max_exponent # <<<<<<<<<<<<<< * * if local and dx and dy: */ __pyx_t_82 = __pyx_v_current_row_index; __pyx_t_83 = __pyx_v_j; __pyx_t_84 = __pyx_v_state; *((long *) ( /* dim=2 */ ((char *) (((long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_exponents.data + __pyx_t_82 * __pyx_v_exponents.strides[0]) ) + __pyx_t_83 * __pyx_v_exponents.strides[1]) )) + __pyx_t_84)) )) = __pyx_v_max_exponent; goto __pyx_L69; } __pyx_L69:; /* "cogent/align/_pairwise_pogs.pyx":318 * exponents[current_row_index, j, state] = max_exponent * * if local and dx and dy: # <<<<<<<<<<<<<< * if (use_scaling and max_exponent > overall_max_exponent) or ( * (not use_scaling or max_exponent == overall_max_exponent) and ( */ if (__pyx_v_local) { if (__pyx_v_dx) { __pyx_t_2 = __pyx_v_dy; } else { __pyx_t_2 = __pyx_v_dx; } __pyx_t_8 = __pyx_t_2; } else { __pyx_t_8 = __pyx_v_local; } if (__pyx_t_8) { /* "cogent/align/_pairwise_pogs.pyx":319 * * if local and dx and dy: * if (use_scaling and max_exponent > overall_max_exponent) or ( # <<<<<<<<<<<<<< * (not use_scaling or max_exponent == overall_max_exponent) and ( * mantissa > overall_max_mantissa)): */ if (__pyx_v_use_scaling) { __pyx_t_8 = (__pyx_v_max_exponent > __pyx_v_overall_max_exponent); __pyx_t_2 = __pyx_t_8; } else { __pyx_t_2 = __pyx_v_use_scaling; } if (!__pyx_t_2) { /* "cogent/align/_pairwise_pogs.pyx":320 * if local and dx and dy: * if (use_scaling and max_exponent > overall_max_exponent) or ( * (not use_scaling or max_exponent == overall_max_exponent) and ( # <<<<<<<<<<<<<< * mantissa > overall_max_mantissa)): * overall_max_exponent = max_exponent */ __pyx_t_8 = (!__pyx_v_use_scaling); if (!__pyx_t_8) { __pyx_t_1 = (__pyx_v_max_exponent == __pyx_v_overall_max_exponent); __pyx_t_7 = __pyx_t_1; } else { __pyx_t_7 = __pyx_t_8; } if (__pyx_t_7) { /* "cogent/align/_pairwise_pogs.pyx":321 * if (use_scaling and max_exponent > overall_max_exponent) or ( * (not use_scaling or max_exponent == overall_max_exponent) and ( * mantissa > overall_max_mantissa)): # <<<<<<<<<<<<<< * overall_max_exponent = max_exponent * overall_max_mantissa = mantissa */ __pyx_t_8 = (__pyx_v_mantissa > __pyx_v_overall_max_mantissa); __pyx_t_1 = __pyx_t_8; } else { __pyx_t_1 = __pyx_t_7; } __pyx_t_7 = __pyx_t_1; } else { __pyx_t_7 = __pyx_t_2; } if (__pyx_t_7) { /* "cogent/align/_pairwise_pogs.pyx":322 * (not use_scaling or max_exponent == overall_max_exponent) and ( * mantissa > overall_max_mantissa)): * overall_max_exponent = max_exponent # <<<<<<<<<<<<<< * overall_max_mantissa = mantissa * last_i = i */ __pyx_v_overall_max_exponent = __pyx_v_max_exponent; /* "cogent/align/_pairwise_pogs.pyx":323 * mantissa > overall_max_mantissa)): * overall_max_exponent = max_exponent * overall_max_mantissa = mantissa # <<<<<<<<<<<<<< * last_i = i * last_j = j */ __pyx_v_overall_max_mantissa = __pyx_v_mantissa; /* "cogent/align/_pairwise_pogs.pyx":324 * overall_max_exponent = max_exponent * overall_max_mantissa = mantissa * last_i = i # <<<<<<<<<<<<<< * last_j = j * last_state = state */ __pyx_v_last_i = __pyx_v_i; /* "cogent/align/_pairwise_pogs.pyx":325 * overall_max_mantissa = mantissa * last_i = i * last_j = j # <<<<<<<<<<<<<< * last_state = state * if not local: */ __pyx_v_last_j = __pyx_v_j; /* "cogent/align/_pairwise_pogs.pyx":326 * last_i = i * last_j = j * last_state = state # <<<<<<<<<<<<<< * if not local: * last_i = i_high - 1 */ __pyx_v_last_state = __pyx_v_state; goto __pyx_L71; } __pyx_L71:; goto __pyx_L70; } __pyx_L70:; } } } /* "cogent/align/_pairwise_pogs.pyx":327 * last_j = j * last_state = state * if not local: # <<<<<<<<<<<<<< * last_i = i_high - 1 * last_j = j_high - 1 */ __pyx_t_7 = (!__pyx_v_local); if (__pyx_t_7) { /* "cogent/align/_pairwise_pogs.pyx":328 * last_state = state * if not local: * last_i = i_high - 1 # <<<<<<<<<<<<<< * last_j = j_high - 1 * last_state = state */ __pyx_v_last_i = (__pyx_v_i_high - 1); /* "cogent/align/_pairwise_pogs.pyx":329 * if not local: * last_i = i_high - 1 * last_j = j_high - 1 # <<<<<<<<<<<<<< * last_state = state * else: */ __pyx_v_last_j = (__pyx_v_j_high - 1); /* "cogent/align/_pairwise_pogs.pyx":330 * last_i = i_high - 1 * last_j = j_high - 1 * last_state = state # <<<<<<<<<<<<<< * else: * mantissa = overall_max_mantissa */ __pyx_v_last_state = __pyx_v_state; goto __pyx_L72; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":332 * last_state = state * else: * mantissa = overall_max_mantissa # <<<<<<<<<<<<<< * max_exponent = overall_max_exponent * */ __pyx_v_mantissa = __pyx_v_overall_max_mantissa; /* "cogent/align/_pairwise_pogs.pyx":333 * else: * mantissa = overall_max_mantissa * max_exponent = overall_max_exponent # <<<<<<<<<<<<<< * * if use_scaling: */ __pyx_v_max_exponent = __pyx_v_overall_max_exponent; } __pyx_L72:; /* "cogent/align/_pairwise_pogs.pyx":335 * max_exponent = overall_max_exponent * * if use_scaling: # <<<<<<<<<<<<<< * score = log(mantissa) + log(SCALE_STEP) * max_exponent * elif use_logs: */ if (__pyx_v_use_scaling) { /* "cogent/align/_pairwise_pogs.pyx":336 * * if use_scaling: * score = log(mantissa) + log(SCALE_STEP) * max_exponent # <<<<<<<<<<<<<< * elif use_logs: * score = mantissa */ __pyx_v_score = (log(__pyx_v_mantissa) + (log(__pyx_v_6cogent_5align_14_pairwise_pogs_SCALE_STEP) * __pyx_v_max_exponent)); goto __pyx_L73; } /* "cogent/align/_pairwise_pogs.pyx":337 * if use_scaling: * score = log(mantissa) + log(SCALE_STEP) * max_exponent * elif use_logs: # <<<<<<<<<<<<<< * score = mantissa * else: */ if (__pyx_v_use_logs) { /* "cogent/align/_pairwise_pogs.pyx":338 * score = log(mantissa) + log(SCALE_STEP) * max_exponent * elif use_logs: * score = mantissa # <<<<<<<<<<<<<< * else: * score = log(mantissa) */ __pyx_v_score = __pyx_v_mantissa; goto __pyx_L73; } /*else*/ { /* "cogent/align/_pairwise_pogs.pyx":340 * score = mantissa * else: * score = log(mantissa) # <<<<<<<<<<<<<< * return ((last_i, last_j), last_state, score) */ __pyx_v_score = log(__pyx_v_mantissa); } __pyx_L73:; /* "cogent/align/_pairwise_pogs.pyx":341 * else: * score = log(mantissa) * return ((last_i, last_j), last_state, score) # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); __pyx_t_9 = PyInt_FromLong(__pyx_v_last_i); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_11 = PyInt_FromLong(__pyx_v_last_j); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_11); __Pyx_GIVEREF(__pyx_t_11); __pyx_t_9 = 0; __pyx_t_11 = 0; __pyx_t_11 = PyInt_FromLong(__pyx_v_last_state); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __pyx_t_9 = PyFloat_FromDouble(__pyx_v_score); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)__pyx_t_10)); __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_11); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_9 = 0; __pyx_r = ((PyObject *)__pyx_t_13); __pyx_t_13 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_11); __Pyx_XDECREF(__pyx_t_13); __PYX_XDEC_MEMVIEW(&__pyx_t_14, 1); __PYX_XDEC_MEMVIEW(&__pyx_t_15, 1); __PYX_XDEC_MEMVIEW(&__pyx_t_16, 1); __PYX_XDEC_MEMVIEW(&__pyx_t_17, 1); __PYX_XDEC_MEMVIEW(&__pyx_t_20, 1); __Pyx_AddTraceback("cogent.align._pairwise_pogs.calc_rows", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __PYX_XDEC_MEMVIEW(&__pyx_v_mantissas, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_exponents, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_i_sources, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_i_sources_offsets, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_j_sources, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_j_sources_offsets, 1); __Pyx_XDECREF(__pyx_v_pog1); __Pyx_XDECREF(__pyx_v_pog2); __PYX_XDEC_MEMVIEW(&__pyx_v_plan, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_seq1_index, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_seq2_index, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_state_directions, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_T, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_xgap_scores, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_ygap_scores, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_match_scores, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_track, 1); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_u__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); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__shape)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__itemsize)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__format)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mode); if (value) { values[3] = value; kw_args--; } } case 4: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); 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_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { /* "View.MemoryView":114 * * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, * mode=u"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_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (unlikely(((PyObject *)__pyx_v_format) == Py_None)) { PyErr_Format(PyExc_TypeError, "Argument 'format' must not be None"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_r = __pyx_array_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); goto __pyx_L0; __pyx_L1_error:; __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":113 * cdef bint dtype_is_object * * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< * mode=u"c", bint allocate_buffer=True): * */ static int __pyx_array_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; PyObject **__pyx_v_p; PyObject *__pyx_v_encode = NULL; PyObject *__pyx_v_dim = NULL; char __pyx_v_order; PyObject *__pyx_v_decode = NULL; int __pyx_r; __Pyx_RefNannyDeclarations Py_ssize_t __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; int __pyx_t_7; int __pyx_t_8; int __pyx_t_9; Py_ssize_t __pyx_t_10; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); __Pyx_INCREF(__pyx_v_format); __Pyx_INCREF(__pyx_v_mode); /* "View.MemoryView":120 * cdef PyObject **p * * self.ndim = len(shape) # <<<<<<<<<<<<<< * self.itemsize = itemsize * */ if (unlikely(((PyObject *)__pyx_v_shape) == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_1 = PyTuple_GET_SIZE(((PyObject *)__pyx_v_shape)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->ndim = __pyx_t_1; /* "View.MemoryView":121 * * self.ndim = len(shape) * self.itemsize = itemsize # <<<<<<<<<<<<<< * * if not self.ndim: */ __pyx_v_self->itemsize = __pyx_v_itemsize; /* "View.MemoryView":123 * self.itemsize = itemsize * * if not self.ndim: # <<<<<<<<<<<<<< * raise ValueError("Empty shape tuple for cython.array") * */ __pyx_t_2 = (!__pyx_v_self->ndim); if (__pyx_t_2) { /* "View.MemoryView":124 * * if not self.ndim: * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< * * if self.itemsize <= 0: */ __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_16), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":126 * raise ValueError("Empty shape tuple for cython.array") * * if self.itemsize <= 0: # <<<<<<<<<<<<<< * raise ValueError("itemsize <= 0 for cython.array") * */ __pyx_t_2 = (__pyx_v_self->itemsize <= 0); if (__pyx_t_2) { /* "View.MemoryView":127 * * if self.itemsize <= 0: * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< * * encode = getattr(format, 'encode', None) */ __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_18), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; /* "View.MemoryView":129 * raise ValueError("itemsize <= 0 for cython.array") * * encode = getattr(format, 'encode', None) # <<<<<<<<<<<<<< * if encode: * format = encode('ASCII') */ __pyx_t_3 = ((PyObject *)__pyx_n_s__encode); __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = Py_None; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = __Pyx_GetAttr3(__pyx_v_format, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __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_v_encode = __pyx_t_5; __pyx_t_5 = 0; /* "View.MemoryView":130 * * encode = getattr(format, 'encode', None) * if encode: # <<<<<<<<<<<<<< * format = encode('ASCII') * self._format = format */ __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_encode); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_2) { /* "View.MemoryView":131 * encode = getattr(format, 'encode', None) * if encode: * format = encode('ASCII') # <<<<<<<<<<<<<< * self._format = format * self.format = self._format */ __pyx_t_5 = PyObject_Call(__pyx_v_encode, ((PyObject *)__pyx_k_tuple_19), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_v_format); __pyx_v_format = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L5; } __pyx_L5:; /* "View.MemoryView":132 * if encode: * format = encode('ASCII') * self._format = format # <<<<<<<<<<<<<< * self.format = self._format * */ if (!(likely(PyBytes_CheckExact(__pyx_v_format))||((__pyx_v_format) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_format)->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_INCREF(__pyx_v_format); __Pyx_GIVEREF(__pyx_v_format); __Pyx_GOTREF(__pyx_v_self->_format); __Pyx_DECREF(((PyObject *)__pyx_v_self->_format)); __pyx_v_self->_format = ((PyObject*)__pyx_v_format); /* "View.MemoryView":133 * format = encode('ASCII') * self._format = format * self.format = self._format # <<<<<<<<<<<<<< * * self._shape = malloc(sizeof(Py_ssize_t)*self.ndim) */ __pyx_t_6 = PyBytes_AsString(((PyObject *)__pyx_v_self->_format)); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->format = __pyx_t_6; /* "View.MemoryView":135 * self.format = self._format * * self._shape = malloc(sizeof(Py_ssize_t)*self.ndim) # <<<<<<<<<<<<<< * self._strides = malloc(sizeof(Py_ssize_t)*self.ndim) * */ __pyx_v_self->_shape = ((Py_ssize_t *)malloc(((sizeof(Py_ssize_t)) * __pyx_v_self->ndim))); /* "View.MemoryView":136 * * self._shape = malloc(sizeof(Py_ssize_t)*self.ndim) * self._strides = malloc(sizeof(Py_ssize_t)*self.ndim) # <<<<<<<<<<<<<< * * if not self._shape or not self._strides: */ __pyx_v_self->_strides = ((Py_ssize_t *)malloc(((sizeof(Py_ssize_t)) * __pyx_v_self->ndim))); /* "View.MemoryView":138 * self._strides = malloc(sizeof(Py_ssize_t)*self.ndim) * * if not self._shape or not self._strides: # <<<<<<<<<<<<<< * free(self._shape) * free(self._strides) */ __pyx_t_2 = (!(__pyx_v_self->_shape != 0)); if (!__pyx_t_2) { __pyx_t_7 = (!(__pyx_v_self->_strides != 0)); __pyx_t_8 = __pyx_t_7; } else { __pyx_t_8 = __pyx_t_2; } if (__pyx_t_8) { /* "View.MemoryView":139 * * if not self._shape or not self._strides: * free(self._shape) # <<<<<<<<<<<<<< * free(self._strides) * raise MemoryError("unable to allocate shape or strides.") */ free(__pyx_v_self->_shape); /* "View.MemoryView":140 * if not self._shape or not self._strides: * free(self._shape) * free(self._strides) # <<<<<<<<<<<<<< * raise MemoryError("unable to allocate shape or strides.") * */ free(__pyx_v_self->_strides); /* "View.MemoryView":141 * free(self._shape) * free(self._strides) * raise MemoryError("unable to allocate shape or strides.") # <<<<<<<<<<<<<< * * */ __pyx_t_5 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; /* "View.MemoryView":144 * * * idx = 0 # <<<<<<<<<<<<<< * for idx, dim in enumerate(shape): * if dim <= 0: */ __pyx_v_idx = 0; /* "View.MemoryView":145 * * idx = 0 * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<< * if dim <= 0: * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) */ __pyx_t_9 = 0; __pyx_t_5 = ((PyObject *)__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_COMPILING_IN_CPYTHON __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif __Pyx_XDECREF(__pyx_v_dim); __pyx_v_dim = __pyx_t_4; __pyx_t_4 = 0; __pyx_v_idx = __pyx_t_9; __pyx_t_9 = (__pyx_t_9 + 1); /* "View.MemoryView":146 * idx = 0 * for idx, dim in enumerate(shape): * if dim <= 0: # <<<<<<<<<<<<<< * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) * */ __pyx_t_4 = PyObject_RichCompare(__pyx_v_dim, __pyx_int_0, Py_LE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_8) { /* "View.MemoryView":147 * 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 = PyInt_FromLong(__pyx_v_idx); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_dim); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_dim); __Pyx_GIVEREF(__pyx_v_dim); __pyx_t_4 = 0; __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_4)); __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L9; } __pyx_L9:; /* "View.MemoryView":149 * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) * * self._shape[idx] = dim # <<<<<<<<<<<<<< * idx += 1 * */ __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_dim); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} (__pyx_v_self->_shape[__pyx_v_idx]) = __pyx_t_10; /* "View.MemoryView":150 * * self._shape[idx] = dim * idx += 1 # <<<<<<<<<<<<<< * * if mode not in ("fortran", "c"): */ __pyx_v_idx = (__pyx_v_idx + 1); } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; /* "View.MemoryView":152 * idx += 1 * * if mode not in ("fortran", "c"): # <<<<<<<<<<<<<< * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) * */ __Pyx_INCREF(__pyx_v_mode); __pyx_t_5 = __pyx_v_mode; __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__fortran), Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (((int)__pyx_t_8)) { __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__c), Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = ((int)__pyx_t_2); } else { __pyx_t_7 = ((int)__pyx_t_8); } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_8 = __pyx_t_7; if (__pyx_t_8) { /* "View.MemoryView":153 * * if mode not in ("fortran", "c"): * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) # <<<<<<<<<<<<<< * * cdef char order */ __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_23), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_5)); __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L10; } __pyx_L10:; /* "View.MemoryView":156 * * cdef char order * if mode == 'fortran': # <<<<<<<<<<<<<< * order = 'F' * else: */ __pyx_t_5 = PyObject_RichCompare(__pyx_v_mode, ((PyObject *)__pyx_n_s__fortran), Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_8) { /* "View.MemoryView":157 * cdef char order * if mode == 'fortran': * order = 'F' # <<<<<<<<<<<<<< * else: * order = 'C' */ __pyx_v_order = 'F'; goto __pyx_L11; } /*else*/ { /* "View.MemoryView":159 * order = 'F' * else: * order = 'C' # <<<<<<<<<<<<<< * * self.len = fill_contig_strides_array(self._shape, self._strides, */ __pyx_v_order = 'C'; } __pyx_L11:; /* "View.MemoryView":161 * order = 'C' * * 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); /* "View.MemoryView":164 * itemsize, self.ndim, order) * * decode = getattr(mode, 'decode', None) # <<<<<<<<<<<<<< * if decode: * mode = decode('ASCII') */ __pyx_t_5 = ((PyObject *)__pyx_n_s__decode); __Pyx_INCREF(__pyx_t_5); __pyx_t_4 = Py_None; __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = __Pyx_GetAttr3(__pyx_v_mode, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_decode = __pyx_t_3; __pyx_t_3 = 0; /* "View.MemoryView":165 * * decode = getattr(mode, 'decode', None) * if decode: # <<<<<<<<<<<<<< * mode = decode('ASCII') * self.mode = mode */ __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_decode); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_8) { /* "View.MemoryView":166 * decode = getattr(mode, 'decode', None) * if decode: * mode = decode('ASCII') # <<<<<<<<<<<<<< * self.mode = mode * */ __pyx_t_3 = PyObject_Call(__pyx_v_decode, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_v_mode); __pyx_v_mode = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L12; } __pyx_L12:; /* "View.MemoryView":167 * if decode: * mode = decode('ASCII') * self.mode = mode # <<<<<<<<<<<<<< * * self.free_data = allocate_buffer */ if (!(likely(PyUnicode_CheckExact(__pyx_v_mode))||((__pyx_v_mode) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected unicode, got %.200s", Py_TYPE(__pyx_v_mode)->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_INCREF(__pyx_v_mode); __Pyx_GIVEREF(__pyx_v_mode); __Pyx_GOTREF(__pyx_v_self->mode); __Pyx_DECREF(((PyObject *)__pyx_v_self->mode)); __pyx_v_self->mode = ((PyObject*)__pyx_v_mode); /* "View.MemoryView":169 * self.mode = mode * * 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":170 * * self.free_data = allocate_buffer * self.dtype_is_object = format == b'O' # <<<<<<<<<<<<<< * if allocate_buffer: * self.data = malloc(self.len) */ __pyx_t_3 = PyObject_RichCompare(__pyx_v_format, ((PyObject *)__pyx_n_b__O), Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_self->dtype_is_object = __pyx_t_8; /* "View.MemoryView":171 * self.free_data = allocate_buffer * self.dtype_is_object = format == b'O' * if allocate_buffer: # <<<<<<<<<<<<<< * self.data = malloc(self.len) * if not self.data: */ if (__pyx_v_allocate_buffer) { /* "View.MemoryView":172 * self.dtype_is_object = format == b'O' * if allocate_buffer: * 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)); /* "View.MemoryView":173 * if allocate_buffer: * self.data = malloc(self.len) * if not self.data: # <<<<<<<<<<<<<< * raise MemoryError("unable to allocate array data.") * */ __pyx_t_8 = (!(__pyx_v_self->data != 0)); if (__pyx_t_8) { /* "View.MemoryView":174 * self.data = malloc(self.len) * if not self.data: * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< * * if self.dtype_is_object: */ __pyx_t_3 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L14; } __pyx_L14:; /* "View.MemoryView":176 * raise MemoryError("unable to allocate array data.") * * if self.dtype_is_object: # <<<<<<<<<<<<<< * p = self.data * for i in range(self.len / itemsize): */ if (__pyx_v_self->dtype_is_object) { /* "View.MemoryView":177 * * 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":178 * 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_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else if (sizeof(Py_ssize_t) == sizeof(long) && unlikely(__pyx_v_itemsize == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_self->len))) { PyErr_Format(PyExc_OverflowError, "value too large to perform division"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_1 = __Pyx_div_Py_ssize_t(__pyx_v_self->len, __pyx_v_itemsize); for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_1; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; /* "View.MemoryView":179 * p = self.data * for i in range(self.len / itemsize): * p[i] = Py_None # <<<<<<<<<<<<<< * Py_INCREF(Py_None) * */ (__pyx_v_p[__pyx_v_i]) = Py_None; /* "View.MemoryView":180 * for i in range(self.len / itemsize): * p[i] = Py_None * Py_INCREF(Py_None) # <<<<<<<<<<<<<< * * @cname('getbuffer') */ Py_INCREF(Py_None); } goto __pyx_L15; } __pyx_L15:; goto __pyx_L13; } __pyx_L13:; __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("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_encode); __Pyx_XDECREF(__pyx_v_dim); __Pyx_XDECREF(__pyx_v_decode); __Pyx_XDECREF(__pyx_v_format); __Pyx_XDECREF(__pyx_v_mode); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ static int __pyx_array_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_array_getbuffer_MemoryView_5array_2__getbuffer__(((struct __pyx_array_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":183 * * @cname('getbuffer') * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< * cdef int bufmode = -1 * if self.mode == b"c": */ static int __pyx_array_getbuffer_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_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getbuffer__", 0); if (__pyx_v_info != NULL) { __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); __Pyx_GIVEREF(__pyx_v_info->obj); } /* "View.MemoryView":184 * @cname('getbuffer') * def __getbuffer__(self, Py_buffer *info, int flags): * cdef int bufmode = -1 # <<<<<<<<<<<<<< * if self.mode == b"c": * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS */ __pyx_v_bufmode = -1; /* "View.MemoryView":185 * def __getbuffer__(self, Py_buffer *info, int flags): * cdef int bufmode = -1 * if self.mode == b"c": # <<<<<<<<<<<<<< * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS * elif self.mode == b"fortran": */ __pyx_t_1 = (__Pyx_PyUnicode_Equals(((PyObject *)__pyx_v_self->mode), ((PyObject *)__pyx_n_b__c), Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { /* "View.MemoryView":186 * cdef int bufmode = -1 * if self.mode == b"c": * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<< * elif self.mode == b"fortran": * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS */ __pyx_v_bufmode = (PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS); goto __pyx_L3; } /* "View.MemoryView":187 * if self.mode == b"c": * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS * elif self.mode == b"fortran": # <<<<<<<<<<<<<< * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS * if not (flags & bufmode): */ __pyx_t_1 = (__Pyx_PyUnicode_Equals(((PyObject *)__pyx_v_self->mode), ((PyObject *)__pyx_n_b__fortran), Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { /* "View.MemoryView":188 * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS * elif self.mode == b"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); goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":189 * elif self.mode == b"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)); if (__pyx_t_1) { /* "View.MemoryView":190 * 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_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_28), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; /* "View.MemoryView":191 * 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_v_info->buf = __pyx_v_self->data; /* "View.MemoryView":192 * 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_v_info->len = __pyx_v_self->len; /* "View.MemoryView":193 * info.buf = self.data * info.len = self.len * info.ndim = self.ndim # <<<<<<<<<<<<<< * info.shape = self._shape * info.strides = self._strides */ __pyx_v_info->ndim = __pyx_v_self->ndim; /* "View.MemoryView":194 * info.len = self.len * info.ndim = self.ndim * info.shape = self._shape # <<<<<<<<<<<<<< * info.strides = self._strides * info.suboffsets = NULL */ __pyx_v_info->shape = __pyx_v_self->_shape; /* "View.MemoryView":195 * info.ndim = self.ndim * info.shape = self._shape * info.strides = self._strides # <<<<<<<<<<<<<< * info.suboffsets = NULL * info.itemsize = self.itemsize */ __pyx_v_info->strides = __pyx_v_self->_strides; /* "View.MemoryView":196 * 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":197 * info.strides = self._strides * info.suboffsets = NULL * info.itemsize = self.itemsize # <<<<<<<<<<<<<< * info.readonly = 0 * */ __pyx_v_info->itemsize = __pyx_v_self->itemsize; /* "View.MemoryView":198 * info.suboffsets = NULL * info.itemsize = self.itemsize * info.readonly = 0 # <<<<<<<<<<<<<< * * if flags & PyBUF_FORMAT: */ __pyx_v_info->readonly = 0; /* "View.MemoryView":200 * info.readonly = 0 * * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< * info.format = self.format * else: */ __pyx_t_3 = (__pyx_v_flags & PyBUF_FORMAT); if (__pyx_t_3) { /* "View.MemoryView":201 * * if flags & PyBUF_FORMAT: * info.format = self.format # <<<<<<<<<<<<<< * else: * info.format = NULL */ __pyx_v_info->format = __pyx_v_self->format; goto __pyx_L5; } /*else*/ { /* "View.MemoryView":203 * info.format = self.format * else: * info.format = NULL # <<<<<<<<<<<<<< * * info.obj = self */ __pyx_v_info->format = NULL; } __pyx_L5:; /* "View.MemoryView":205 * 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); __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("View.MemoryView.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; if (__pyx_v_info != NULL && __pyx_v_info->obj != NULL) { __Pyx_GOTREF(__pyx_v_info->obj); __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL; } goto __pyx_L2; __pyx_L0:; if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) { __Pyx_GOTREF(Py_None); __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL; } __pyx_L2:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_5array_4__dealloc__(((struct __pyx_array_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":209 * __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) */ static void __pyx_array_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self) { __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); /* "View.MemoryView":210 * * def __dealloc__(array self): * if self.callback_free_data != NULL: # <<<<<<<<<<<<<< * self.callback_free_data(self.data) * elif self.free_data: */ __pyx_t_1 = (__pyx_v_self->callback_free_data != NULL); if (__pyx_t_1) { /* "View.MemoryView":211 * 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); goto __pyx_L3; } /* "View.MemoryView":212 * 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, */ if (__pyx_v_self->free_data) { /* "View.MemoryView":213 * 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) */ if (__pyx_v_self->dtype_is_object) { /* "View.MemoryView":215 * 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); goto __pyx_L4; } __pyx_L4:; /* "View.MemoryView":216 * refcount_objects_in_slice(self.data, self._shape, * self._strides, self.ndim, False) * free(self.data) # <<<<<<<<<<<<<< * * free(self._strides) */ free(__pyx_v_self->data); goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":218 * free(self.data) * * free(self._strides) # <<<<<<<<<<<<<< * free(self._shape) * */ free(__pyx_v_self->_strides); /* "View.MemoryView":219 * * free(self._strides) * free(self._shape) # <<<<<<<<<<<<<< * * property memview: */ free(__pyx_v_self->_shape); __Pyx_RefNannyFinishContext(); } /* Python wrapper */ static PyObject *get_memview(PyObject *__pyx_v_self); /*proto*/ static PyObject *get_memview(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = get_memview_MemoryView_5array_7memview___get__(((struct __pyx_array_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":223 * property memview: * @cname('get_memview') * def __get__(self): # <<<<<<<<<<<<<< * * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE */ static PyObject *get_memview_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self) { int __pyx_v_flags; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":225 * def __get__(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":226 * * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE * return memoryview(self, flags, self.dtype_is_object) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyInt_FromLong(__pyx_v_flags); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject *)__pyx_memoryview_type)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; __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_AddTraceback("View.MemoryView.array.memview.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_5array_6__getattr__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_attr)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":229 * * * def __getattr__(self, attr): # <<<<<<<<<<<<<< * return getattr(self.memview, attr) * */ static PyObject *__pyx_array_MemoryView_5array_6__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getattr__", 0); /* "View.MemoryView":230 * * def __getattr__(self, attr): * return getattr(self.memview, attr) # <<<<<<<<<<<<<< * * def __getitem__(self, item): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__memview); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_v_attr); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __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_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.array.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); __pyx_r = __pyx_array_MemoryView_5array_8__getitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":232 * return getattr(self.memview, attr) * * def __getitem__(self, item): # <<<<<<<<<<<<<< * return self.memview[item] * */ static PyObject *__pyx_array_MemoryView_5array_8__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); /* "View.MemoryView":233 * * def __getitem__(self, item): * return self.memview[item] # <<<<<<<<<<<<<< * * def __setitem__(self, item, value): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__memview); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetItem(__pyx_t_1, __pyx_v_item); if (!__pyx_t_2) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __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_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.array.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_5array_10__setitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item), ((PyObject *)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":235 * return self.memview[item] * * def __setitem__(self, item, value): # <<<<<<<<<<<<<< * self.memview[item] = value * */ static int __pyx_array_MemoryView_5array_10__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setitem__", 0); /* "View.MemoryView":236 * * def __setitem__(self, item, value): * self.memview[item] = value # <<<<<<<<<<<<<< * * */ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__memview); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetItem(__pyx_t_1, __pyx_v_item, __pyx_v_value) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __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_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":240 * * @cname("__pyx_array_new") * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<< * char *mode, char *buf): * cdef array result */ 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_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; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("array_cwrapper", 0); /* "View.MemoryView":244 * cdef array result * * if buf == NULL: # <<<<<<<<<<<<<< * result = array(shape, itemsize, format, mode.decode('ASCII')) * else: */ __pyx_t_1 = (__pyx_v_buf == NULL); if (__pyx_t_1) { /* "View.MemoryView":245 * * if buf == NULL: * result = array(shape, itemsize, format, mode.decode('ASCII')) # <<<<<<<<<<<<<< * else: * result = array(shape, itemsize, format, mode.decode('ASCII'), */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_t_4 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(((PyObject *)__pyx_v_shape)); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_shape)); __Pyx_GIVEREF(((PyObject *)__pyx_v_shape)); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); PyTuple_SET_ITEM(__pyx_t_5, 3, ((PyObject *)__pyx_t_4)); __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject *)__pyx_array_type)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":247 * 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_4 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_t_3 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_shape)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_shape)); __Pyx_GIVEREF(((PyObject *)__pyx_v_shape)); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_t_5)); __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_4 = 0; __pyx_t_5 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); /* "View.MemoryView":248 * else: * result = array(shape, itemsize, format, mode.decode('ASCII'), * allocate_buffer=False) # <<<<<<<<<<<<<< * result.data = buf * */ __pyx_t_5 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__allocate_buffer), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject *)__pyx_array_type)), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_5); __pyx_t_5 = 0; /* "View.MemoryView":249 * 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":251 * result.data = buf * * return result # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(((PyObject *)__pyx_r)); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = __pyx_v_result; goto __pyx_L0; __pyx_r = ((struct __pyx_array_obj *)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("View.MemoryView.array_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__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_filename = __pyx_f[2]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __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_MemoryView_4Enum___init__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), __pyx_v_name); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":277 * cdef class Enum(object): * cdef object name * def __init__(self, name): # <<<<<<<<<<<<<< * self.name = name * def __repr__(self): */ static int __pyx_MemviewEnum_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__", 0); /* "View.MemoryView":278 * cdef object name * def __init__(self, name): * self.name = name # <<<<<<<<<<<<<< * def __repr__(self): * return self.name */ __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_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_4Enum_2__repr__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":279 * def __init__(self, name): * self.name = name * def __repr__(self): # <<<<<<<<<<<<<< * return self.name * */ static PyObject *__pyx_MemviewEnum_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__repr__", 0); /* "View.MemoryView":280 * 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; __pyx_r = Py_None; __Pyx_INCREF(Py_None); __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":294 * * @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; int __pyx_t_1; /* "View.MemoryView":296 * 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_v_aligned_p = ((Py_intptr_t)__pyx_v_memory); /* "View.MemoryView":300 * * with cython.cdivision(True): * offset = aligned_p % alignment # <<<<<<<<<<<<<< * * if offset > 0: */ __pyx_v_offset = (__pyx_v_aligned_p % __pyx_v_alignment); /* "View.MemoryView":302 * offset = aligned_p % alignment * * if offset > 0: # <<<<<<<<<<<<<< * aligned_p += alignment - offset * */ __pyx_t_1 = (__pyx_v_offset > 0); if (__pyx_t_1) { /* "View.MemoryView":303 * * if offset > 0: * aligned_p += alignment - offset # <<<<<<<<<<<<<< * * return aligned_p */ __pyx_v_aligned_p = (__pyx_v_aligned_p + (__pyx_v_alignment - __pyx_v_offset)); goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":305 * aligned_p += alignment - offset * * return aligned_p # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview') */ __pyx_r = ((void *)__pyx_v_aligned_p); goto __pyx_L0; __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* 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); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__obj)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__flags)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[2]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); 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_AsInt(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { /* "View.MemoryView":323 * 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_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_filename = __pyx_f[2]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __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_MemoryView_10memoryview___cinit__(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_obj, __pyx_v_flags, __pyx_v_dtype_is_object); __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_memoryview_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_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_t_4; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); /* "View.MemoryView":324 * * 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; /* "View.MemoryView":325 * 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_v_self->flags = __pyx_v_flags; /* "View.MemoryView":326 * 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_1 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)((PyObject *)__pyx_memoryview_type))); if (!__pyx_t_1) { __pyx_t_2 = (__pyx_v_obj != Py_None); __pyx_t_3 = __pyx_t_2; } else { __pyx_t_3 = __pyx_t_1; } if (__pyx_t_3) { /* "View.MemoryView":327 * 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 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":328 * 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_3 = (((PyObject *)__pyx_v_self->view.obj) == NULL); if (__pyx_t_3) { /* "View.MemoryView":329 * __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":330 * if self.view.obj == NULL: * (<__pyx_buffer *> &self.view).obj = Py_None * Py_INCREF(Py_None) # <<<<<<<<<<<<<< * * self.lock = PyThread_allocate_lock() */ Py_INCREF(Py_None); goto __pyx_L4; } __pyx_L4:; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":332 * Py_INCREF(Py_None) * * self.lock = PyThread_allocate_lock() # <<<<<<<<<<<<<< * if self.lock == NULL: * raise MemoryError */ __pyx_v_self->lock = PyThread_allocate_lock(); /* "View.MemoryView":333 * * self.lock = PyThread_allocate_lock() * if self.lock == NULL: # <<<<<<<<<<<<<< * raise MemoryError * */ __pyx_t_3 = (__pyx_v_self->lock == NULL); if (__pyx_t_3) { /* "View.MemoryView":334 * self.lock = PyThread_allocate_lock() * if self.lock == NULL: * raise MemoryError # <<<<<<<<<<<<<< * * if flags & PyBUF_FORMAT: */ PyErr_NoMemory(); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; /* "View.MemoryView":336 * raise MemoryError * * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< * self.dtype_is_object = self.view.format == b'O' * else: */ __pyx_t_4 = (__pyx_v_flags & PyBUF_FORMAT); if (__pyx_t_4) { /* "View.MemoryView":337 * * if flags & PyBUF_FORMAT: * self.dtype_is_object = self.view.format == b'O' # <<<<<<<<<<<<<< * else: * self.dtype_is_object = dtype_is_object */ __pyx_t_5 = PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_t_6 = PyObject_RichCompare(((PyObject *)__pyx_t_5), ((PyObject *)__pyx_n_b__O), Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_self->dtype_is_object = __pyx_t_3; goto __pyx_L6; } /*else*/ { /* "View.MemoryView":339 * self.dtype_is_object = self.view.format == b'O' * else: * self.dtype_is_object = dtype_is_object # <<<<<<<<<<<<<< * * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( */ __pyx_v_self->dtype_is_object = __pyx_v_dtype_is_object; } __pyx_L6:; /* "View.MemoryView":341 * 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":343 * 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_v_self->typeinfo = NULL; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_2__dealloc__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":345 * self.typeinfo = NULL * * def __dealloc__(memoryview self): # <<<<<<<<<<<<<< * if self.obj is not None: * __Pyx_ReleaseBuffer(&self.view) */ static void __pyx_memoryview_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self) { __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); /* "View.MemoryView":346 * * def __dealloc__(memoryview self): * if self.obj is not None: # <<<<<<<<<<<<<< * __Pyx_ReleaseBuffer(&self.view) * */ __pyx_t_1 = (__pyx_v_self->obj != Py_None); if (__pyx_t_1) { /* "View.MemoryView":347 * def __dealloc__(memoryview self): * if self.obj is not None: * __Pyx_ReleaseBuffer(&self.view) # <<<<<<<<<<<<<< * * if self.lock != NULL: */ __Pyx_ReleaseBuffer((&__pyx_v_self->view)); goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":349 * __Pyx_ReleaseBuffer(&self.view) * * if self.lock != NULL: # <<<<<<<<<<<<<< * PyThread_free_lock(self.lock) * */ __pyx_t_1 = (__pyx_v_self->lock != NULL); if (__pyx_t_1) { /* "View.MemoryView":350 * * if self.lock != NULL: * PyThread_free_lock(self.lock) # <<<<<<<<<<<<<< * * cdef char *get_item_pointer(memoryview self, object index) except NULL: */ PyThread_free_lock(__pyx_v_self->lock); goto __pyx_L4; } __pyx_L4:; __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":352 * 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 */ 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_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; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("get_item_pointer", 0); /* "View.MemoryView":354 * cdef char *get_item_pointer(memoryview self, object index) except NULL: * cdef Py_ssize_t dim * cdef char *itemp = self.view.buf # <<<<<<<<<<<<<< * * for dim, idx in enumerate(index): */ __pyx_v_itemp = ((char *)__pyx_v_self->view.buf); /* "View.MemoryView":356 * cdef char *itemp = self.view.buf * * for dim, idx in enumerate(index): # <<<<<<<<<<<<<< * itemp = pybuffer_index(&self.view, itemp, idx, dim) * */ __pyx_t_1 = 0; if (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_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; } for (;;) { if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) { if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) { if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { __pyx_t_5 = __pyx_t_4(__pyx_t_2); if (unlikely(!__pyx_t_5)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } __Pyx_GOTREF(__pyx_t_5); } __Pyx_XDECREF(__pyx_v_idx); __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":357 * * for dim, idx in enumerate(index): * itemp = pybuffer_index(&self.view, itemp, idx, dim) # <<<<<<<<<<<<<< * * return itemp */ __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __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 == NULL)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_itemp = __pyx_t_7; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "View.MemoryView":359 * itemp = pybuffer_index(&self.view, itemp, idx, dim) * * return itemp # <<<<<<<<<<<<<< * * */ __pyx_r = __pyx_v_itemp; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_4__getitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":362 * * * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<< * if index is Ellipsis: * return self */ static PyObject *__pyx_memoryview_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_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)(PyObject *); char *__pyx_t_7; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); /* "View.MemoryView":363 * * def __getitem__(memoryview self, object index): * if index is Ellipsis: # <<<<<<<<<<<<<< * return self * */ __pyx_t_1 = (__pyx_v_index == __pyx_builtin_Ellipsis); if (__pyx_t_1) { /* "View.MemoryView":364 * 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; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":366 * return self * * have_slices, indices = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< * * cdef char *itemp */ __pyx_t_2 = ((PyObject *)_unellipsify(__pyx_v_index, __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (likely(PyTuple_CheckExact(__pyx_t_2))) { PyObject* sequence = __pyx_t_2; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else if (1) { __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else { Py_ssize_t index = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext; index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_6 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L5_unpacking_done; __pyx_L4_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L5_unpacking_done:; } __pyx_v_have_slices = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_indices = __pyx_t_4; __pyx_t_4 = 0; /* "View.MemoryView":369 * * cdef char *itemp * if have_slices: # <<<<<<<<<<<<<< * return memview_slice(self, indices) * else: */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { /* "View.MemoryView":370 * cdef char *itemp * if have_slices: * return memview_slice(self, indices) # <<<<<<<<<<<<<< * else: * itemp = self.get_item_pointer(indices) */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = ((PyObject *)__pyx_memview_slice(__pyx_v_self, __pyx_v_indices)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; goto __pyx_L6; } /*else*/ { /* "View.MemoryView":372 * return memview_slice(self, indices) * else: * itemp = self.get_item_pointer(indices) # <<<<<<<<<<<<<< * return self.convert_item_to_object(itemp) * */ __pyx_t_7 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_indices); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_itemp = __pyx_t_7; /* "View.MemoryView":373 * 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_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->convert_item_to_object(__pyx_v_self, __pyx_v_itemp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } __pyx_L6:; __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("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_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_6__setitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index), ((PyObject *)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":375 * return self.convert_item_to_object(itemp) * * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<< * have_slices, index = _unellipsify(index, self.view.ndim) * */ static int __pyx_memoryview_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_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_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setitem__", 0); __Pyx_INCREF(__pyx_v_index); /* "View.MemoryView":376 * * def __setitem__(memoryview self, object index, object value): * have_slices, index = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< * * if have_slices: */ __pyx_t_1 = ((PyObject *)_unellipsify(__pyx_v_index, __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (likely(PyTuple_CheckExact(__pyx_t_1))) { PyObject* sequence = __pyx_t_1; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); #else __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else if (1) { __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else { Py_ssize_t index = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); 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_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L4_unpacking_done:; } __pyx_v_have_slices = __pyx_t_2; __pyx_t_2 = 0; __Pyx_DECREF(__pyx_v_index); __pyx_v_index = __pyx_t_3; __pyx_t_3 = 0; /* "View.MemoryView":378 * have_slices, index = _unellipsify(index, self.view.ndim) * * if have_slices: # <<<<<<<<<<<<<< * obj = self.is_slice(value) * if obj: */ __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_6) { /* "View.MemoryView":379 * * if have_slices: * obj = self.is_slice(value) # <<<<<<<<<<<<<< * if obj: * self.setitem_slice_assignment(self[index], obj) */ __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->is_slice(__pyx_v_self, __pyx_v_value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_obj = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":380 * if have_slices: * obj = self.is_slice(value) * if obj: # <<<<<<<<<<<<<< * self.setitem_slice_assignment(self[index], obj) * else: */ __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_obj); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_6) { /* "View.MemoryView":381 * obj = self.is_slice(value) * if obj: * self.setitem_slice_assignment(self[index], obj) # <<<<<<<<<<<<<< * else: * self.setitem_slice_assign_scalar(self[index], value) */ __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (!__pyx_t_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assignment(__pyx_v_self, __pyx_t_1, __pyx_v_obj); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L6; } /*else*/ { /* "View.MemoryView":383 * self.setitem_slice_assignment(self[index], obj) * else: * self.setitem_slice_assign_scalar(self[index], value) # <<<<<<<<<<<<<< * else: * self.setitem_indexed(index, value) */ __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assign_scalar(__pyx_v_self, ((struct __pyx_memoryview_obj *)__pyx_t_3), __pyx_v_value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __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_L6:; goto __pyx_L5; } /*else*/ { /* "View.MemoryView":385 * self.setitem_slice_assign_scalar(self[index], value) * else: * self.setitem_indexed(index, value) # <<<<<<<<<<<<<< * * cdef is_slice(self, obj): */ __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_indexed(__pyx_v_self, __pyx_v_index, __pyx_v_value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 385; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L5:; __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("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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":387 * self.setitem_indexed(index, value) * * cdef is_slice(self, obj): # <<<<<<<<<<<<<< * if not isinstance(obj, memoryview): * try: */ static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj) { PyObject *__pyx_r = NULL; __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; PyObject *__pyx_t_8 = NULL; int __pyx_t_9; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("is_slice", 0); __Pyx_INCREF(__pyx_v_obj); /* "View.MemoryView":388 * * cdef is_slice(self, obj): * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<< * try: * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, */ __pyx_t_1 = ((PyObject *)((PyObject *)__pyx_memoryview_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_obj, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = (!__pyx_t_2); if (__pyx_t_3) { /* "View.MemoryView":389 * cdef is_slice(self, obj): * if not isinstance(obj, memoryview): * try: # <<<<<<<<<<<<<< * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, * self.dtype_is_object) */ { __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:*/ { /* "View.MemoryView":390 * if not isinstance(obj, memoryview): * try: * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<< * self.dtype_is_object) * except TypeError: */ __pyx_t_1 = PyInt_FromLong((__pyx_v_self->flags | PyBUF_ANY_CONTIGUOUS)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L4_error;} __Pyx_GOTREF(__pyx_t_1); /* "View.MemoryView":391 * 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_filename = __pyx_f[2]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L4_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L4_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_INCREF(__pyx_v_obj); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_obj); __Pyx_GIVEREF(__pyx_v_obj); PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_7); __pyx_t_1 = 0; __pyx_t_7 = 0; __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject *)__pyx_memoryview_type)), ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L4_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_v_obj); __pyx_v_obj = __pyx_t_7; __pyx_t_7 = 0; } __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_L4_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; /* "View.MemoryView":392 * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, * self.dtype_is_object) * except TypeError: # <<<<<<<<<<<<<< * return None * */ __pyx_t_9 = 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_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_GOTREF(__pyx_t_8); __Pyx_GOTREF(__pyx_t_1); /* "View.MemoryView":393 * self.dtype_is_object) * except TypeError: * return None # <<<<<<<<<<<<<< * * return obj */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_None); __pyx_r = Py_None; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; goto __pyx_L7_except_return; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L5_exception_handled; } __pyx_L6_except_error:; __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_L7_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_L5_exception_handled:; __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); __pyx_L11_try_end:; } goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":395 * return None * * return obj # <<<<<<<<<<<<<< * * cdef setitem_slice_assignment(self, dst, src): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_obj); __pyx_r = __pyx_v_obj; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":397 * return obj * * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<< * cdef __Pyx_memviewslice dst_slice * cdef __Pyx_memviewslice src_slice */ 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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; int __pyx_t_5; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("setitem_slice_assignment", 0); /* "View.MemoryView":401 * 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) */ if (!(likely(((__pyx_v_src) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_src, __pyx_memoryview_type))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_src; __Pyx_INCREF(__pyx_t_1); /* "View.MemoryView":402 * * 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_filename = __pyx_f[2]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_2 = __pyx_v_dst; __Pyx_INCREF(__pyx_t_2); /* "View.MemoryView":403 * 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_3 = PyObject_GetAttr(__pyx_v_src, __pyx_n_s__ndim); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyObject_GetAttr(__pyx_v_dst, __pyx_n_s__ndim); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_6 = __pyx_memoryview_copy_contents((__pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_t_1), (&__pyx_v_src_slice))[0]), (__pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_t_2), (&__pyx_v_dst_slice))[0]), __pyx_t_4, __pyx_t_5, __pyx_v_self->dtype_is_object); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __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_AddTraceback("View.MemoryView.memoryview.setitem_slice_assignment", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":405 * 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 */ 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[128]; void *__pyx_v_tmp; void *__pyx_v_item; __Pyx_memviewslice __pyx_v_tmp_slice; __Pyx_memviewslice *__pyx_v_dst_slice; PyObject *__pyx_r = NULL; __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; PyObject *__pyx_t_7 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("setitem_slice_assign_scalar", 0); /* "View.MemoryView":407 * 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":411 * * cdef __Pyx_memviewslice tmp_slice, *dst_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)); /* "View.MemoryView":413 * dst_slice = get_slice_from_memview(dst, &tmp_slice) * * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<< * tmp = malloc(self.view.itemsize) * if tmp == NULL: */ __pyx_t_1 = (((size_t)__pyx_v_self->view.itemsize) > (sizeof(__pyx_v_array))); if (__pyx_t_1) { /* "View.MemoryView":414 * * if self.view.itemsize > sizeof(array): * tmp = malloc(self.view.itemsize) # <<<<<<<<<<<<<< * if tmp == NULL: * raise MemoryError */ __pyx_v_tmp = malloc(__pyx_v_self->view.itemsize); /* "View.MemoryView":415 * if self.view.itemsize > sizeof(array): * tmp = malloc(self.view.itemsize) * if tmp == NULL: # <<<<<<<<<<<<<< * raise MemoryError * item = tmp */ __pyx_t_1 = (__pyx_v_tmp == NULL); if (__pyx_t_1) { /* "View.MemoryView":416 * tmp = malloc(self.view.itemsize) * if tmp == NULL: * raise MemoryError # <<<<<<<<<<<<<< * item = tmp * else: */ PyErr_NoMemory(); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; /* "View.MemoryView":417 * if tmp == NULL: * raise MemoryError * item = tmp # <<<<<<<<<<<<<< * else: * item = array */ __pyx_v_item = __pyx_v_tmp; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":419 * item = tmp * else: * item = array # <<<<<<<<<<<<<< * * if self.dtype_is_object: */ __pyx_v_item = ((void *)__pyx_v_array); } __pyx_L3:; /* "View.MemoryView":421 * item = array * * if self.dtype_is_object: # <<<<<<<<<<<<<< * ( item)[0] = value * else: */ if (__pyx_v_self->dtype_is_object) { /* "View.MemoryView":422 * * if self.dtype_is_object: * ( item)[0] = value # <<<<<<<<<<<<<< * else: * try: */ (((PyObject **)__pyx_v_item)[0]) = ((PyObject *)__pyx_v_value); goto __pyx_L5; } /*else*/ { /* "View.MemoryView":424 * ( item)[0] = value * else: * try: # <<<<<<<<<<<<<< * self.assign_item_from_object( item, value) * except: */ { __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":425 * else: * try: * self.assign_item_from_object( item, value) # <<<<<<<<<<<<<< * except: * free(tmp) */ __pyx_t_5 = ((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_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L6_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L13_try_end; __pyx_L6_error:; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; /* "View.MemoryView":426 * try: * self.assign_item_from_object( item, value) * except: # <<<<<<<<<<<<<< * free(tmp) * raise */ /*except:*/ { __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L8_except_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); /* "View.MemoryView":427 * self.assign_item_from_object( item, value) * except: * free(tmp) # <<<<<<<<<<<<<< * raise * */ free(__pyx_v_tmp); /* "View.MemoryView":428 * except: * free(tmp) * raise # <<<<<<<<<<<<<< * * */ __Pyx_GIVEREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_7); __Pyx_ErrRestore(__pyx_t_5, __pyx_t_6, __pyx_t_7); __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0; {__pyx_filename = __pyx_f[2]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L8_except_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L7_exception_handled; } __pyx_L8_except_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_L7_exception_handled:; __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); __pyx_L13_try_end:; } } __pyx_L5:; /* "View.MemoryView":432 * * * 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); if (__pyx_t_1) { /* "View.MemoryView":433 * * 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) */ __pyx_t_7 = assert_direct_dimensions(__pyx_v_self->view.suboffsets, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L16; } __pyx_L16:; /* "View.MemoryView":435 * 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) # <<<<<<<<<<<<<< * free(tmp) * */ __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":436 * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, * item, self.dtype_is_object) * free(tmp) # <<<<<<<<<<<<<< * * cdef setitem_indexed(self, index, value): */ free(__pyx_v_tmp); __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_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":438 * free(tmp) * * 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; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations char *__pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("setitem_indexed", 0); /* "View.MemoryView":439 * * cdef setitem_indexed(self, index, value): * cdef char *itemp = self.get_item_pointer(index) # <<<<<<<<<<<<<< * self.assign_item_from_object(itemp, value) * */ __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 == NULL)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_itemp = __pyx_t_1; /* "View.MemoryView":440 * 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_filename = __pyx_f[2]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":442 * 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""" */ 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_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; size_t __pyx_t_7; int __pyx_t_8; int __pyx_t_9; PyObject *__pyx_t_10 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("convert_item_to_object", 0); /* "View.MemoryView":445 * """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_1 = __Pyx_Import(((PyObject *)__pyx_n_s__struct), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_struct = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":448 * cdef bytes bytesitem * * bytesitem = itemp[:self.view.itemsize] # <<<<<<<<<<<<<< * try: * result = struct.unpack(self.view.format, bytesitem) */ __pyx_t_1 = PyBytes_FromStringAndSize(((const char*)__pyx_v_itemp) + 0, __pyx_v_self->view.itemsize - 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_v_bytesitem = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":449 * * bytesitem = itemp[:self.view.itemsize] * try: # <<<<<<<<<<<<<< * result = struct.unpack(self.view.format, bytesitem) * except struct.error: */ { __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":450 * 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_1 = PyObject_GetAttr(__pyx_v_struct, __pyx_n_s__unpack); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); __Pyx_INCREF(((PyObject *)__pyx_v_bytesitem)); PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_v_bytesitem)); __Pyx_GIVEREF(((PyObject *)__pyx_v_bytesitem)); __pyx_t_5 = 0; __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; __pyx_v_result = __pyx_t_5; __pyx_t_5 = 0; } /*else:*/ { /* "View.MemoryView":454 * raise ValueError("Unable to convert item to object") * else: * if len(self.view.format) == 1: # <<<<<<<<<<<<<< * return result[0] * return result */ __pyx_t_7 = strlen(__pyx_v_self->view.format); __pyx_t_8 = (__pyx_t_7 == 1); if (__pyx_t_8) { /* "View.MemoryView":455 * else: * if len(self.view.format) == 1: * return result[0] # <<<<<<<<<<<<<< * return result * */ __Pyx_XDECREF(__pyx_r); __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_result, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;} __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L6_except_return; goto __pyx_L11; } __pyx_L11:; /* "View.MemoryView":456 * 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_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L10_try_end; __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; /* "View.MemoryView":451 * try: * result = struct.unpack(self.view.format, bytesitem) * except struct.error: # <<<<<<<<<<<<<< * raise ValueError("Unable to convert item to object") * else: */ __pyx_t_5 = PyObject_GetAttr(__pyx_v_struct, __pyx_n_s__error); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;} __Pyx_GOTREF(__pyx_t_5); __pyx_t_9 = PyErr_ExceptionMatches(__pyx_t_5); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_9) { __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_1); /* "View.MemoryView":452 * 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_10 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_30), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_Raise(__pyx_t_10, 0, 0, 0); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; {__pyx_filename = __pyx_f[2]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L4_exception_handled; } __pyx_L5_except_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; __pyx_L4_exception_handled:; __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); __pyx_L10_try_end:; } __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_10); __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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":458 * 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""" */ 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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; 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 = NULL; char *__pyx_t_8; char *__pyx_t_9; char *__pyx_t_10; char *__pyx_t_11; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("assign_item_from_object", 0); /* "View.MemoryView":461 * """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(((PyObject *)__pyx_n_s__struct), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_struct = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":466 * cdef Py_ssize_t i * * if isinstance(value, tuple): # <<<<<<<<<<<<<< * bytesvalue = struct.pack(self.view.format, *value) * else: */ __pyx_t_1 = ((PyObject *)((PyObject*)(&PyTuple_Type))); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_value, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "View.MemoryView":467 * * if isinstance(value, tuple): * bytesvalue = struct.pack(self.view.format, *value) # <<<<<<<<<<<<<< * else: * bytesvalue = struct.pack(self.view.format, value) */ __pyx_t_1 = PyObject_GetAttr(__pyx_v_struct, __pyx_n_s__pack); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PySequence_Tuple(__pyx_v_value); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_t_5 = PyNumber_Add(((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_bytesvalue = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":469 * bytesvalue = struct.pack(self.view.format, *value) * else: * bytesvalue = struct.pack(self.view.format, value) # <<<<<<<<<<<<<< * * for i, c in enumerate(bytesvalue): */ __pyx_t_3 = PyObject_GetAttr(__pyx_v_struct, __pyx_n_s__pack); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5)); __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); __Pyx_INCREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); __pyx_t_5 = 0; __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_bytesvalue = ((PyObject*)__pyx_t_5); __pyx_t_5 = 0; } __pyx_L3:; /* "View.MemoryView":471 * bytesvalue = struct.pack(self.view.format, value) * * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< * itemp[i] = c * */ __pyx_t_6 = 0; if (unlikely(((PyObject *)__pyx_v_bytesvalue) == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __Pyx_INCREF(((PyObject *)__pyx_v_bytesvalue)); __pyx_t_7 = __pyx_v_bytesvalue; __pyx_t_9 = PyBytes_AS_STRING(__pyx_t_7); __pyx_t_10 = (__pyx_t_9 + PyBytes_GET_SIZE(__pyx_t_7)); for (__pyx_t_11 = __pyx_t_9; __pyx_t_11 < __pyx_t_10; __pyx_t_11++) { __pyx_t_8 = __pyx_t_11; __pyx_v_c = (__pyx_t_8[0]); /* "View.MemoryView":472 * * for i, c in enumerate(bytesvalue): * itemp[i] = c # <<<<<<<<<<<<<< * * @cname('getbuffer') */ __pyx_v_i = __pyx_t_6; /* "View.MemoryView":471 * bytesvalue = struct.pack(self.view.format, value) * * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< * itemp[i] = c * */ __pyx_t_6 = (__pyx_t_6 + 1); /* "View.MemoryView":472 * * for i, c in enumerate(bytesvalue): * itemp[i] = c # <<<<<<<<<<<<<< * * @cname('getbuffer') */ (__pyx_v_itemp[__pyx_v_i]) = __pyx_v_c; } __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; __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_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(((PyObject *)__pyx_t_7)); __Pyx_AddTraceback("View.MemoryView.memoryview.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_struct); __Pyx_XDECREF(__pyx_v_bytesvalue); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ static 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_getbuffer_MemoryView_10memoryview_8__getbuffer__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":475 * * @cname('getbuffer') * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< * if flags & PyBUF_STRIDES: * info.shape = self.view.shape */ static int __pyx_memoryview_getbuffer_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__getbuffer__", 0); if (__pyx_v_info != NULL) { __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); __Pyx_GIVEREF(__pyx_v_info->obj); } /* "View.MemoryView":476 * @cname('getbuffer') * def __getbuffer__(self, Py_buffer *info, int flags): * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< * info.shape = self.view.shape * else: */ __pyx_t_1 = (__pyx_v_flags & PyBUF_STRIDES); if (__pyx_t_1) { /* "View.MemoryView":477 * def __getbuffer__(self, Py_buffer *info, int flags): * if flags & PyBUF_STRIDES: * info.shape = self.view.shape # <<<<<<<<<<<<<< * else: * info.shape = NULL */ __pyx_v_info->shape = __pyx_v_self->view.shape; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":479 * info.shape = self.view.shape * else: * info.shape = NULL # <<<<<<<<<<<<<< * * if flags & PyBUF_STRIDES: */ __pyx_v_info->shape = NULL; } __pyx_L3:; /* "View.MemoryView":481 * info.shape = NULL * * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< * info.strides = self.view.strides * else: */ __pyx_t_1 = (__pyx_v_flags & PyBUF_STRIDES); if (__pyx_t_1) { /* "View.MemoryView":482 * * if flags & PyBUF_STRIDES: * info.strides = self.view.strides # <<<<<<<<<<<<<< * else: * info.strides = NULL */ __pyx_v_info->strides = __pyx_v_self->view.strides; goto __pyx_L4; } /*else*/ { /* "View.MemoryView":484 * info.strides = self.view.strides * else: * info.strides = NULL # <<<<<<<<<<<<<< * * if flags & PyBUF_INDIRECT: */ __pyx_v_info->strides = NULL; } __pyx_L4:; /* "View.MemoryView":486 * info.strides = NULL * * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<< * info.suboffsets = self.view.suboffsets * else: */ __pyx_t_1 = (__pyx_v_flags & PyBUF_INDIRECT); if (__pyx_t_1) { /* "View.MemoryView":487 * * if flags & PyBUF_INDIRECT: * info.suboffsets = self.view.suboffsets # <<<<<<<<<<<<<< * else: * info.suboffsets = NULL */ __pyx_v_info->suboffsets = __pyx_v_self->view.suboffsets; goto __pyx_L5; } /*else*/ { /* "View.MemoryView":489 * info.suboffsets = self.view.suboffsets * else: * info.suboffsets = NULL # <<<<<<<<<<<<<< * * if flags & PyBUF_FORMAT: */ __pyx_v_info->suboffsets = NULL; } __pyx_L5:; /* "View.MemoryView":491 * info.suboffsets = NULL * * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< * info.format = self.view.format * else: */ __pyx_t_1 = (__pyx_v_flags & PyBUF_FORMAT); if (__pyx_t_1) { /* "View.MemoryView":492 * * if flags & PyBUF_FORMAT: * info.format = self.view.format # <<<<<<<<<<<<<< * else: * info.format = NULL */ __pyx_v_info->format = __pyx_v_self->view.format; goto __pyx_L6; } /*else*/ { /* "View.MemoryView":494 * info.format = self.view.format * else: * info.format = NULL # <<<<<<<<<<<<<< * * info.buf = self.view.buf */ __pyx_v_info->format = NULL; } __pyx_L6:; /* "View.MemoryView":496 * info.format = NULL * * info.buf = self.view.buf # <<<<<<<<<<<<<< * info.ndim = self.view.ndim * info.itemsize = self.view.itemsize */ __pyx_v_info->buf = __pyx_v_self->view.buf; /* "View.MemoryView":497 * * info.buf = self.view.buf * info.ndim = self.view.ndim # <<<<<<<<<<<<<< * info.itemsize = self.view.itemsize * info.len = self.view.len */ __pyx_v_info->ndim = __pyx_v_self->view.ndim; /* "View.MemoryView":498 * info.buf = self.view.buf * info.ndim = self.view.ndim * info.itemsize = self.view.itemsize # <<<<<<<<<<<<<< * info.len = self.view.len * info.readonly = 0 */ __pyx_v_info->itemsize = __pyx_v_self->view.itemsize; /* "View.MemoryView":499 * info.ndim = self.view.ndim * info.itemsize = self.view.itemsize * info.len = self.view.len # <<<<<<<<<<<<<< * info.readonly = 0 * info.obj = self */ __pyx_v_info->len = __pyx_v_self->view.len; /* "View.MemoryView":500 * info.itemsize = self.view.itemsize * info.len = self.view.len * info.readonly = 0 # <<<<<<<<<<<<<< * info.obj = self * */ __pyx_v_info->readonly = 0; /* "View.MemoryView":501 * info.len = self.view.len * info.readonly = 0 * info.obj = self # <<<<<<<<<<<<<< * * __pyx_getbuffer = capsule( &__pyx_memoryview_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); __pyx_r = 0; if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) { __Pyx_GOTREF(Py_None); __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL; } __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_transpose(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_transpose(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_transpose_MemoryView_10memoryview_1T___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":508 * property T: * @cname('__pyx_memoryview_transpose') * def __get__(self): # <<<<<<<<<<<<<< * cdef _memoryviewslice result = memoryview_copy(self) * transpose_memslice(&result.from_slice) */ static PyObject *__pyx_memoryview_transpose_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self) { struct __pyx_memoryviewslice_obj *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":509 * @cname('__pyx_memoryview_transpose') * def __get__(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_filename = __pyx_f[2]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_1); __pyx_t_1 = 0; /* "View.MemoryView":510 * def __get__(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 == 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":511 * cdef _memoryviewslice result = memoryview_copy(self) * transpose_memslice(&result.from_slice) * return result # <<<<<<<<<<<<<< * * property base: */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview__get__base(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview__get__base(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview__get__base_MemoryView_10memoryview_4base___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":515 * property base: * @cname('__pyx_memoryview__get__base') * def __get__(self): # <<<<<<<<<<<<<< * return self.obj * */ static PyObject *__pyx_memoryview__get__base_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":516 * @cname('__pyx_memoryview__get__base') * def __get__(self): * return self.obj # <<<<<<<<<<<<<< * * property shape: */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->obj); __pyx_r = __pyx_v_self->obj; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_shape(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_shape(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_shape_MemoryView_10memoryview_5shape___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":520 * property shape: * @cname('__pyx_memoryview_get_shape') * def __get__(self): # <<<<<<<<<<<<<< * return tuple([self.view.shape[i] for i in xrange(self.view.ndim)]) * */ static PyObject *__pyx_memoryview_get_shape_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self) { int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":521 * @cname('__pyx_memoryview_get_shape') * def __get__(self): * return tuple([self.view.shape[i] for i in xrange(self.view.ndim)]) # <<<<<<<<<<<<<< * * property strides: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_v_self->view.ndim; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; __pyx_t_4 = PyInt_FromSsize_t((__pyx_v_self->view.shape[__pyx_v_i])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); if (unlikely(__Pyx_PyList_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_t_4 = ((PyObject *)PyList_AsTuple(__pyx_t_1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_r = ((PyObject *)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L0; __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("View.MemoryView.memoryview.shape.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_strides(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_strides(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_strides_MemoryView_10memoryview_7strides___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":525 * property strides: * @cname('__pyx_memoryview_get_strides') * def __get__(self): # <<<<<<<<<<<<<< * if self.view.strides == NULL: * */ static PyObject *__pyx_memoryview_get_strides_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self) { int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_t_4; PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":526 * @cname('__pyx_memoryview_get_strides') * def __get__(self): * if self.view.strides == NULL: # <<<<<<<<<<<<<< * * raise ValueError("Buffer view does not expose strides") */ __pyx_t_1 = (__pyx_v_self->view.strides == NULL); if (__pyx_t_1) { /* "View.MemoryView":528 * if self.view.strides == NULL: * * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< * * return tuple([self.view.strides[i] for i in xrange(self.view.ndim)]) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_32), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":530 * raise ValueError("Buffer view does not expose strides") * * return tuple([self.view.strides[i] for i in xrange(self.view.ndim)]) # <<<<<<<<<<<<<< * * property suboffsets: */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_v_self->view.ndim; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; __pyx_t_5 = PyInt_FromSsize_t((__pyx_v_self->view.strides[__pyx_v_i])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); if (unlikely(__Pyx_PyList_Append(__pyx_t_2, (PyObject*)__pyx_t_5))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __pyx_t_5 = ((PyObject *)PyList_AsTuple(__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = ((PyObject *)__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L0; __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_AddTraceback("View.MemoryView.memoryview.strides.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_suboffsets(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_suboffsets(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_suboffsets_MemoryView_10memoryview_10suboffsets___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":534 * property suboffsets: * @cname('__pyx_memoryview_get_suboffsets') * def __get__(self): # <<<<<<<<<<<<<< * if self.view.suboffsets == NULL: * return [-1] * self.view.ndim */ static PyObject *__pyx_memoryview_get_suboffsets_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self) { int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_t_4; PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":535 * @cname('__pyx_memoryview_get_suboffsets') * def __get__(self): * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<< * return [-1] * self.view.ndim * */ __pyx_t_1 = (__pyx_v_self->view.suboffsets == NULL); if (__pyx_t_1) { /* "View.MemoryView":536 * def __get__(self): * if self.view.suboffsets == NULL: * return [-1] * self.view.ndim # <<<<<<<<<<<<<< * * return tuple([self.view.suboffsets[i] for i in xrange(self.view.ndim)]) */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyList_New(1 * ((__pyx_v_self->view.ndim<0) ? 0:__pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < __pyx_v_self->view.ndim; __pyx_temp++) { __Pyx_INCREF(__pyx_int_neg_1); PyList_SET_ITEM(__pyx_t_2, __pyx_temp, __pyx_int_neg_1); __Pyx_GIVEREF(__pyx_int_neg_1); } } __pyx_r = ((PyObject *)__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L0; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":538 * return [-1] * self.view.ndim * * return tuple([self.view.suboffsets[i] for i in xrange(self.view.ndim)]) # <<<<<<<<<<<<<< * * property ndim: */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_v_self->view.ndim; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; __pyx_t_5 = PyInt_FromSsize_t((__pyx_v_self->view.suboffsets[__pyx_v_i])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); if (unlikely(__Pyx_PyList_Append(__pyx_t_2, (PyObject*)__pyx_t_5))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __pyx_t_5 = ((PyObject *)PyList_AsTuple(__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = ((PyObject *)__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L0; __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_AddTraceback("View.MemoryView.memoryview.suboffsets.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_ndim(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_ndim(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_ndim_MemoryView_10memoryview_4ndim___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":542 * property ndim: * @cname('__pyx_memoryview_get_ndim') * def __get__(self): # <<<<<<<<<<<<<< * return self.view.ndim * */ static PyObject *__pyx_memoryview_get_ndim_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":543 * @cname('__pyx_memoryview_get_ndim') * def __get__(self): * return self.view.ndim # <<<<<<<<<<<<<< * * property itemsize: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyInt_FromLong(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_itemsize(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_itemsize(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_itemsize_MemoryView_10memoryview_8itemsize___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":547 * property itemsize: * @cname('__pyx_memoryview_get_itemsize') * def __get__(self): # <<<<<<<<<<<<<< * return self.view.itemsize * */ static PyObject *__pyx_memoryview_get_itemsize_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":548 * @cname('__pyx_memoryview_get_itemsize') * def __get__(self): * return self.view.itemsize # <<<<<<<<<<<<<< * * property nbytes: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 548; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_nbytes(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_nbytes(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_nbytes_MemoryView_10memoryview_6nbytes___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":552 * property nbytes: * @cname('__pyx_memoryview_get_nbytes') * def __get__(self): # <<<<<<<<<<<<<< * return self.size * self.view.itemsize * */ static PyObject *__pyx_memoryview_get_nbytes_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":553 * @cname('__pyx_memoryview_get_nbytes') * def __get__(self): * return self.size * self.view.itemsize # <<<<<<<<<<<<<< * * property size: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __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_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_AddTraceback("View.MemoryView.memoryview.nbytes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_size(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_size(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_size_MemoryView_10memoryview_4size___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":557 * property size: * @cname('__pyx_memoryview_get_size') * def __get__(self): # <<<<<<<<<<<<<< * if self._size is None: * result = 1 */ static PyObject *__pyx_memoryview_get_size_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_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_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":558 * @cname('__pyx_memoryview_get_size') * def __get__(self): * if self._size is None: # <<<<<<<<<<<<<< * result = 1 * */ __pyx_t_1 = (__pyx_v_self->_size == Py_None); if (__pyx_t_1) { /* "View.MemoryView":559 * def __get__(self): * if self._size is None: * result = 1 # <<<<<<<<<<<<<< * * for length in self.shape: */ __Pyx_INCREF(__pyx_int_1); __pyx_v_result = __pyx_int_1; /* "View.MemoryView":561 * result = 1 * * for length in self.shape: # <<<<<<<<<<<<<< * result *= length * */ __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (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_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_3)) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_3)) { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { __pyx_t_2 = __pyx_t_5(__pyx_t_3); if (unlikely(!__pyx_t_2)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } __Pyx_GOTREF(__pyx_t_2); } __Pyx_XDECREF(__pyx_v_length); __pyx_v_length = __pyx_t_2; __pyx_t_2 = 0; /* "View.MemoryView":562 * * for length in self.shape: * result *= length # <<<<<<<<<<<<<< * * self._size = result */ __pyx_t_2 = PyNumber_InPlaceMultiply(__pyx_v_result, __pyx_v_length); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_v_result); __pyx_v_result = __pyx_t_2; __pyx_t_2 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "View.MemoryView":564 * result *= length * * 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; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":566 * self._size = result * * return self._size # <<<<<<<<<<<<<< * * def __len__(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_size); __pyx_r = __pyx_v_self->_size; goto __pyx_L0; __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.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_RefNannyFinishContext(); return __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_MemoryView_10memoryview_10__len__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":568 * return self._size * * def __len__(self): # <<<<<<<<<<<<<< * if self.view.ndim >= 1: * return self.view.shape[0] */ static Py_ssize_t __pyx_memoryview_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self) { Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__len__", 0); /* "View.MemoryView":569 * * def __len__(self): * if self.view.ndim >= 1: # <<<<<<<<<<<<<< * return self.view.shape[0] * */ __pyx_t_1 = (__pyx_v_self->view.ndim >= 1); if (__pyx_t_1) { /* "View.MemoryView":570 * def __len__(self): * if self.view.ndim >= 1: * return self.view.shape[0] # <<<<<<<<<<<<<< * * return 0 */ __pyx_r = (__pyx_v_self->view.shape[0]); goto __pyx_L0; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":572 * return self.view.shape[0] * * return 0 # <<<<<<<<<<<<<< * * def __repr__(self): */ __pyx_r = 0; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_12__repr__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":574 * return 0 * * def __repr__(self): # <<<<<<<<<<<<<< * return "" % (self.base.__class__.__name__, * id(self)) */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__repr__", 0); /* "View.MemoryView":575 * * def __repr__(self): * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<< * id(self)) * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__base); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____class__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____name__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "View.MemoryView":576 * def __repr__(self): * return "" % (self.base.__class__.__name__, * id(self)) # <<<<<<<<<<<<<< * * def __str__(self): */ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); __pyx_t_3 = PyObject_Call(__pyx_builtin_id, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_33), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = ((PyObject *)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; __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_AddTraceback("View.MemoryView.memoryview.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_14__str__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":578 * id(self)) * * def __str__(self): # <<<<<<<<<<<<<< * return "" % (self.base.__class__.__name__,) * */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__str__", 0); /* "View.MemoryView":579 * * def __str__(self): * return "" % (self.base.__class__.__name__,) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__base); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____class__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____name__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_34), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; __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.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_16is_c_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":582 * * * def is_c_contig(self): # <<<<<<<<<<<<<< * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) */ static PyObject *__pyx_memoryview_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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("is_c_contig", 0); /* "View.MemoryView":584 * def is_c_contig(self): * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< * return slice_is_contig(mslice, 'C', self.view.ndim) * */ __pyx_v_mslice = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); /* "View.MemoryView":585 * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) * return slice_is_contig(mslice, 'C', self.view.ndim) # <<<<<<<<<<<<<< * * def is_f_contig(self): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig(__pyx_v_mslice, 'C', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 585; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); 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_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_18is_f_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":587 * return slice_is_contig(mslice, 'C', self.view.ndim) * * def is_f_contig(self): # <<<<<<<<<<<<<< * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) */ static PyObject *__pyx_memoryview_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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("is_f_contig", 0); /* "View.MemoryView":589 * def is_f_contig(self): * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< * return slice_is_contig(mslice, 'F', self.view.ndim) * */ __pyx_v_mslice = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); /* "View.MemoryView":590 * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) * return slice_is_contig(mslice, 'F', self.view.ndim) # <<<<<<<<<<<<<< * * def copy(self): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig(__pyx_v_mslice, 'F', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __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_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_20copy(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":592 * return slice_is_contig(mslice, 'F', self.view.ndim) * * def copy(self): # <<<<<<<<<<<<<< * cdef __Pyx_memviewslice mslice * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self) { __Pyx_memviewslice __pyx_v_mslice; int __pyx_v_flags; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_memviewslice __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("copy", 0); /* "View.MemoryView":594 * def copy(self): * cdef __Pyx_memviewslice mslice * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS # <<<<<<<<<<<<<< * * slice_copy(self, &mslice) */ __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_F_CONTIGUOUS)); /* "View.MemoryView":596 * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS * * 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":600 * self.view.itemsize, * flags|PyBUF_C_CONTIGUOUS, * self.dtype_is_object) # <<<<<<<<<<<<<< * * return memoryview_copy_from_slice(self, &mslice) */ __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_mslice), __pyx_k__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_filename = __pyx_f[2]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_mslice = __pyx_t_1; /* "View.MemoryView":602 * self.dtype_is_object) * * return memoryview_copy_from_slice(self, &mslice) # <<<<<<<<<<<<<< * * 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_filename = __pyx_f[2]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("View.MemoryView.memoryview.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __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_MemoryView_10memoryview_22copy_fortran(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":604 * return memoryview_copy_from_slice(self, &mslice) * * def copy_fortran(self): # <<<<<<<<<<<<<< * cdef __Pyx_memviewslice src, dst * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS */ static PyObject *__pyx_memoryview_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_RefNannyDeclarations __Pyx_memviewslice __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("copy_fortran", 0); /* "View.MemoryView":606 * def copy_fortran(self): * cdef __Pyx_memviewslice src, dst * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS # <<<<<<<<<<<<<< * * slice_copy(self, &src) */ __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_C_CONTIGUOUS)); /* "View.MemoryView":608 * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS * * 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":612 * self.view.itemsize, * flags|PyBUF_F_CONTIGUOUS, * self.dtype_is_object) # <<<<<<<<<<<<<< * * return memoryview_copy_from_slice(self, &dst) */ __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_src), __pyx_k__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_filename = __pyx_f[2]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_dst = __pyx_t_1; /* "View.MemoryView":614 * self.dtype_is_object) * * return memoryview_copy_from_slice(self, &dst) # <<<<<<<<<<<<<< * * */ __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_filename = __pyx_f[2]; __pyx_lineno = 614; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); 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_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":618 * * @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 */ 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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("memoryview_cwrapper", 0); /* "View.MemoryView":619 * @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_t_1 = PyInt_FromLong(__pyx_v_flags); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_o); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_o); __Pyx_GIVEREF(__pyx_v_o); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject *)__pyx_memoryview_type)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_v_result = ((struct __pyx_memoryview_obj *)__pyx_t_2); __pyx_t_2 = 0; /* "View.MemoryView":620 * 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_v_result->typeinfo = __pyx_v_typeinfo; /* "View.MemoryView":621 * cdef memoryview result = memoryview(o, flags, dtype_is_object) * result.typeinfo = typeinfo * return result # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_check') */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0; __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_AddTraceback("View.MemoryView.memoryview_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":624 * * @cname('__pyx_memoryview_check') * cdef bint memoryview_check(object o): # <<<<<<<<<<<<<< * return isinstance(o, memoryview) * */ static int __pyx_memoryview_check(PyObject *__pyx_v_o) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; __Pyx_RefNannySetupContext("memoryview_check", 0); /* "View.MemoryView":625 * @cname('__pyx_memoryview_check') * cdef bint memoryview_check(object o): * return isinstance(o, memoryview) # <<<<<<<<<<<<<< * * cdef tuple _unellipsify(object index, int ndim): */ __pyx_t_1 = ((PyObject *)((PyObject *)__pyx_memoryview_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_o, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":627 * return isinstance(o, memoryview) * * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<< * """ * Replace all ellipses with full slices and fill incomplete indices with */ static PyObject *_unellipsify(PyObject *__pyx_v_index, int __pyx_v_ndim) { PyObject *__pyx_v_tup = NULL; PyObject *__pyx_v_result = NULL; PyObject *__pyx_v_have_slices = NULL; int __pyx_v_seen_ellipsis; CYTHON_UNUSED PyObject *__pyx_v_idx = NULL; PyObject *__pyx_v_item = NULL; PyObject *__pyx_v_nslices = NULL; PyObject *__pyx_r = NULL; __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; Py_ssize_t __pyx_t_9; PyObject *__pyx_t_10 = NULL; int __pyx_t_11; int __pyx_t_12; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("_unellipsify", 0); /* "View.MemoryView":632 * full slices. * """ * if not isinstance(index, tuple): # <<<<<<<<<<<<<< * tup = (index,) * else: */ __pyx_t_1 = ((PyObject *)((PyObject*)(&PyTuple_Type))); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_index, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = (!__pyx_t_2); if (__pyx_t_3) { /* "View.MemoryView":633 * """ * if not isinstance(index, tuple): * tup = (index,) # <<<<<<<<<<<<<< * else: * tup = index */ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_index); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_index); __Pyx_GIVEREF(__pyx_v_index); __pyx_v_tup = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":635 * tup = (index,) * else: * tup = index # <<<<<<<<<<<<<< * * result = [] */ __Pyx_INCREF(__pyx_v_index); __pyx_v_tup = __pyx_v_index; } __pyx_L3:; /* "View.MemoryView":637 * tup = index * * result = [] # <<<<<<<<<<<<<< * have_slices = False * seen_ellipsis = False */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":638 * * result = [] * have_slices = False # <<<<<<<<<<<<<< * seen_ellipsis = False * for idx, item in enumerate(tup): */ __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_have_slices = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":639 * result = [] * have_slices = False * seen_ellipsis = False # <<<<<<<<<<<<<< * for idx, item in enumerate(tup): * if item is Ellipsis: */ __pyx_v_seen_ellipsis = 0; /* "View.MemoryView":640 * have_slices = False * seen_ellipsis = False * for idx, item in enumerate(tup): # <<<<<<<<<<<<<< * if item is Ellipsis: * if not seen_ellipsis: */ __Pyx_INCREF(__pyx_int_0); __pyx_t_1 = __pyx_int_0; if (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_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; } for (;;) { if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_4)) { if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_4)) { if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { __pyx_t_7 = __pyx_t_6(__pyx_t_4); if (unlikely(!__pyx_t_7)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } __Pyx_GOTREF(__pyx_t_7); } __Pyx_XDECREF(__pyx_v_item); __pyx_v_item = __pyx_t_7; __pyx_t_7 = 0; __Pyx_INCREF(__pyx_t_1); __Pyx_XDECREF(__pyx_v_idx); __pyx_v_idx = __pyx_t_1; __pyx_t_7 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = __pyx_t_7; __pyx_t_7 = 0; /* "View.MemoryView":641 * 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)) */ __pyx_t_3 = (__pyx_v_item == __pyx_builtin_Ellipsis); if (__pyx_t_3) { /* "View.MemoryView":642 * 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_3 = (!__pyx_v_seen_ellipsis); if (__pyx_t_3) { /* "View.MemoryView":643 * if item is Ellipsis: * if not seen_ellipsis: * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<< * seen_ellipsis = True * else: */ __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_result), __pyx_n_s__extend); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = PyObject_Call(((PyObject *)((PyObject*)(&PySlice_Type))), ((PyObject *)__pyx_k_tuple_35), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = PyObject_Length(__pyx_v_tup); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_10 = PyList_New(1 * ((((__pyx_v_ndim - __pyx_t_9) + 1)<0) ? 0:((__pyx_v_ndim - __pyx_t_9) + 1))); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < ((__pyx_v_ndim - __pyx_t_9) + 1); __pyx_temp++) { __Pyx_INCREF(__pyx_t_8); PyList_SET_ITEM(__pyx_t_10, __pyx_temp, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); } } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_10)); __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; /* "View.MemoryView":644 * 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; goto __pyx_L7; } /*else*/ { /* "View.MemoryView":646 * seen_ellipsis = True * else: * result.append(slice(None)) # <<<<<<<<<<<<<< * have_slices = True * else: */ __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)(&PySlice_Type))), ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_11 = PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } __pyx_L7:; /* "View.MemoryView":647 * else: * result.append(slice(None)) * have_slices = True # <<<<<<<<<<<<<< * else: * if not isinstance(item, slice) and not PyIndex_Check(item): */ __pyx_t_10 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_v_have_slices); __pyx_v_have_slices = __pyx_t_10; __pyx_t_10 = 0; goto __pyx_L6; } /*else*/ { /* "View.MemoryView":649 * have_slices = True * else: * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<< * raise TypeError("Cannot index with type '%s'" % type(item)) * */ __pyx_t_10 = ((PyObject *)((PyObject*)(&PySlice_Type))); __Pyx_INCREF(__pyx_t_10); __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_item, __pyx_t_10); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_2 = (!__pyx_t_3); if (__pyx_t_2) { __pyx_t_3 = (!PyIndex_Check(__pyx_v_item)); __pyx_t_12 = __pyx_t_3; } else { __pyx_t_12 = __pyx_t_2; } if (__pyx_t_12) { /* "View.MemoryView":650 * else: * if not isinstance(item, slice) and not PyIndex_Check(item): * raise TypeError("Cannot index with type '%s'" % type(item)) # <<<<<<<<<<<<<< * * have_slices = have_slices or isinstance(item, slice) */ __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_37), ((PyObject *)Py_TYPE(__pyx_v_item))); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_10)); __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_10)); __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; __Pyx_Raise(__pyx_t_10, 0, 0, 0); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; {__pyx_filename = __pyx_f[2]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L8; } __pyx_L8:; /* "View.MemoryView":652 * raise TypeError("Cannot index with type '%s'" % type(item)) * * have_slices = have_slices or isinstance(item, slice) # <<<<<<<<<<<<<< * result.append(item) * */ __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (!__pyx_t_12) { __pyx_t_10 = ((PyObject *)((PyObject*)(&PySlice_Type))); __Pyx_INCREF(__pyx_t_10); __pyx_t_12 = __Pyx_TypeCheck(__pyx_v_item, __pyx_t_10); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyBool_FromLong(__pyx_t_12); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_8 = __pyx_t_10; __pyx_t_10 = 0; } else { __Pyx_INCREF(__pyx_v_have_slices); __pyx_t_8 = __pyx_v_have_slices; } __Pyx_DECREF(__pyx_v_have_slices); __pyx_v_have_slices = __pyx_t_8; __pyx_t_8 = 0; /* "View.MemoryView":653 * * have_slices = have_slices or isinstance(item, slice) * result.append(item) # <<<<<<<<<<<<<< * * nslices = ndim - len(result) */ __pyx_t_11 = PyList_Append(__pyx_v_result, __pyx_v_item); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L6:; } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "View.MemoryView":655 * result.append(item) * * nslices = ndim - len(result) # <<<<<<<<<<<<<< * if nslices: * result.extend([slice(None)] * nslices) */ __pyx_t_5 = PyList_GET_SIZE(((PyObject *)__pyx_v_result)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = PyInt_FromSsize_t((__pyx_v_ndim - __pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_nslices = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":656 * * nslices = ndim - len(result) * if nslices: # <<<<<<<<<<<<<< * result.extend([slice(None)] * nslices) * */ __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_nslices); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_12) { /* "View.MemoryView":657 * nslices = ndim - len(result) * if nslices: * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<< * * return have_slices or nslices, tuple(result) */ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_result), __pyx_n_s__extend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PySlice_Type))), ((PyObject *)__pyx_k_tuple_38), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); PyList_SET_ITEM(__pyx_t_8, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); { PyObject* __pyx_temp = PyNumber_InPlaceMultiply(__pyx_t_8, __pyx_v_nslices); if (unlikely(!__pyx_temp)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_temp); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = __pyx_temp; } __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_8)); __Pyx_GIVEREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; __pyx_t_8 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; goto __pyx_L9; } __pyx_L9:; /* "View.MemoryView":659 * result.extend([slice(None)] * nslices) * * return have_slices or nslices, tuple(result) # <<<<<<<<<<<<<< * * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): */ __Pyx_XDECREF(((PyObject *)__pyx_r)); __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (!__pyx_t_12) { __Pyx_INCREF(__pyx_v_nslices); __pyx_t_8 = __pyx_v_nslices; } else { __Pyx_INCREF(__pyx_v_have_slices); __pyx_t_8 = __pyx_v_have_slices; } __pyx_t_4 = ((PyObject *)PyList_AsTuple(__pyx_v_result)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_t_4)); __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); __pyx_t_8 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = ((PyObject*)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_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_10); __Pyx_AddTraceback("View.MemoryView._unellipsify", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_tup); __Pyx_XDECREF(__pyx_v_result); __Pyx_XDECREF(__pyx_v_have_slices); __Pyx_XDECREF(__pyx_v_idx); __Pyx_XDECREF(__pyx_v_item); __Pyx_XDECREF(__pyx_v_nslices); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":661 * return have_slices or nslices, tuple(result) * * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<< * cdef int i * for i in range(ndim): */ static PyObject *assert_direct_dimensions(Py_ssize_t *__pyx_v_suboffsets, int __pyx_v_ndim) { int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("assert_direct_dimensions", 0); /* "View.MemoryView":663 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): * cdef int i * for i in range(ndim): # <<<<<<<<<<<<<< * if suboffsets[i] >= 0: * raise ValueError("Indirect dimensions not supported") */ __pyx_t_1 = __pyx_v_ndim; for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":664 * cdef int i * for i in range(ndim): * if suboffsets[i] >= 0: # <<<<<<<<<<<<<< * raise ValueError("Indirect dimensions not supported") * */ __pyx_t_3 = ((__pyx_v_suboffsets[__pyx_v_i]) >= 0); if (__pyx_t_3) { /* "View.MemoryView":665 * for i in range(ndim): * if suboffsets[i] >= 0: * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< * * */ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; } __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("View.MemoryView.assert_direct_dimensions", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":672 * * @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 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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_t_3; Py_ssize_t __pyx_t_4; PyObject *(*__pyx_t_5)(PyObject *); PyObject *__pyx_t_6 = NULL; int __pyx_t_7; Py_ssize_t __pyx_t_8; PyObject *__pyx_t_9 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("memview_slice", 0); /* "View.MemoryView":673 * @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_v_new_ndim = 0; __pyx_v_suboffset_dim = -1; /* "View.MemoryView":680 * * * memset(&dst, 0, sizeof(dst)) # <<<<<<<<<<<<<< * * cdef _memoryviewslice memviewsliceobj */ memset((&__pyx_v_dst), 0, (sizeof(__pyx_v_dst))); /* "View.MemoryView":684 * cdef _memoryviewslice memviewsliceobj * * assert memview.view.ndim > 0 # <<<<<<<<<<<<<< * * if isinstance(memview, _memoryviewslice): */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!(__pyx_v_memview->view.ndim > 0))) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif /* "View.MemoryView":686 * assert memview.view.ndim > 0 * * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< * memviewsliceobj = memview * p_src = &memviewsliceobj.from_slice */ __pyx_t_1 = ((PyObject *)((PyObject *)__pyx_memoryviewslice_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "View.MemoryView":687 * * 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_filename = __pyx_f[2]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_INCREF(((PyObject *)__pyx_v_memview)); __pyx_v_memviewsliceobj = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview); /* "View.MemoryView":688 * if isinstance(memview, _memoryviewslice): * memviewsliceobj = memview * p_src = &memviewsliceobj.from_slice # <<<<<<<<<<<<<< * else: * slice_copy(memview, &src) */ __pyx_v_p_src = (&__pyx_v_memviewsliceobj->from_slice); goto __pyx_L3; } /*else*/ { /* "View.MemoryView":690 * p_src = &memviewsliceobj.from_slice * else: * slice_copy(memview, &src) # <<<<<<<<<<<<<< * p_src = &src * */ __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_src)); /* "View.MemoryView":691 * else: * slice_copy(memview, &src) * p_src = &src # <<<<<<<<<<<<<< * * */ __pyx_v_p_src = (&__pyx_v_src); } __pyx_L3:; /* "View.MemoryView":697 * * * dst.memview = p_src.memview # <<<<<<<<<<<<<< * dst.data = p_src.data * */ __pyx_v_dst.memview = __pyx_v_p_src->memview; /* "View.MemoryView":698 * * dst.memview = p_src.memview * dst.data = p_src.data # <<<<<<<<<<<<<< * * */ __pyx_v_dst.data = __pyx_v_p_src->data; /* "View.MemoryView":703 * * * 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":704 * * 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_p_suboffset_dim = (&__pyx_v_suboffset_dim); /* "View.MemoryView":708 * cdef bint have_start, have_stop, have_step * * for dim, index in enumerate(indices): # <<<<<<<<<<<<<< * if PyIndex_Check(index): * slice_memviewslice( */ __pyx_t_3 = 0; if (PyList_CheckExact(__pyx_v_indices) || PyTuple_CheckExact(__pyx_v_indices)) { __pyx_t_1 = __pyx_v_indices; __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_indices); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; } for (;;) { if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_1)) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_1)) { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { __pyx_t_6 = __pyx_t_5(__pyx_t_1); if (unlikely(!__pyx_t_6)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } __Pyx_GOTREF(__pyx_t_6); } __Pyx_XDECREF(__pyx_v_index); __pyx_v_index = __pyx_t_6; __pyx_t_6 = 0; __pyx_v_dim = __pyx_t_3; __pyx_t_3 = (__pyx_t_3 + 1); /* "View.MemoryView":709 * * 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_7 = PyIndex_Check(__pyx_v_index); if (__pyx_t_7) { /* "View.MemoryView":713 * 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_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":715 * index, 0, 0, # start, stop, step * 0, 0, 0, # have_{start,stop,step} * False) # <<<<<<<<<<<<<< * elif index is None: * p_dst.shape[new_ndim] = 1 */ __pyx_t_7 = __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_8, 0, 0, 0, 0, 0, 0); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } /* "View.MemoryView":716 * 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); if (__pyx_t_2) { /* "View.MemoryView":717 * 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":718 * 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":719 * 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]) = -1; /* "View.MemoryView":720 * 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); goto __pyx_L6; } /*else*/ { /* "View.MemoryView":722 * new_ndim += 1 * else: * start = index.start or 0 # <<<<<<<<<<<<<< * stop = index.stop or 0 * step = index.step or 0 */ __pyx_t_6 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__start); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 722; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 722; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (!__pyx_t_2) { __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_INCREF(__pyx_int_0); __pyx_t_9 = __pyx_int_0; } else { __pyx_t_9 = __pyx_t_6; __pyx_t_6 = 0; } __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 722; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_start = __pyx_t_8; /* "View.MemoryView":723 * else: * start = index.start or 0 * stop = index.stop or 0 # <<<<<<<<<<<<<< * step = index.step or 0 * */ __pyx_t_9 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__stop); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (!__pyx_t_2) { __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_INCREF(__pyx_int_0); __pyx_t_6 = __pyx_int_0; } else { __pyx_t_6 = __pyx_t_9; __pyx_t_9 = 0; } __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_6); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_stop = __pyx_t_8; /* "View.MemoryView":724 * start = index.start or 0 * stop = index.stop or 0 * step = index.step or 0 # <<<<<<<<<<<<<< * * have_start = index.start is not None */ __pyx_t_6 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__step); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (!__pyx_t_2) { __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_INCREF(__pyx_int_0); __pyx_t_9 = __pyx_int_0; } else { __pyx_t_9 = __pyx_t_6; __pyx_t_6 = 0; } __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_step = __pyx_t_8; /* "View.MemoryView":726 * 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 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__start); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = (__pyx_t_9 != Py_None); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_have_start = __pyx_t_2; /* "View.MemoryView":727 * * have_start = index.start is not None * have_stop = index.stop is not None # <<<<<<<<<<<<<< * have_step = index.step is not None * */ __pyx_t_9 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__stop); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = (__pyx_t_9 != Py_None); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_have_stop = __pyx_t_2; /* "View.MemoryView":728 * 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 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__step); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = (__pyx_t_9 != Py_None); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_have_step = __pyx_t_2; /* "View.MemoryView":735 * start, stop, step, * have_start, have_stop, have_step, * True) # <<<<<<<<<<<<<< * new_ndim += 1 * */ __pyx_t_7 = __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_7 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 730; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":736 * 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:; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "View.MemoryView":738 * new_ndim += 1 * * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< * return memoryview_fromslice(dst, new_ndim, * memviewsliceobj.to_object_func, */ __pyx_t_1 = ((PyObject *)((PyObject *)__pyx_memoryviewslice_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "View.MemoryView":739 * * 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":740 * 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_filename = __pyx_f[2]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "View.MemoryView":742 * memviewsliceobj.to_object_func, * memviewsliceobj.to_dtype_func, * memview.dtype_is_object) # <<<<<<<<<<<<<< * else: * return memoryview_fromslice(dst, new_ndim, NULL, NULL, */ __pyx_t_1 = __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_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryview_type))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; goto __pyx_L7; } /*else*/ { /* "View.MemoryView":744 * memview.dtype_is_object) * else: * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<< * memview.dtype_is_object) * */ __Pyx_XDECREF(((PyObject *)__pyx_r)); /* "View.MemoryView":745 * else: * return memoryview_fromslice(dst, new_ndim, NULL, NULL, * memview.dtype_is_object) # <<<<<<<<<<<<<< * * */ __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, NULL, NULL, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryview_type))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; } __pyx_L7:; __pyx_r = ((struct __pyx_memoryview_obj *)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_9); __Pyx_AddTraceback("View.MemoryView.memview_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_memviewsliceobj); __Pyx_XDECREF(__pyx_v_index); __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":769 * * @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_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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_t_4; Py_ssize_t __pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* "View.MemoryView":789 * cdef bint negative_step * * if not is_slice: # <<<<<<<<<<<<<< * * if start < 0: */ __pyx_t_1 = (!__pyx_v_is_slice); if (__pyx_t_1) { /* "View.MemoryView":791 * if not is_slice: * * if start < 0: # <<<<<<<<<<<<<< * start += shape * if not 0 <= start < shape: */ __pyx_t_1 = (__pyx_v_start < 0); if (__pyx_t_1) { /* "View.MemoryView":792 * * 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); goto __pyx_L4; } __pyx_L4:; /* "View.MemoryView":793 * 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_2 = (!__pyx_t_1); if (__pyx_t_2) { /* "View.MemoryView":794 * 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, __pyx_k_41, __pyx_v_dim); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":797 * else: * * negative_step = have_step != 0 and step < 0 # <<<<<<<<<<<<<< * * if have_step and step == 0: */ __pyx_t_2 = (__pyx_v_have_step != 0); if (__pyx_t_2) { __pyx_t_1 = (__pyx_v_step < 0); __pyx_t_4 = __pyx_t_1; } else { __pyx_t_4 = __pyx_t_2; } __pyx_v_negative_step = __pyx_t_4; /* "View.MemoryView":799 * 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) * */ if (__pyx_v_have_step) { __pyx_t_4 = (__pyx_v_step == 0); __pyx_t_2 = __pyx_t_4; } else { __pyx_t_2 = __pyx_v_have_step; } if (__pyx_t_2) { /* "View.MemoryView":800 * * 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, __pyx_k_42, __pyx_v_dim); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; /* "View.MemoryView":803 * * * if have_start: # <<<<<<<<<<<<<< * if start < 0: * start += shape */ if (__pyx_v_have_start) { /* "View.MemoryView":804 * * if have_start: * if start < 0: # <<<<<<<<<<<<<< * start += shape * if start < 0: */ __pyx_t_2 = (__pyx_v_start < 0); if (__pyx_t_2) { /* "View.MemoryView":805 * if have_start: * if start < 0: * start += shape # <<<<<<<<<<<<<< * if start < 0: * start = 0 */ __pyx_v_start = (__pyx_v_start + __pyx_v_shape); /* "View.MemoryView":806 * if start < 0: * start += shape * if start < 0: # <<<<<<<<<<<<<< * start = 0 * elif start >= shape: */ __pyx_t_2 = (__pyx_v_start < 0); if (__pyx_t_2) { /* "View.MemoryView":807 * start += shape * if start < 0: * start = 0 # <<<<<<<<<<<<<< * elif start >= shape: * if negative_step: */ __pyx_v_start = 0; goto __pyx_L9; } __pyx_L9:; goto __pyx_L8; } /* "View.MemoryView":808 * if start < 0: * start = 0 * elif start >= shape: # <<<<<<<<<<<<<< * if negative_step: * start = shape - 1 */ __pyx_t_2 = (__pyx_v_start >= __pyx_v_shape); if (__pyx_t_2) { /* "View.MemoryView":809 * start = 0 * elif start >= shape: * if negative_step: # <<<<<<<<<<<<<< * start = shape - 1 * else: */ if (__pyx_v_negative_step) { /* "View.MemoryView":810 * elif start >= shape: * if negative_step: * start = shape - 1 # <<<<<<<<<<<<<< * else: * start = shape */ __pyx_v_start = (__pyx_v_shape - 1); goto __pyx_L10; } /*else*/ { /* "View.MemoryView":812 * start = shape - 1 * else: * start = shape # <<<<<<<<<<<<<< * else: * if negative_step: */ __pyx_v_start = __pyx_v_shape; } __pyx_L10:; goto __pyx_L8; } __pyx_L8:; goto __pyx_L7; } /*else*/ { /* "View.MemoryView":814 * start = shape * else: * if negative_step: # <<<<<<<<<<<<<< * start = shape - 1 * else: */ if (__pyx_v_negative_step) { /* "View.MemoryView":815 * else: * if negative_step: * start = shape - 1 # <<<<<<<<<<<<<< * else: * start = 0 */ __pyx_v_start = (__pyx_v_shape - 1); goto __pyx_L11; } /*else*/ { /* "View.MemoryView":817 * start = shape - 1 * else: * start = 0 # <<<<<<<<<<<<<< * * if have_stop: */ __pyx_v_start = 0; } __pyx_L11:; } __pyx_L7:; /* "View.MemoryView":819 * start = 0 * * if have_stop: # <<<<<<<<<<<<<< * if stop < 0: * stop += shape */ if (__pyx_v_have_stop) { /* "View.MemoryView":820 * * if have_stop: * if stop < 0: # <<<<<<<<<<<<<< * stop += shape * if stop < 0: */ __pyx_t_2 = (__pyx_v_stop < 0); if (__pyx_t_2) { /* "View.MemoryView":821 * if have_stop: * if stop < 0: * stop += shape # <<<<<<<<<<<<<< * if stop < 0: * stop = 0 */ __pyx_v_stop = (__pyx_v_stop + __pyx_v_shape); /* "View.MemoryView":822 * if stop < 0: * stop += shape * if stop < 0: # <<<<<<<<<<<<<< * stop = 0 * elif stop > shape: */ __pyx_t_2 = (__pyx_v_stop < 0); if (__pyx_t_2) { /* "View.MemoryView":823 * stop += shape * if stop < 0: * stop = 0 # <<<<<<<<<<<<<< * elif stop > shape: * stop = shape */ __pyx_v_stop = 0; goto __pyx_L14; } __pyx_L14:; goto __pyx_L13; } /* "View.MemoryView":824 * if stop < 0: * stop = 0 * elif stop > shape: # <<<<<<<<<<<<<< * stop = shape * else: */ __pyx_t_2 = (__pyx_v_stop > __pyx_v_shape); if (__pyx_t_2) { /* "View.MemoryView":825 * stop = 0 * elif stop > shape: * stop = shape # <<<<<<<<<<<<<< * else: * if negative_step: */ __pyx_v_stop = __pyx_v_shape; goto __pyx_L13; } __pyx_L13:; goto __pyx_L12; } /*else*/ { /* "View.MemoryView":827 * stop = shape * else: * if negative_step: # <<<<<<<<<<<<<< * stop = -1 * else: */ if (__pyx_v_negative_step) { /* "View.MemoryView":828 * else: * if negative_step: * stop = -1 # <<<<<<<<<<<<<< * else: * stop = shape */ __pyx_v_stop = -1; goto __pyx_L15; } /*else*/ { /* "View.MemoryView":830 * stop = -1 * else: * stop = shape # <<<<<<<<<<<<<< * * if not have_step: */ __pyx_v_stop = __pyx_v_shape; } __pyx_L15:; } __pyx_L12:; /* "View.MemoryView":832 * stop = shape * * if not have_step: # <<<<<<<<<<<<<< * step = 1 * */ __pyx_t_2 = (!__pyx_v_have_step); if (__pyx_t_2) { /* "View.MemoryView":833 * * if not have_step: * step = 1 # <<<<<<<<<<<<<< * * */ __pyx_v_step = 1; goto __pyx_L16; } __pyx_L16:; /* "View.MemoryView":837 * * with cython.cdivision(True): * new_shape = (stop - start) // step # <<<<<<<<<<<<<< * * if (stop - start) % step: */ __pyx_v_new_shape = ((__pyx_v_stop - __pyx_v_start) / __pyx_v_step); /* "View.MemoryView":839 * new_shape = (stop - start) // step * * if (stop - start) % step: # <<<<<<<<<<<<<< * new_shape += 1 * */ __pyx_t_5 = ((__pyx_v_stop - __pyx_v_start) % __pyx_v_step); if (__pyx_t_5) { /* "View.MemoryView":840 * * if (stop - start) % step: * new_shape += 1 # <<<<<<<<<<<<<< * * if new_shape < 0: */ __pyx_v_new_shape = (__pyx_v_new_shape + 1); goto __pyx_L17; } __pyx_L17:; /* "View.MemoryView":842 * new_shape += 1 * * if new_shape < 0: # <<<<<<<<<<<<<< * new_shape = 0 * */ __pyx_t_2 = (__pyx_v_new_shape < 0); if (__pyx_t_2) { /* "View.MemoryView":843 * * if new_shape < 0: * new_shape = 0 # <<<<<<<<<<<<<< * * */ __pyx_v_new_shape = 0; goto __pyx_L18; } __pyx_L18:; /* "View.MemoryView":846 * * * dst.strides[new_ndim] = stride * step # <<<<<<<<<<<<<< * dst.shape[new_ndim] = new_shape * dst.suboffsets[new_ndim] = suboffset */ (__pyx_v_dst->strides[__pyx_v_new_ndim]) = (__pyx_v_stride * __pyx_v_step); /* "View.MemoryView":847 * * 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":848 * dst.strides[new_ndim] = stride * step * dst.shape[new_ndim] = new_shape * dst.suboffsets[new_ndim] = suboffset # <<<<<<<<<<<<<< * * */ (__pyx_v_dst->suboffsets[__pyx_v_new_ndim]) = __pyx_v_suboffset; } __pyx_L3:; /* "View.MemoryView":851 * * * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<< * dst.data += start * stride * else: */ __pyx_t_2 = ((__pyx_v_suboffset_dim[0]) < 0); if (__pyx_t_2) { /* "View.MemoryView":852 * * if suboffset_dim[0] < 0: * dst.data += start * stride # <<<<<<<<<<<<<< * else: * dst.suboffsets[suboffset_dim[0]] += start * stride */ __pyx_v_dst->data = (__pyx_v_dst->data + (__pyx_v_start * __pyx_v_stride)); goto __pyx_L19; } /*else*/ { /* "View.MemoryView":854 * dst.data += start * stride * else: * dst.suboffsets[suboffset_dim[0]] += start * stride # <<<<<<<<<<<<<< * * if suboffset >= 0: */ __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_L19:; /* "View.MemoryView":856 * 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); if (__pyx_t_2) { /* "View.MemoryView":857 * * if suboffset >= 0: * if not is_slice: # <<<<<<<<<<<<<< * if new_ndim == 0: * dst.data = ( dst.data)[0] + suboffset */ __pyx_t_2 = (!__pyx_v_is_slice); if (__pyx_t_2) { /* "View.MemoryView":858 * 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); if (__pyx_t_2) { /* "View.MemoryView":859 * 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); goto __pyx_L22; } /*else*/ { /* "View.MemoryView":862 * 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, __pyx_k_43, __pyx_v_dim); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L22:; goto __pyx_L21; } /*else*/ { /* "View.MemoryView":864 * "must be indexed and not sliced", dim) * else: * suboffset_dim[0] = new_ndim # <<<<<<<<<<<<<< * * return 0 */ (__pyx_v_suboffset_dim[0]) = __pyx_v_new_ndim; } __pyx_L21:; goto __pyx_L20; } __pyx_L20:; /* "View.MemoryView":866 * suboffset_dim[0] = new_ndim * * return 0 # <<<<<<<<<<<<<< * * */ __pyx_r = 0; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; { #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_AddTraceback("View.MemoryView.slice_memviewslice", __pyx_clineno, __pyx_lineno, __pyx_filename); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif } __pyx_r = -1; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":872 * * @cname('__pyx_pybuffer_index') * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<< * int dim) except NULL: * cdef Py_ssize_t shape, stride, suboffset = -1 */ static char *__pyx_pybuffer_index(Py_buffer *__pyx_v_view, char *__pyx_v_bufp, Py_ssize_t __pyx_v_index, int __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_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("pybuffer_index", 0); /* "View.MemoryView":874 * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, * int dim) except NULL: * cdef Py_ssize_t shape, stride, suboffset = -1 # <<<<<<<<<<<<<< * cdef Py_ssize_t itemsize = view.itemsize * cdef char *resultp */ __pyx_v_suboffset = -1; /* "View.MemoryView":875 * int dim) except NULL: * cdef Py_ssize_t shape, stride, suboffset = -1 * cdef Py_ssize_t itemsize = view.itemsize # <<<<<<<<<<<<<< * cdef char *resultp * */ __pyx_v_itemsize = __pyx_v_view->itemsize; /* "View.MemoryView":878 * cdef char *resultp * * if view.ndim == 0: # <<<<<<<<<<<<<< * shape = view.len / itemsize * stride = itemsize */ __pyx_t_1 = (__pyx_v_view->ndim == 0); if (__pyx_t_1) { /* "View.MemoryView":879 * * if view.ndim == 0: * shape = view.len / itemsize # <<<<<<<<<<<<<< * stride = itemsize * else: */ if (unlikely(__pyx_v_itemsize == 0)) { PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else if (sizeof(Py_ssize_t) == sizeof(long) && unlikely(__pyx_v_itemsize == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_view->len))) { PyErr_Format(PyExc_OverflowError, "value too large to perform division"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_v_shape = __Pyx_div_Py_ssize_t(__pyx_v_view->len, __pyx_v_itemsize); /* "View.MemoryView":880 * if view.ndim == 0: * shape = view.len / itemsize * stride = itemsize # <<<<<<<<<<<<<< * else: * shape = view.shape[dim] */ __pyx_v_stride = __pyx_v_itemsize; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":882 * stride = itemsize * else: * shape = view.shape[dim] # <<<<<<<<<<<<<< * stride = view.strides[dim] * if view.suboffsets != NULL: */ __pyx_v_shape = (__pyx_v_view->shape[__pyx_v_dim]); /* "View.MemoryView":883 * 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]); /* "View.MemoryView":884 * shape = view.shape[dim] * stride = view.strides[dim] * if view.suboffsets != NULL: # <<<<<<<<<<<<<< * suboffset = view.suboffsets[dim] * */ __pyx_t_1 = (__pyx_v_view->suboffsets != NULL); if (__pyx_t_1) { /* "View.MemoryView":885 * 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]); goto __pyx_L4; } __pyx_L4:; } __pyx_L3:; /* "View.MemoryView":887 * suboffset = view.suboffsets[dim] * * if index < 0: # <<<<<<<<<<<<<< * index += view.shape[dim] * if index < 0: */ __pyx_t_1 = (__pyx_v_index < 0); if (__pyx_t_1) { /* "View.MemoryView":888 * * 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":889 * if index < 0: * index += view.shape[dim] * if index < 0: # <<<<<<<<<<<<<< * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) * */ __pyx_t_1 = (__pyx_v_index < 0); if (__pyx_t_1) { /* "View.MemoryView":890 * index += view.shape[dim] * if index < 0: * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< * * if index >= shape: */ __pyx_t_2 = PyInt_FromLong(__pyx_v_dim); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_44), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; goto __pyx_L5; } __pyx_L5:; /* "View.MemoryView":892 * 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) * */ __pyx_t_1 = (__pyx_v_index >= __pyx_v_shape); if (__pyx_t_1) { /* "View.MemoryView":893 * * if index >= shape: * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< * * resultp = bufp + index * stride */ __pyx_t_3 = PyInt_FromLong(__pyx_v_dim); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_44), __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L7; } __pyx_L7:; /* "View.MemoryView":895 * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) * * resultp = bufp + index * stride # <<<<<<<<<<<<<< * if suboffset >= 0: * resultp = ( resultp)[0] + suboffset */ __pyx_v_resultp = (__pyx_v_bufp + (__pyx_v_index * __pyx_v_stride)); /* "View.MemoryView":896 * * resultp = bufp + index * stride * if suboffset >= 0: # <<<<<<<<<<<<<< * resultp = ( resultp)[0] + suboffset * */ __pyx_t_1 = (__pyx_v_suboffset >= 0); if (__pyx_t_1) { /* "View.MemoryView":897 * resultp = bufp + index * stride * if suboffset >= 0: * resultp = ( resultp)[0] + suboffset # <<<<<<<<<<<<<< * * return resultp */ __pyx_v_resultp = ((((char **)__pyx_v_resultp)[0]) + __pyx_v_suboffset); goto __pyx_L8; } __pyx_L8:; /* "View.MemoryView":899 * resultp = ( resultp)[0] + suboffset * * return resultp # <<<<<<<<<<<<<< * * */ __pyx_r = __pyx_v_resultp; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("View.MemoryView.pybuffer_index", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":905 * * @cname('__pyx_memslice_transpose') * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<< * cdef int ndim = memslice.memview.view.ndim * */ 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; long __pyx_t_1; int __pyx_t_2; Py_ssize_t __pyx_t_3; Py_ssize_t __pyx_t_4; int __pyx_t_5; int __pyx_t_6; int __pyx_t_7; int __pyx_t_8; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* "View.MemoryView":906 * @cname('__pyx_memslice_transpose') * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: * cdef int ndim = memslice.memview.view.ndim # <<<<<<<<<<<<<< * * cdef Py_ssize_t *shape = memslice.shape */ __pyx_v_ndim = __pyx_v_memslice->memview->view.ndim; /* "View.MemoryView":908 * cdef int ndim = memslice.memview.view.ndim * * cdef Py_ssize_t *shape = memslice.shape # <<<<<<<<<<<<<< * cdef Py_ssize_t *strides = memslice.strides * */ __pyx_v_shape = __pyx_v_memslice->shape; /* "View.MemoryView":909 * * cdef Py_ssize_t *shape = memslice.shape * cdef Py_ssize_t *strides = memslice.strides # <<<<<<<<<<<<<< * * */ __pyx_v_strides = __pyx_v_memslice->strides; /* "View.MemoryView":913 * * cdef int i, j * for i in range(ndim / 2): # <<<<<<<<<<<<<< * j = ndim - 1 - i * strides[i], strides[j] = strides[j], strides[i] */ __pyx_t_1 = __Pyx_div_long(__pyx_v_ndim, 2); for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":914 * 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] */ __pyx_v_j = ((__pyx_v_ndim - 1) - __pyx_v_i); /* "View.MemoryView":915 * 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] * */ __pyx_t_3 = (__pyx_v_strides[__pyx_v_j]); __pyx_t_4 = (__pyx_v_strides[__pyx_v_i]); (__pyx_v_strides[__pyx_v_i]) = __pyx_t_3; (__pyx_v_strides[__pyx_v_j]) = __pyx_t_4; /* "View.MemoryView":916 * j = ndim - 1 - i * strides[i], strides[j] = strides[j], strides[i] * shape[i], shape[j] = shape[j], shape[i] # <<<<<<<<<<<<<< * * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: */ __pyx_t_4 = (__pyx_v_shape[__pyx_v_j]); __pyx_t_3 = (__pyx_v_shape[__pyx_v_i]); (__pyx_v_shape[__pyx_v_i]) = __pyx_t_4; (__pyx_v_shape[__pyx_v_j]) = __pyx_t_3; /* "View.MemoryView":918 * 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_5 = ((__pyx_v_memslice->suboffsets[__pyx_v_i]) >= 0); if (!__pyx_t_5) { __pyx_t_6 = ((__pyx_v_memslice->suboffsets[__pyx_v_j]) >= 0); __pyx_t_7 = __pyx_t_6; } else { __pyx_t_7 = __pyx_t_5; } if (__pyx_t_7) { /* "View.MemoryView":919 * * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") # <<<<<<<<<<<<<< * * return 1 */ __pyx_t_8 = __pyx_memoryview_err(__pyx_builtin_ValueError, __pyx_k_45); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; } /* "View.MemoryView":921 * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") * * return 1 # <<<<<<<<<<<<<< * * */ __pyx_r = 1; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; { #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_AddTraceback("View.MemoryView.transpose_memslice", __pyx_clineno, __pyx_lineno, __pyx_filename); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif } __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* 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_MemoryView_16_memoryviewslice___dealloc__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":938 * cdef int (*to_dtype_func)(char *, object) except 0 * * def __dealloc__(self): # <<<<<<<<<<<<<< * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) * */ static void __pyx_memoryviewslice_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); /* "View.MemoryView":939 * * def __dealloc__(self): * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) # <<<<<<<<<<<<<< * * cdef convert_item_to_object(self, char *itemp): */ __PYX_XDEC_MEMVIEW((&__pyx_v_self->from_slice), 1); __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":941 * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) * * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< * if self.to_object_func != NULL: * return self.to_object_func(itemp) */ static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("convert_item_to_object", 0); /* "View.MemoryView":942 * * 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_self->to_object_func != NULL); if (__pyx_t_1) { /* "View.MemoryView":943 * 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_XDECREF(__pyx_r); __pyx_t_2 = __pyx_v_self->to_object_func(__pyx_v_itemp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":945 * 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_XDECREF(__pyx_r); __pyx_t_2 = __pyx_vtabptr_memoryview->convert_item_to_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 945; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } __pyx_L3:; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":947 * 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) */ 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_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("assign_item_from_object", 0); /* "View.MemoryView":948 * * 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_self->to_dtype_func != NULL); if (__pyx_t_1) { /* "View.MemoryView":949 * 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_v_self->to_dtype_func(__pyx_v_itemp, __pyx_v_value); if (unlikely(__pyx_t_2 == 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } /*else*/ { /* "View.MemoryView":951 * self.to_dtype_func(itemp, value) * else: * memoryview.assign_item_from_object(self, itemp, value) # <<<<<<<<<<<<<< * * property base: */ __pyx_t_3 = __pyx_vtabptr_memoryview->assign_item_from_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L3:; __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_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryviewslice__get__base(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryviewslice__get__base(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryviewslice__get__base_MemoryView_16_memoryviewslice_4base___get__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":955 * property base: * @cname('__pyx_memoryviewslice__get__base') * def __get__(self): # <<<<<<<<<<<<<< * return self.from_object * */ static PyObject *__pyx_memoryviewslice__get__base_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":956 * @cname('__pyx_memoryviewslice__get__base') * def __get__(self): * return self.from_object # <<<<<<<<<<<<<< * * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->from_object); __pyx_r = __pyx_v_self->from_object; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":962 * * @cname('__pyx_memoryview_fromslice') * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice, # <<<<<<<<<<<<<< * int ndim, * object (*to_object_func)(char *), */ 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; int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; int __pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("memoryview_fromslice", 0); /* "View.MemoryView":971 * cdef int i * * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<< * return None * */ __pyx_t_1 = (((PyObject *)__pyx_v_memviewslice.memview) == Py_None); if (__pyx_t_1) { /* "View.MemoryView":972 * * if memviewslice.memview == Py_None: * return None # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_None); __pyx_r = Py_None; goto __pyx_L0; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":977 * * * 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_filename = __pyx_f[2]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(Py_None); PyTuple_SET_ITEM(__pyx_t_3, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(__pyx_int_0); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject *)__pyx_memoryviewslice_type)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_2); __pyx_t_2 = 0; /* "View.MemoryView":979 * result = _memoryviewslice(None, 0, dtype_is_object) * * result.from_slice = memviewslice # <<<<<<<<<<<<<< * __PYX_INC_MEMVIEW(&memviewslice, 1) * */ __pyx_v_result->from_slice = __pyx_v_memviewslice; /* "View.MemoryView":980 * * result.from_slice = memviewslice * __PYX_INC_MEMVIEW(&memviewslice, 1) # <<<<<<<<<<<<<< * * result.from_object = ( memviewslice.memview).base */ __PYX_INC_MEMVIEW((&__pyx_v_memviewslice), 1); /* "View.MemoryView":982 * __PYX_INC_MEMVIEW(&memviewslice, 1) * * result.from_object = ( memviewslice.memview).base # <<<<<<<<<<<<<< * result.typeinfo = memviewslice.memview.typeinfo * */ __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_memviewslice.memview), __pyx_n_s__base); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 982; __pyx_clineno = __LINE__; goto __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; /* "View.MemoryView":983 * * result.from_object = ( memviewslice.memview).base * result.typeinfo = memviewslice.memview.typeinfo # <<<<<<<<<<<<<< * * result.view = memviewslice.memview.view */ __pyx_v_result->__pyx_base.typeinfo = __pyx_v_memviewslice.memview->typeinfo; /* "View.MemoryView":985 * result.typeinfo = memviewslice.memview.typeinfo * * result.view = memviewslice.memview.view # <<<<<<<<<<<<<< * result.view.buf = memviewslice.data * result.view.ndim = ndim */ __pyx_v_result->__pyx_base.view = __pyx_v_memviewslice.memview->view; /* "View.MemoryView":986 * * 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":987 * 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; /* "View.MemoryView":988 * 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; /* "View.MemoryView":989 * result.view.ndim = ndim * (<__pyx_buffer *> &result.view).obj = Py_None * Py_INCREF(Py_None) # <<<<<<<<<<<<<< * * result.flags = PyBUF_RECORDS */ Py_INCREF(Py_None); /* "View.MemoryView":991 * Py_INCREF(Py_None) * * result.flags = PyBUF_RECORDS # <<<<<<<<<<<<<< * * result.view.shape = result.from_slice.shape */ __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS; /* "View.MemoryView":993 * result.flags = PyBUF_RECORDS * * result.view.shape = result.from_slice.shape # <<<<<<<<<<<<<< * result.view.strides = result.from_slice.strides * result.view.suboffsets = result.from_slice.suboffsets */ __pyx_v_result->__pyx_base.view.shape = ((Py_ssize_t *)__pyx_v_result->from_slice.shape); /* "View.MemoryView":994 * * result.view.shape = result.from_slice.shape * result.view.strides = result.from_slice.strides # <<<<<<<<<<<<<< * result.view.suboffsets = result.from_slice.suboffsets * */ __pyx_v_result->__pyx_base.view.strides = ((Py_ssize_t *)__pyx_v_result->from_slice.strides); /* "View.MemoryView":995 * result.view.shape = result.from_slice.shape * result.view.strides = result.from_slice.strides * result.view.suboffsets = result.from_slice.suboffsets # <<<<<<<<<<<<<< * * result.view.len = result.view.itemsize */ __pyx_v_result->__pyx_base.view.suboffsets = ((Py_ssize_t *)__pyx_v_result->from_slice.suboffsets); /* "View.MemoryView":997 * result.view.suboffsets = result.from_slice.suboffsets * * result.view.len = result.view.itemsize # <<<<<<<<<<<<<< * for i in range(ndim): * result.view.len *= result.view.shape[i] */ __pyx_v_result->__pyx_base.view.len = __pyx_v_result->__pyx_base.view.itemsize; /* "View.MemoryView":998 * * result.view.len = result.view.itemsize * for i in range(ndim): # <<<<<<<<<<<<<< * result.view.len *= result.view.shape[i] * */ __pyx_t_4 = __pyx_v_ndim; for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_v_i = __pyx_t_5; /* "View.MemoryView":999 * result.view.len = result.view.itemsize * for i in range(ndim): * result.view.len *= result.view.shape[i] # <<<<<<<<<<<<<< * * result.to_object_func = to_object_func */ __pyx_v_result->__pyx_base.view.len = (__pyx_v_result->__pyx_base.view.len * (__pyx_v_result->__pyx_base.view.shape[__pyx_v_i])); } /* "View.MemoryView":1001 * result.view.len *= result.view.shape[i] * * 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; /* "View.MemoryView":1002 * * 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; /* "View.MemoryView":1004 * 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; __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_fromslice", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":1007 * * @cname('__pyx_memoryview_get_slice_from_memoryview') * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview, # <<<<<<<<<<<<<< * __Pyx_memviewslice *mslice): * cdef _memoryviewslice obj */ 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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("get_slice_from_memview", 0); /* "View.MemoryView":1010 * __Pyx_memviewslice *mslice): * cdef _memoryviewslice obj * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< * obj = memview * return &obj.from_slice */ __pyx_t_1 = ((PyObject *)((PyObject *)__pyx_memoryviewslice_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "View.MemoryView":1011 * 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_filename = __pyx_f[2]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_INCREF(((PyObject *)__pyx_v_memview)); __pyx_v_obj = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview); /* "View.MemoryView":1012 * 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; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1014 * return &obj.from_slice * else: * slice_copy(memview, mslice) # <<<<<<<<<<<<<< * return mslice * */ __pyx_memoryview_slice_copy(__pyx_v_memview, __pyx_v_mslice); /* "View.MemoryView":1015 * else: * slice_copy(memview, mslice) * return mslice # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_slice_copy') */ __pyx_r = __pyx_v_mslice; goto __pyx_L0; } __pyx_L3:; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_WriteUnraisable("View.MemoryView.get_slice_from_memview", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_obj); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":1018 * * @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 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_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; __Pyx_RefNannySetupContext("slice_copy", 0); /* "View.MemoryView":1022 * cdef Py_ssize_t *shape, *strides, *suboffsets * * shape = memview.view.shape # <<<<<<<<<<<<<< * strides = memview.view.strides * suboffsets = memview.view.suboffsets */ __pyx_v_shape = __pyx_v_memview->view.shape; /* "View.MemoryView":1023 * * shape = memview.view.shape * strides = memview.view.strides # <<<<<<<<<<<<<< * suboffsets = memview.view.suboffsets * */ __pyx_v_strides = __pyx_v_memview->view.strides; /* "View.MemoryView":1024 * shape = memview.view.shape * strides = memview.view.strides * suboffsets = memview.view.suboffsets # <<<<<<<<<<<<<< * * dst.memview = <__pyx_memoryview *> memview */ __pyx_v_suboffsets = __pyx_v_memview->view.suboffsets; /* "View.MemoryView":1026 * 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); /* "View.MemoryView":1027 * * 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); /* "View.MemoryView":1029 * dst.data = memview.view.buf * * for dim in range(memview.view.ndim): # <<<<<<<<<<<<<< * dst.shape[dim] = shape[dim] * dst.strides[dim] = strides[dim] */ __pyx_t_1 = __pyx_v_memview->view.ndim; for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_dim = __pyx_t_2; /* "View.MemoryView":1030 * * for dim in range(memview.view.ndim): * dst.shape[dim] = shape[dim] # <<<<<<<<<<<<<< * dst.strides[dim] = strides[dim] * if suboffsets == NULL: */ (__pyx_v_dst->shape[__pyx_v_dim]) = (__pyx_v_shape[__pyx_v_dim]); /* "View.MemoryView":1031 * for dim in range(memview.view.ndim): * dst.shape[dim] = shape[dim] * dst.strides[dim] = strides[dim] # <<<<<<<<<<<<<< * if suboffsets == NULL: * dst.suboffsets[dim] = -1 */ (__pyx_v_dst->strides[__pyx_v_dim]) = (__pyx_v_strides[__pyx_v_dim]); /* "View.MemoryView":1032 * dst.shape[dim] = shape[dim] * dst.strides[dim] = strides[dim] * if suboffsets == NULL: # <<<<<<<<<<<<<< * dst.suboffsets[dim] = -1 * else: */ __pyx_t_3 = (__pyx_v_suboffsets == NULL); if (__pyx_t_3) { /* "View.MemoryView":1033 * dst.strides[dim] = strides[dim] * if suboffsets == NULL: * dst.suboffsets[dim] = -1 # <<<<<<<<<<<<<< * else: * dst.suboffsets[dim] = suboffsets[dim] */ (__pyx_v_dst->suboffsets[__pyx_v_dim]) = -1; goto __pyx_L5; } /*else*/ { /* "View.MemoryView":1035 * dst.suboffsets[dim] = -1 * else: * dst.suboffsets[dim] = suboffsets[dim] # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_copy_object') */ (__pyx_v_dst->suboffsets[__pyx_v_dim]) = (__pyx_v_suboffsets[__pyx_v_dim]); } __pyx_L5:; } __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":1038 * * @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; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("memoryview_copy", 0); /* "View.MemoryView":1041 * "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)); /* "View.MemoryView":1042 * 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_filename = __pyx_f[2]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":1045 * * @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_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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("memoryview_copy_from_slice", 0); /* "View.MemoryView":1052 * 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 = ((PyObject *)((PyObject *)__pyx_memoryviewslice_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "View.MemoryView":1053 * * if isinstance(memview, _memoryviewslice): * to_object_func = (<_memoryviewslice> memview).to_object_func # <<<<<<<<<<<<<< * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func * else: */ __pyx_v_to_object_func = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_object_func; /* "View.MemoryView":1054 * 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_v_to_dtype_func = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_dtype_func; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1056 * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func * else: * to_object_func = NULL # <<<<<<<<<<<<<< * to_dtype_func = NULL * */ __pyx_v_to_object_func = NULL; /* "View.MemoryView":1057 * else: * to_object_func = NULL * to_dtype_func = NULL # <<<<<<<<<<<<<< * * return memoryview_fromslice(memviewslice[0], memview.view.ndim, */ __pyx_v_to_dtype_func = NULL; } __pyx_L3:; /* "View.MemoryView":1059 * 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); /* "View.MemoryView":1061 * return memoryview_fromslice(memviewslice[0], memview.view.ndim, * to_object_func, to_dtype_func, * memview.dtype_is_object) # <<<<<<<<<<<<<< * * */ __pyx_t_1 = __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_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("View.MemoryView.memoryview_copy_from_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":1067 * * * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: # <<<<<<<<<<<<<< * if arg < 0: * return -arg */ static Py_ssize_t abs_py_ssize_t(Py_ssize_t __pyx_v_arg) { Py_ssize_t __pyx_r; int __pyx_t_1; /* "View.MemoryView":1068 * * 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); if (__pyx_t_1) { /* "View.MemoryView":1069 * 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; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1071 * return -arg * else: * return arg # <<<<<<<<<<<<<< * * @cname('__pyx_get_best_slice_order') */ __pyx_r = __pyx_v_arg; goto __pyx_L0; } __pyx_L3:; __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1074 * * @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 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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; /* "View.MemoryView":1079 * """ * cdef int i * cdef Py_ssize_t c_stride = 0 # <<<<<<<<<<<<<< * cdef Py_ssize_t f_stride = 0 * */ __pyx_v_c_stride = 0; /* "View.MemoryView":1080 * 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; /* "View.MemoryView":1082 * 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; /* "View.MemoryView":1083 * * 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); if (__pyx_t_2) { /* "View.MemoryView":1084 * 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]); /* "View.MemoryView":1085 * if mslice.shape[i] > 1: * c_stride = mslice.strides[i] * break # <<<<<<<<<<<<<< * * for i in range(ndim): */ goto __pyx_L4_break; goto __pyx_L5; } __pyx_L5:; } __pyx_L4_break:; /* "View.MemoryView":1087 * break * * for i in range(ndim): # <<<<<<<<<<<<<< * if mslice.shape[i] > 1: * f_stride = mslice.strides[i] */ __pyx_t_1 = __pyx_v_ndim; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_1; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; /* "View.MemoryView":1088 * * 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); if (__pyx_t_2) { /* "View.MemoryView":1089 * 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]); /* "View.MemoryView":1090 * 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; goto __pyx_L8; } __pyx_L8:; } __pyx_L7_break:; /* "View.MemoryView":1092 * 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)); if (__pyx_t_2) { /* "View.MemoryView":1093 * * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): * return 'C' # <<<<<<<<<<<<<< * else: * return 'F' */ __pyx_r = 'C'; goto __pyx_L0; goto __pyx_L9; } /*else*/ { /* "View.MemoryView":1095 * return 'C' * else: * return 'F' # <<<<<<<<<<<<<< * * @cython.cdivision(True) */ __pyx_r = 'F'; goto __pyx_L0; } __pyx_L9:; __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1098 * * @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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_t_4; Py_ssize_t __pyx_t_5; Py_ssize_t __pyx_t_6; /* "View.MemoryView":1105 * * 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]); /* "View.MemoryView":1106 * 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":1107 * 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]); /* "View.MemoryView":1108 * 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]); /* "View.MemoryView":1110 * 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); if (__pyx_t_1) { /* "View.MemoryView":1111 * * 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_1 = (__pyx_v_src_stride > 0); if (__pyx_t_1) { __pyx_t_2 = (__pyx_v_dst_stride > 0); if (__pyx_t_2) { /* "View.MemoryView":1112 * 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_3 = (((size_t)__pyx_v_src_stride) == __pyx_v_itemsize); if (__pyx_t_3) { __pyx_t_3 = (__pyx_v_itemsize == ((size_t)__pyx_v_dst_stride)); } __pyx_t_4 = __pyx_t_3; } else { __pyx_t_4 = __pyx_t_2; } __pyx_t_2 = __pyx_t_4; } else { __pyx_t_2 = __pyx_t_1; } if (__pyx_t_2) { /* "View.MemoryView":1113 * 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): */ memcpy(__pyx_v_dst_data, __pyx_v_src_data, (__pyx_v_itemsize * __pyx_v_dst_extent)); goto __pyx_L4; } /*else*/ { /* "View.MemoryView":1115 * 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 */ __pyx_t_5 = __pyx_v_dst_extent; for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; /* "View.MemoryView":1116 * else: * for i in range(dst_extent): * memcpy(dst_data, src_data, itemsize) # <<<<<<<<<<<<<< * src_data += src_stride * dst_data += dst_stride */ memcpy(__pyx_v_dst_data, __pyx_v_src_data, __pyx_v_itemsize); /* "View.MemoryView":1117 * 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); /* "View.MemoryView":1118 * 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:; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1120 * 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, */ __pyx_t_5 = __pyx_v_dst_extent; for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; /* "View.MemoryView":1124 * dst_data, dst_strides + 1, * src_shape + 1, dst_shape + 1, * ndim - 1, itemsize) # <<<<<<<<<<<<<< * src_data += src_stride * dst_data += dst_stride */ _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); /* "View.MemoryView":1125 * 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); /* "View.MemoryView":1126 * 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); } } __pyx_L3:; } /* "View.MemoryView":1128 * dst_data += dst_stride * * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< * __Pyx_memviewslice *dst, * int ndim, size_t itemsize) nogil: */ 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) { /* "View.MemoryView":1132 * int ndim, size_t itemsize) nogil: * _copy_strided_to_strided(src.data, src.strides, dst.data, dst.strides, * src.shape, dst.shape, ndim, itemsize) # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_slice_get_size') */ _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); } /* "View.MemoryView":1135 * * @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; int __pyx_t_1; int __pyx_t_2; /* "View.MemoryView":1138 * "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_v_size = __pyx_v_src->memview->view.itemsize; /* "View.MemoryView":1140 * cdef Py_ssize_t size = src.memview.view.itemsize * * for i in range(ndim): # <<<<<<<<<<<<<< * size *= src.shape[i] * */ __pyx_t_1 = __pyx_v_ndim; for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":1141 * * for i in range(ndim): * size *= src.shape[i] # <<<<<<<<<<<<<< * * return size */ __pyx_v_size = (__pyx_v_size * (__pyx_v_src->shape[__pyx_v_i])); } /* "View.MemoryView":1143 * size *= src.shape[i] * * return size # <<<<<<<<<<<<<< * * @cname('__pyx_fill_contig_strides_array') */ __pyx_r = __pyx_v_size; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1146 * * @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 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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; /* "View.MemoryView":1155 * cdef int idx * * if order == 'F': # <<<<<<<<<<<<<< * for idx in range(ndim): * strides[idx] = stride */ __pyx_t_1 = (__pyx_v_order == 'F'); if (__pyx_t_1) { /* "View.MemoryView":1156 * * if order == 'F': * for idx in range(ndim): # <<<<<<<<<<<<<< * strides[idx] = stride * stride = stride * shape[idx] */ __pyx_t_2 = __pyx_v_ndim; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_idx = __pyx_t_3; /* "View.MemoryView":1157 * 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":1158 * 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])); } goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1160 * stride = stride * shape[idx] * else: * for idx in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< * strides[idx] = stride * stride = stride * shape[idx] */ for (__pyx_t_2 = (__pyx_v_ndim - 1); __pyx_t_2 > -1; __pyx_t_2-=1) { __pyx_v_idx = __pyx_t_2; /* "View.MemoryView":1161 * 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; /* "View.MemoryView":1162 * 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:; /* "View.MemoryView":1164 * stride = stride * shape[idx] * * return stride # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_copy_data_to_temp') */ __pyx_r = __pyx_v_stride; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1167 * * @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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* "View.MemoryView":1178 * cdef void *result * * cdef size_t itemsize = src.memview.view.itemsize # <<<<<<<<<<<<<< * cdef size_t size = slice_get_size(src, ndim) * */ __pyx_v_itemsize = __pyx_v_src->memview->view.itemsize; /* "View.MemoryView":1179 * * 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":1181 * 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":1182 * * result = malloc(size) * if not result: # <<<<<<<<<<<<<< * _err(MemoryError, NULL) * */ __pyx_t_1 = (!(__pyx_v_result != 0)); if (__pyx_t_1) { /* "View.MemoryView":1183 * result = malloc(size) * if not result: * _err(MemoryError, NULL) # <<<<<<<<<<<<<< * * */ __pyx_t_2 = __pyx_memoryview_err(__pyx_builtin_MemoryError, NULL); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":1186 * * * tmpslice.data = result # <<<<<<<<<<<<<< * tmpslice.memview = src.memview * for i in range(ndim): */ __pyx_v_tmpslice->data = ((char *)__pyx_v_result); /* "View.MemoryView":1187 * * tmpslice.data = result * tmpslice.memview = src.memview # <<<<<<<<<<<<<< * for i in range(ndim): * tmpslice.shape[i] = src.shape[i] */ __pyx_v_tmpslice->memview = __pyx_v_src->memview; /* "View.MemoryView":1188 * tmpslice.data = result * tmpslice.memview = src.memview * for i in range(ndim): # <<<<<<<<<<<<<< * tmpslice.shape[i] = src.shape[i] * tmpslice.suboffsets[i] = -1 */ __pyx_t_2 = __pyx_v_ndim; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; /* "View.MemoryView":1189 * 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":1190 * 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]) = -1; } /* "View.MemoryView":1193 * * fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize, * ndim, order) # <<<<<<<<<<<<<< * * */ __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":1196 * * * for i in range(ndim): # <<<<<<<<<<<<<< * if tmpslice.shape[i] == 1: * tmpslice.strides[i] = 0 */ __pyx_t_2 = __pyx_v_ndim; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; /* "View.MemoryView":1197 * * for i in range(ndim): * if tmpslice.shape[i] == 1: # <<<<<<<<<<<<<< * tmpslice.strides[i] = 0 * */ __pyx_t_1 = ((__pyx_v_tmpslice->shape[__pyx_v_i]) == 1); if (__pyx_t_1) { /* "View.MemoryView":1198 * for i in range(ndim): * if tmpslice.shape[i] == 1: * tmpslice.strides[i] = 0 # <<<<<<<<<<<<<< * * if slice_is_contig(src, order, ndim): */ (__pyx_v_tmpslice->strides[__pyx_v_i]) = 0; goto __pyx_L8; } __pyx_L8:; } /* "View.MemoryView":1200 * tmpslice.strides[i] = 0 * * if slice_is_contig(src, order, ndim): # <<<<<<<<<<<<<< * memcpy(result, src.data, size) * else: */ __pyx_t_1 = __pyx_memviewslice_is_contig(__pyx_v_src, __pyx_v_order, __pyx_v_ndim); if (__pyx_t_1) { /* "View.MemoryView":1201 * * if slice_is_contig(src, order, ndim): * memcpy(result, src.data, size) # <<<<<<<<<<<<<< * else: * copy_strided_to_strided(src, tmpslice, ndim, itemsize) */ memcpy(__pyx_v_result, __pyx_v_src->data, __pyx_v_size); goto __pyx_L9; } /*else*/ { /* "View.MemoryView":1203 * memcpy(result, src.data, size) * else: * copy_strided_to_strided(src, tmpslice, ndim, itemsize) # <<<<<<<<<<<<<< * * return result */ copy_strided_to_strided(__pyx_v_src, __pyx_v_tmpslice, __pyx_v_ndim, __pyx_v_itemsize); } __pyx_L9:; /* "View.MemoryView":1205 * copy_strided_to_strided(src, tmpslice, ndim, itemsize) * * return result # <<<<<<<<<<<<<< * * */ __pyx_r = __pyx_v_result; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; { #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_AddTraceback("View.MemoryView.copy_data_to_temp", __pyx_clineno, __pyx_lineno, __pyx_filename); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif } __pyx_r = NULL; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1210 * * @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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_RefNannySetupContext("_err_extents", 0); /* "View.MemoryView":1213 * 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 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_extent1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_extent2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_46), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __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("View.MemoryView._err_extents", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif return __pyx_r; } /* "View.MemoryView":1216 * * @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 int __pyx_memoryview_err_dim(PyObject *__pyx_v_error, char *__pyx_v_msg, int __pyx_v_dim) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_RefNannySetupContext("_err_dim", 0); __Pyx_INCREF(__pyx_v_error); /* "View.MemoryView":1217 * @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_1 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_t_2 = PyInt_FromLong(__pyx_v_dim); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_t_1), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_v_error, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __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._err_dim", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_error); __Pyx_RefNannyFinishContext(); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif return __pyx_r; } /* "View.MemoryView":1220 * * @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_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_RefNannySetupContext("_err", 0); __Pyx_INCREF(__pyx_v_error); /* "View.MemoryView":1221 * @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); if (__pyx_t_1) { /* "View.MemoryView":1222 * cdef int _err(object error, char *msg) except -1 with gil: * if msg != NULL: * raise error(msg.decode('ascii')) # <<<<<<<<<<<<<< * else: * raise error */ __pyx_t_2 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_v_error, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1224 * raise error(msg.decode('ascii')) * else: * raise error # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_copy_contents') */ __Pyx_Raise(__pyx_v_error, 0, 0, 0); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("View.MemoryView._err", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_error); __Pyx_RefNannyFinishContext(); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif return __pyx_r; } /* "View.MemoryView":1227 * * @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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_t_4; void *__pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* "View.MemoryView":1235 * 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":1236 * """ * 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_v_itemsize = __pyx_v_src.memview->view.itemsize; /* "View.MemoryView":1238 * 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":1239 * 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":1240 * 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":1243 * cdef __Pyx_memviewslice tmp * * if src_ndim < dst_ndim: # <<<<<<<<<<<<<< * broadcast_leading(&src, src_ndim, dst_ndim) * elif dst_ndim < src_ndim: */ __pyx_t_1 = (__pyx_v_src_ndim < __pyx_v_dst_ndim); if (__pyx_t_1) { /* "View.MemoryView":1244 * * 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); goto __pyx_L3; } /* "View.MemoryView":1245 * 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_1 = (__pyx_v_dst_ndim < __pyx_v_src_ndim); if (__pyx_t_1) { /* "View.MemoryView":1246 * 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); goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":1248 * broadcast_leading(&dst, dst_ndim, src_ndim) * * cdef int ndim = max(src_ndim, dst_ndim) # <<<<<<<<<<<<<< * * for i in range(ndim): */ __pyx_t_2 = __pyx_v_dst_ndim; __pyx_t_3 = __pyx_v_src_ndim; if ((__pyx_t_2 > __pyx_t_3)) { __pyx_t_4 = __pyx_t_2; } else { __pyx_t_4 = __pyx_t_3; } __pyx_v_ndim = __pyx_t_4; /* "View.MemoryView":1250 * 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_4 = __pyx_v_ndim; for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_4; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":1251 * * for i in range(ndim): * if src.shape[i] != dst.shape[i]: # <<<<<<<<<<<<<< * if src.shape[i] == 1: * broadcasting = True */ __pyx_t_1 = ((__pyx_v_src.shape[__pyx_v_i]) != (__pyx_v_dst.shape[__pyx_v_i])); if (__pyx_t_1) { /* "View.MemoryView":1252 * 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_1 = ((__pyx_v_src.shape[__pyx_v_i]) == 1); if (__pyx_t_1) { /* "View.MemoryView":1253 * 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":1254 * 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; goto __pyx_L7; } /*else*/ { /* "View.MemoryView":1256 * src.strides[i] = 0 * else: * _err_extents(i, dst.shape[i], src.shape[i]) # <<<<<<<<<<<<<< * * if src.suboffsets[i] >= 0: */ __pyx_t_3 = __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_3 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L7:; goto __pyx_L6; } __pyx_L6:; /* "View.MemoryView":1258 * _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_1 = ((__pyx_v_src.suboffsets[__pyx_v_i]) >= 0); if (__pyx_t_1) { /* "View.MemoryView":1259 * * if src.suboffsets[i] >= 0: * _err_dim(ValueError, "Dimension %d is not direct", i) # <<<<<<<<<<<<<< * * if slices_overlap(&src, &dst, ndim, itemsize): */ __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, __pyx_k_47, __pyx_v_i); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L8; } __pyx_L8:; } /* "View.MemoryView":1261 * _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_1 = __pyx_slices_overlap((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize); if (__pyx_t_1) { /* "View.MemoryView":1263 * if slices_overlap(&src, &dst, ndim, itemsize): * * if not slice_is_contig(&src, order, ndim): # <<<<<<<<<<<<<< * order = get_best_order(&dst, ndim) * */ __pyx_t_1 = (!__pyx_memviewslice_is_contig((&__pyx_v_src), __pyx_v_order, __pyx_v_ndim)); if (__pyx_t_1) { /* "View.MemoryView":1264 * * 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); goto __pyx_L10; } __pyx_L10:; /* "View.MemoryView":1266 * order = get_best_order(&dst, ndim) * * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) # <<<<<<<<<<<<<< * src = tmp * */ __pyx_t_5 = __pyx_memoryview_copy_data_to_temp((&__pyx_v_src), (&__pyx_v_tmp), __pyx_v_order, __pyx_v_ndim); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_tmpdata = __pyx_t_5; /* "View.MemoryView":1267 * * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) * src = tmp # <<<<<<<<<<<<<< * * if not broadcasting: */ __pyx_v_src = __pyx_v_tmp; goto __pyx_L9; } __pyx_L9:; /* "View.MemoryView":1269 * src = tmp * * if not broadcasting: # <<<<<<<<<<<<<< * * */ __pyx_t_1 = (!__pyx_v_broadcasting); if (__pyx_t_1) { /* "View.MemoryView":1272 * * * if slice_is_contig(&src, 'C', ndim): # <<<<<<<<<<<<<< * direct_copy = slice_is_contig(&dst, 'C', ndim) * elif slice_is_contig(&src, 'F', ndim): */ __pyx_t_1 = __pyx_memviewslice_is_contig((&__pyx_v_src), 'C', __pyx_v_ndim); if (__pyx_t_1) { /* "View.MemoryView":1273 * * 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); goto __pyx_L12; } /* "View.MemoryView":1274 * 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_1 = __pyx_memviewslice_is_contig((&__pyx_v_src), 'F', __pyx_v_ndim); if (__pyx_t_1) { /* "View.MemoryView":1275 * 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); goto __pyx_L12; } __pyx_L12:; /* "View.MemoryView":1277 * direct_copy = slice_is_contig(&dst, 'F', ndim) * * if direct_copy: # <<<<<<<<<<<<<< * * refcount_copying(&dst, dtype_is_object, ndim, False) */ if (__pyx_v_direct_copy) { /* "View.MemoryView":1279 * 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":1280 * * 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) * return 0 */ memcpy(__pyx_v_dst.data, __pyx_v_src.data, __pyx_memoryview_slice_get_size((&__pyx_v_src), __pyx_v_ndim)); /* "View.MemoryView":1281 * 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) # <<<<<<<<<<<<<< * return 0 * */ __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1); /* "View.MemoryView":1282 * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) * refcount_copying(&dst, dtype_is_object, ndim, True) * return 0 # <<<<<<<<<<<<<< * * if order == 'F' == get_best_order(&dst, ndim): */ __pyx_r = 0; goto __pyx_L0; goto __pyx_L13; } __pyx_L13:; goto __pyx_L11; } __pyx_L11:; /* "View.MemoryView":1284 * return 0 * * if order == 'F' == get_best_order(&dst, ndim): # <<<<<<<<<<<<<< * * */ __pyx_t_1 = (__pyx_v_order == 'F'); if (__pyx_t_1) { __pyx_t_1 = ('F' == __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim)); } if (__pyx_t_1) { /* "View.MemoryView":1287 * * * transpose_memslice(&src) # <<<<<<<<<<<<<< * transpose_memslice(&dst) * */ __pyx_t_4 = __pyx_memslice_transpose((&__pyx_v_src)); if (unlikely(__pyx_t_4 == 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":1288 * * transpose_memslice(&src) * transpose_memslice(&dst) # <<<<<<<<<<<<<< * * refcount_copying(&dst, dtype_is_object, ndim, False) */ __pyx_t_4 = __pyx_memslice_transpose((&__pyx_v_dst)); if (unlikely(__pyx_t_4 == 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L14; } __pyx_L14:; /* "View.MemoryView":1290 * 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":1291 * * 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":1292 * 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":1294 * refcount_copying(&dst, dtype_is_object, ndim, True) * * free(tmpdata) # <<<<<<<<<<<<<< * return 0 * */ free(__pyx_v_tmpdata); /* "View.MemoryView":1295 * * free(tmpdata) * return 0 # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_broadcast_leading') */ __pyx_r = 0; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; { #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_AddTraceback("View.MemoryView.memoryview_copy_contents", __pyx_clineno, __pyx_lineno, __pyx_filename); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif } __pyx_r = -1; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1298 * * @cname('__pyx_memoryview_broadcast_leading') * cdef void broadcast_leading(__Pyx_memviewslice *slice, # <<<<<<<<<<<<<< * int ndim, * int ndim_other) nogil: */ static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *__pyx_v_slice, int __pyx_v_ndim, int __pyx_v_ndim_other) { int __pyx_v_i; int __pyx_v_offset; int __pyx_t_1; int __pyx_t_2; /* "View.MemoryView":1302 * 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":1304 * cdef int offset = ndim_other - ndim * * for i in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< * slice.shape[i + offset] = slice.shape[i] * slice.strides[i + offset] = slice.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":1305 * * for i in range(ndim - 1, -1, -1): * slice.shape[i + offset] = slice.shape[i] # <<<<<<<<<<<<<< * slice.strides[i + offset] = slice.strides[i] * slice.suboffsets[i + offset] = slice.suboffsets[i] */ (__pyx_v_slice->shape[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_slice->shape[__pyx_v_i]); /* "View.MemoryView":1306 * for i in range(ndim - 1, -1, -1): * slice.shape[i + offset] = slice.shape[i] * slice.strides[i + offset] = slice.strides[i] # <<<<<<<<<<<<<< * slice.suboffsets[i + offset] = slice.suboffsets[i] * */ (__pyx_v_slice->strides[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_slice->strides[__pyx_v_i]); /* "View.MemoryView":1307 * slice.shape[i + offset] = slice.shape[i] * slice.strides[i + offset] = slice.strides[i] * slice.suboffsets[i + offset] = slice.suboffsets[i] # <<<<<<<<<<<<<< * * for i in range(offset): */ (__pyx_v_slice->suboffsets[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_slice->suboffsets[__pyx_v_i]); } /* "View.MemoryView":1309 * slice.suboffsets[i + offset] = slice.suboffsets[i] * * for i in range(offset): # <<<<<<<<<<<<<< * slice.shape[i] = 1 * slice.strides[i] = slice.strides[0] */ __pyx_t_1 = __pyx_v_offset; for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":1310 * * for i in range(offset): * slice.shape[i] = 1 # <<<<<<<<<<<<<< * slice.strides[i] = slice.strides[0] * slice.suboffsets[i] = -1 */ (__pyx_v_slice->shape[__pyx_v_i]) = 1; /* "View.MemoryView":1311 * for i in range(offset): * slice.shape[i] = 1 * slice.strides[i] = slice.strides[0] # <<<<<<<<<<<<<< * slice.suboffsets[i] = -1 * */ (__pyx_v_slice->strides[__pyx_v_i]) = (__pyx_v_slice->strides[0]); /* "View.MemoryView":1312 * slice.shape[i] = 1 * slice.strides[i] = slice.strides[0] * slice.suboffsets[i] = -1 # <<<<<<<<<<<<<< * * */ (__pyx_v_slice->suboffsets[__pyx_v_i]) = -1; } } /* "View.MemoryView":1320 * * @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) { /* "View.MemoryView":1324 * * * if dtype_is_object: # <<<<<<<<<<<<<< * refcount_objects_in_slice_with_gil(dst.data, dst.shape, * dst.strides, ndim, inc) */ if (__pyx_v_dtype_is_object) { /* "View.MemoryView":1326 * if dtype_is_object: * refcount_objects_in_slice_with_gil(dst.data, dst.shape, * dst.strides, ndim, inc) # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil') */ __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); goto __pyx_L3; } __pyx_L3:; } /* "View.MemoryView":1329 * * @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_RefNannyDeclarations #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_RefNannySetupContext("refcount_objects_in_slice_with_gil", 0); /* "View.MemoryView":1332 * 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); __Pyx_RefNannyFinishContext(); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif } /* "View.MemoryView":1335 * * @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_RefNannyDeclarations Py_ssize_t __pyx_t_1; Py_ssize_t __pyx_t_2; int __pyx_t_3; __Pyx_RefNannySetupContext("refcount_objects_in_slice", 0); /* "View.MemoryView":1339 * cdef Py_ssize_t i * * for i in range(shape[0]): # <<<<<<<<<<<<<< * if ndim == 1: * if inc: */ __pyx_t_1 = (__pyx_v_shape[0]); for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":1340 * * for i in range(shape[0]): * if ndim == 1: # <<<<<<<<<<<<<< * if inc: * Py_INCREF(( data)[0]) */ __pyx_t_3 = (__pyx_v_ndim == 1); if (__pyx_t_3) { /* "View.MemoryView":1341 * for i in range(shape[0]): * if ndim == 1: * if inc: # <<<<<<<<<<<<<< * Py_INCREF(( data)[0]) * else: */ if (__pyx_v_inc) { /* "View.MemoryView":1342 * if ndim == 1: * if inc: * Py_INCREF(( data)[0]) # <<<<<<<<<<<<<< * else: * Py_DECREF(( data)[0]) */ Py_INCREF((((PyObject **)__pyx_v_data)[0])); goto __pyx_L6; } /*else*/ { /* "View.MemoryView":1344 * Py_INCREF(( data)[0]) * else: * Py_DECREF(( data)[0]) # <<<<<<<<<<<<<< * else: * refcount_objects_in_slice(data, shape + 1, strides + 1, */ Py_DECREF((((PyObject **)__pyx_v_data)[0])); } __pyx_L6:; goto __pyx_L5; } /*else*/ { /* "View.MemoryView":1347 * 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":1349 * ndim - 1, inc) * * data += strides[0] # <<<<<<<<<<<<<< * * */ __pyx_v_data = (__pyx_v_data + (__pyx_v_strides[0])); } __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":1355 * * @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) { /* "View.MemoryView":1358 * 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":1360 * 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":1361 * _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":1365 * * @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; int __pyx_t_1; Py_ssize_t __pyx_t_2; Py_ssize_t __pyx_t_3; /* "View.MemoryView":1369 * 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":1370 * 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":1372 * 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); if (__pyx_t_1) { /* "View.MemoryView":1373 * * if ndim == 1: * for i in range(extent): # <<<<<<<<<<<<<< * memcpy(data, item, itemsize) * data += stride */ __pyx_t_2 = __pyx_v_extent; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; /* "View.MemoryView":1374 * if ndim == 1: * for i in range(extent): * memcpy(data, item, itemsize) # <<<<<<<<<<<<<< * data += stride * else: */ memcpy(__pyx_v_data, __pyx_v_item, __pyx_v_itemsize); /* "View.MemoryView":1375 * 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); } goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1377 * data += stride * else: * for i in range(extent): # <<<<<<<<<<<<<< * _slice_assign_scalar(data, shape + 1, strides + 1, * ndim - 1, itemsize, item) */ __pyx_t_2 = __pyx_v_extent; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; /* "View.MemoryView":1379 * 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":1380 * _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:; } static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_array_obj *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; p = ((struct __pyx_array_obj *)o); p->mode = ((PyObject*)Py_None); Py_INCREF(Py_None); p->_format = ((PyObject*)Py_None); Py_INCREF(Py_None); if (__pyx_array___cinit__(o, a, k) < 0) { Py_DECREF(o); o = 0; } return o; } static void __pyx_tp_dealloc_array(PyObject *o) { struct __pyx_array_obj *p = (struct __pyx_array_obj *)o; { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); __pyx_array___dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } Py_CLEAR(p->mode); Py_CLEAR(p->_format); (*Py_TYPE(o)->tp_free)(o); } static int __pyx_tp_traverse_array(PyObject *o, visitproc v, void *a) { int e; struct __pyx_array_obj *p = (struct __pyx_array_obj *)o; if (p->mode) { e = (*v)(p->mode, a); if (e) return e; } if (p->_format) { e = (*v)(p->_format, a); if (e) return e; } return 0; } static int __pyx_tp_clear_array(PyObject *o) { struct __pyx_array_obj *p = (struct __pyx_array_obj *)o; PyObject* tmp; tmp = ((PyObject*)p->mode); p->mode = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->_format); p->_format = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } 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 %s", Py_TYPE(o)->tp_name); return -1; } } static PyObject *__pyx_tp_getattro_array(PyObject *o, PyObject *n) { PyObject *v = 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 get_memview(o); } static PyMethodDef __pyx_methods_array[] = { {__Pyx_NAMESTR("__getattr__"), (PyCFunction)__pyx_array___getattr__, METH_O|METH_COEXIST, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets_array[] = { {(char *)"memview", __pyx_getprop___pyx_array_memview, 0, 0, 0}, {0, 0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_array = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*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 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 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 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*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_array = { 0, /*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 = { 0, /*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 #if PY_VERSION_HEX >= 0x02060000 __pyx_array_getbuffer, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type___pyx_array = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("cogent.align._pairwise_pogs.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*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ &__pyx_tp_as_number_array, /*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_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ __pyx_tp_traverse_array, /*tp_traverse*/ __pyx_tp_clear_array, /*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*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_MemviewEnum_obj *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!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; 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) { struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; PyObject* tmp; tmp = ((PyObject*)p->name); p->name = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyMethodDef __pyx_methods_Enum[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_Enum = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*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 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 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 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*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_Enum = { 0, /*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_Enum = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_Enum = { #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 #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type___pyx_MemviewEnum = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("cogent.align._pairwise_pogs.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*/ #else 0, /*reserved*/ #endif __pyx_MemviewEnum___repr__, /*tp_repr*/ &__pyx_tp_as_number_Enum, /*tp_as_number*/ &__pyx_tp_as_sequence_Enum, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Enum, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Enum, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|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*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #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 = (*t->tp_alloc)(t, 0); if (!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 (__pyx_memoryview___cinit__(o, a, k) < 0) { Py_DECREF(o); o = 0; } return o; } static void __pyx_tp_dealloc_memoryview(PyObject *o) { struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); __pyx_memoryview___dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(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) { struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; PyObject* tmp; 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 %s", Py_TYPE(o)->tp_name); return -1; } } static PyObject *__pyx_getprop___pyx_memoryview_T(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_transpose(o); } static PyObject *__pyx_getprop___pyx_memoryview_base(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview__get__base(o); } static PyObject *__pyx_getprop___pyx_memoryview_shape(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_shape(o); } static PyObject *__pyx_getprop___pyx_memoryview_strides(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_strides(o); } static PyObject *__pyx_getprop___pyx_memoryview_suboffsets(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_suboffsets(o); } static PyObject *__pyx_getprop___pyx_memoryview_ndim(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_ndim(o); } static PyObject *__pyx_getprop___pyx_memoryview_itemsize(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_itemsize(o); } static PyObject *__pyx_getprop___pyx_memoryview_nbytes(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_nbytes(o); } static PyObject *__pyx_getprop___pyx_memoryview_size(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_size(o); } static PyMethodDef __pyx_methods_memoryview[] = { {__Pyx_NAMESTR("is_c_contig"), (PyCFunction)__pyx_memoryview_is_c_contig, METH_NOARGS, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("is_f_contig"), (PyCFunction)__pyx_memoryview_is_f_contig, METH_NOARGS, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_memoryview_copy, METH_NOARGS, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("copy_fortran"), (PyCFunction)__pyx_memoryview_copy_fortran, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets_memoryview[] = { {(char *)"T", __pyx_getprop___pyx_memoryview_T, 0, 0, 0}, {(char *)"base", __pyx_getprop___pyx_memoryview_base, 0, 0, 0}, {(char *)"shape", __pyx_getprop___pyx_memoryview_shape, 0, 0, 0}, {(char *)"strides", __pyx_getprop___pyx_memoryview_strides, 0, 0, 0}, {(char *)"suboffsets", __pyx_getprop___pyx_memoryview_suboffsets, 0, 0, 0}, {(char *)"ndim", __pyx_getprop___pyx_memoryview_ndim, 0, 0, 0}, {(char *)"itemsize", __pyx_getprop___pyx_memoryview_itemsize, 0, 0, 0}, {(char *)"nbytes", __pyx_getprop___pyx_memoryview_nbytes, 0, 0, 0}, {(char *)"size", __pyx_getprop___pyx_memoryview_size, 0, 0, 0}, {0, 0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_memoryview = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*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 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 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 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*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; 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 #if PY_VERSION_HEX >= 0x02060000 __pyx_memoryview_getbuffer, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type___pyx_memoryview = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("cogent.align._pairwise_pogs.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*/ #else 0, /*reserved*/ #endif __pyx_memoryview___repr__, /*tp_repr*/ &__pyx_tp_as_number_memoryview, /*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_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*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #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 (!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; { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); __pyx_memoryviewslice___dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } Py_CLEAR(p->from_object); __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) { struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; PyObject* tmp; __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_memoryviewslice__get__base(o); } static PyMethodDef __pyx_methods__memoryviewslice[] = { {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets__memoryviewslice[] = { {(char *)"base", __pyx_getprop___pyx_memoryviewslice_base, 0, 0, 0}, {0, 0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number__memoryviewslice = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*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 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 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 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*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence__memoryviewslice = { #if CYTHON_COMPILING_IN_PYPY __pyx_memoryview___len__, /*sq_length*/ #else 0, /*sq_length*/ #endif 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__memoryviewslice = { #if CYTHON_COMPILING_IN_PYPY __pyx_memoryview___len__, /*mp_length*/ #else 0, /*mp_length*/ #endif #if CYTHON_COMPILING_IN_PYPY __pyx_memoryview___getitem__, /*mp_subscript*/ #else 0, /*mp_subscript*/ #endif 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer__memoryviewslice = { #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 #if CYTHON_COMPILING_IN_PYPY __pyx_memoryview_getbuffer, /*bf_getbuffer*/ #else #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type___pyx_memoryviewslice = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("cogent.align._pairwise_pogs._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*/ #else 0, /*reserved*/ #endif #if CYTHON_COMPILING_IN_PYPY __pyx_memoryview___repr__, /*tp_repr*/ #else 0, /*tp_repr*/ #endif &__pyx_tp_as_number__memoryviewslice, /*tp_as_number*/ &__pyx_tp_as_sequence__memoryviewslice, /*tp_as_sequence*/ &__pyx_tp_as_mapping__memoryviewslice, /*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*/ &__pyx_tp_as_buffer__memoryviewslice, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("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*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef __pyx_moduledef = { PyModuleDef_HEAD_INIT, __Pyx_NAMESTR("_pairwise_pogs"), 0, /* m_doc */ -1, /* m_size */ __pyx_methods /* m_methods */, NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0}, {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0}, {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0}, {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0}, {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 0}, {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0}, {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0}, {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 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_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 0, 1, 0}, {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0}, {&__pyx_kp_s_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 1, 0}, {&__pyx_kp_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 0}, {&__pyx_kp_s_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 1, 0}, {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0}, {&__pyx_kp_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 0}, {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0}, {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0}, {&__pyx_kp_s_52, __pyx_k_52, sizeof(__pyx_k_52), 0, 0, 1, 0}, {&__pyx_n_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 1}, {&__pyx_n_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 1}, {&__pyx_n_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 1}, {&__pyx_n_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 1}, {&__pyx_kp_s_60, __pyx_k_60, sizeof(__pyx_k_60), 0, 0, 1, 0}, {&__pyx_kp_s_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 0, 1, 0}, {&__pyx_kp_s_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 0, 1, 0}, {&__pyx_kp_s_66, __pyx_k_66, sizeof(__pyx_k_66), 0, 0, 1, 0}, {&__pyx_kp_s_68, __pyx_k_68, sizeof(__pyx_k_68), 0, 0, 1, 0}, {&__pyx_kp_s__1st, __pyx_k__1st, sizeof(__pyx_k__1st), 0, 0, 1, 0}, {&__pyx_kp_s__2nd, __pyx_k__2nd, sizeof(__pyx_k__2nd), 0, 0, 1, 0}, {&__pyx_kp_s__3rd, __pyx_k__3rd, sizeof(__pyx_k__3rd), 0, 0, 1, 0}, {&__pyx_n_s__ASCII, __pyx_k__ASCII, sizeof(__pyx_k__ASCII), 0, 0, 1, 1}, {&__pyx_n_s__ArithmeticError, __pyx_k__ArithmeticError, sizeof(__pyx_k__ArithmeticError), 0, 0, 1, 1}, {&__pyx_n_s__Ellipsis, __pyx_k__Ellipsis, sizeof(__pyx_k__Ellipsis), 0, 0, 1, 1}, {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 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_b__O, __pyx_k__O, sizeof(__pyx_k__O), 0, 0, 0, 1}, {&__pyx_n_s__T, __pyx_k__T, sizeof(__pyx_k__T), 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_n_s____class__, __pyx_k____class__, sizeof(__pyx_k____class__), 0, 0, 1, 1}, {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, {&__pyx_n_s____name__, __pyx_k____name__, sizeof(__pyx_k____name__), 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____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, {&__pyx_n_s____version__, __pyx_k____version__, sizeof(__pyx_k____version__), 0, 0, 1, 1}, {&__pyx_n_s__a, __pyx_k__a, sizeof(__pyx_k__a), 0, 0, 1, 1}, {&__pyx_n_s__a_count, __pyx_k__a_count, sizeof(__pyx_k__a_count), 0, 0, 1, 1}, {&__pyx_n_s__a_high, __pyx_k__a_high, sizeof(__pyx_k__a_high), 0, 0, 1, 1}, {&__pyx_n_s__a_low, __pyx_k__a_low, sizeof(__pyx_k__a_low), 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__asCombinedArray, __pyx_k__asCombinedArray, sizeof(__pyx_k__asCombinedArray), 0, 0, 1, 1}, {&__pyx_n_s__b, __pyx_k__b, sizeof(__pyx_k__b), 0, 0, 1, 1}, {&__pyx_n_s__b_count, __pyx_k__b_count, sizeof(__pyx_k__b_count), 0, 0, 1, 1}, {&__pyx_n_s__b_high, __pyx_k__b_high, sizeof(__pyx_k__b_high), 0, 0, 1, 1}, {&__pyx_n_s__b_low, __pyx_k__b_low, sizeof(__pyx_k__b_low), 0, 0, 1, 1}, {&__pyx_n_s__base, __pyx_k__base, sizeof(__pyx_k__base), 0, 0, 1, 1}, {&__pyx_n_s__bin, __pyx_k__bin, sizeof(__pyx_k__bin), 0, 0, 1, 1}, {&__pyx_n_s__bin_count, __pyx_k__bin_count, sizeof(__pyx_k__bin_count), 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_n_s__calc_rows, __pyx_k__calc_rows, sizeof(__pyx_k__calc_rows), 0, 0, 1, 1}, {&__pyx_n_s__current_row_index, __pyx_k__current_row_index, sizeof(__pyx_k__current_row_index), 0, 0, 1, 1}, {&__pyx_n_s__d4, __pyx_k__d4, sizeof(__pyx_k__d4), 0, 0, 1, 1}, {&__pyx_n_s__d_score, __pyx_k__d_score, sizeof(__pyx_k__d_score), 0, 0, 1, 1}, {&__pyx_n_s__decode, __pyx_k__decode, sizeof(__pyx_k__decode), 0, 0, 1, 1}, {&__pyx_n_s__dest_state, __pyx_k__dest_state, sizeof(__pyx_k__dest_state), 0, 0, 1, 1}, {&__pyx_n_s__dest_states, __pyx_k__dest_states, sizeof(__pyx_k__dest_states), 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__dx, __pyx_k__dx, sizeof(__pyx_k__dx), 0, 0, 1, 1}, {&__pyx_n_s__dy, __pyx_k__dy, sizeof(__pyx_k__dy), 0, 0, 1, 1}, {&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 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__exponent, __pyx_k__exponent, sizeof(__pyx_k__exponent), 0, 0, 1, 1}, {&__pyx_n_s__exponents, __pyx_k__exponents, sizeof(__pyx_k__exponents), 0, 0, 1, 1}, {&__pyx_n_s__extend, __pyx_k__extend, sizeof(__pyx_k__extend), 0, 0, 1, 1}, {&__pyx_n_s__flags, __pyx_k__flags, sizeof(__pyx_k__flags), 0, 0, 1, 1}, {&__pyx_n_s__fmpt, __pyx_k__fmpt, sizeof(__pyx_k__fmpt), 0, 0, 1, 1}, {&__pyx_n_s__format, __pyx_k__format, sizeof(__pyx_k__format), 0, 0, 1, 1}, {&__pyx_n_b__fortran, __pyx_k__fortran, sizeof(__pyx_k__fortran), 0, 0, 0, 1}, {&__pyx_n_s__fortran, __pyx_k__fortran, sizeof(__pyx_k__fortran), 0, 0, 1, 1}, {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1}, {&__pyx_n_s__i_high, __pyx_k__i_high, sizeof(__pyx_k__i_high), 0, 0, 1, 1}, {&__pyx_n_s__i_link_count, __pyx_k__i_link_count, sizeof(__pyx_k__i_link_count), 0, 0, 1, 1}, {&__pyx_n_s__i_low, __pyx_k__i_low, sizeof(__pyx_k__i_low), 0, 0, 1, 1}, {&__pyx_n_s__i_sources, __pyx_k__i_sources, sizeof(__pyx_k__i_sources), 0, 0, 1, 1}, {&__pyx_n_s__i_sources_end, __pyx_k__i_sources_end, sizeof(__pyx_k__i_sources_end), 0, 0, 1, 1}, {&__pyx_n_s__i_sources_offsets, __pyx_k__i_sources_offsets, sizeof(__pyx_k__i_sources_offsets), 0, 0, 1, 1}, {&__pyx_n_s__i_sources_start, __pyx_k__i_sources_start, sizeof(__pyx_k__i_sources_start), 0, 0, 1, 1}, {&__pyx_n_s__id, __pyx_k__id, sizeof(__pyx_k__id), 0, 0, 1, 1}, {&__pyx_n_s__impossible, __pyx_k__impossible, sizeof(__pyx_k__impossible), 0, 0, 1, 1}, {&__pyx_n_s__itemsize, __pyx_k__itemsize, sizeof(__pyx_k__itemsize), 0, 0, 1, 1}, {&__pyx_n_s__j, __pyx_k__j, sizeof(__pyx_k__j), 0, 0, 1, 1}, {&__pyx_n_s__j_high, __pyx_k__j_high, sizeof(__pyx_k__j_high), 0, 0, 1, 1}, {&__pyx_n_s__j_link_count, __pyx_k__j_link_count, sizeof(__pyx_k__j_link_count), 0, 0, 1, 1}, {&__pyx_n_s__j_low, __pyx_k__j_low, sizeof(__pyx_k__j_low), 0, 0, 1, 1}, {&__pyx_n_s__j_sources, __pyx_k__j_sources, sizeof(__pyx_k__j_sources), 0, 0, 1, 1}, {&__pyx_n_s__j_sources_end, __pyx_k__j_sources_end, sizeof(__pyx_k__j_sources_end), 0, 0, 1, 1}, {&__pyx_n_s__j_sources_offsets, __pyx_k__j_sources_offsets, sizeof(__pyx_k__j_sources_offsets), 0, 0, 1, 1}, {&__pyx_n_s__j_sources_start, __pyx_k__j_sources_start, sizeof(__pyx_k__j_sources_start), 0, 0, 1, 1}, {&__pyx_n_s__last_i, __pyx_k__last_i, sizeof(__pyx_k__last_i), 0, 0, 1, 1}, {&__pyx_n_s__last_j, __pyx_k__last_j, sizeof(__pyx_k__last_j), 0, 0, 1, 1}, {&__pyx_n_s__last_state, __pyx_k__last_state, sizeof(__pyx_k__last_state), 0, 0, 1, 1}, {&__pyx_n_s__local, __pyx_k__local, sizeof(__pyx_k__local), 0, 0, 1, 1}, {&__pyx_n_s__mantissa, __pyx_k__mantissa, sizeof(__pyx_k__mantissa), 0, 0, 1, 1}, {&__pyx_n_s__mantissas, __pyx_k__mantissas, sizeof(__pyx_k__mantissas), 0, 0, 1, 1}, {&__pyx_n_s__match_scores, __pyx_k__match_scores, sizeof(__pyx_k__match_scores), 0, 0, 1, 1}, {&__pyx_n_s__max_exponent, __pyx_k__max_exponent, sizeof(__pyx_k__max_exponent), 0, 0, 1, 1}, {&__pyx_n_s__max_mantissa, __pyx_k__max_mantissa, sizeof(__pyx_k__max_mantissa), 0, 0, 1, 1}, {&__pyx_n_s__max_x, __pyx_k__max_x, sizeof(__pyx_k__max_x), 0, 0, 1, 1}, {&__pyx_n_s__max_y, __pyx_k__max_y, sizeof(__pyx_k__max_y), 0, 0, 1, 1}, {&__pyx_n_s__memview, __pyx_k__memview, sizeof(__pyx_k__memview), 0, 0, 1, 1}, {&__pyx_n_s__min_prev_state, __pyx_k__min_prev_state, sizeof(__pyx_k__min_prev_state), 0, 0, 1, 1}, {&__pyx_n_s__mode, __pyx_k__mode, sizeof(__pyx_k__mode), 0, 0, 1, 1}, {&__pyx_n_s__msg, __pyx_k__msg, sizeof(__pyx_k__msg), 0, 0, 1, 1}, {&__pyx_n_s__name, __pyx_k__name, sizeof(__pyx_k__name), 0, 0, 1, 1}, {&__pyx_n_s__ndim, __pyx_k__ndim, sizeof(__pyx_k__ndim), 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__partial_sum, __pyx_k__partial_sum, sizeof(__pyx_k__partial_sum), 0, 0, 1, 1}, {&__pyx_n_s__plan, __pyx_k__plan, sizeof(__pyx_k__plan), 0, 0, 1, 1}, {&__pyx_n_s__pog1, __pyx_k__pog1, sizeof(__pyx_k__pog1), 0, 0, 1, 1}, {&__pyx_n_s__pog2, __pyx_k__pog2, sizeof(__pyx_k__pog2), 0, 0, 1, 1}, {&__pyx_n_s__pointer_a, __pyx_k__pointer_a, sizeof(__pyx_k__pointer_a), 0, 0, 1, 1}, {&__pyx_n_s__pointer_b, __pyx_k__pointer_b, sizeof(__pyx_k__pointer_b), 0, 0, 1, 1}, {&__pyx_n_s__pointer_state, __pyx_k__pointer_state, sizeof(__pyx_k__pointer_state), 0, 0, 1, 1}, {&__pyx_n_s__preds, __pyx_k__preds, sizeof(__pyx_k__preds), 0, 0, 1, 1}, {&__pyx_n_s__prev_i, __pyx_k__prev_i, sizeof(__pyx_k__prev_i), 0, 0, 1, 1}, {&__pyx_n_s__prev_j, __pyx_k__prev_j, sizeof(__pyx_k__prev_j), 0, 0, 1, 1}, {&__pyx_n_s__prev_state, __pyx_k__prev_state, sizeof(__pyx_k__prev_state), 0, 0, 1, 1}, {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, {&__pyx_n_s__row_count, __pyx_k__row_count, sizeof(__pyx_k__row_count), 0, 0, 1, 1}, {&__pyx_n_s__row_count1, __pyx_k__row_count1, sizeof(__pyx_k__row_count1), 0, 0, 1, 1}, {&__pyx_n_s__row_length, __pyx_k__row_length, sizeof(__pyx_k__row_length), 0, 0, 1, 1}, {&__pyx_n_s__row_length1, __pyx_k__row_length1, sizeof(__pyx_k__row_length1), 0, 0, 1, 1}, {&__pyx_n_s__rows, __pyx_k__rows, sizeof(__pyx_k__rows), 0, 0, 1, 1}, {&__pyx_n_s__score, __pyx_k__score, sizeof(__pyx_k__score), 0, 0, 1, 1}, {&__pyx_n_s__seq1_index, __pyx_k__seq1_index, sizeof(__pyx_k__seq1_index), 0, 0, 1, 1}, {&__pyx_n_s__seq2_index, __pyx_k__seq2_index, sizeof(__pyx_k__seq2_index), 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__source_row_index, __pyx_k__source_row_index, sizeof(__pyx_k__source_row_index), 0, 0, 1, 1}, {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1}, {&__pyx_n_s__state, __pyx_k__state, sizeof(__pyx_k__state), 0, 0, 1, 1}, {&__pyx_n_s__state_directions, __pyx_k__state_directions, sizeof(__pyx_k__state_directions), 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__struct, __pyx_k__struct, sizeof(__pyx_k__struct), 0, 0, 1, 1}, {&__pyx_n_s__sub_partial_sum, __pyx_k__sub_partial_sum, sizeof(__pyx_k__sub_partial_sum), 0, 0, 1, 1}, {&__pyx_n_s__tcode_s, __pyx_k__tcode_s, sizeof(__pyx_k__tcode_s), 0, 0, 1, 1}, {&__pyx_n_s__tcode_x, __pyx_k__tcode_x, sizeof(__pyx_k__tcode_x), 0, 0, 1, 1}, {&__pyx_n_s__tcode_y, __pyx_k__tcode_y, sizeof(__pyx_k__tcode_y), 0, 0, 1, 1}, {&__pyx_n_s__tmp_rows, __pyx_k__tmp_rows, sizeof(__pyx_k__tmp_rows), 0, 0, 1, 1}, {&__pyx_n_s__track, __pyx_k__track, sizeof(__pyx_k__track), 0, 0, 1, 1}, {&__pyx_n_s__track_enc, __pyx_k__track_enc, sizeof(__pyx_k__track_enc), 0, 0, 1, 1}, {&__pyx_n_s__underflows, __pyx_k__underflows, sizeof(__pyx_k__underflows), 0, 0, 1, 1}, {&__pyx_n_s__unpack, __pyx_k__unpack, sizeof(__pyx_k__unpack), 0, 0, 1, 1}, {&__pyx_n_s__use_logs, __pyx_k__use_logs, sizeof(__pyx_k__use_logs), 0, 0, 1, 1}, {&__pyx_n_s__use_scaling, __pyx_k__use_scaling, sizeof(__pyx_k__use_scaling), 0, 0, 1, 1}, {&__pyx_n_s__version_info, __pyx_k__version_info, sizeof(__pyx_k__version_info), 0, 0, 1, 1}, {&__pyx_n_s__viterbi, __pyx_k__viterbi, sizeof(__pyx_k__viterbi), 0, 0, 1, 1}, {&__pyx_n_s__x, __pyx_k__x, sizeof(__pyx_k__x), 0, 0, 1, 1}, {&__pyx_n_s__xgap_scores, __pyx_k__xgap_scores, sizeof(__pyx_k__xgap_scores), 0, 0, 1, 1}, {&__pyx_n_s__xrange, __pyx_k__xrange, sizeof(__pyx_k__xrange), 0, 0, 1, 1}, {&__pyx_n_s__y, __pyx_k__y, sizeof(__pyx_k__y), 0, 0, 1, 1}, {&__pyx_n_s__ygap_scores, __pyx_k__ygap_scores, sizeof(__pyx_k__ygap_scores), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_ArithmeticError = __Pyx_GetName(__pyx_b, __pyx_n_s__ArithmeticError); if (!__pyx_builtin_ArithmeticError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_Ellipsis = __Pyx_GetName(__pyx_b, __pyx_n_s__Ellipsis); if (!__pyx_builtin_Ellipsis) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if PY_MAJOR_VERSION >= 3 __pyx_builtin_xrange = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_builtin_xrange = __Pyx_GetName(__pyx_b, __pyx_n_s__xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif __pyx_builtin_id = __Pyx_GetName(__pyx_b, __pyx_n_s__id); if (!__pyx_builtin_id) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; } static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":64 * cdef int checkArray1D(num[::1] a, dim *x) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * */ __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_4); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4)); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":69 * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_5); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_6); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6)); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":75 * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_7); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7)); __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_8); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_8, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8)); __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_9); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_9)); /* "View.MemoryView":124 * * if not self.ndim: * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< * * if self.itemsize <= 0: */ __pyx_k_tuple_16 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_16); __Pyx_INCREF(((PyObject *)__pyx_kp_s_15)); PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, ((PyObject *)__pyx_kp_s_15)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_15)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16)); /* "View.MemoryView":127 * * if self.itemsize <= 0: * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< * * encode = getattr(format, 'encode', None) */ __pyx_k_tuple_18 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_18)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_18); __Pyx_INCREF(((PyObject *)__pyx_kp_s_17)); PyTuple_SET_ITEM(__pyx_k_tuple_18, 0, ((PyObject *)__pyx_kp_s_17)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18)); /* "View.MemoryView":131 * encode = getattr(format, 'encode', None) * if encode: * format = encode('ASCII') # <<<<<<<<<<<<<< * self._format = format * self.format = self._format */ __pyx_k_tuple_19 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_19); __Pyx_INCREF(((PyObject *)__pyx_n_s__ASCII)); PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_n_s__ASCII)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ASCII)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19)); /* "View.MemoryView":141 * free(self._shape) * free(self._strides) * raise MemoryError("unable to allocate shape or strides.") # <<<<<<<<<<<<<< * * */ __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_21); __Pyx_INCREF(((PyObject *)__pyx_kp_s_20)); PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_20)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_20)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); /* "View.MemoryView":166 * decode = getattr(mode, 'decode', None) * if decode: * mode = decode('ASCII') # <<<<<<<<<<<<<< * self.mode = mode * */ __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_24); __Pyx_INCREF(((PyObject *)__pyx_n_s__ASCII)); PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_n_s__ASCII)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ASCII)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); /* "View.MemoryView":174 * self.data = malloc(self.len) * if not self.data: * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< * * if self.dtype_is_object: */ __pyx_k_tuple_26 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_26); __Pyx_INCREF(((PyObject *)__pyx_kp_s_25)); PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, ((PyObject *)__pyx_kp_s_25)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_25)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26)); /* "View.MemoryView":190 * 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_k_tuple_28 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_28)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_28); __Pyx_INCREF(((PyObject *)__pyx_kp_s_27)); PyTuple_SET_ITEM(__pyx_k_tuple_28, 0, ((PyObject *)__pyx_kp_s_27)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_27)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_28)); /* "View.MemoryView":452 * 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_k_tuple_30 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_30); __Pyx_INCREF(((PyObject *)__pyx_kp_s_29)); PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, ((PyObject *)__pyx_kp_s_29)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_29)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30)); /* "View.MemoryView":528 * if self.view.strides == NULL: * * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< * * return tuple([self.view.strides[i] for i in xrange(self.view.ndim)]) */ __pyx_k_tuple_32 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_32); __Pyx_INCREF(((PyObject *)__pyx_kp_s_31)); PyTuple_SET_ITEM(__pyx_k_tuple_32, 0, ((PyObject *)__pyx_kp_s_31)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32)); /* "View.MemoryView":643 * if item is Ellipsis: * if not seen_ellipsis: * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<< * seen_ellipsis = True * else: */ __pyx_k_tuple_35 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_35); __Pyx_INCREF(Py_None); PyTuple_SET_ITEM(__pyx_k_tuple_35, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35)); /* "View.MemoryView":646 * seen_ellipsis = True * else: * result.append(slice(None)) # <<<<<<<<<<<<<< * have_slices = True * else: */ __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_36); __Pyx_INCREF(Py_None); PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); /* "View.MemoryView":657 * nslices = ndim - len(result) * if nslices: * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<< * * return have_slices or nslices, tuple(result) */ __pyx_k_tuple_38 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_38)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_38); __Pyx_INCREF(Py_None); PyTuple_SET_ITEM(__pyx_k_tuple_38, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_38)); /* "View.MemoryView":665 * for i in range(ndim): * if suboffsets[i] >= 0: * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< * * */ __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_40); __Pyx_INCREF(((PyObject *)__pyx_kp_s_39)); PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, ((PyObject *)__pyx_kp_s_39)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_39)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40)); /* "cogent/align/_pairwise_pogs.pyx":14 * double log (double x) * * version_info = (3, 2) # <<<<<<<<<<<<<< * __version__ = "('1', '5', '3-dev')" * */ __pyx_k_tuple_49 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_49)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_49); __Pyx_INCREF(__pyx_int_3); PyTuple_SET_ITEM(__pyx_k_tuple_49, 0, __pyx_int_3); __Pyx_GIVEREF(__pyx_int_3); __Pyx_INCREF(__pyx_int_2); PyTuple_SET_ITEM(__pyx_k_tuple_49, 1, __pyx_int_2); __Pyx_GIVEREF(__pyx_int_2); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_49)); /* "cogent/align/_pairwise_pogs.pyx":28 * MAX_SCALE = +10000 # or 0 if all numbers should be probabilities * * def fmpt(mantissa, exponent, msg=''): # <<<<<<<<<<<<<< * return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) * */ __pyx_k_tuple_50 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_50); __Pyx_INCREF(((PyObject *)__pyx_n_s__mantissa)); PyTuple_SET_ITEM(__pyx_k_tuple_50, 0, ((PyObject *)__pyx_n_s__mantissa)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mantissa)); __Pyx_INCREF(((PyObject *)__pyx_n_s__exponent)); PyTuple_SET_ITEM(__pyx_k_tuple_50, 1, ((PyObject *)__pyx_n_s__exponent)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__exponent)); __Pyx_INCREF(((PyObject *)__pyx_n_s__msg)); PyTuple_SET_ITEM(__pyx_k_tuple_50, 2, ((PyObject *)__pyx_n_s__msg)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50)); __pyx_k_codeobj_51 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_50, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_52, __pyx_n_s__fmpt, 28, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_51)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":33 * ctypedef unsigned char [:,:,::1] UChar3D * * def calc_rows(Long1D plan, Long1D seq1_index, Long1D seq2_index, # <<<<<<<<<<<<<< * int i_low, int i_high, int j_low, int j_high, preds, * Long2D state_directions, Double2D T, */ __pyx_k_tuple_57 = PyTuple_New(89); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_57); __Pyx_INCREF(((PyObject *)__pyx_n_s__plan)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 0, ((PyObject *)__pyx_n_s__plan)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__plan)); __Pyx_INCREF(((PyObject *)__pyx_n_s__seq1_index)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 1, ((PyObject *)__pyx_n_s__seq1_index)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__seq1_index)); __Pyx_INCREF(((PyObject *)__pyx_n_s__seq2_index)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 2, ((PyObject *)__pyx_n_s__seq2_index)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__seq2_index)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i_low)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 3, ((PyObject *)__pyx_n_s__i_low)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_low)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i_high)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 4, ((PyObject *)__pyx_n_s__i_high)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_high)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j_low)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 5, ((PyObject *)__pyx_n_s__j_low)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j_low)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j_high)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 6, ((PyObject *)__pyx_n_s__j_high)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j_high)); __Pyx_INCREF(((PyObject *)__pyx_n_s__preds)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 7, ((PyObject *)__pyx_n_s__preds)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__preds)); __Pyx_INCREF(((PyObject *)__pyx_n_s__state_directions)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 8, ((PyObject *)__pyx_n_s__state_directions)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__state_directions)); __Pyx_INCREF(((PyObject *)__pyx_n_s__T)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 9, ((PyObject *)__pyx_n_s__T)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__T)); __Pyx_INCREF(((PyObject *)__pyx_n_s__xgap_scores)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 10, ((PyObject *)__pyx_n_s__xgap_scores)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__xgap_scores)); __Pyx_INCREF(((PyObject *)__pyx_n_s__ygap_scores)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 11, ((PyObject *)__pyx_n_s__ygap_scores)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ygap_scores)); __Pyx_INCREF(((PyObject *)__pyx_n_s__match_scores)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 12, ((PyObject *)__pyx_n_s__match_scores)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__match_scores)); __Pyx_INCREF(((PyObject *)__pyx_n_s__rows)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 13, ((PyObject *)__pyx_n_s__rows)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rows)); __Pyx_INCREF(((PyObject *)__pyx_n_s__track)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 14, ((PyObject *)__pyx_n_s__track)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__track)); __Pyx_INCREF(((PyObject *)__pyx_n_s__track_enc)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 15, ((PyObject *)__pyx_n_s__track_enc)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__track_enc)); __Pyx_INCREF(((PyObject *)__pyx_n_s__viterbi)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 16, ((PyObject *)__pyx_n_s__viterbi)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__viterbi)); __Pyx_INCREF(((PyObject *)__pyx_n_s__use_logs)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 17, ((PyObject *)__pyx_n_s__use_logs)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__use_logs)); __Pyx_INCREF(((PyObject *)__pyx_n_s__local)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 18, ((PyObject *)__pyx_n_s__local)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__local)); __Pyx_INCREF(((PyObject *)__pyx_n_s__use_scaling)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 19, ((PyObject *)__pyx_n_s__use_scaling)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__use_scaling)); __Pyx_INCREF(((PyObject *)__pyx_n_s__prev_i)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 20, ((PyObject *)__pyx_n_s__prev_i)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__prev_i)); __Pyx_INCREF(((PyObject *)__pyx_n_s__prev_j)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 21, ((PyObject *)__pyx_n_s__prev_j)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__prev_j)); __Pyx_INCREF(((PyObject *)__pyx_n_s__state)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 22, ((PyObject *)__pyx_n_s__state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__prev_state)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 23, ((PyObject *)__pyx_n_s__prev_state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__prev_state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__min_prev_state)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 24, ((PyObject *)__pyx_n_s__min_prev_state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__min_prev_state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__N)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 25, ((PyObject *)__pyx_n_s__N)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__N)); __Pyx_INCREF(((PyObject *)__pyx_n_s__row_length)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 26, ((PyObject *)__pyx_n_s__row_length)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__row_length)); __Pyx_INCREF(((PyObject *)__pyx_n_s__row_length1)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 27, ((PyObject *)__pyx_n_s__row_length1)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__row_length1)); __Pyx_INCREF(((PyObject *)__pyx_n_s__row_count)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 28, ((PyObject *)__pyx_n_s__row_count)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__row_count)); __Pyx_INCREF(((PyObject *)__pyx_n_s__row_count1)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 29, ((PyObject *)__pyx_n_s__row_count1)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__row_count1)); __Pyx_INCREF(((PyObject *)__pyx_n_s__tmp_rows)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 30, ((PyObject *)__pyx_n_s__tmp_rows)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tmp_rows)); __Pyx_INCREF(((PyObject *)__pyx_n_s__a_count)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 31, ((PyObject *)__pyx_n_s__a_count)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__a_count)); __Pyx_INCREF(((PyObject *)__pyx_n_s__b_count)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 32, ((PyObject *)__pyx_n_s__b_count)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__b_count)); __Pyx_INCREF(((PyObject *)__pyx_n_s__a)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 33, ((PyObject *)__pyx_n_s__a)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__a)); __Pyx_INCREF(((PyObject *)__pyx_n_s__b)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 34, ((PyObject *)__pyx_n_s__b)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__b)); __Pyx_INCREF(((PyObject *)__pyx_n_s__a_low)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 35, ((PyObject *)__pyx_n_s__a_low)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__a_low)); __Pyx_INCREF(((PyObject *)__pyx_n_s__a_high)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 36, ((PyObject *)__pyx_n_s__a_high)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__a_high)); __Pyx_INCREF(((PyObject *)__pyx_n_s__b_low)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 37, ((PyObject *)__pyx_n_s__b_low)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__b_low)); __Pyx_INCREF(((PyObject *)__pyx_n_s__b_high)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 38, ((PyObject *)__pyx_n_s__b_high)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__b_high)); __Pyx_INCREF(((PyObject *)__pyx_n_s__dest_states)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 39, ((PyObject *)__pyx_n_s__dest_states)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dest_states)); __Pyx_INCREF(((PyObject *)__pyx_n_s__dest_state)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 40, ((PyObject *)__pyx_n_s__dest_state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dest_state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__d4)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 41, ((PyObject *)__pyx_n_s__d4)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__d4)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 42, ((PyObject *)__pyx_n_s__j)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 43, ((PyObject *)__pyx_n_s__i)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i)); __Pyx_INCREF(((PyObject *)__pyx_n_s__last_i)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 44, ((PyObject *)__pyx_n_s__last_i)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__last_i)); __Pyx_INCREF(((PyObject *)__pyx_n_s__last_j)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 45, ((PyObject *)__pyx_n_s__last_j)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__last_j)); __Pyx_INCREF(((PyObject *)__pyx_n_s__last_state)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 46, ((PyObject *)__pyx_n_s__last_state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__last_state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__bin)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 47, ((PyObject *)__pyx_n_s__bin)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bin)); __Pyx_INCREF(((PyObject *)__pyx_n_s__x)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 48, ((PyObject *)__pyx_n_s__x)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__x)); __Pyx_INCREF(((PyObject *)__pyx_n_s__y)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 49, ((PyObject *)__pyx_n_s__y)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__y)); __Pyx_INCREF(((PyObject *)__pyx_n_s__bin_count)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 50, ((PyObject *)__pyx_n_s__bin_count)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bin_count)); __Pyx_INCREF(((PyObject *)__pyx_n_s__max_x)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 51, ((PyObject *)__pyx_n_s__max_x)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_x)); __Pyx_INCREF(((PyObject *)__pyx_n_s__max_y)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 52, ((PyObject *)__pyx_n_s__max_y)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_y)); __Pyx_INCREF(((PyObject *)__pyx_n_s__current_row_index)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 53, ((PyObject *)__pyx_n_s__current_row_index)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__current_row_index)); __Pyx_INCREF(((PyObject *)__pyx_n_s__source_row_index)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 54, ((PyObject *)__pyx_n_s__source_row_index)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__source_row_index)); __Pyx_INCREF(((PyObject *)__pyx_n_s_54)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 55, ((PyObject *)__pyx_n_s_54)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s_54)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i_link_count)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 56, ((PyObject *)__pyx_n_s__i_link_count)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_link_count)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j_link_count)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 57, ((PyObject *)__pyx_n_s__j_link_count)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j_link_count)); __Pyx_INCREF(((PyObject *)__pyx_n_s__dx)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 58, ((PyObject *)__pyx_n_s__dx)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dx)); __Pyx_INCREF(((PyObject *)__pyx_n_s__dy)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 59, ((PyObject *)__pyx_n_s__dy)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dy)); __Pyx_INCREF(((PyObject *)__pyx_n_s__tcode_x)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 60, ((PyObject *)__pyx_n_s__tcode_x)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tcode_x)); __Pyx_INCREF(((PyObject *)__pyx_n_s__tcode_y)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 61, ((PyObject *)__pyx_n_s__tcode_y)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tcode_y)); __Pyx_INCREF(((PyObject *)__pyx_n_s__tcode_s)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 62, ((PyObject *)__pyx_n_s__tcode_s)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tcode_s)); __Pyx_INCREF(((PyObject *)__pyx_n_s__d_score)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 63, ((PyObject *)__pyx_n_s__d_score)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__d_score)); __Pyx_INCREF(((PyObject *)__pyx_n_s__mantissa)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 64, ((PyObject *)__pyx_n_s__mantissa)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mantissa)); __Pyx_INCREF(((PyObject *)__pyx_n_s__partial_sum)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 65, ((PyObject *)__pyx_n_s__partial_sum)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__partial_sum)); __Pyx_INCREF(((PyObject *)__pyx_n_s__sub_partial_sum)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 66, ((PyObject *)__pyx_n_s__sub_partial_sum)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sub_partial_sum)); __Pyx_INCREF(((PyObject *)__pyx_n_s__max_mantissa)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 67, ((PyObject *)__pyx_n_s__max_mantissa)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_mantissa)); __Pyx_INCREF(((PyObject *)__pyx_n_s_55)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 68, ((PyObject *)__pyx_n_s_55)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s_55)); __Pyx_INCREF(((PyObject *)__pyx_n_s__exponent)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 69, ((PyObject *)__pyx_n_s__exponent)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__exponent)); __Pyx_INCREF(((PyObject *)__pyx_n_s__max_exponent)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 70, ((PyObject *)__pyx_n_s__max_exponent)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_exponent)); __Pyx_INCREF(((PyObject *)__pyx_n_s_56)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 71, ((PyObject *)__pyx_n_s_56)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s_56)); __Pyx_INCREF(((PyObject *)__pyx_n_s__mantissas)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 72, ((PyObject *)__pyx_n_s__mantissas)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mantissas)); __Pyx_INCREF(((PyObject *)__pyx_n_s__exponents)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 73, ((PyObject *)__pyx_n_s__exponents)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__exponents)); __Pyx_INCREF(((PyObject *)__pyx_n_s__pointer_a)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 74, ((PyObject *)__pyx_n_s__pointer_a)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pointer_a)); __Pyx_INCREF(((PyObject *)__pyx_n_s__pointer_b)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 75, ((PyObject *)__pyx_n_s__pointer_b)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pointer_b)); __Pyx_INCREF(((PyObject *)__pyx_n_s__pointer_state)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 76, ((PyObject *)__pyx_n_s__pointer_state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pointer_state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i_sources)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 77, ((PyObject *)__pyx_n_s__i_sources)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_sources)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i_sources_offsets)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 78, ((PyObject *)__pyx_n_s__i_sources_offsets)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_sources_offsets)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j_sources)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 79, ((PyObject *)__pyx_n_s__j_sources)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j_sources)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j_sources_offsets)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 80, ((PyObject *)__pyx_n_s__j_sources_offsets)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j_sources_offsets)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i_sources_start)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 81, ((PyObject *)__pyx_n_s__i_sources_start)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_sources_start)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i_sources_end)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 82, ((PyObject *)__pyx_n_s__i_sources_end)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_sources_end)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j_sources_start)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 83, ((PyObject *)__pyx_n_s__j_sources_start)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j_sources_start)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j_sources_end)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 84, ((PyObject *)__pyx_n_s__j_sources_end)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j_sources_end)); __Pyx_INCREF(((PyObject *)__pyx_n_s__pog1)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 85, ((PyObject *)__pyx_n_s__pog1)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pog1)); __Pyx_INCREF(((PyObject *)__pyx_n_s__pog2)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 86, ((PyObject *)__pyx_n_s__pog2)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pog2)); __Pyx_INCREF(((PyObject *)__pyx_n_s__impossible)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 87, ((PyObject *)__pyx_n_s__impossible)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__impossible)); __Pyx_INCREF(((PyObject *)__pyx_n_s__score)); PyTuple_SET_ITEM(__pyx_k_tuple_57, 88, ((PyObject *)__pyx_n_s__score)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__score)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_57)); __pyx_k_codeobj_58 = (PyObject*)__Pyx_PyCode_New(20, 0, 89, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_57, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_52, __pyx_n_s__calc_rows, 33, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_58)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":282 * return self.name * * cdef generic = Enum("") # <<<<<<<<<<<<<< * cdef strided = Enum("") # default * cdef indirect = Enum("") */ __pyx_k_tuple_61 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_61)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_61); __Pyx_INCREF(((PyObject *)__pyx_kp_s_60)); PyTuple_SET_ITEM(__pyx_k_tuple_61, 0, ((PyObject *)__pyx_kp_s_60)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_60)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_61)); /* "View.MemoryView":283 * * cdef generic = Enum("") * cdef strided = Enum("") # default # <<<<<<<<<<<<<< * cdef indirect = Enum("") * */ __pyx_k_tuple_63 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_63)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_63); __Pyx_INCREF(((PyObject *)__pyx_kp_s_62)); PyTuple_SET_ITEM(__pyx_k_tuple_63, 0, ((PyObject *)__pyx_kp_s_62)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_62)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_63)); /* "View.MemoryView":284 * cdef generic = Enum("") * cdef strided = Enum("") # default * cdef indirect = Enum("") # <<<<<<<<<<<<<< * * */ __pyx_k_tuple_65 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_65)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_65); __Pyx_INCREF(((PyObject *)__pyx_kp_s_64)); PyTuple_SET_ITEM(__pyx_k_tuple_65, 0, ((PyObject *)__pyx_kp_s_64)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_64)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_65)); /* "View.MemoryView":287 * * * cdef contiguous = Enum("") # <<<<<<<<<<<<<< * cdef indirect_contiguous = Enum("") * */ __pyx_k_tuple_67 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_67)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_67); __Pyx_INCREF(((PyObject *)__pyx_kp_s_66)); PyTuple_SET_ITEM(__pyx_k_tuple_67, 0, ((PyObject *)__pyx_kp_s_66)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_66)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_67)); /* "View.MemoryView":288 * * cdef contiguous = Enum("") * cdef indirect_contiguous = Enum("") # <<<<<<<<<<<<<< * * */ __pyx_k_tuple_69 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_69)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_69); __Pyx_INCREF(((PyObject *)__pyx_kp_s_68)); PyTuple_SET_ITEM(__pyx_k_tuple_69, 0, ((PyObject *)__pyx_kp_s_68)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_68)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_69)); __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; return 0; __pyx_L1_error:; return -1; } #if PY_MAJOR_VERSION < 3 PyMODINIT_FUNC init_pairwise_pogs(void); /*proto*/ PyMODINIT_FUNC init_pairwise_pogs(void) #else PyMODINIT_FUNC PyInit__pairwise_pogs(void); /*proto*/ PyMODINIT_FUNC PyInit__pairwise_pogs(void) #endif { PyObject *__pyx_t_1 = NULL; __Pyx_RefNannyDeclarations #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("PyMODINIT_FUNC PyInit__pairwise_pogs(void)", 0); if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #ifdef __Pyx_CyFunction_USED if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif #ifdef __Pyx_FusedFunction_USED if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif #ifdef __Pyx_Generator_USED if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __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 PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_pairwise_pogs"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if CYTHON_COMPILING_IN_PYPY Py_INCREF(__pyx_b); #endif if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; /*--- Initialize various global constants etc. ---*/ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_module_is_main_cogent__align___pairwise_pogs) { if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; } /*--- Builtin init code ---*/ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Constants init code ---*/ if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- 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); /*--- Variable export code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ if (PyType_Ready(&__pyx_type___pyx_array) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "array", (PyObject *)&__pyx_type___pyx_array) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_array_type = &__pyx_type___pyx_array; if (PyType_Ready(&__pyx_type___pyx_MemviewEnum) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Enum", (PyObject *)&__pyx_type___pyx_MemviewEnum) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type___pyx_memoryview.tp_dict, __pyx_vtabptr_memoryview) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "memoryview", (PyObject *)&__pyx_type___pyx_memoryview) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type___pyx_memoryviewslice.tp_dict, __pyx_vtabptr__memoryviewslice) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "_memoryviewslice", (PyObject *)&__pyx_type___pyx_memoryviewslice) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_memoryviewslice_type = &__pyx_type___pyx_memoryviewslice; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":13 * # * * __version__ = "('1', '5', '3-dev')" # <<<<<<<<<<<<<< * * cdef extern from "limits.h": */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____version__, ((PyObject *)__pyx_kp_s_48)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":14 * double log (double x) * * version_info = (3, 2) # <<<<<<<<<<<<<< * __version__ = "('1', '5', '3-dev')" * */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__version_info, ((PyObject *)__pyx_k_tuple_49)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":15 * * version_info = (3, 2) * __version__ = "('1', '5', '3-dev')" # <<<<<<<<<<<<<< * * cdef double SCALE_STEP, MIN_FLOAT_VALUE */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____version__, ((PyObject *)__pyx_kp_s_48)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_pogs.pyx":18 * * cdef double SCALE_STEP, MIN_FLOAT_VALUE * SCALE_STEP = 2.0**50 # <<<<<<<<<<<<<< * MIN_FLOAT_VALUE = 1.0 / SCALE_STEP * */ __pyx_v_6cogent_5align_14_pairwise_pogs_SCALE_STEP = pow(2.0, 50.0); /* "cogent/align/_pairwise_pogs.pyx":19 * cdef double SCALE_STEP, MIN_FLOAT_VALUE * SCALE_STEP = 2.0**50 * MIN_FLOAT_VALUE = 1.0 / SCALE_STEP # <<<<<<<<<<<<<< * * cdef int MAX_XCOUNT */ if (unlikely(__pyx_v_6cogent_5align_14_pairwise_pogs_SCALE_STEP == 0)) { PyErr_Format(PyExc_ZeroDivisionError, "float division"); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_FLOAT_VALUE = (1.0 / __pyx_v_6cogent_5align_14_pairwise_pogs_SCALE_STEP); /* "cogent/align/_pairwise_pogs.pyx":22 * * cdef int MAX_XCOUNT * MAX_XCOUNT = 256 # <<<<<<<<<<<<<< * * cdef long MIN_SCALE, MAX_SCALE */ __pyx_v_6cogent_5align_14_pairwise_pogs_MAX_XCOUNT = 256; /* "cogent/align/_pairwise_pogs.pyx":25 * * cdef long MIN_SCALE, MAX_SCALE * MIN_SCALE = -10000 # <<<<<<<<<<<<<< * MAX_SCALE = +10000 # or 0 if all numbers should be probabilities * */ __pyx_v_6cogent_5align_14_pairwise_pogs_MIN_SCALE = -10000; /* "cogent/align/_pairwise_pogs.pyx":26 * cdef long MIN_SCALE, MAX_SCALE * MIN_SCALE = -10000 * MAX_SCALE = +10000 # or 0 if all numbers should be probabilities # <<<<<<<<<<<<<< * * def fmpt(mantissa, exponent, msg=''): */ __pyx_v_6cogent_5align_14_pairwise_pogs_MAX_SCALE = 10000; /* "cogent/align/_pairwise_pogs.pyx":28 * MAX_SCALE = +10000 # or 0 if all numbers should be probabilities * * def fmpt(mantissa, exponent, msg=''): # <<<<<<<<<<<<<< * return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) * */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6cogent_5align_14_pairwise_pogs_1fmpt, NULL, __pyx_n_s_53); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__fmpt, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "cogent/align/_pairwise_pogs.pyx":33 * ctypedef unsigned char [:,:,::1] UChar3D * * def calc_rows(Long1D plan, Long1D seq1_index, Long1D seq2_index, # <<<<<<<<<<<<<< * int i_low, int i_high, int j_low, int j_high, preds, * Long2D state_directions, Double2D T, */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6cogent_5align_14_pairwise_pogs_3calc_rows, NULL, __pyx_n_s_53); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__calc_rows, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "cogent/align/_pairwise_pogs.pyx":1 * #cython: boundscheck=False # <<<<<<<<<<<<<< * #cython: wraparound=False * */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; /* "View.MemoryView":207 * info.obj = self * * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< * * def __dealloc__(array self): */ __pyx_t_1 = __pyx_capsule_create(((void *)(&__pyx_array_getbuffer)), __pyx_k_59); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_array_type->tp_dict, __pyx_n_s____pyx_getbuffer, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyType_Modified(__pyx_array_type); /* "View.MemoryView":282 * return self.name * * cdef generic = Enum("") # <<<<<<<<<<<<<< * cdef strided = Enum("") # default * cdef indirect = Enum("") */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject *)__pyx_MemviewEnum_type)), ((PyObject *)__pyx_k_tuple_61), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(generic); __Pyx_DECREF(generic); __Pyx_GIVEREF(__pyx_t_1); generic = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":283 * * cdef generic = Enum("") * cdef strided = Enum("") # default # <<<<<<<<<<<<<< * cdef indirect = Enum("") * */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject *)__pyx_MemviewEnum_type)), ((PyObject *)__pyx_k_tuple_63), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(strided); __Pyx_DECREF(strided); __Pyx_GIVEREF(__pyx_t_1); strided = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":284 * cdef generic = Enum("") * cdef strided = Enum("") # default * cdef indirect = Enum("") # <<<<<<<<<<<<<< * * */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject *)__pyx_MemviewEnum_type)), ((PyObject *)__pyx_k_tuple_65), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(indirect); __Pyx_DECREF(indirect); __Pyx_GIVEREF(__pyx_t_1); indirect = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":287 * * * cdef contiguous = Enum("") # <<<<<<<<<<<<<< * cdef indirect_contiguous = Enum("") * */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject *)__pyx_MemviewEnum_type)), ((PyObject *)__pyx_k_tuple_67), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(contiguous); __Pyx_DECREF(contiguous); __Pyx_GIVEREF(__pyx_t_1); contiguous = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":288 * * cdef contiguous = Enum("") * cdef indirect_contiguous = Enum("") # <<<<<<<<<<<<<< * * */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject *)__pyx_MemviewEnum_type)), ((PyObject *)__pyx_k_tuple_69), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(indirect_contiguous); __Pyx_DECREF(indirect_contiguous); __Pyx_GIVEREF(__pyx_t_1); indirect_contiguous = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":503 * info.obj = self * * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< * * */ __pyx_t_1 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), __pyx_k_59); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_memoryview_type->tp_dict, __pyx_n_s____pyx_getbuffer, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyType_Modified(__pyx_memoryview_type); /* "View.MemoryView":958 * return self.from_object * * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< * * */ __pyx_t_1 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), __pyx_k_59); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_memoryviewslice_type->tp_dict, __pyx_n_s____pyx_getbuffer, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyType_Modified(__pyx_memoryviewslice_type); /* "View.MemoryView":1365 * * @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: */ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); if (__pyx_m) { __Pyx_AddTraceback("init cogent.align._pairwise_pogs", __pyx_clineno, __pyx_lineno, __pyx_filename); Py_DECREF(__pyx_m); __pyx_m = 0; } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init cogent.align._pairwise_pogs"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); #if PY_MAJOR_VERSION < 3 return; #else return __pyx_m; #endif } /* Runtime support code */ #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 /* CYTHON_REFNANNY */ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { PyObject *result; result = PyObject_GetAttr(dict, name); if (!result) { if (dict != __pyx_b) { PyErr_Clear(); result = PyObject_GetAttr(__pyx_b, name); } if (!result) { PyErr_SetObject(PyExc_NameError, name); } } return result; } static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { #if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); 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); #else PyErr_Restore(type, value, tb); #endif } static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { #if CYTHON_COMPILING_IN_CPYTHON PyThreadState *tstate = PyThreadState_GET(); *type = tstate->curexc_type; *value = tstate->curexc_value; *tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; #else PyErr_Fetch(type, value, tb); #endif } #if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, CYTHON_UNUSED PyObject *cause) { 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 PY_VERSION_HEX < 0x02050000 if (PyClass_Check(type)) { #else if (PyType_Check(type)) { #endif #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; #if PY_VERSION_HEX < 0x02050000 if (PyInstance_Check(type)) { type = (PyObject*) ((PyInstanceObject*)type)->in_class; Py_INCREF(type); } else { type = 0; PyErr_SetString(PyExc_TypeError, "raise: exception must be an old-style class or instance"); goto raise_error; } #else 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; } #endif } __Pyx_ErrRestore(type, value, tb); return; raise_error: Py_XDECREF(value); Py_XDECREF(type); Py_XDECREF(tb); return; } #else /* Python 3+ */ 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 *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 = PyEval_CallObject(type, args); 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 && cause != Py_None) { PyObject *fixed_cause; 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) { PyThreadState *tstate = PyThreadState_GET(); PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { Py_INCREF(tb); tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } } bad: Py_XDECREF(owned_instance); return; } #endif 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, "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } 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 } 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++; } 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; } } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 "%s() got an unexpected keyword argument '%s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", function_name, key); #endif bad: return -1; } 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); } static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, "need more than %" CYTHON_FORMAT_SSIZE_T "d value%s to unpack", index, (index == 1) ? "" : "s"); } static CYTHON_INLINE int __Pyx_IterFinish(void) { #if CYTHON_COMPILING_IN_CPYTHON PyThreadState *tstate = PyThreadState_GET(); PyObject* exc_type = tstate->curexc_type; if (unlikely(exc_type)) { if (likely(exc_type == PyExc_StopIteration) || 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 } 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; } static CYTHON_INLINE int __Pyx_IsLittleEndian(void) { unsigned int n = 1; return *(unsigned char*)(&n) != 0; } static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx, __Pyx_BufFmt_StackElem* stack, __Pyx_TypeInfo* type) { stack[0].field = &ctx->root; stack[0].parent_offset = 0; ctx->root.type = type; ctx->root.name = "buffer dtype"; ctx->root.offset = 0; ctx->head = stack; ctx->head->field = &ctx->root; ctx->fmt_offset = 0; ctx->head->parent_offset = 0; ctx->new_packmode = '@'; ctx->enc_packmode = '@'; ctx->new_count = 1; ctx->enc_count = 0; ctx->enc_type = 0; ctx->is_complex = 0; ctx->is_valid_array = 0; ctx->struct_alignment = 0; while (type->typegroup == 'S') { ++ctx->head; ctx->head->field = type->fields; ctx->head->parent_offset = 0; type = type->fields->type; } } static int __Pyx_BufFmt_ParseNumber(const char** ts) { int count; const char* t = *ts; if (*t < '0' || *t > '9') { return -1; } else { count = *t++ - '0'; while (*t >= '0' && *t < '9') { count *= 10; count += *t++ - '0'; } } *ts = t; return count; } static int __Pyx_BufFmt_ExpectNumber(const char **ts) { int number = __Pyx_BufFmt_ParseNumber(ts); if (number == -1) /* First char was not a digit */ PyErr_Format(PyExc_ValueError,\ "Does not understand character buffer dtype format string ('%c')", **ts); return number; } static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) { PyErr_Format(PyExc_ValueError, "Unexpected format string character: '%c'", ch); } static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) { switch (ch) { case 'c': return "'char'"; case 'b': return "'signed char'"; case 'B': return "'unsigned char'"; case 'h': return "'short'"; case 'H': return "'unsigned short'"; case 'i': return "'int'"; case 'I': return "'unsigned int'"; case 'l': return "'long'"; case 'L': return "'unsigned long'"; case 'q': return "'long long'"; case 'Q': return "'unsigned long long'"; case 'f': return (is_complex ? "'complex float'" : "'float'"); case 'd': return (is_complex ? "'complex double'" : "'double'"); case 'g': return (is_complex ? "'complex long double'" : "'long double'"); case 'T': return "a struct"; case 'O': return "Python object"; case 'P': return "a pointer"; case 's': case 'p': return "a string"; case 0: return "end"; default: return "unparseable format string"; } } static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) { switch (ch) { case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; case 'h': case 'H': return 2; case 'i': case 'I': case 'l': case 'L': return 4; case 'q': case 'Q': return 8; case 'f': return (is_complex ? 8 : 4); case 'd': return (is_complex ? 16 : 8); case 'g': { PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g').."); return 0; } case 'O': case 'P': return sizeof(void*); default: __Pyx_BufFmt_RaiseUnexpectedChar(ch); return 0; } } static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) { switch (ch) { case 'c': case 'b': case 'B': case 's': case 'p': return 1; case 'h': case 'H': return sizeof(short); case 'i': case 'I': return sizeof(int); case 'l': case 'L': return sizeof(long); #ifdef HAVE_LONG_LONG case 'q': case 'Q': return sizeof(PY_LONG_LONG); #endif case 'f': return sizeof(float) * (is_complex ? 2 : 1); case 'd': return sizeof(double) * (is_complex ? 2 : 1); case 'g': return sizeof(long double) * (is_complex ? 2 : 1); case 'O': case 'P': return sizeof(void*); default: { __Pyx_BufFmt_RaiseUnexpectedChar(ch); return 0; } } } typedef struct { char c; short x; } __Pyx_st_short; typedef struct { char c; int x; } __Pyx_st_int; typedef struct { char c; long x; } __Pyx_st_long; typedef struct { char c; float x; } __Pyx_st_float; typedef struct { char c; double x; } __Pyx_st_double; typedef struct { char c; long double x; } __Pyx_st_longdouble; typedef struct { char c; void *x; } __Pyx_st_void_p; #ifdef HAVE_LONG_LONG typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong; #endif static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, CYTHON_UNUSED int is_complex) { switch (ch) { case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short); case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int); case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long); #ifdef HAVE_LONG_LONG case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG); #endif case 'f': return sizeof(__Pyx_st_float) - sizeof(float); case 'd': return sizeof(__Pyx_st_double) - sizeof(double); case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double); case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*); default: __Pyx_BufFmt_RaiseUnexpectedChar(ch); return 0; } } /* These are for computing the padding at the end of the struct to align on the first member of the struct. This will probably the same as above, but we don't have any guarantees. */ typedef struct { short x; char c; } __Pyx_pad_short; typedef struct { int x; char c; } __Pyx_pad_int; typedef struct { long x; char c; } __Pyx_pad_long; typedef struct { float x; char c; } __Pyx_pad_float; typedef struct { double x; char c; } __Pyx_pad_double; typedef struct { long double x; char c; } __Pyx_pad_longdouble; typedef struct { void *x; char c; } __Pyx_pad_void_p; #ifdef HAVE_LONG_LONG typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong; #endif static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int is_complex) { switch (ch) { case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short); case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int); case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long); #ifdef HAVE_LONG_LONG case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG); #endif case 'f': return sizeof(__Pyx_pad_float) - sizeof(float); case 'd': return sizeof(__Pyx_pad_double) - sizeof(double); case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double); case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*); default: __Pyx_BufFmt_RaiseUnexpectedChar(ch); return 0; } } static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) { switch (ch) { case 'c': return 'H'; case 'b': case 'h': case 'i': case 'l': case 'q': case 's': case 'p': return 'I'; case 'B': case 'H': case 'I': case 'L': case 'Q': return 'U'; case 'f': case 'd': case 'g': return (is_complex ? 'C' : 'R'); case 'O': return 'O'; case 'P': return 'P'; default: { __Pyx_BufFmt_RaiseUnexpectedChar(ch); return 0; } } } static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) { if (ctx->head == NULL || ctx->head->field == &ctx->root) { const char* expected; const char* quote; if (ctx->head == NULL) { expected = "end"; quote = ""; } else { expected = ctx->head->field->type->name; quote = "'"; } PyErr_Format(PyExc_ValueError, "Buffer dtype mismatch, expected %s%s%s but got %s", quote, expected, quote, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex)); } else { __Pyx_StructField* field = ctx->head->field; __Pyx_StructField* parent = (ctx->head - 1)->field; PyErr_Format(PyExc_ValueError, "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'", field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex), parent->type->name, field->name); } } static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) { char group; size_t size, offset, arraysize = 1; if (ctx->enc_type == 0) return 0; if (ctx->head->field->type->arraysize[0]) { int i, ndim = 0; if (ctx->enc_type == 's' || ctx->enc_type == 'p') { ctx->is_valid_array = ctx->head->field->type->ndim == 1; ndim = 1; if (ctx->enc_count != ctx->head->field->type->arraysize[0]) { PyErr_Format(PyExc_ValueError, "Expected a dimension of size %zu, got %zu", ctx->head->field->type->arraysize[0], ctx->enc_count); return -1; } } if (!ctx->is_valid_array) { PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d", ctx->head->field->type->ndim, ndim); return -1; } for (i = 0; i < ctx->head->field->type->ndim; i++) { arraysize *= ctx->head->field->type->arraysize[i]; } ctx->is_valid_array = 0; ctx->enc_count = 1; } group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex); do { __Pyx_StructField* field = ctx->head->field; __Pyx_TypeInfo* type = field->type; if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') { size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex); } else { size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex); } if (ctx->enc_packmode == '@') { size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex); size_t align_mod_offset; if (align_at == 0) return -1; align_mod_offset = ctx->fmt_offset % align_at; if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset; if (ctx->struct_alignment == 0) ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type, ctx->is_complex); } if (type->size != size || type->typegroup != group) { if (type->typegroup == 'C' && type->fields != NULL) { size_t parent_offset = ctx->head->parent_offset + field->offset; ++ctx->head; ctx->head->field = type->fields; ctx->head->parent_offset = parent_offset; continue; } if ((type->typegroup == 'H' || group == 'H') && type->size == size) { } else { __Pyx_BufFmt_RaiseExpected(ctx); return -1; } } offset = ctx->head->parent_offset + field->offset; if (ctx->fmt_offset != offset) { PyErr_Format(PyExc_ValueError, "Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected", (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset); return -1; } ctx->fmt_offset += size; if (arraysize) ctx->fmt_offset += (arraysize - 1) * size; --ctx->enc_count; /* Consume from buffer string */ while (1) { if (field == &ctx->root) { ctx->head = NULL; if (ctx->enc_count != 0) { __Pyx_BufFmt_RaiseExpected(ctx); return -1; } break; /* breaks both loops as ctx->enc_count == 0 */ } ctx->head->field = ++field; if (field->type == NULL) { --ctx->head; field = ctx->head->field; continue; } else if (field->type->typegroup == 'S') { size_t parent_offset = ctx->head->parent_offset + field->offset; if (field->type->fields->type == NULL) continue; /* empty struct */ field = field->type->fields; ++ctx->head; ctx->head->field = field; ctx->head->parent_offset = parent_offset; break; } else { break; } } } while (ctx->enc_count); ctx->enc_type = 0; ctx->is_complex = 0; return 0; } static CYTHON_INLINE PyObject * __pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp) { const char *ts = *tsp; int i = 0, number; int ndim = ctx->head->field->type->ndim; ; ++ts; if (ctx->new_count != 1) { PyErr_SetString(PyExc_ValueError, "Cannot handle repeated arrays in format string"); return NULL; } if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; while (*ts && *ts != ')') { if (isspace(*ts)) continue; number = __Pyx_BufFmt_ExpectNumber(&ts); if (number == -1) return NULL; if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i]) return PyErr_Format(PyExc_ValueError, "Expected a dimension of size %zu, got %d", ctx->head->field->type->arraysize[i], number); if (*ts != ',' && *ts != ')') return PyErr_Format(PyExc_ValueError, "Expected a comma in format string, got '%c'", *ts); if (*ts == ',') ts++; i++; } if (i != ndim) return PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d", ctx->head->field->type->ndim, i); if (!*ts) { PyErr_SetString(PyExc_ValueError, "Unexpected end of format string, expected ')'"); return NULL; } ctx->is_valid_array = 1; ctx->new_count = 1; *tsp = ++ts; return Py_None; } static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) { int got_Z = 0; while (1) { switch(*ts) { case 0: if (ctx->enc_type != 0 && ctx->head == NULL) { __Pyx_BufFmt_RaiseExpected(ctx); return NULL; } if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; if (ctx->head != NULL) { __Pyx_BufFmt_RaiseExpected(ctx); return NULL; } return ts; case ' ': case 10: case 13: ++ts; break; case '<': if (!__Pyx_IsLittleEndian()) { PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler"); return NULL; } ctx->new_packmode = '='; ++ts; break; case '>': case '!': if (__Pyx_IsLittleEndian()) { PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler"); return NULL; } ctx->new_packmode = '='; ++ts; break; case '=': case '@': case '^': ctx->new_packmode = *ts++; break; case 'T': /* substruct */ { const char* ts_after_sub; size_t i, struct_count = ctx->new_count; size_t struct_alignment = ctx->struct_alignment; ctx->new_count = 1; ++ts; if (*ts != '{') { PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'"); return NULL; } if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; ctx->enc_type = 0; /* Erase processed last struct element */ ctx->enc_count = 0; ctx->struct_alignment = 0; ++ts; ts_after_sub = ts; for (i = 0; i != struct_count; ++i) { ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts); if (!ts_after_sub) return NULL; } ts = ts_after_sub; if (struct_alignment) ctx->struct_alignment = struct_alignment; } break; case '}': /* end of substruct; either repeat or move on */ { size_t alignment = ctx->struct_alignment; ++ts; if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; ctx->enc_type = 0; /* Erase processed last struct element */ if (alignment && ctx->fmt_offset % alignment) { ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment); } } return ts; case 'x': if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; ctx->fmt_offset += ctx->new_count; ctx->new_count = 1; ctx->enc_count = 0; ctx->enc_type = 0; ctx->enc_packmode = ctx->new_packmode; ++ts; break; case 'Z': got_Z = 1; ++ts; if (*ts != 'f' && *ts != 'd' && *ts != 'g') { __Pyx_BufFmt_RaiseUnexpectedChar('Z'); return NULL; } /* fall through */ case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I': case 'l': case 'L': case 'q': case 'Q': case 'f': case 'd': case 'g': case 'O': case 's': case 'p': if (ctx->enc_type == *ts && got_Z == ctx->is_complex && ctx->enc_packmode == ctx->new_packmode) { ctx->enc_count += ctx->new_count; } else { if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; ctx->enc_count = ctx->new_count; ctx->enc_packmode = ctx->new_packmode; ctx->enc_type = *ts; ctx->is_complex = got_Z; } ++ts; ctx->new_count = 1; got_Z = 0; break; case ':': ++ts; while(*ts != ':') ++ts; ++ts; break; case '(': if (!__pyx_buffmt_parse_array(ctx, &ts)) return NULL; break; default: { int number = __Pyx_BufFmt_ExpectNumber(&ts); if (number == -1) return NULL; ctx->new_count = (size_t)number; } } } } static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) { buf->buf = NULL; buf->obj = NULL; buf->strides = __Pyx_zeros; buf->shape = __Pyx_zeros; buf->suboffsets = __Pyx_minusones; } static CYTHON_INLINE int __Pyx_GetBufferAndValidate( Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack) { if (obj == Py_None || obj == NULL) { __Pyx_ZeroBuffer(buf); return 0; } buf->buf = NULL; if (__Pyx_GetBuffer(obj, buf, flags) == -1) goto fail; if (buf->ndim != nd) { PyErr_Format(PyExc_ValueError, "Buffer has wrong number of dimensions (expected %d, got %d)", nd, buf->ndim); goto fail; } if (!cast) { __Pyx_BufFmt_Context ctx; __Pyx_BufFmt_Init(&ctx, stack, dtype); if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail; } if ((unsigned)buf->itemsize != dtype->size) { PyErr_Format(PyExc_ValueError, "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)", buf->itemsize, (buf->itemsize > 1) ? "s" : "", dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : ""); goto fail; } if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones; return 0; fail:; __Pyx_ZeroBuffer(buf); return -1; } static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) { if (info->buf == NULL) return; if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL; __Pyx_ReleaseBuffer(info); } static int __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b) { int i; if (!a || !b) return 0; if (a == b) return 1; if (a->size != b->size || a->typegroup != b->typegroup || a->is_unsigned != b->is_unsigned || a->ndim != b->ndim) { if (a->typegroup == 'H' || b->typegroup == 'H') { return a->size == b->size; } else { return 0; } } if (a->ndim) { for (i = 0; i < a->ndim; i++) if (a->arraysize[i] != b->arraysize[i]) return 0; } if (a->typegroup == 'S') { if (a->flags != b->flags) return 0; if (a->fields || b->fields) { if (!(a->fields && b->fields)) return 0; for (i = 0; a->fields[i].type && b->fields[i].type; i++) { __Pyx_StructField *field_a = a->fields + i; __Pyx_StructField *field_b = b->fields + i; if (field_a->offset != field_b->offset || !__pyx_typeinfo_cmp(field_a->type, field_b->type)) return 0; } return !a->fields[i].type && !b->fields[i].type; } } return 1; } static int __Pyx_ValidateAndInit_memviewslice( int *axes_specs, int c_or_f_flag, int buf_flags, int ndim, __Pyx_TypeInfo *dtype, __Pyx_BufFmt_StackElem stack[], __Pyx_memviewslice *memviewslice, PyObject *original_obj) { struct __pyx_memoryview_obj *memview, *new_memview; __Pyx_RefNannyDeclarations Py_buffer *buf; int i, spec = 0, retval = -1; __Pyx_BufFmt_Context ctx; int from_memoryview = __pyx_memoryview_check(original_obj); __Pyx_RefNannySetupContext("ValidateAndInit_memviewslice", 0); if (from_memoryview && __pyx_typeinfo_cmp(dtype, ((struct __pyx_memoryview_obj *) original_obj)->typeinfo)) { memview = (struct __pyx_memoryview_obj *) original_obj; new_memview = NULL; } else { memview = (struct __pyx_memoryview_obj *) __pyx_memoryview_new( original_obj, buf_flags, 0, dtype); new_memview = memview; if (unlikely(!memview)) goto fail; } buf = &memview->view; if (buf->ndim != ndim) { PyErr_Format(PyExc_ValueError, "Buffer has wrong number of dimensions (expected %d, got %d)", ndim, buf->ndim); goto fail; } if (new_memview) { __Pyx_BufFmt_Init(&ctx, stack, dtype); if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail; } if ((unsigned)buf->itemsize != dtype->size) { PyErr_Format(PyExc_ValueError, "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "u byte%s) " "does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "u byte%s)", buf->itemsize, (buf->itemsize > 1) ? "s" : "", dtype->name, dtype->size, (dtype->size > 1) ? "s" : ""); goto fail; } for (i = 0; i < ndim; i++) { spec = axes_specs[i]; if (buf->strides) { if (spec & __Pyx_MEMVIEW_CONTIG) { if (spec & (__Pyx_MEMVIEW_PTR|__Pyx_MEMVIEW_FULL)) { if (buf->strides[i] != sizeof(void *)) { PyErr_Format(PyExc_ValueError, "Buffer is not indirectly contiguous in dimension %d.", i); goto fail; } } else if (buf->strides[i] != buf->itemsize) { PyErr_SetString(PyExc_ValueError, "Buffer and memoryview are not contiguous in the same dimension."); goto fail; } } if (spec & __Pyx_MEMVIEW_FOLLOW) { Py_ssize_t stride = buf->strides[i]; if (stride < 0) stride = -stride; if (stride < buf->itemsize) { PyErr_SetString(PyExc_ValueError, "Buffer and memoryview are not contiguous in the same dimension."); goto fail; } } } else { if (spec & __Pyx_MEMVIEW_CONTIG && i != ndim - 1) { PyErr_Format(PyExc_ValueError, "C-contiguous buffer is not contiguous in " "dimension %d", i); goto fail; } else if (spec & (__Pyx_MEMVIEW_PTR)) { PyErr_Format(PyExc_ValueError, "C-contiguous buffer is not indirect in " "dimension %d", i); goto fail; } else if (buf->suboffsets) { PyErr_SetString(PyExc_ValueError, "Buffer exposes suboffsets but no strides"); goto fail; } } /* Todo: without PyBUF_INDIRECT we may not have suboffset information, i.e., the ptr may not be set to NULL but may be uninitialized? */ if (spec & __Pyx_MEMVIEW_DIRECT) { if (buf->suboffsets && buf->suboffsets[i] >= 0) { PyErr_Format(PyExc_ValueError, "Buffer not compatible with direct access in dimension %d.", i); goto fail; } } if (spec & __Pyx_MEMVIEW_PTR) { if (!buf->suboffsets || (buf->suboffsets && buf->suboffsets[i] < 0)) { PyErr_Format(PyExc_ValueError, "Buffer is not indirectly accessisble in dimension %d.", i); goto fail; } } } if (buf->strides) { if (c_or_f_flag & __Pyx_IS_F_CONTIG) { Py_ssize_t stride = 1; for (i=0; iitemsize != buf->strides[i]) { PyErr_SetString(PyExc_ValueError, "Buffer not fortran contiguous."); goto fail; } stride = stride * buf->shape[i]; } } else if (c_or_f_flag & __Pyx_IS_C_CONTIG) { Py_ssize_t stride = 1; for (i = ndim-1; i>-1; i--) { if(stride * buf->itemsize != buf->strides[i]) { PyErr_SetString(PyExc_ValueError, "Buffer not C contiguous."); goto fail; } stride = stride * buf->shape[i]; } } } if (unlikely(__Pyx_init_memviewslice(memview, ndim, memviewslice, new_memview != NULL) == -1)) { goto fail; } retval = 0; goto no_fail; fail: Py_XDECREF(new_memview); retval = -1; no_fail: __Pyx_RefNannyFinishContext(); return retval; } static int __Pyx_init_memviewslice(struct __pyx_memoryview_obj *memview, int ndim, __Pyx_memviewslice *memviewslice, int memview_is_new_reference) { __Pyx_RefNannyDeclarations int i, retval=-1; Py_buffer *buf = &memview->view; __Pyx_RefNannySetupContext("init_memviewslice", 0); if (!buf) { PyErr_SetString(PyExc_ValueError, "buf is NULL."); goto fail; } else if (memviewslice->memview || memviewslice->data) { PyErr_SetString(PyExc_ValueError, "memviewslice is already initialized!"); goto fail; } if (buf->strides) { for (i = 0; i < ndim; i++) { memviewslice->strides[i] = buf->strides[i]; } } else { Py_ssize_t stride = buf->itemsize; for (i = ndim - 1; i >= 0; i--) { memviewslice->strides[i] = stride; stride *= buf->shape[i]; } } for (i = 0; i < ndim; i++) { memviewslice->shape[i] = buf->shape[i]; if (buf->suboffsets) { memviewslice->suboffsets[i] = buf->suboffsets[i]; } else { memviewslice->suboffsets[i] = -1; } } memviewslice->memview = memview; memviewslice->data = (char *)buf->buf; if (__pyx_add_acquisition_count(memview) == 0 && !memview_is_new_reference) { Py_INCREF(memview); } retval = 0; goto no_fail; fail: memviewslice->memview = 0; memviewslice->data = 0; retval = -1; no_fail: __Pyx_RefNannyFinishContext(); return retval; } static CYTHON_INLINE void __pyx_fatalerror(const char *fmt, ...) { va_list vargs; char msg[200]; va_start(vargs, fmt); #ifdef HAVE_STDARG_PROTOTYPES va_start(vargs, fmt); #else va_start(vargs); #endif vsnprintf(msg, 200, fmt, vargs); Py_FatalError(msg); va_end(vargs); } static CYTHON_INLINE int __pyx_add_acquisition_count_locked(__pyx_atomic_int *acquisition_count, PyThread_type_lock lock) { int result; PyThread_acquire_lock(lock, 1); result = (*acquisition_count)++; PyThread_release_lock(lock); return result; } static CYTHON_INLINE int __pyx_sub_acquisition_count_locked(__pyx_atomic_int *acquisition_count, PyThread_type_lock lock) { int result; PyThread_acquire_lock(lock, 1); result = (*acquisition_count)--; PyThread_release_lock(lock); return result; } static CYTHON_INLINE void __Pyx_INC_MEMVIEW(__Pyx_memviewslice *memslice, int have_gil, int lineno) { int first_time; struct __pyx_memoryview_obj *memview = memslice->memview; if (!memview || (PyObject *) memview == Py_None) return; /* allow uninitialized memoryview assignment */ if (__pyx_get_slice_count(memview) < 0) __pyx_fatalerror("Acquisition count is %d (line %d)", __pyx_get_slice_count(memview), lineno); first_time = __pyx_add_acquisition_count(memview) == 0; if (first_time) { if (have_gil) { Py_INCREF((PyObject *) memview); } else { PyGILState_STATE _gilstate = PyGILState_Ensure(); Py_INCREF((PyObject *) memview); PyGILState_Release(_gilstate); } } } static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *memslice, int have_gil, int lineno) { int last_time; struct __pyx_memoryview_obj *memview = memslice->memview; if (!memview ) { return; } else if ((PyObject *) memview == Py_None) { memslice->memview = NULL; return; } if (__pyx_get_slice_count(memview) <= 0) __pyx_fatalerror("Acquisition count is %d (line %d)", __pyx_get_slice_count(memview), lineno); last_time = __pyx_sub_acquisition_count(memview) == 1; memslice->data = NULL; if (last_time) { if (have_gil) { Py_CLEAR(memslice->memview); } else { PyGILState_STATE _gilstate = PyGILState_Ensure(); Py_CLEAR(memslice->memview); PyGILState_Release(_gilstate); } } else { memslice->memview = NULL; } } static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact) { if (!type) { PyErr_Format(PyExc_SystemError, "Missing type object"); return 0; } if (none_allowed && obj == Py_None) return 1; else if (exact) { if (Py_TYPE(obj) == type) return 1; } else { if (PyObject_TypeCheck(obj, type)) return 1; } PyErr_Format(PyExc_TypeError, "Argument '%s' has incorrect type (expected %s, got %s)", name, type->tp_name, Py_TYPE(obj)->tp_name); return 0; } static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { PyObject *r = PyObject_GetAttr(o, n); if (!r) { if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; PyErr_Clear(); r = d; Py_INCREF(d); } return r; bad: return NULL; } static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t a, Py_ssize_t b) { Py_ssize_t q = a / b; Py_ssize_t r = a - q*b; q -= ((r != 0) & ((r ^ b) < 0)); return q; } 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 (s1 == s2) { return (equals == Py_EQ); } else if (PyUnicode_CheckExact(s1) & PyUnicode_CheckExact(s2)) { #if CYTHON_PEP393_ENABLED if ((PyUnicode_READY(s1) < 0) || (PyUnicode_READY(s2) < 0)) return -1; if (PyUnicode_GET_LENGTH(s1) != PyUnicode_GET_LENGTH(s2)) { return (equals == Py_NE); } else if (PyUnicode_GET_LENGTH(s1) == 1) { Py_UCS4 ch1 = PyUnicode_READ_CHAR(s1, 0); Py_UCS4 ch2 = PyUnicode_READ_CHAR(s2, 0); return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2); #else if (PyUnicode_GET_SIZE(s1) != PyUnicode_GET_SIZE(s2)) { return (equals == Py_NE); } else if (PyUnicode_GET_SIZE(s1) == 1) { Py_UNICODE ch1 = PyUnicode_AS_UNICODE(s1)[0]; Py_UNICODE ch2 = PyUnicode_AS_UNICODE(s2)[0]; return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2); #endif } else { int result = PyUnicode_Compare(s1, s2); if ((result == -1) && unlikely(PyErr_Occurred())) return -1; return (equals == Py_EQ) ? (result == 0) : (result != 0); } } else if ((s1 == Py_None) & PyUnicode_CheckExact(s2)) { return (equals == Py_NE); } else if ((s2 == Py_None) & PyUnicode_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 } static CYTHON_INLINE PyObject* __Pyx_decode_c_string( const char* cstring, Py_ssize_t start, Py_ssize_t stop, const char* encoding, const char* errors, PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) { Py_ssize_t length; if (unlikely((start < 0) | (stop < 0))) { length = strlen(cstring); if (start < 0) { start += length; if (start < 0) start = 0; } if (stop < 0) stop += length; } length = stop - start; if (unlikely(length <= 0)) return PyUnicode_FromUnicode(NULL, 0); cstring += start; if (decode_func) { return decode_func(cstring, length, errors); } else { return PyUnicode_Decode(cstring, length, encoding, errors); } } static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); } static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { if (unlikely(!type)) { PyErr_Format(PyExc_SystemError, "Missing type object"); return 0; } if (likely(PyObject_TypeCheck(obj, type))) return 1; PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", Py_TYPE(obj)->tp_name, type->tp_name); return 0; } static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { PyObject *local_type, *local_value, *local_tb; #if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); 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_COMPILING_IN_CPYTHON if (unlikely(tstate->curexc_type)) #else if (unlikely(PyErr_Occurred())) #endif goto bad; #if PY_MAJOR_VERSION >= 3 if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) goto bad; #endif Py_INCREF(local_type); Py_INCREF(local_value); Py_INCREF(local_tb); *type = local_type; *value = local_value; *tb = local_tb; #if CYTHON_COMPILING_IN_CPYTHON 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; /* Make sure tstate is in a consistent state when we XDECREF these objects (DECREF may run arbitrary code). */ 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; } static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); } 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; } #if PY_MAJOR_VERSION < 3 static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { CYTHON_UNUSED PyObject *getbuffer_cobj; #if PY_VERSION_HEX >= 0x02060000 if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags); #endif if (PyObject_TypeCheck(obj, __pyx_array_type)) return __pyx_array_getbuffer(obj, view, flags); if (PyObject_TypeCheck(obj, __pyx_memoryview_type)) return __pyx_memoryview_getbuffer(obj, view, flags); #if PY_VERSION_HEX < 0x02060000 if (obj->ob_type->tp_dict && (getbuffer_cobj = PyMapping_GetItemString(obj->ob_type->tp_dict, "__pyx_getbuffer"))) { getbufferproc func; #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 0) func = (getbufferproc) PyCapsule_GetPointer(getbuffer_cobj, "getbuffer(obj, view, flags)"); #else func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj); #endif Py_DECREF(getbuffer_cobj); if (!func) goto fail; return func(obj, view, flags); } else { PyErr_Clear(); } #endif PyErr_Format(PyExc_TypeError, "'%100s' does not have the buffer interface", Py_TYPE(obj)->tp_name); #if PY_VERSION_HEX < 0x02060000 fail: #endif return -1; } static void __Pyx_ReleaseBuffer(Py_buffer *view) { PyObject *obj = view->obj; CYTHON_UNUSED PyObject *releasebuffer_cobj; if (!obj) return; #if PY_VERSION_HEX >= 0x02060000 if (PyObject_CheckBuffer(obj)) { PyBuffer_Release(view); return; } #endif #if PY_VERSION_HEX < 0x02060000 if (obj->ob_type->tp_dict && (releasebuffer_cobj = PyMapping_GetItemString(obj->ob_type->tp_dict, "__pyx_releasebuffer"))) { releasebufferproc func; #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 0) func = (releasebufferproc) PyCapsule_GetPointer(releasebuffer_cobj, "releasebuffer(obj, view)"); #else func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj); #endif Py_DECREF(releasebuffer_cobj); if (!func) goto fail; func(obj, view); return; } else { PyErr_Clear(); } #endif goto nofail; #if PY_VERSION_HEX < 0x02060000 fail: #endif PyErr_WriteUnraisable(obj); nofail: Py_DECREF(obj); view->obj = NULL; } #endif /* PY_MAJOR_VERSION < 3 */ static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dc_long(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 1, &__Pyx_TypeInfo_long, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_dc_long(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 2, &__Pyx_TypeInfo_long, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 2, &__Pyx_TypeInfo_double, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_double(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 3, &__Pyx_TypeInfo_double, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_unsigned_char(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 3, &__Pyx_TypeInfo_unsigned_char, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static int __pyx_memviewslice_is_contig(const __Pyx_memviewslice *mvs, char order, int ndim) { int i, index, step, start; Py_ssize_t itemsize = mvs->memview->view.itemsize; if (order == 'F') { step = 1; start = 0; } else { step = -1; start = ndim - 1; } for (i = 0; i < ndim; i++) { index = start + step * i; if (mvs->suboffsets[index] >= 0 || mvs->strides[index] != itemsize) return 0; itemsize *= mvs->shape[index]; } return 1; } static void __pyx_get_array_memory_extents(__Pyx_memviewslice *slice, void **out_start, void **out_end, int ndim, size_t itemsize) { char *start, *end; int i; start = end = slice->data; for (i = 0; i < ndim; i++) { Py_ssize_t stride = slice->strides[i]; Py_ssize_t extent = slice->shape[i]; if (extent == 0) { *out_start = *out_end = start; return; } else { if (stride > 0) end += stride * (extent - 1); else start += stride * (extent - 1); } } *out_start = start; *out_end = end + itemsize; } static int __pyx_slices_overlap(__Pyx_memviewslice *slice1, __Pyx_memviewslice *slice2, int ndim, size_t itemsize) { void *start1, *end1, *start2, *end2; __pyx_get_array_memory_extents(slice1, &start1, &end1, ndim, itemsize); __pyx_get_array_memory_extents(slice2, &start2, &end2, ndim, itemsize); return (start1 < end2) && (start2 < end1); } 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, int dtype_is_object) { __Pyx_RefNannyDeclarations int i; __Pyx_memviewslice new_mvs = { 0, 0, { 0 }, { 0 }, { 0 } }; struct __pyx_memoryview_obj *from_memview = from_mvs->memview; Py_buffer *buf = &from_memview->view; PyObject *shape_tuple = NULL; PyObject *temp_int = NULL; struct __pyx_array_obj *array_obj = NULL; struct __pyx_memoryview_obj *memview_obj = NULL; __Pyx_RefNannySetupContext("__pyx_memoryview_copy_new_contig", 0); for (i = 0; i < ndim; i++) { if (from_mvs->suboffsets[i] >= 0) { PyErr_Format(PyExc_ValueError, "Cannot copy memoryview slice with " "indirect dimensions (axis %d)", i); goto fail; } } shape_tuple = PyTuple_New(ndim); if (unlikely(!shape_tuple)) { goto fail; } __Pyx_GOTREF(shape_tuple); for(i = 0; i < ndim; i++) { temp_int = PyInt_FromLong(from_mvs->shape[i]); if(unlikely(!temp_int)) { goto fail; } else { PyTuple_SET_ITEM(shape_tuple, i, temp_int); temp_int = NULL; } } array_obj = __pyx_array_new(shape_tuple, sizeof_dtype, buf->format, (char *) mode, NULL); if (unlikely(!array_obj)) { goto fail; } __Pyx_GOTREF(array_obj); memview_obj = (struct __pyx_memoryview_obj *) __pyx_memoryview_new( (PyObject *) array_obj, contig_flag, dtype_is_object, from_mvs->memview->typeinfo); if (unlikely(!memview_obj)) goto fail; if (unlikely(__Pyx_init_memviewslice(memview_obj, ndim, &new_mvs, 1) < 0)) goto fail; if (unlikely(__pyx_memoryview_copy_contents(*from_mvs, new_mvs, ndim, ndim, dtype_is_object) < 0)) goto fail; goto no_fail; fail: __Pyx_XDECREF(new_mvs.memview); new_mvs.memview = NULL; new_mvs.data = NULL; no_fail: __Pyx_XDECREF(shape_tuple); __Pyx_XDECREF(temp_int); __Pyx_XDECREF(array_obj); __Pyx_RefNannyFinishContext(); return new_mvs; } static CYTHON_INLINE PyObject * __pyx_capsule_create(void *p, const char *sig) { PyObject *cobj; #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 0) cobj = PyCapsule_New(p, sig, NULL); #else cobj = PyCObject_FromVoidPtr(p, NULL); #endif return cobj; } static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) { #if CYTHON_COMPILING_IN_CPYTHON PyThreadState *tstate = PyThreadState_GET(); *type = tstate->exc_type; *value = tstate->exc_value; *tb = tstate->exc_traceback; Py_XINCREF(*type); Py_XINCREF(*value); Py_XINCREF(*tb); #else PyErr_GetExcInfo(type, value, tb); #endif } static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) { #if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); 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; Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); #else PyErr_SetExcInfo(type, value, tb); #endif } static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { PyObject *py_import = 0; PyObject *empty_list = 0; PyObject *module = 0; PyObject *global_dict = 0; PyObject *empty_dict = 0; PyObject *list; py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); if (!py_import) goto bad; if (from_list) list = from_list; else { empty_list = PyList_New(0); if (!empty_list) goto bad; list = empty_list; } global_dict = PyModule_GetDict(__pyx_m); if (!global_dict) goto bad; empty_dict = PyDict_New(); if (!empty_dict) goto bad; #if PY_VERSION_HEX >= 0x02050000 { #if PY_MAJOR_VERSION >= 3 if (level == -1) { if (strchr(__Pyx_MODULE_NAME, '.')) { /* try package relative import first */ PyObject *py_level = PyInt_FromLong(1); if (!py_level) goto bad; module = PyObject_CallFunctionObjArgs(py_import, name, global_dict, empty_dict, list, py_level, NULL); Py_DECREF(py_level); if (!module) { if (!PyErr_ExceptionMatches(PyExc_ImportError)) goto bad; PyErr_Clear(); } } level = 0; /* try absolute import on failure */ } #endif if (!module) { 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 if (level>0) { PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); goto bad; } module = PyObject_CallFunctionObjArgs(py_import, name, global_dict, empty_dict, list, NULL); #endif bad: Py_XDECREF(empty_list); Py_XDECREF(py_import); Py_XDECREF(empty_dict); return module; } static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { const unsigned char neg_one = (unsigned char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned char" : "value too large to convert to unsigned char"); } return (unsigned char)-1; } return (unsigned char)val; } return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { const unsigned short neg_one = (unsigned short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned short" : "value too large to convert to unsigned short"); } return (unsigned short)-1; } return (unsigned short)val; } return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { const unsigned int neg_one = (unsigned int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned int" : "value too large to convert to unsigned int"); } return (unsigned int)-1; } return (unsigned int)val; } return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { const char neg_one = (char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to char" : "value too large to convert to char"); } return (char)-1; } return (char)val; } return (char)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { const short neg_one = (short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to short" : "value too large to convert to short"); } return (short)-1; } return (short)val; } return (short)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { const int neg_one = (int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to int" : "value too large to convert to int"); } return (int)-1; } return (int)val; } return (int)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { const signed char neg_one = (signed char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed char" : "value too large to convert to signed char"); } return (signed char)-1; } return (signed char)val; } return (signed char)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { const signed short neg_one = (signed short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed short" : "value too large to convert to signed short"); } return (signed short)-1; } return (signed short)val; } return (signed short)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { const signed int neg_one = (signed int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed int" : "value too large to convert to signed int"); } return (signed int)-1; } return (signed int)val; } return (signed int)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { const int neg_one = (int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to int" : "value too large to convert to int"); } return (int)-1; } return (int)val; } return (int)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { const unsigned long neg_one = (unsigned long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned long"); return (unsigned long)-1; } return (unsigned long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned long"); return (unsigned long)-1; } return (unsigned long)PyLong_AsUnsignedLong(x); } else { return (unsigned long)PyLong_AsLong(x); } } else { unsigned long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (unsigned long)-1; val = __Pyx_PyInt_AsUnsignedLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG)-1; } return (unsigned PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG)-1; } return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); } else { return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); } } else { unsigned PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (unsigned PY_LONG_LONG)-1; val = __Pyx_PyInt_AsUnsignedLongLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { const long neg_one = (long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long)-1; } return (long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long)-1; } return (long)PyLong_AsUnsignedLong(x); } else { return (long)PyLong_AsLong(x); } } else { long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (long)-1; val = __Pyx_PyInt_AsLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to PY_LONG_LONG"); return (PY_LONG_LONG)-1; } return (PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to PY_LONG_LONG"); return (PY_LONG_LONG)-1; } return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); } else { return (PY_LONG_LONG)PyLong_AsLongLong(x); } } else { PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (PY_LONG_LONG)-1; val = __Pyx_PyInt_AsLongLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { const signed long neg_one = (signed long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed long"); return (signed long)-1; } return (signed long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed long"); return (signed long)-1; } return (signed long)PyLong_AsUnsignedLong(x); } else { return (signed long)PyLong_AsLong(x); } } else { signed long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (signed long)-1; val = __Pyx_PyInt_AsSignedLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed PY_LONG_LONG"); return (signed PY_LONG_LONG)-1; } return (signed PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed PY_LONG_LONG"); return (signed PY_LONG_LONG)-1; } return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); } else { return (signed PY_LONG_LONG)PyLong_AsLongLong(x); } } else { signed PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (signed PY_LONG_LONG)-1; val = __Pyx_PyInt_AsSignedLongLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_long(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 3, &__Pyx_TypeInfo_long, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename) { PyObject *old_exc, *old_val, *old_tb; PyObject *ctx; __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); #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); } } 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); #if PY_VERSION_HEX < 0x02050000 return PyErr_Warn(NULL, message); #else return PyErr_WarnEx(NULL, message, 1); #endif } return 0; } static int __Pyx_SetVtable(PyObject *dict, void *vtable) { #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) PyObject *ob = PyCapsule_New(vtable, 0, 0); #else PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); #endif if (!ob) goto bad; if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0) goto bad; Py_DECREF(ob); return 0; bad: Py_XDECREF(ob); return -1; } 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) / 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, 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); } #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, /*int argcount,*/ 0, /*int kwonlyargcount,*/ 0, /*int nlocals,*/ 0, /*int stacksize,*/ 0, /*int flags,*/ __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, /*int firstlineno,*/ __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; PyObject *py_globals = 0; PyFrameObject *py_frame = 0; 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_globals = PyModule_GetDict(__pyx_m); if (!py_globals) goto bad; py_frame = PyFrame_New( PyThreadState_GET(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ py_globals, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; py_frame->f_lineno = py_line; PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_code); Py_XDECREF(py_frame); } 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 /* Python 3+ has unicode identifiers */ 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; ++t; } return 0; } /* Type Conversion Functions */ 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 CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { PyNumberMethods *m; const char *name = NULL; PyObject *res = NULL; #if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(x) || PyLong_Check(x)) #else if (PyLong_Check(x)) #endif return Py_INCREF(x), x; m = Py_TYPE(x)->tp_as_number; #if PY_VERSION_HEX < 0x03000000 if (m && m->nb_int) { name = "int"; res = PyNumber_Int(x); } else if (m && m->nb_long) { name = "long"; res = PyNumber_Long(x); } #else if (m && m->nb_int) { name = "int"; res = PyNumber_Long(x); } #endif if (res) { #if PY_VERSION_HEX < 0x03000000 if (!PyInt_Check(res) && !PyLong_Check(res)) { #else if (!PyLong_Check(res)) { #endif PyErr_Format(PyExc_TypeError, "__%s__ returned non-%s (type %.200s)", name, name, Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } } 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 = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); return ival; } static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { #if PY_VERSION_HEX < 0x02050000 if (ival <= LONG_MAX) return PyInt_FromLong((long)ival); else { unsigned char *bytes = (unsigned char *) &ival; int one = 1; int little = (int)*(unsigned char*)&one; return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); } #else return PyInt_FromSize_t(ival); #endif } static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { return (size_t)-1; } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { PyErr_SetString(PyExc_OverflowError, "value too large to convert to size_t"); return (size_t)-1; } return (size_t)val; } #endif /* Py_PYTHON_H */ pycogent-1.9/cogent/align/_pairwise_pogs.pyx000066400000000000000000000334531273014367000213530ustar00rootroot00000000000000#cython: boundscheck=False #cython: wraparound=False include "../../include/numerical_pyrex.pyx" cdef extern from "Python.h": PyErr_Occurred() int PyErr_CheckSignals() double Py_HUGE_VAL cdef extern from "math.h": double log (double x) version_info = (3, 2) __version__ = "('1', '9')" cdef double SCALE_STEP, MIN_FLOAT_VALUE SCALE_STEP = 2.0**50 MIN_FLOAT_VALUE = 1.0 / SCALE_STEP cdef int MAX_XCOUNT MAX_XCOUNT = 256 cdef long MIN_SCALE, MAX_SCALE MIN_SCALE = -10000 MAX_SCALE = +10000 # or 0 if all numbers should be probabilities def fmpt(mantissa, exponent, msg=''): return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) ctypedef unsigned char [:,:,::1] UChar3D def calc_rows(Long1D plan, Long1D seq1_index, Long1D seq2_index, int i_low, int i_high, int j_low, int j_high, preds, Long2D state_directions, Double2D T, Double2D xgap_scores, Double2D ygap_scores, Double3D match_scores, rows, UChar3D track, track_enc, int viterbi, int use_logs=0, int local=False, int use_scaling=True): """The ultimate in 2D Pyrex dynamic programming - Forward or Viterbi algorithm, with doubles or with slower but practically unoverflowable (double, long) GMP-like numbers. Viterbi is also available in the ever popular addition-of-logs version. All this with any possible pair HMM transition matrix. One time to use something faster than this is when the inputs are sequences rather than alignments. This code expects alignments (which can be single sequences) represented as POGs (ie: DAGs). Limitations - HMM states must be in a sensible order: M and X, then Y, then END. """ # These are array lengths/indicies and so could be Py_ssize_t cdef int prev_i, prev_j, state, prev_state, min_prev_state, N cdef int row_length, row_length1, row_count, row_count1, tmp_rows cdef int a_count, b_count, a, b, a_low, a_high, b_low, b_high cdef int dest_states, dest_state, d4, j, i cdef int last_i, last_j, last_state cdef int bin, x, y, bin_count, max_x, max_y cdef int current_row_index, source_row_index cdef int source_row_index_cache[256] # MAX_XCOUNT cdef int i_link_count, j_link_count cdef int dx, dy cdef int tcode_x, tcode_y, tcode_s cdef double d_score, mantissa, partial_sum, sub_partial_sum, max_mantissa, overall_max_mantissa cdef long exponent, max_exponent, overall_max_exponent cdef Double3D mantissas cdef Long3D exponents cdef long pointer_a, pointer_b, pointer_state cdef Long1D i_sources, i_sources_offsets cdef Long1D j_sources, j_sources_offsets cdef long i_sources_start, i_sources_end cdef long j_sources_start, j_sources_end assert not (use_logs and not viterbi) assert not (use_logs and use_scaling) assert not (local and not viterbi) N = 0 checkArray2D(T, &N, &N) row_length = 0 row_count = 0 checkArray1D(plan, &row_count) dest_states = 0 d4 = 4 # Array of (state, bin, dx, dy) tuples describing the HMM states. checkArray2D(state_directions, &dest_states, &d4) checkArray1D(seq1_index, &row_count) checkArray1D(seq2_index, &row_length) max_x = max_y = bin_count = 0 checkArray3D(match_scores, &bin_count, &max_x, &max_y) checkArray2D(xgap_scores, &bin_count, &max_x) checkArray2D(ygap_scores, &bin_count, &max_y) for i from 0 <= i < row_count: assert 0 <= seq1_index[i] < max_x for j from 0 <= j < row_length: assert 0 <= seq2_index[j] < max_y assert j_low >= 0 and j_high > j_low and j_high <= row_length (pog1, pog2) = preds (j_sources, j_sources_offsets) = pog2.asCombinedArray() j_link_count = 0 checkArray1D(j_sources, &j_link_count) row_length1 = row_length + 1 checkArray1D(j_sources_offsets, &row_length1) (i_sources, i_sources_offsets) = pog1.asCombinedArray() i_link_count = 0 checkArray1D(i_sources, &i_link_count) row_count1 = row_count + 1 checkArray1D(i_sources_offsets, &row_count1) (mantissas, exponents) = rows tmp_rows = 0 checkArray3D(mantissas, &tmp_rows, &row_length, &N) if use_scaling: checkArray3D(exponents, &tmp_rows, &row_length, &N) cdef double impossible if use_logs: impossible = log(0.0) # -inf else: impossible = 0.0 if viterbi and track is not None and track_enc is not None: checkArray3D(track, &row_count, &row_length, &N) (tcode_x, tcode_y, tcode_s) = track_enc else: track = None tcode_x = tcode_y = tcode_s = 0 # For local overall_max_exponent = MIN_SCALE overall_max_mantissa = impossible last_i = last_j = last_state = -1 for i from i_low <= i < i_high: x = seq1_index[i] if PyErr_CheckSignals(): raise PyErr_Occurred() i_sources_start = i_sources_offsets[i] i_sources_end = i_sources_offsets[i+1] current_row_index = plan[i] source_row_index_cache[0] = current_row_index a_count = i_sources_end-i_sources_start for a from 0 <= a < a_count: prev_i = i_sources[a+i_sources_start] source_row_index_cache[a+1] = plan[prev_i] if i == 0: mantissas[current_row_index, 0, 0] = (0.0 if use_logs else 1.0) if use_scaling: exponents[current_row_index, 0, 0] = 0 else: mantissas[current_row_index, 0, 0] = impossible if use_scaling: exponents[current_row_index, 0, 0] = MIN_SCALE j_sources_end = j_sources_offsets[j_low] for j from j_low <= j < j_high: j_sources_start = j_sources_end j_sources_end = j_sources_offsets[j+1] for dest_state from 0 <= dest_state < dest_states: state = state_directions[dest_state, 0] bin = state_directions[dest_state, 1] dx = state_directions[dest_state, 2] dy = state_directions[dest_state, 3] max_mantissa = impossible max_exponent = MIN_SCALE partial_sum = 0.0 pointer_state = N # ie ERROR if dx: a_low = 1 a_high = a_count + 1 else: a_low = 0 a_high = 1 if dy: b_low = 1 b_high = j_sources_end - j_sources_start + 1 else: b_low = 0 b_high = 1 if use_scaling: sub_partial_sum = 0.0 # keep these next 9 lines same as below for a from a_low <= a < a_high: source_row_index = source_row_index_cache[a] for b from b_low <= b < b_high: if dy: prev_j = j_sources[b-1+j_sources_start] else: prev_j = j min_prev_state = (prev_j > 0) for prev_state from min_prev_state <= prev_state < N: exponent = exponents[source_row_index, prev_j, prev_state] if exponent == MIN_SCALE: continue mantissa = mantissas[source_row_index, prev_j, prev_state] mantissa = mantissa * T[prev_state, state] if mantissa < MIN_FLOAT_VALUE: if mantissa == 0.0: continue if mantissa < 0.0: if T[prev_state, state] < 0.0: raise ArithmeticError(fmpt(mantissa, exponent, "transition is a negative probability")) raise ArithmeticError(fmpt(mantissa, exponent, "product is a negative probability")) while mantissa < MIN_FLOAT_VALUE: mantissa *= SCALE_STEP exponent += -1 if exponent <= MIN_SCALE: raise ArithmeticError(fmpt(mantissa, exponent, "underflows")) elif mantissa > 1.0: mantissa *= MIN_FLOAT_VALUE exponent += 1 if exponent > MAX_SCALE: raise ArithmeticError(fmpt(mantissa, exponent, "is unexpectedly large")) if exponent > max_exponent: if exponent == max_exponent + 1: sub_partial_sum = partial_sum else: sub_partial_sum = 0.0 partial_sum = 0.0 max_mantissa = 0.0 max_exponent = exponent if exponent == max_exponent: partial_sum += mantissa if viterbi and mantissa > max_mantissa: max_mantissa = mantissa pointer_state = prev_state pointer_a = a pointer_b = b elif exponent == max_exponent - 1: sub_partial_sum += mantissa partial_sum += sub_partial_sum * MIN_FLOAT_VALUE else: # keep these next 9 lines same as above for a from a_low <= a < a_high: source_row_index = source_row_index_cache[a] for b from b_low <= b < b_high: if dy: prev_j = j_sources[b-1+j_sources_start] else: prev_j = j min_prev_state = (prev_j > 0) for prev_state from min_prev_state <= prev_state < N: mantissa = mantissas[source_row_index, prev_j, prev_state] if use_logs: mantissa = mantissa + T[prev_state, state] else: mantissa = mantissa * T[prev_state, state] partial_sum += mantissa if viterbi and mantissa > max_mantissa: max_mantissa = mantissa pointer_state = prev_state pointer_a = a pointer_b = b if viterbi: mantissa = max_mantissa if track is not None: track[i, j, state] = ( (pointer_a << tcode_x) | (pointer_b << tcode_y) | (pointer_state << tcode_s)) else: mantissa = partial_sum if dy: y = seq2_index[j] if dx: d_score = match_scores[bin, x, y] else: d_score = ygap_scores[bin, y] elif dx: d_score = xgap_scores[bin, x] elif use_logs: d_score = 0.0 else: d_score = 1.0 if use_logs: mantissa += d_score else: mantissa *= d_score mantissas[current_row_index, j, state] = mantissa if use_scaling: exponents[current_row_index, j, state] = max_exponent if local and dx and dy: if (use_scaling and max_exponent > overall_max_exponent) or ( (not use_scaling or max_exponent == overall_max_exponent) and ( mantissa > overall_max_mantissa)): overall_max_exponent = max_exponent overall_max_mantissa = mantissa last_i = i last_j = j last_state = state if not local: last_i = i_high - 1 last_j = j_high - 1 last_state = state else: mantissa = overall_max_mantissa max_exponent = overall_max_exponent if use_scaling: score = log(mantissa) + log(SCALE_STEP) * max_exponent elif use_logs: score = mantissa else: score = log(mantissa) return ((last_i, last_j), last_state, score) pycogent-1.9/cogent/align/_pairwise_seqs.c000066400000000000000000027611531273014367000207670ustar00rootroot00000000000000/* Generated by Cython 0.17.1 on Sat Nov 3 13:26:59 2012 */ #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 < 0x02040000 #error Cython requires Python 2.4+. #else #include /* For offsetof */ #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 #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_CPYTHON 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #endif #if PY_VERSION_HEX < 0x02050000 typedef int Py_ssize_t; #define PY_SSIZE_T_MAX INT_MAX #define PY_SSIZE_T_MIN INT_MIN #define PY_FORMAT_SIZE_T "" #define CYTHON_FORMAT_SSIZE_T "" #define PyInt_FromSsize_t(z) PyInt_FromLong(z) #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ (PyErr_Format(PyExc_TypeError, \ "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ (PyObject*)0)) #define PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && !PyComplex_Check(o)) #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) #define __PYX_BUILD_PY_SSIZE_T "i" #else #define __PYX_BUILD_PY_SSIZE_T "n" #define CYTHON_FORMAT_SSIZE_T "z" #endif #if PY_VERSION_HEX < 0x02060000 #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) #define PyVarObject_HEAD_INIT(type, size) \ PyObject_HEAD_INIT(type) size, #define PyType_Modified(t) typedef struct { void *buf; PyObject *obj; Py_ssize_t len; Py_ssize_t itemsize; int readonly; int ndim; char *format; Py_ssize_t *shape; Py_ssize_t *strides; Py_ssize_t *suboffsets; void *internal; } Py_buffer; #define PyBUF_SIMPLE 0 #define PyBUF_WRITABLE 0x0001 #define PyBUF_FORMAT 0x0004 #define PyBUF_ND 0x0008 #define PyBUF_STRIDES (0x0010 | PyBUF_ND) #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); typedef void (*releasebufferproc)(PyObject *, Py_buffer *); #endif #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, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #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) #endif #if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") #endif #if PY_MAJOR_VERSION >= 3 #define Py_TPFLAGS_CHECKTYPES 0 #define Py_TPFLAGS_HAVE_INDEX 0 #endif #if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) #define Py_TPFLAGS_HAVE_NEWBUFFER 0 #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_READ(k, d, i) PyUnicode_READ(k, d, i) #else #define CYTHON_PEP393_ENABLED 0 #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_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i])) #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 #endif #if PY_VERSION_HEX < 0x02060000 #define PyBytesObject PyStringObject #define PyBytes_Type PyString_Type #define PyBytes_Check PyString_Check #define PyBytes_CheckExact PyString_CheckExact #define PyBytes_FromString PyString_FromString #define PyBytes_FromStringAndSize PyString_FromStringAndSize #define PyBytes_FromFormat PyString_FromFormat #define PyBytes_DecodeEscape PyString_DecodeEscape #define PyBytes_AsString PyString_AsString #define PyBytes_AsStringAndSize PyString_AsStringAndSize #define PyBytes_Size PyString_Size #define PyBytes_AS_STRING PyString_AS_STRING #define PyBytes_GET_SIZE PyString_GET_SIZE #define PyBytes_Repr PyString_Repr #define PyBytes_Concat PyString_Concat #define PyBytes_ConcatAndDel PyString_ConcatAndDel #endif #if PY_VERSION_HEX < 0x02060000 #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) #endif #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) #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 #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif #if PY_VERSION_HEX < 0x03020000 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) || (PY_VERSION_HEX >= 0x03010300) #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) #else #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) #endif #if PY_MAJOR_VERSION >= 3 #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) #endif #if PY_VERSION_HEX < 0x02050000 #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) #else #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) #endif #if PY_VERSION_HEX < 0x02050000 #define __Pyx_NAMESTR(n) ((char *)(n)) #define __Pyx_DOCSTR(n) ((char *)(n)) #else #define __Pyx_NAMESTR(n) (n) #define __Pyx_DOCSTR(n) (n) #endif #if PY_MAJOR_VERSION >= 3 #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 #ifndef __PYX_EXTERN_C #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" #else #define __PYX_EXTERN_C extern #endif #endif #if defined(WIN32) || defined(MS_WINDOWS) #define _USE_MATH_DEFINES #endif #include #define __PYX_HAVE__cogent__align___pairwise_seqs #define __PYX_HAVE_API__cogent__align___pairwise_seqs #include "limits.h" #include "math.h" #include "pythread.h" #include "string.h" #include "stdlib.h" #include "stdio.h" #include "pystate.h" #ifdef _OPENMP #include #endif /* _OPENMP */ #ifdef PYREX_WITHOUT_ASSERTIONS #define CYTHON_WITHOUT_ASSERTIONS #endif /* inline attribute */ #ifndef CYTHON_INLINE #if 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 /* unused attribute */ #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 typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ /* Type Conversion Predeclarations */ #define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) #define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) #define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) #define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); #if CYTHON_COMPILING_IN_CPYTHON #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)) #ifdef __GNUC__ /* Test for GCC > 2.95 */ #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else /* __GNUC__ > 2 ... */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ > 2 ... */ #else /* __GNUC__ */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ static PyObject *__pyx_m; static PyObject *__pyx_b; static PyObject *__pyx_empty_tuple; static PyObject *__pyx_empty_bytes; 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[] = { "numerical_pyrex.pyx", "_pairwise_seqs.pyx", "stringsource", }; struct __pyx_memoryview_obj; typedef struct { struct __pyx_memoryview_obj *memview; char *data; Py_ssize_t shape[8]; Py_ssize_t strides[8]; Py_ssize_t suboffsets[8]; } __Pyx_memviewslice; #define IS_UNSIGNED(type) (((type) -1) > 0) struct __Pyx_StructField_; #define __PYX_BUF_FLAGS_PACKED_STRUCT (1 << 0) typedef struct { const char* name; /* for error messages only */ struct __Pyx_StructField_* fields; size_t size; /* sizeof(type) */ size_t arraysize[8]; /* length of array in each dimension */ int ndim; char typegroup; /* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject, c_H_ar */ char is_unsigned; int flags; } __Pyx_TypeInfo; typedef struct __Pyx_StructField_ { __Pyx_TypeInfo* type; const char* name; size_t offset; } __Pyx_StructField; typedef struct { __Pyx_StructField* field; size_t parent_offset; } __Pyx_BufFmt_StackElem; typedef struct { __Pyx_StructField root; __Pyx_BufFmt_StackElem* head; size_t fmt_offset; size_t new_count, enc_count; size_t struct_alignment; int is_complex; char enc_type; char new_packmode; char enc_packmode; char is_valid_array; } __Pyx_BufFmt_Context; #include #ifndef CYTHON_ATOMICS #define CYTHON_ATOMICS 1 #endif #define __pyx_atomic_int_type int /* todo: Portland pgcc, maybe OS X's OSAtomicIncrement32, libatomic + autotools-like distutils support? Such a pain... */ #if CYTHON_ATOMICS && __GNUC__ >= 4 && (__GNUC_MINOR__ > 1 || \ (__GNUC_MINOR__ == 1 && __GNUC_PATHLEVEL >= 2)) #define __pyx_atomic_incr_aligned(value, lock) __sync_fetch_and_add(value, 1) #define __pyx_atomic_decr_aligned(value, lock) __sync_fetch_and_sub(value, 1) #ifdef __PYX_DEBUG_ATOMICS #warning "Using GNU atomics" #endif #elif CYTHON_ATOMICS && MSC_VER #include #define __pyx_atomic_int_type LONG #define __pyx_atomic_incr_aligned(value, lock) InterlockedIncrement(value) #define __pyx_atomic_decr_aligned(value, lock) InterlockedDecrement(value) #ifdef __PYX_DEBUG_ATOMICS #warning "Using MSVC atomics" #endif #elif CYTHON_ATOMICS && (defined(__ICC) || defined(__INTEL_COMPILER)) && 0 #define __pyx_atomic_incr_aligned(value, lock) _InterlockedIncrement(value) #define __pyx_atomic_decr_aligned(value, lock) _InterlockedDecrement(value) #ifdef __PYX_DEBUG_ATOMICS #warning "Using Intel atomics" #endif #else #undef CYTHON_ATOMICS #define CYTHON_ATOMICS 0 #ifdef __PYX_DEBUG_ATOMICS #warning "Not using atomics" #endif #endif typedef volatile __pyx_atomic_int_type __pyx_atomic_int; #if CYTHON_ATOMICS #define __pyx_add_acquisition_count(memview) \ __pyx_atomic_incr_aligned(__pyx_get_slice_count_pointer(memview), memview->lock) #define __pyx_sub_acquisition_count(memview) \ __pyx_atomic_decr_aligned(__pyx_get_slice_count_pointer(memview), memview->lock) #else #define __pyx_add_acquisition_count(memview) \ __pyx_add_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock) #define __pyx_sub_acquisition_count(memview) \ __pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock) #endif /*--- Type declarations ---*/ struct __pyx_memoryview_obj; struct __pyx_array_obj; struct __pyx_MemviewEnum_obj; struct __pyx_memoryviewslice_obj; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":31 * int * * ctypedef double[::1] Double1D # <<<<<<<<<<<<<< * ctypedef double[:, ::1] Double2D * ctypedef double[:, :, ::1] Double3D */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_seqs_Double1D; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":32 * * ctypedef double[::1] Double1D * ctypedef double[:, ::1] Double2D # <<<<<<<<<<<<<< * ctypedef double[:, :, ::1] Double3D * ctypedef long[::1] Long1D */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_seqs_Double2D; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":33 * ctypedef double[::1] Double1D * ctypedef double[:, ::1] Double2D * ctypedef double[:, :, ::1] Double3D # <<<<<<<<<<<<<< * ctypedef long[::1] Long1D * ctypedef long[:, ::1] Long2D */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_seqs_Double3D; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":34 * ctypedef double[:, ::1] Double2D * ctypedef double[:, :, ::1] Double3D * ctypedef long[::1] Long1D # <<<<<<<<<<<<<< * ctypedef long[:, ::1] Long2D * ctypedef long[:, :, ::1] Long3D */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_seqs_Long1D; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":35 * ctypedef double[:, :, ::1] Double3D * ctypedef long[::1] Long1D * ctypedef long[:, ::1] Long2D # <<<<<<<<<<<<<< * ctypedef long[:, :, ::1] Long3D * */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_seqs_Long2D; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":36 * ctypedef long[::1] Long1D * ctypedef long[:, ::1] Long2D * ctypedef long[:, :, ::1] Long3D # <<<<<<<<<<<<<< * * */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_seqs_Long3D; /* "cogent/align/_pairwise_seqs.pyx":33 * return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) * * ctypedef unsigned char [:,:,::1] UChar3D # <<<<<<<<<<<<<< * * def calc_rows(Long1D plan, Long1D seq1_index, Long1D seq2_index, */ typedef __Pyx_memviewslice __pyx_t_6cogent_5align_14_pairwise_seqs_UChar3D; /* "View.MemoryView":308 * * @cname('__pyx_memoryview') * cdef class memoryview(object): # <<<<<<<<<<<<<< * * cdef object obj */ struct __pyx_memoryview_obj { PyObject_HEAD struct __pyx_vtabstruct_memoryview *__pyx_vtab; PyObject *obj; PyObject *_size; PyObject *_array_interface; PyThread_type_lock lock; __pyx_atomic_int acquisition_count[2]; __pyx_atomic_int *acquisition_count_aligned_p; Py_buffer view; int flags; int dtype_is_object; __Pyx_TypeInfo *typeinfo; }; /* "View.MemoryView":96 * * @cname("__pyx_array") * cdef class array: # <<<<<<<<<<<<<< * * cdef: */ struct __pyx_array_obj { PyObject_HEAD char *data; Py_ssize_t len; char *format; int ndim; Py_ssize_t *_shape; Py_ssize_t *_strides; Py_ssize_t itemsize; PyObject *mode; PyObject *_format; void (*callback_free_data)(void *); int free_data; int dtype_is_object; }; /* "View.MemoryView":275 * * @cname('__pyx_MemviewEnum') * cdef class Enum(object): # <<<<<<<<<<<<<< * cdef object name * def __init__(self, name): */ struct __pyx_MemviewEnum_obj { PyObject_HEAD PyObject *name; }; /* "View.MemoryView":927 * * @cname('__pyx_memoryviewslice') * cdef class _memoryviewslice(memoryview): # <<<<<<<<<<<<<< * "Internal class for passing memoryview slices to Python" * */ struct __pyx_memoryviewslice_obj { struct __pyx_memoryview_obj __pyx_base; __Pyx_memviewslice from_slice; PyObject *from_object; PyObject *(*to_object_func)(char *); int (*to_dtype_func)(char *, PyObject *); }; /* "View.MemoryView":308 * * @cname('__pyx_memoryview') * cdef class memoryview(object): # <<<<<<<<<<<<<< * * cdef object obj */ struct __pyx_vtabstruct_memoryview { char *(*get_item_pointer)(struct __pyx_memoryview_obj *, PyObject *); PyObject *(*is_slice)(struct __pyx_memoryview_obj *, PyObject *); PyObject *(*setitem_slice_assignment)(struct __pyx_memoryview_obj *, PyObject *, PyObject *); PyObject *(*setitem_slice_assign_scalar)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *); PyObject *(*setitem_indexed)(struct __pyx_memoryview_obj *, PyObject *, PyObject *); PyObject *(*convert_item_to_object)(struct __pyx_memoryview_obj *, char *); PyObject *(*assign_item_from_object)(struct __pyx_memoryview_obj *, char *, PyObject *); }; static struct __pyx_vtabstruct_memoryview *__pyx_vtabptr_memoryview; /* "View.MemoryView":927 * * @cname('__pyx_memoryviewslice') * cdef class _memoryviewslice(memoryview): # <<<<<<<<<<<<<< * "Internal class for passing memoryview slices to Python" * */ struct __pyx_vtabstruct__memoryviewslice { struct __pyx_vtabstruct_memoryview __pyx_base; }; static struct __pyx_vtabstruct__memoryviewslice *__pyx_vtabptr__memoryviewslice; #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); /*proto*/ #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 /* CYTHON_REFNANNY */ #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) static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*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); /*proto*/ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ const char* function_name); /*proto*/ static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack); static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info); static int __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b); #define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d #define __Pyx_MEMVIEW_DIRECT 1 #define __Pyx_MEMVIEW_PTR 2 #define __Pyx_MEMVIEW_FULL 4 #define __Pyx_MEMVIEW_CONTIG 8 #define __Pyx_MEMVIEW_STRIDED 16 #define __Pyx_MEMVIEW_FOLLOW 32 #define __Pyx_IS_C_CONTIG 1 #define __Pyx_IS_F_CONTIG 2 static int __Pyx_ValidateAndInit_memviewslice( int *axes_specs, int c_or_f_flag, int buf_flags, int ndim, __Pyx_TypeInfo *dtype, __Pyx_BufFmt_StackElem stack[], __Pyx_memviewslice *memviewslice, PyObject *original_obj); static int __Pyx_init_memviewslice( struct __pyx_memoryview_obj *memview, int ndim, __Pyx_memviewslice *memviewslice, int memview_is_new_reference); static CYTHON_INLINE int __pyx_add_acquisition_count_locked(__pyx_atomic_int *acquisition_count, PyThread_type_lock lock); static CYTHON_INLINE int __pyx_sub_acquisition_count_locked(__pyx_atomic_int *acquisition_count, PyThread_type_lock lock); #define __pyx_get_slice_count_pointer(memview) (memview->acquisition_count_aligned_p) #define __pyx_get_slice_count(memview) (*__pyx_get_slice_count_pointer(memview)) #define __PYX_INC_MEMVIEW(slice, have_gil) __Pyx_INC_MEMVIEW(slice, have_gil, __LINE__) #define __PYX_XDEC_MEMVIEW(slice, have_gil) __Pyx_XDEC_MEMVIEW(slice, have_gil, __LINE__) static CYTHON_INLINE void __Pyx_INC_MEMVIEW(__Pyx_memviewslice *, int, int); static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *, int, int); static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact); /*proto*/ static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); /*proto*/ static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t, Py_ssize_t); /* proto */ #define UNARY_NEG_WOULD_OVERFLOW(x) (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) static int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/ static PyObject *get_memview(PyObject *__pyx_v_self); /*proto*/ static CYTHON_INLINE PyObject* __Pyx_decode_c_string( const char* cstring, Py_ssize_t start, Py_ssize_t stop, const char* encoding, const char* errors, PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)); #include static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; if (!j) return NULL; r = PyObject_GetItem(o, j); Py_DECREF(j); return r; } #define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_GetItemInt_List_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { #if CYTHON_COMPILING_IN_CPYTHON if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { PyObject *r = PyList_GET_ITEM(o, i); Py_INCREF(r); return r; } else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } #define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_GetItemInt_Tuple_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { #if CYTHON_COMPILING_IN_CPYTHON if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, i); Py_INCREF(r); return r; } else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } #define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_GetItemInt_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { #if CYTHON_COMPILING_IN_CPYTHON if (PyList_CheckExact(o)) { Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); if (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 = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, n); Py_INCREF(r); return r; } } else { /* inlined PySequence_GetItem() */ PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; if (likely(m && m->sq_item)) { if (unlikely(i < 0) && likely(m->sq_length)) { Py_ssize_t l = m->sq_length(o); if (unlikely(l < 0)) return NULL; i += l; } return m->sq_item(o, i); } } #else if (PySequence_Check(o)) { return PySequence_GetItem(o, i); } #endif return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } static int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ static PyObject *__pyx_memoryview_transpose(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview__get__base(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_shape(PyObject *__pyx_v_self); /*proto*/ #if CYTHON_COMPILING_IN_CPYTHON 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)) { 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 static PyObject *__pyx_memoryview_get_strides(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_suboffsets(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_ndim(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_itemsize(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_nbytes(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_size(PyObject *__pyx_v_self); /*proto*/ static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); #ifndef __PYX_FORCE_INIT_THREADS #define __PYX_FORCE_INIT_THREADS 0 #endif static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */ static PyObject *__pyx_memoryviewslice__get__base(PyObject *__pyx_v_self); /*proto*/ typedef struct { Py_ssize_t shape, strides, suboffsets; } __Pyx_Buf_DimInfo; typedef struct { size_t refcount; Py_buffer pybuffer; } __Pyx_Buffer; typedef struct { __Pyx_Buffer *rcbuffer; char *data; __Pyx_Buf_DimInfo diminfo[8]; } __Pyx_LocalBuf_ND; #if PY_MAJOR_VERSION < 3 static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags); static void __Pyx_ReleaseBuffer(Py_buffer *view); #else #define __Pyx_GetBuffer PyObject_GetBuffer #define __Pyx_ReleaseBuffer PyBuffer_Release #endif static Py_ssize_t __Pyx_zeros[] = {0, 0, 0, 0, 0, 0, 0, 0}; static Py_ssize_t __Pyx_minusones[] = {-1, -1, -1, -1, -1, -1, -1, -1}; static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dc_long(PyObject *); static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_dc_long(PyObject *); static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(PyObject *); static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_double(PyObject *); static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_unsigned_char(PyObject *); static int __pyx_memviewslice_is_contig(const __Pyx_memviewslice *mvs, char order, int ndim); static int __pyx_slices_overlap(__Pyx_memviewslice *slice1, __Pyx_memviewslice *slice2, int ndim, size_t itemsize); 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, int dtype_is_object); static CYTHON_INLINE PyObject *__pyx_capsule_create(void *p, const char *sig); static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_long(PyObject *); static void __Pyx_WriteUnraisable(const char *name, int clineno, int lineno, const char *filename); /*proto*/ static int __Pyx_check_binary_version(void); static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ typedef struct { int code_line; PyCodeObject* code_object; } __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); static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename); /*proto*/ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'cogent.align._pairwise_seqs' */ 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 double __pyx_v_6cogent_5align_14_pairwise_seqs_SCALE_STEP; static double __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_FLOAT_VALUE; static int __pyx_v_6cogent_5align_14_pairwise_seqs_MAX_XCOUNT; static long __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_SCALE; static long __pyx_v_6cogent_5align_14_pairwise_seqs_MAX_SCALE; static PyObject *generic = 0; static PyObject *strided = 0; static PyObject *indirect = 0; static PyObject *contiguous = 0; static PyObject *indirect_contiguous = 0; static int __pyx_fuse_0__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(PyObject *, Py_ssize_t, Py_ssize_t *); /*proto*/ static int __pyx_fuse_1__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(PyObject *, Py_ssize_t, long *); /*proto*/ static int __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(PyObject *, Py_ssize_t, int *); /*proto*/ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray1D(__Pyx_memviewslice, int *); /*proto*/ static int __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray2D(__Pyx_memviewslice, int *, int *); /*proto*/ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray2D(__Pyx_memviewslice, int *, int *); /*proto*/ static int __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray3D(__Pyx_memviewslice, int *, int *, int *); /*proto*/ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray3D(__Pyx_memviewslice, int *, int *, int *); /*proto*/ static int __pyx_fuse_2_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray3D(__Pyx_memviewslice, int *, int *, int *); /*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*/ static int __pyx_memoryview_check(PyObject *); /*proto*/ static PyObject *_unellipsify(PyObject *, int); /*proto*/ static PyObject *assert_direct_dimensions(Py_ssize_t *, int); /*proto*/ static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *, PyObject *); /*proto*/ static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int, int); /*proto*/ static char *__pyx_pybuffer_index(Py_buffer *, char *, Py_ssize_t, int); /*proto*/ static int __pyx_memslice_transpose(__Pyx_memviewslice *); /*proto*/ static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice, int, PyObject *(*)(char *), int (*)(char *, PyObject *), int); /*proto*/ static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *); /*proto*/ static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ static Py_ssize_t abs_py_ssize_t(Py_ssize_t); /*proto*/ static char __pyx_get_best_slice_order(__Pyx_memviewslice *, int); /*proto*/ static void _copy_strided_to_strided(char *, Py_ssize_t *, char *, Py_ssize_t *, Py_ssize_t *, Py_ssize_t *, int, size_t); /*proto*/ static void copy_strided_to_strided(__Pyx_memviewslice *, __Pyx_memviewslice *, int, size_t); /*proto*/ static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *, int); /*proto*/ static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *, Py_ssize_t *, Py_ssize_t, int, char); /*proto*/ static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *, __Pyx_memviewslice *, char, int); /*proto*/ static int __pyx_memoryview_err_extents(int, Py_ssize_t, Py_ssize_t); /*proto*/ static int __pyx_memoryview_err_dim(PyObject *, char *, int); /*proto*/ static int __pyx_memoryview_err(PyObject *, char *); /*proto*/ static int __pyx_memoryview_copy_contents(__Pyx_memviewslice, __Pyx_memviewslice, int, int, int); /*proto*/ static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *, int, int); /*proto*/ static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *, int, int, int); /*proto*/ static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/ static void __pyx_memoryview_refcount_objects_in_slice(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/ static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *, int, size_t, void *, int); /*proto*/ static void __pyx_memoryview__slice_assign_scalar(char *, Py_ssize_t *, Py_ssize_t *, int, size_t, void *); /*proto*/ static __Pyx_TypeInfo __Pyx_TypeInfo_long = { "long", NULL, sizeof(long), { 0 }, 0, IS_UNSIGNED(long) ? 'U' : 'I', IS_UNSIGNED(long), 0 }; static __Pyx_TypeInfo __Pyx_TypeInfo_double = { "double", NULL, sizeof(double), { 0 }, 0, 'R', 0, 0 }; static __Pyx_TypeInfo __Pyx_TypeInfo_unsigned_char = { "unsigned char", NULL, sizeof(unsigned char), { 0 }, 0, IS_UNSIGNED(unsigned char) ? 'U' : 'I', IS_UNSIGNED(unsigned char), 0 }; #define __Pyx_MODULE_NAME "cogent.align._pairwise_seqs" int __pyx_module_is_main_cogent__align___pairwise_seqs = 0; /* Implementation of 'cogent.align._pairwise_seqs' */ static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_ArithmeticError; static PyObject *__pyx_builtin_MemoryError; static PyObject *__pyx_builtin_enumerate; static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_Ellipsis; static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_xrange; static PyObject *__pyx_builtin_id; static PyObject *__pyx_builtin_IndexError; static PyObject *__pyx_pf_6cogent_5align_14_pairwise_seqs_fmpt(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_mantissa, PyObject *__pyx_v_exponent, PyObject *__pyx_v_msg); /* proto */ static PyObject *__pyx_pf_6cogent_5align_14_pairwise_seqs_2calc_rows(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_6cogent_5align_14_pairwise_seqs_Long1D __pyx_v_plan, __pyx_t_6cogent_5align_14_pairwise_seqs_Long1D __pyx_v_seq1_index, __pyx_t_6cogent_5align_14_pairwise_seqs_Long1D __pyx_v_seq2_index, int __pyx_v_i_low, int __pyx_v_i_high, int __pyx_v_j_low, int __pyx_v_j_high, CYTHON_UNUSED PyObject *__pyx_v_preds, __pyx_t_6cogent_5align_14_pairwise_seqs_Long2D __pyx_v_state_directions, __pyx_t_6cogent_5align_14_pairwise_seqs_Double2D __pyx_v_T, __pyx_t_6cogent_5align_14_pairwise_seqs_Double2D __pyx_v_xgap_scores, __pyx_t_6cogent_5align_14_pairwise_seqs_Double2D __pyx_v_ygap_scores, __pyx_t_6cogent_5align_14_pairwise_seqs_Double3D __pyx_v_match_scores, PyObject *__pyx_v_rows, __pyx_t_6cogent_5align_14_pairwise_seqs_UChar3D __pyx_v_track, PyObject *__pyx_v_track_enc, int __pyx_v_viterbi, int __pyx_v_use_logs, int __pyx_v_local, int __pyx_v_use_scaling); /* proto */ static int __pyx_array_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_getbuffer_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_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self); /* proto */ static PyObject *get_memview_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_array_MemoryView_5array_6__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr); /* proto */ static PyObject *__pyx_array_MemoryView_5array_8__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item); /* proto */ static int __pyx_array_MemoryView_5array_10__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /* proto */ static int __pyx_MemviewEnum_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name); /* proto */ static PyObject *__pyx_MemviewEnum_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self); /* proto */ static int __pyx_memoryview_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object); /* proto */ static void __pyx_memoryview_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index); /* proto */ static int __pyx_memoryview_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /* proto */ static int __pyx_memoryview_getbuffer_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ static PyObject *__pyx_memoryview_transpose_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview__get__base_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_shape_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_strides_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_suboffsets_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_ndim_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_itemsize_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_nbytes_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_get_size_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static Py_ssize_t __pyx_memoryview_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ static void __pyx_memoryviewslice_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */ static PyObject *__pyx_memoryviewslice__get__base_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */ static char __pyx_k_1[] = "%s dimension is %s, expected %s"; static char __pyx_k_2[] = "%s dimension is %s, too big"; static char __pyx_k_3[] = "Array required, got None"; static char __pyx_k_10[] = ""; static char __pyx_k_11[] = "%s * SCALE_STEP ** %s %s"; static char __pyx_k_12[] = "transition is a negative probability"; static char __pyx_k_13[] = "product is a negative probability"; static char __pyx_k_14[] = "is unexpectedly large"; static char __pyx_k_15[] = "Empty shape tuple for cython.array"; static char __pyx_k_17[] = "itemsize <= 0 for cython.array"; static char __pyx_k_20[] = "unable to allocate shape or strides."; static char __pyx_k_22[] = "Invalid shape in axis %d: %d."; static char __pyx_k_23[] = "Invalid mode, expected 'c' or 'fortran', got %s"; static char __pyx_k_25[] = "unable to allocate array data."; static char __pyx_k_27[] = "Can only create a buffer that is contiguous in memory."; static char __pyx_k_29[] = "Unable to convert item to object"; static char __pyx_k_31[] = "Buffer view does not expose strides"; static char __pyx_k_33[] = ""; static char __pyx_k_34[] = ""; static char __pyx_k_37[] = "Cannot index with type '%s'"; static char __pyx_k_39[] = "Indirect dimensions not supported"; static char __pyx_k_41[] = "Index out of bounds (axis %d)"; static char __pyx_k_42[] = "Step may not be zero (axis %d)"; static char __pyx_k_43[] = "All dimensions preceding dimension %d must be indexed and not sliced"; static char __pyx_k_44[] = "Out of bounds on buffer access (axis %d)"; static char __pyx_k_45[] = "Cannot transpose memoryview with indirect dimensions"; static char __pyx_k_46[] = "got differing extents in dimension %d (got %d and %d)"; static char __pyx_k_47[] = "Dimension %d is not direct"; static char __pyx_k_48[] = "('1', '5', '3-dev')"; static char __pyx_k_52[] = "/Users/maxwell/Documents/Work/Cogent/cogent/align/_pairwise_seqs.pyx"; static char __pyx_k_53[] = "cogent.align._pairwise_seqs"; static char __pyx_k_54[] = "overall_max_mantissa"; static char __pyx_k_55[] = "overall_max_exponent"; static char __pyx_k_58[] = "getbuffer(obj, view, flags)"; static char __pyx_k_59[] = ""; static char __pyx_k_61[] = ""; static char __pyx_k_63[] = ""; static char __pyx_k_65[] = ""; static char __pyx_k_67[] = ""; static char __pyx_k__N[] = "N"; static char __pyx_k__O[] = "O"; static char __pyx_k__T[] = "T"; static char __pyx_k__a[] = "a"; static char __pyx_k__b[] = "b"; static char __pyx_k__c[] = "c"; static char __pyx_k__i[] = "i"; static char __pyx_k__j[] = "j"; static char __pyx_k__x[] = "x"; static char __pyx_k__y[] = "y"; static char __pyx_k__d4[] = "d4"; static char __pyx_k__dx[] = "dx"; static char __pyx_k__dy[] = "dy"; static char __pyx_k__id[] = "id"; static char __pyx_k__1st[] = "1st"; static char __pyx_k__2nd[] = "2nd"; static char __pyx_k__3rd[] = "3rd"; static char __pyx_k__bin[] = "bin"; static char __pyx_k__msg[] = "msg"; static char __pyx_k__obj[] = "obj"; static char __pyx_k__base[] = "base"; static char __pyx_k__fmpt[] = "fmpt"; static char __pyx_k__mode[] = "mode"; static char __pyx_k__name[] = "name"; static char __pyx_k__ndim[] = "ndim"; static char __pyx_k__pack[] = "pack"; static char __pyx_k__plan[] = "plan"; static char __pyx_k__rows[] = "rows"; static char __pyx_k__size[] = "size"; static char __pyx_k__step[] = "step"; static char __pyx_k__stop[] = "stop"; static char __pyx_k__ASCII[] = "ASCII"; static char __pyx_k__a_low[] = "a_low"; static char __pyx_k__b_low[] = "b_low"; static char __pyx_k__error[] = "error"; static char __pyx_k__flags[] = "flags"; static char __pyx_k__i_low[] = "i_low"; static char __pyx_k__j_low[] = "j_low"; static char __pyx_k__local[] = "local"; static char __pyx_k__max_x[] = "max_x"; static char __pyx_k__max_y[] = "max_y"; static char __pyx_k__preds[] = "preds"; static char __pyx_k__range[] = "range"; static char __pyx_k__score[] = "score"; static char __pyx_k__shape[] = "shape"; static char __pyx_k__start[] = "start"; static char __pyx_k__state[] = "state"; static char __pyx_k__track[] = "track"; static char __pyx_k__a_high[] = "a_high"; static char __pyx_k__b_high[] = "b_high"; static char __pyx_k__decode[] = "decode"; static char __pyx_k__encode[] = "encode"; static char __pyx_k__extend[] = "extend"; static char __pyx_k__format[] = "format"; static char __pyx_k__i_high[] = "i_high"; static char __pyx_k__j_high[] = "j_high"; static char __pyx_k__last_i[] = "last_i"; static char __pyx_k__last_j[] = "last_j"; static char __pyx_k__prev_i[] = "prev_i"; static char __pyx_k__prev_j[] = "prev_j"; static char __pyx_k__struct[] = "struct"; static char __pyx_k__unpack[] = "unpack"; static char __pyx_k__xrange[] = "xrange"; static char __pyx_k__a_count[] = "a_count"; static char __pyx_k__b_count[] = "b_count"; static char __pyx_k__d_score[] = "d_score"; static char __pyx_k__fortran[] = "fortran"; static char __pyx_k__memview[] = "memview"; static char __pyx_k__tcode_s[] = "tcode_s"; static char __pyx_k__tcode_x[] = "tcode_x"; static char __pyx_k__tcode_y[] = "tcode_y"; static char __pyx_k__viterbi[] = "viterbi"; static char __pyx_k__Ellipsis[] = "Ellipsis"; static char __pyx_k____main__[] = "__main__"; static char __pyx_k____name__[] = "__name__"; static char __pyx_k____test__[] = "__test__"; static char __pyx_k__exponent[] = "exponent"; static char __pyx_k__itemsize[] = "itemsize"; static char __pyx_k__mantissa[] = "mantissa"; static char __pyx_k__source_i[] = "source_i"; static char __pyx_k__tmp_rows[] = "tmp_rows"; static char __pyx_k__use_logs[] = "use_logs"; static char __pyx_k__TypeError[] = "TypeError"; static char __pyx_k____class__[] = "__class__"; static char __pyx_k__bin_count[] = "bin_count"; static char __pyx_k__calc_rows[] = "calc_rows"; static char __pyx_k__enumerate[] = "enumerate"; static char __pyx_k__exponents[] = "exponents"; static char __pyx_k__mantissas[] = "mantissas"; static char __pyx_k__pointer_a[] = "pointer_a"; static char __pyx_k__pointer_b[] = "pointer_b"; static char __pyx_k__row_count[] = "row_count"; static char __pyx_k__track_enc[] = "track_enc"; static char __pyx_k__IndexError[] = "IndexError"; static char __pyx_k__ValueError[] = "ValueError"; static char __pyx_k__dest_state[] = "dest_state"; static char __pyx_k__impossible[] = "impossible"; static char __pyx_k__last_state[] = "last_state"; static char __pyx_k__prev_state[] = "prev_state"; static char __pyx_k__row_count1[] = "row_count1"; static char __pyx_k__row_length[] = "row_length"; static char __pyx_k__seq1_index[] = "seq1_index"; static char __pyx_k__seq2_index[] = "seq2_index"; static char __pyx_k__underflows[] = "underflows"; static char __pyx_k__MemoryError[] = "MemoryError"; static char __pyx_k____version__[] = "__version__"; static char __pyx_k__dest_states[] = "dest_states"; static char __pyx_k__partial_sum[] = "partial_sum"; static char __pyx_k__row_length1[] = "row_length1"; static char __pyx_k__use_scaling[] = "use_scaling"; static char __pyx_k__xgap_scores[] = "xgap_scores"; static char __pyx_k__ygap_scores[] = "ygap_scores"; static char __pyx_k__match_scores[] = "match_scores"; static char __pyx_k__max_exponent[] = "max_exponent"; static char __pyx_k__max_mantissa[] = "max_mantissa"; static char __pyx_k__version_info[] = "version_info"; static char __pyx_k__pointer_state[] = "pointer_state"; static char __pyx_k__min_prev_state[] = "min_prev_state"; static char __pyx_k__ArithmeticError[] = "ArithmeticError"; static char __pyx_k____pyx_getbuffer[] = "__pyx_getbuffer"; static char __pyx_k__allocate_buffer[] = "allocate_buffer"; static char __pyx_k__dtype_is_object[] = "dtype_is_object"; static char __pyx_k__sub_partial_sum[] = "sub_partial_sum"; static char __pyx_k__source_row_index[] = "source_row_index"; static char __pyx_k__state_directions[] = "state_directions"; static char __pyx_k__current_row_index[] = "current_row_index"; static PyObject *__pyx_kp_s_1; static PyObject *__pyx_kp_s_10; static PyObject *__pyx_kp_s_11; static PyObject *__pyx_kp_s_12; static PyObject *__pyx_kp_s_13; static PyObject *__pyx_kp_s_14; static PyObject *__pyx_kp_s_15; static PyObject *__pyx_kp_s_17; static PyObject *__pyx_kp_s_2; static PyObject *__pyx_kp_s_20; static PyObject *__pyx_kp_s_22; static PyObject *__pyx_kp_s_23; static PyObject *__pyx_kp_s_25; static PyObject *__pyx_kp_s_27; static PyObject *__pyx_kp_s_29; static PyObject *__pyx_kp_s_3; static PyObject *__pyx_kp_s_31; static PyObject *__pyx_kp_s_33; static PyObject *__pyx_kp_s_34; static PyObject *__pyx_kp_s_37; static PyObject *__pyx_kp_s_39; static PyObject *__pyx_kp_s_44; static PyObject *__pyx_kp_s_46; static PyObject *__pyx_kp_s_48; static PyObject *__pyx_kp_s_52; static PyObject *__pyx_n_s_53; static PyObject *__pyx_n_s_54; static PyObject *__pyx_n_s_55; static PyObject *__pyx_kp_s_59; static PyObject *__pyx_kp_s_61; static PyObject *__pyx_kp_s_63; static PyObject *__pyx_kp_s_65; static PyObject *__pyx_kp_s_67; static PyObject *__pyx_kp_s__1st; static PyObject *__pyx_kp_s__2nd; static PyObject *__pyx_kp_s__3rd; static PyObject *__pyx_n_s__ASCII; static PyObject *__pyx_n_s__ArithmeticError; static PyObject *__pyx_n_s__Ellipsis; static PyObject *__pyx_n_s__IndexError; static PyObject *__pyx_n_s__MemoryError; static PyObject *__pyx_n_s__N; static PyObject *__pyx_n_b__O; static PyObject *__pyx_n_s__T; static PyObject *__pyx_n_s__TypeError; static PyObject *__pyx_n_s__ValueError; static PyObject *__pyx_n_s____class__; static PyObject *__pyx_n_s____main__; static PyObject *__pyx_n_s____name__; static PyObject *__pyx_n_s____pyx_getbuffer; static PyObject *__pyx_n_s____test__; static PyObject *__pyx_n_s____version__; static PyObject *__pyx_n_s__a; static PyObject *__pyx_n_s__a_count; static PyObject *__pyx_n_s__a_high; static PyObject *__pyx_n_s__a_low; static PyObject *__pyx_n_s__allocate_buffer; static PyObject *__pyx_n_s__b; static PyObject *__pyx_n_s__b_count; static PyObject *__pyx_n_s__b_high; static PyObject *__pyx_n_s__b_low; static PyObject *__pyx_n_s__base; static PyObject *__pyx_n_s__bin; static PyObject *__pyx_n_s__bin_count; static PyObject *__pyx_n_b__c; static PyObject *__pyx_n_s__c; static PyObject *__pyx_n_u__c; static PyObject *__pyx_n_s__calc_rows; static PyObject *__pyx_n_s__current_row_index; static PyObject *__pyx_n_s__d4; static PyObject *__pyx_n_s__d_score; static PyObject *__pyx_n_s__decode; static PyObject *__pyx_n_s__dest_state; static PyObject *__pyx_n_s__dest_states; static PyObject *__pyx_n_s__dtype_is_object; static PyObject *__pyx_n_s__dx; static PyObject *__pyx_n_s__dy; static PyObject *__pyx_n_s__encode; static PyObject *__pyx_n_s__enumerate; static PyObject *__pyx_n_s__error; static PyObject *__pyx_n_s__exponent; static PyObject *__pyx_n_s__exponents; static PyObject *__pyx_n_s__extend; static PyObject *__pyx_n_s__flags; static PyObject *__pyx_n_s__fmpt; static PyObject *__pyx_n_s__format; static PyObject *__pyx_n_b__fortran; static PyObject *__pyx_n_s__fortran; static PyObject *__pyx_n_s__i; static PyObject *__pyx_n_s__i_high; static PyObject *__pyx_n_s__i_low; static PyObject *__pyx_n_s__id; static PyObject *__pyx_n_s__impossible; static PyObject *__pyx_n_s__itemsize; static PyObject *__pyx_n_s__j; static PyObject *__pyx_n_s__j_high; static PyObject *__pyx_n_s__j_low; static PyObject *__pyx_n_s__last_i; static PyObject *__pyx_n_s__last_j; static PyObject *__pyx_n_s__last_state; static PyObject *__pyx_n_s__local; static PyObject *__pyx_n_s__mantissa; static PyObject *__pyx_n_s__mantissas; static PyObject *__pyx_n_s__match_scores; static PyObject *__pyx_n_s__max_exponent; static PyObject *__pyx_n_s__max_mantissa; static PyObject *__pyx_n_s__max_x; static PyObject *__pyx_n_s__max_y; static PyObject *__pyx_n_s__memview; static PyObject *__pyx_n_s__min_prev_state; static PyObject *__pyx_n_s__mode; static PyObject *__pyx_n_s__msg; static PyObject *__pyx_n_s__name; static PyObject *__pyx_n_s__ndim; static PyObject *__pyx_n_s__obj; static PyObject *__pyx_n_s__pack; static PyObject *__pyx_n_s__partial_sum; static PyObject *__pyx_n_s__plan; static PyObject *__pyx_n_s__pointer_a; static PyObject *__pyx_n_s__pointer_b; static PyObject *__pyx_n_s__pointer_state; static PyObject *__pyx_n_s__preds; static PyObject *__pyx_n_s__prev_i; static PyObject *__pyx_n_s__prev_j; static PyObject *__pyx_n_s__prev_state; static PyObject *__pyx_n_s__range; static PyObject *__pyx_n_s__row_count; static PyObject *__pyx_n_s__row_count1; static PyObject *__pyx_n_s__row_length; static PyObject *__pyx_n_s__row_length1; static PyObject *__pyx_n_s__rows; static PyObject *__pyx_n_s__score; static PyObject *__pyx_n_s__seq1_index; static PyObject *__pyx_n_s__seq2_index; static PyObject *__pyx_n_s__shape; static PyObject *__pyx_n_s__size; static PyObject *__pyx_n_s__source_i; static PyObject *__pyx_n_s__source_row_index; static PyObject *__pyx_n_s__start; static PyObject *__pyx_n_s__state; static PyObject *__pyx_n_s__state_directions; static PyObject *__pyx_n_s__step; static PyObject *__pyx_n_s__stop; static PyObject *__pyx_n_s__struct; static PyObject *__pyx_n_s__sub_partial_sum; static PyObject *__pyx_n_s__tcode_s; static PyObject *__pyx_n_s__tcode_x; static PyObject *__pyx_n_s__tcode_y; static PyObject *__pyx_n_s__tmp_rows; static PyObject *__pyx_n_s__track; static PyObject *__pyx_n_s__track_enc; static PyObject *__pyx_n_s__underflows; static PyObject *__pyx_n_s__unpack; static PyObject *__pyx_n_s__use_logs; static PyObject *__pyx_n_s__use_scaling; static PyObject *__pyx_n_s__version_info; static PyObject *__pyx_n_s__viterbi; static PyObject *__pyx_n_s__x; static PyObject *__pyx_n_s__xgap_scores; static PyObject *__pyx_n_s__xrange; static PyObject *__pyx_n_s__y; static PyObject *__pyx_n_s__ygap_scores; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_int_2; static PyObject *__pyx_int_3; static PyObject *__pyx_int_neg_1; static PyObject *__pyx_k_tuple_4; static PyObject *__pyx_k_tuple_5; static PyObject *__pyx_k_tuple_6; static PyObject *__pyx_k_tuple_7; static PyObject *__pyx_k_tuple_8; static PyObject *__pyx_k_tuple_9; static PyObject *__pyx_k_tuple_16; static PyObject *__pyx_k_tuple_18; static PyObject *__pyx_k_tuple_19; static PyObject *__pyx_k_tuple_21; static PyObject *__pyx_k_tuple_24; static PyObject *__pyx_k_tuple_26; static PyObject *__pyx_k_tuple_28; static PyObject *__pyx_k_tuple_30; static PyObject *__pyx_k_tuple_32; static PyObject *__pyx_k_tuple_35; static PyObject *__pyx_k_tuple_36; static PyObject *__pyx_k_tuple_38; static PyObject *__pyx_k_tuple_40; static PyObject *__pyx_k_tuple_49; static PyObject *__pyx_k_tuple_50; static PyObject *__pyx_k_tuple_56; static PyObject *__pyx_k_tuple_60; static PyObject *__pyx_k_tuple_62; static PyObject *__pyx_k_tuple_64; static PyObject *__pyx_k_tuple_66; static PyObject *__pyx_k_tuple_68; static PyObject *__pyx_k_codeobj_51; static PyObject *__pyx_k_codeobj_57; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":39 * * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: # <<<<<<<<<<<<<< * if var[0] == 0: * # Length unspecified, take it from the provided array */ static int __pyx_fuse_0__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(PyObject *__pyx_v_dimension, Py_ssize_t __pyx_v_val, Py_ssize_t *__pyx_v_var) { 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_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_0checkDim", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":40 * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: * if var[0] == 0: # <<<<<<<<<<<<<< * # Length unspecified, take it from the provided array * if dim is int: */ __pyx_t_1 = ((__pyx_v_var[0]) == 0); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":51 * var[0] = val * else: * var[0] = val # <<<<<<<<<<<<<< * * elif var[0] != val: */ (__pyx_v_var[0]) = __pyx_v_val; goto __pyx_L3; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":53 * var[0] = val * * elif var[0] != val: # <<<<<<<<<<<<<< * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % */ __pyx_t_1 = ((__pyx_v_var[0]) != __pyx_v_val); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":56 * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % * (dimension, val, var[0])) # <<<<<<<<<<<<<< * else: * # Length matches what was expected */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyInt_FromSsize_t((__pyx_v_var[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_dimension); __Pyx_GIVEREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } /*else*/ { } __pyx_L3:; __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("cogent.align._pairwise_seqs.checkDim", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":39 * * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: # <<<<<<<<<<<<<< * if var[0] == 0: * # Length unspecified, take it from the provided array */ static int __pyx_fuse_1__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(PyObject *__pyx_v_dimension, Py_ssize_t __pyx_v_val, long *__pyx_v_var) { 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_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_1checkDim", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":40 * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: * if var[0] == 0: # <<<<<<<<<<<<<< * # Length unspecified, take it from the provided array * if dim is int: */ __pyx_t_1 = ((__pyx_v_var[0]) == 0); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":47 * var[0] = val * elif dim is long: * if val > LONG_MAX: # <<<<<<<<<<<<<< * raise ValueError("%s dimension is %s, too big" % (dimension, val)) * var[0] = val */ __pyx_t_1 = (__pyx_v_val > LONG_MAX); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":48 * elif dim is long: * if val > LONG_MAX: * raise ValueError("%s dimension is %s, too big" % (dimension, val)) # <<<<<<<<<<<<<< * var[0] = val * else: */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_dimension); __Pyx_GIVEREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":49 * if val > LONG_MAX: * raise ValueError("%s dimension is %s, too big" % (dimension, val)) * var[0] = val # <<<<<<<<<<<<<< * else: * var[0] = val */ (__pyx_v_var[0]) = ((long)__pyx_v_val); goto __pyx_L3; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":53 * var[0] = val * * elif var[0] != val: # <<<<<<<<<<<<<< * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % */ __pyx_t_1 = ((__pyx_v_var[0]) != __pyx_v_val); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":56 * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % * (dimension, val, var[0])) # <<<<<<<<<<<<<< * else: * # Length matches what was expected */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyInt_FromLong((__pyx_v_var[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_dimension); __Pyx_GIVEREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } /*else*/ { } __pyx_L3:; __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("cogent.align._pairwise_seqs.checkDim", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":39 * * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: # <<<<<<<<<<<<<< * if var[0] == 0: * # Length unspecified, take it from the provided array */ static int __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(PyObject *__pyx_v_dimension, Py_ssize_t __pyx_v_val, int *__pyx_v_var) { 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_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_2checkDim", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":40 * * cdef int checkDim(dimension, Py_ssize_t val, dim *var) except 1: * if var[0] == 0: # <<<<<<<<<<<<<< * # Length unspecified, take it from the provided array * if dim is int: */ __pyx_t_1 = ((__pyx_v_var[0]) == 0); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":43 * # Length unspecified, take it from the provided array * if dim is int: * if val > INT_MAX: # <<<<<<<<<<<<<< * raise ValueError("%s dimension is %s, too big" % (dimension, val)) * var[0] = val */ __pyx_t_1 = (__pyx_v_val > INT_MAX); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":44 * if dim is int: * if val > INT_MAX: * raise ValueError("%s dimension is %s, too big" % (dimension, val)) # <<<<<<<<<<<<<< * var[0] = val * elif dim is long: */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_dimension); __Pyx_GIVEREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":45 * if val > INT_MAX: * raise ValueError("%s dimension is %s, too big" % (dimension, val)) * var[0] = val # <<<<<<<<<<<<<< * elif dim is long: * if val > LONG_MAX: */ (__pyx_v_var[0]) = ((int)__pyx_v_val); goto __pyx_L3; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":53 * var[0] = val * * elif var[0] != val: # <<<<<<<<<<<<<< * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % */ __pyx_t_1 = ((__pyx_v_var[0]) != __pyx_v_val); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":56 * # Length already specified, but not the same * raise ValueError("%s dimension is %s, expected %s" % * (dimension, val, var[0])) # <<<<<<<<<<<<<< * else: * # Length matches what was expected */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyInt_FromLong((__pyx_v_var[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_dimension); __Pyx_GIVEREF(__pyx_v_dimension); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } /*else*/ { } __pyx_L3:; __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("cogent.align._pairwise_seqs.checkDim", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":62 * * * cdef int checkArray1D(num[::1] a, dim *x) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray1D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_1_2checkArray1D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":63 * * cdef int checkArray1D(num[::1] a, dim *x) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":64 * cdef int checkArray1D(num[::1] a, dim *x) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":65 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_seqs.checkArray1D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":67 * checkDim('1st', a.shape[0], x) * * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray2D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_0_2checkArray2D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":68 * * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":69 * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":70 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * checkDim('2nd', a.shape[1], y) * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":71 * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) # <<<<<<<<<<<<<< * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__2nd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[1]), __pyx_v_y); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_seqs.checkArray2D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":67 * checkDim('1st', a.shape[0], x) * * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray2D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_1_2checkArray2D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":68 * * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":69 * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":70 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * checkDim('2nd', a.shape[1], y) * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":71 * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) # <<<<<<<<<<<<<< * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__2nd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[1]), __pyx_v_y); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_seqs.checkArray2D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":73 * checkDim('2nd', a.shape[1], y) * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray3D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y, int *__pyx_v_z) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_0_2checkArray3D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":74 * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":75 * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":76 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":77 * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) # <<<<<<<<<<<<<< * checkDim('3rd', a.shape[2], z) * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__2nd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[1]), __pyx_v_y); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":78 * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) # <<<<<<<<<<<<<< * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__3rd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[2]), __pyx_v_z); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_seqs.checkArray3D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":73 * checkDim('2nd', a.shape[1], y) * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray3D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y, int *__pyx_v_z) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_1_2checkArray3D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":74 * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":75 * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":76 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":77 * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) # <<<<<<<<<<<<<< * checkDim('3rd', a.shape[2], z) * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__2nd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[1]), __pyx_v_y); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":78 * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) # <<<<<<<<<<<<<< * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__3rd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[2]), __pyx_v_z); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_seqs.checkArray3D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":73 * checkDim('2nd', a.shape[1], y) * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: # <<<<<<<<<<<<<< * if a is None: * raise ValueError('Array required, got None') */ static int __pyx_fuse_2_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray3D(__Pyx_memviewslice __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y, int *__pyx_v_z) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_fuse_2_2checkArray3D", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":74 * * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: # <<<<<<<<<<<<<< * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) */ __pyx_t_1 = (((PyObject *) __pyx_v_a.memview) == Py_None); if (__pyx_t_1) { /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":75 * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":76 * if a is None: * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) # <<<<<<<<<<<<<< * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__1st); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[0]), __pyx_v_x); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":77 * raise ValueError('Array required, got None') * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) # <<<<<<<<<<<<<< * checkDim('3rd', a.shape[2], z) * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__2nd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[1]), __pyx_v_y); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":78 * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) * checkDim('3rd', a.shape[2], z) # <<<<<<<<<<<<<< * */ __pyx_t_2 = ((PyObject *)__pyx_kp_s__3rd); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_fuse_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkDim(__pyx_t_2, (__pyx_v_a.shape[2]), __pyx_v_z); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("cogent.align._pairwise_seqs.checkArray3D", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_6cogent_5align_14_pairwise_seqs_1fmpt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_6cogent_5align_14_pairwise_seqs_1fmpt = {__Pyx_NAMESTR("fmpt"), (PyCFunction)__pyx_pw_6cogent_5align_14_pairwise_seqs_1fmpt, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}; static PyObject *__pyx_pw_6cogent_5align_14_pairwise_seqs_1fmpt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_mantissa = 0; PyObject *__pyx_v_exponent = 0; PyObject *__pyx_v_msg = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("fmpt (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__mantissa,&__pyx_n_s__exponent,&__pyx_n_s__msg,0}; PyObject* values[3] = {0,0,0}; values[2] = ((PyObject *)__pyx_kp_s_10); 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); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mantissa)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__exponent)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("fmpt", 0, 2, 3, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__msg); if (value) { values[2] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fmpt") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); 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_mantissa = values[0]; __pyx_v_exponent = values[1]; __pyx_v_msg = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("fmpt", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("cogent.align._pairwise_seqs.fmpt", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_6cogent_5align_14_pairwise_seqs_fmpt(__pyx_self, __pyx_v_mantissa, __pyx_v_exponent, __pyx_v_msg); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cogent/align/_pairwise_seqs.pyx":30 * MAX_SCALE = +10000 # or 0 if all numbers should be probabilities * * def fmpt(mantissa, exponent, msg=''): # <<<<<<<<<<<<<< * return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) * */ static PyObject *__pyx_pf_6cogent_5align_14_pairwise_seqs_fmpt(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_mantissa, PyObject *__pyx_v_exponent, PyObject *__pyx_v_msg) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("fmpt", 0); /* "cogent/align/_pairwise_seqs.pyx":31 * * def fmpt(mantissa, exponent, msg=''): * return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) # <<<<<<<<<<<<<< * * ctypedef unsigned char [:,:,::1] UChar3D */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_mantissa); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_mantissa); __Pyx_GIVEREF(__pyx_v_mantissa); __Pyx_INCREF(__pyx_v_exponent); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_exponent); __Pyx_GIVEREF(__pyx_v_exponent); __Pyx_INCREF(__pyx_v_msg); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_msg); __Pyx_GIVEREF(__pyx_v_msg); __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_r = ((PyObject *)__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L0; __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("cogent.align._pairwise_seqs.fmpt", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_6cogent_5align_14_pairwise_seqs_3calc_rows(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_6cogent_5align_14_pairwise_seqs_2calc_rows[] = "The faster, sequence only (no POG) version. Forward or Viterbi \n algorithm, with doubles or with slower but practically unoverflowable \n (double, long) GMP-like numbers. Viterbi is also available in the ever \n popular addition-of-logs version. All this with any possible pair HMM \n transition matrix.\n \n Limitations\n - HMM states must be in a sensible order: M and X, then Y, then END.\n "; static PyMethodDef __pyx_mdef_6cogent_5align_14_pairwise_seqs_3calc_rows = {__Pyx_NAMESTR("calc_rows"), (PyCFunction)__pyx_pw_6cogent_5align_14_pairwise_seqs_3calc_rows, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6cogent_5align_14_pairwise_seqs_2calc_rows)}; static PyObject *__pyx_pw_6cogent_5align_14_pairwise_seqs_3calc_rows(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { __pyx_t_6cogent_5align_14_pairwise_seqs_Long1D __pyx_v_plan = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_seqs_Long1D __pyx_v_seq1_index = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_seqs_Long1D __pyx_v_seq2_index = { 0, 0, { 0 }, { 0 }, { 0 } }; int __pyx_v_i_low; int __pyx_v_i_high; int __pyx_v_j_low; int __pyx_v_j_high; CYTHON_UNUSED PyObject *__pyx_v_preds = 0; __pyx_t_6cogent_5align_14_pairwise_seqs_Long2D __pyx_v_state_directions = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_seqs_Double2D __pyx_v_T = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_seqs_Double2D __pyx_v_xgap_scores = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_seqs_Double2D __pyx_v_ygap_scores = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_seqs_Double3D __pyx_v_match_scores = { 0, 0, { 0 }, { 0 }, { 0 } }; PyObject *__pyx_v_rows = 0; __pyx_t_6cogent_5align_14_pairwise_seqs_UChar3D __pyx_v_track = { 0, 0, { 0 }, { 0 }, { 0 } }; PyObject *__pyx_v_track_enc = 0; int __pyx_v_viterbi; int __pyx_v_use_logs; int __pyx_v_local; int __pyx_v_use_scaling; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("calc_rows (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__plan,&__pyx_n_s__seq1_index,&__pyx_n_s__seq2_index,&__pyx_n_s__i_low,&__pyx_n_s__i_high,&__pyx_n_s__j_low,&__pyx_n_s__j_high,&__pyx_n_s__preds,&__pyx_n_s__state_directions,&__pyx_n_s__T,&__pyx_n_s__xgap_scores,&__pyx_n_s__ygap_scores,&__pyx_n_s__match_scores,&__pyx_n_s__rows,&__pyx_n_s__track,&__pyx_n_s__track_enc,&__pyx_n_s__viterbi,&__pyx_n_s__use_logs,&__pyx_n_s__local,&__pyx_n_s__use_scaling,0}; PyObject* values[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__plan)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__seq1_index)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__seq2_index)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i_low)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 3); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i_high)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 4); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__j_low)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 5); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 6: if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__j_high)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 6); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 7: if (likely((values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__preds)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 7); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 8: if (likely((values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__state_directions)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 8); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 9: if (likely((values[9] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 9); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 10: if (likely((values[10] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__xgap_scores)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 10); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 11: if (likely((values[11] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ygap_scores)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 11); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 12: if (likely((values[12] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__match_scores)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 12); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 13: if (likely((values[13] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__rows)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 13); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 14: if (likely((values[14] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__track)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 14); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 15: if (likely((values[15] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__track_enc)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 15); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 16: if (likely((values[16] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__viterbi)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, 16); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 17: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_logs); if (value) { values[17] = value; kw_args--; } } case 18: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__local); if (value) { values[18] = value; kw_args--; } } case 19: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_scaling); if (value) { values[19] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "calc_rows") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); values[15] = PyTuple_GET_ITEM(__pyx_args, 15); values[14] = PyTuple_GET_ITEM(__pyx_args, 14); values[13] = PyTuple_GET_ITEM(__pyx_args, 13); values[12] = PyTuple_GET_ITEM(__pyx_args, 12); values[11] = PyTuple_GET_ITEM(__pyx_args, 11); values[10] = PyTuple_GET_ITEM(__pyx_args, 10); values[9] = PyTuple_GET_ITEM(__pyx_args, 9); values[8] = PyTuple_GET_ITEM(__pyx_args, 8); values[7] = PyTuple_GET_ITEM(__pyx_args, 7); values[6] = PyTuple_GET_ITEM(__pyx_args, 6); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[3] = PyTuple_GET_ITEM(__pyx_args, 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_plan = __Pyx_PyObject_to_MemoryviewSlice_dc_long(values[0]); if (unlikely(!__pyx_v_plan.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_seq1_index = __Pyx_PyObject_to_MemoryviewSlice_dc_long(values[1]); if (unlikely(!__pyx_v_seq1_index.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_seq2_index = __Pyx_PyObject_to_MemoryviewSlice_dc_long(values[2]); if (unlikely(!__pyx_v_seq2_index.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_i_low = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_i_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_i_high = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_i_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_j_low = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_j_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_j_high = __Pyx_PyInt_AsInt(values[6]); if (unlikely((__pyx_v_j_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_preds = values[7]; __pyx_v_state_directions = __Pyx_PyObject_to_MemoryviewSlice_d_dc_long(values[8]); if (unlikely(!__pyx_v_state_directions.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_T = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(values[9]); if (unlikely(!__pyx_v_T.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_xgap_scores = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(values[10]); if (unlikely(!__pyx_v_xgap_scores.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_ygap_scores = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(values[11]); if (unlikely(!__pyx_v_ygap_scores.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_match_scores = __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_double(values[12]); if (unlikely(!__pyx_v_match_scores.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_rows = values[13]; __pyx_v_track = __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_unsigned_char(values[14]); if (unlikely(!__pyx_v_track.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_track_enc = values[15]; __pyx_v_viterbi = __Pyx_PyInt_AsInt(values[16]); if (unlikely((__pyx_v_viterbi == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} if (values[17]) { __pyx_v_use_logs = __Pyx_PyInt_AsInt(values[17]); if (unlikely((__pyx_v_use_logs == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { __pyx_v_use_logs = ((int)0); } if (values[18]) { __pyx_v_local = __Pyx_PyInt_AsInt(values[18]); if (unlikely((__pyx_v_local == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { /* "cogent/align/_pairwise_seqs.pyx":39 * Long2D state_directions, Double2D T, * Double2D xgap_scores, Double2D ygap_scores, Double3D match_scores, * rows, UChar3D track, track_enc, int viterbi, int use_logs=0, int local=False, # <<<<<<<<<<<<<< * int use_scaling=True): * */ __pyx_v_local = ((int)0); } if (values[19]) { __pyx_v_use_scaling = __Pyx_PyInt_AsInt(values[19]); if (unlikely((__pyx_v_use_scaling == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { /* "cogent/align/_pairwise_seqs.pyx":40 * Double2D xgap_scores, Double2D ygap_scores, Double3D match_scores, * rows, UChar3D track, track_enc, int viterbi, int use_logs=0, int local=False, * int use_scaling=True): # <<<<<<<<<<<<<< * * """The faster, sequence only (no POG) version. Forward or Viterbi */ __pyx_v_use_scaling = ((int)1); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("calc_rows", 0, 17, 20, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("cogent.align._pairwise_seqs.calc_rows", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_6cogent_5align_14_pairwise_seqs_2calc_rows(__pyx_self, __pyx_v_plan, __pyx_v_seq1_index, __pyx_v_seq2_index, __pyx_v_i_low, __pyx_v_i_high, __pyx_v_j_low, __pyx_v_j_high, __pyx_v_preds, __pyx_v_state_directions, __pyx_v_T, __pyx_v_xgap_scores, __pyx_v_ygap_scores, __pyx_v_match_scores, __pyx_v_rows, __pyx_v_track, __pyx_v_track_enc, __pyx_v_viterbi, __pyx_v_use_logs, __pyx_v_local, __pyx_v_use_scaling); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "cogent/align/_pairwise_seqs.pyx":35 * ctypedef unsigned char [:,:,::1] UChar3D * * def calc_rows(Long1D plan, Long1D seq1_index, Long1D seq2_index, # <<<<<<<<<<<<<< * int i_low, int i_high, int j_low, int j_high, preds, * Long2D state_directions, Double2D T, */ static PyObject *__pyx_pf_6cogent_5align_14_pairwise_seqs_2calc_rows(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_6cogent_5align_14_pairwise_seqs_Long1D __pyx_v_plan, __pyx_t_6cogent_5align_14_pairwise_seqs_Long1D __pyx_v_seq1_index, __pyx_t_6cogent_5align_14_pairwise_seqs_Long1D __pyx_v_seq2_index, int __pyx_v_i_low, int __pyx_v_i_high, int __pyx_v_j_low, int __pyx_v_j_high, CYTHON_UNUSED PyObject *__pyx_v_preds, __pyx_t_6cogent_5align_14_pairwise_seqs_Long2D __pyx_v_state_directions, __pyx_t_6cogent_5align_14_pairwise_seqs_Double2D __pyx_v_T, __pyx_t_6cogent_5align_14_pairwise_seqs_Double2D __pyx_v_xgap_scores, __pyx_t_6cogent_5align_14_pairwise_seqs_Double2D __pyx_v_ygap_scores, __pyx_t_6cogent_5align_14_pairwise_seqs_Double3D __pyx_v_match_scores, PyObject *__pyx_v_rows, __pyx_t_6cogent_5align_14_pairwise_seqs_UChar3D __pyx_v_track, PyObject *__pyx_v_track_enc, int __pyx_v_viterbi, int __pyx_v_use_logs, int __pyx_v_local, int __pyx_v_use_scaling) { int __pyx_v_prev_j; int __pyx_v_state; int __pyx_v_prev_state; int __pyx_v_min_prev_state; int __pyx_v_N; int __pyx_v_row_length; int __pyx_v_row_count; int __pyx_v_tmp_rows; int __pyx_v_a; int __pyx_v_b; int __pyx_v_dest_states; int __pyx_v_dest_state; int __pyx_v_d4; int __pyx_v_j; int __pyx_v_i; int __pyx_v_last_i; int __pyx_v_last_j; int __pyx_v_last_state; int __pyx_v_bin; int __pyx_v_x; int __pyx_v_y; int __pyx_v_bin_count; int __pyx_v_max_x; int __pyx_v_max_y; int __pyx_v_current_row_index; int __pyx_v_source_row_index; int __pyx_v_source_i; int __pyx_v_dx; int __pyx_v_dy; int __pyx_v_tcode_x; int __pyx_v_tcode_y; int __pyx_v_tcode_s; double __pyx_v_d_score; double __pyx_v_mantissa; double __pyx_v_partial_sum; double __pyx_v_sub_partial_sum; double __pyx_v_max_mantissa; double __pyx_v_overall_max_mantissa; long __pyx_v_exponent; long __pyx_v_max_exponent; long __pyx_v_overall_max_exponent; __pyx_t_6cogent_5align_14_pairwise_seqs_Double3D __pyx_v_mantissas = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_seqs_Long3D __pyx_v_exponents = { 0, 0, { 0 }, { 0 }, { 0 } }; long __pyx_v_pointer_a; long __pyx_v_pointer_b; long __pyx_v_pointer_state; double __pyx_v_impossible; double __pyx_v_score; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_t_4; long __pyx_t_5; 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; PyObject *(*__pyx_t_12)(PyObject *); __pyx_t_6cogent_5align_14_pairwise_seqs_Double3D __pyx_t_13 = { 0, 0, { 0 }, { 0 }, { 0 } }; __pyx_t_6cogent_5align_14_pairwise_seqs_Long3D __pyx_t_14 = { 0, 0, { 0 }, { 0 }, { 0 } }; PyObject *__pyx_t_15 = NULL; int __pyx_t_16; int __pyx_t_17; __pyx_t_6cogent_5align_14_pairwise_seqs_UChar3D __pyx_t_18 = { 0, 0, { 0 }, { 0 }, { 0 } }; int __pyx_t_19; int __pyx_t_20; int __pyx_t_21; Py_ssize_t __pyx_t_22; int __pyx_t_23; Py_ssize_t __pyx_t_24; int __pyx_t_25; Py_ssize_t __pyx_t_26; int __pyx_t_27; Py_ssize_t __pyx_t_28; int __pyx_t_29; Py_ssize_t __pyx_t_30; int __pyx_t_31; double __pyx_t_32; int __pyx_t_33; int __pyx_t_34; int __pyx_t_35; int __pyx_t_36; int __pyx_t_37; int __pyx_t_38; int __pyx_t_39; int __pyx_t_40; int __pyx_t_41; int __pyx_t_42; int __pyx_t_43; int __pyx_t_44; int __pyx_t_45; int __pyx_t_46; int __pyx_t_47; int __pyx_t_48; int __pyx_t_49; int __pyx_t_50; int __pyx_t_51; int __pyx_t_52; int __pyx_t_53; int __pyx_t_54; int __pyx_t_55; int __pyx_t_56; int __pyx_t_57; int __pyx_t_58; int __pyx_t_59; int __pyx_t_60; int __pyx_t_61; int __pyx_t_62; int __pyx_t_63; int __pyx_t_64; int __pyx_t_65; int __pyx_t_66; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("calc_rows", 0); /* "cogent/align/_pairwise_seqs.pyx":70 * cdef long pointer_a, pointer_b, pointer_state * * assert not (use_logs and not viterbi) # <<<<<<<<<<<<<< * assert not (use_logs and use_scaling) * assert not (local and not viterbi) */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (__pyx_v_use_logs) { __pyx_t_1 = (!__pyx_v_viterbi); __pyx_t_2 = __pyx_t_1; } else { __pyx_t_2 = __pyx_v_use_logs; } if (unlikely(!(!__pyx_t_2))) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif /* "cogent/align/_pairwise_seqs.pyx":71 * * assert not (use_logs and not viterbi) * assert not (use_logs and use_scaling) # <<<<<<<<<<<<<< * assert not (local and not viterbi) * */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (__pyx_v_use_logs) { __pyx_t_2 = __pyx_v_use_scaling; } else { __pyx_t_2 = __pyx_v_use_logs; } if (unlikely(!(!__pyx_t_2))) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif /* "cogent/align/_pairwise_seqs.pyx":72 * assert not (use_logs and not viterbi) * assert not (use_logs and use_scaling) * assert not (local and not viterbi) # <<<<<<<<<<<<<< * * N = 0 */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (__pyx_v_local) { __pyx_t_2 = (!__pyx_v_viterbi); __pyx_t_1 = __pyx_t_2; } else { __pyx_t_1 = __pyx_v_local; } if (unlikely(!(!__pyx_t_1))) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif /* "cogent/align/_pairwise_seqs.pyx":74 * assert not (local and not viterbi) * * N = 0 # <<<<<<<<<<<<<< * checkArray2D(T, &N, &N) * row_length = 0 */ __pyx_v_N = 0; /* "cogent/align/_pairwise_seqs.pyx":75 * * N = 0 * checkArray2D(T, &N, &N) # <<<<<<<<<<<<<< * row_length = 0 * row_count = 0 */ __pyx_t_3 = __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray2D(__pyx_v_T, (&__pyx_v_N), (&__pyx_v_N)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":76 * N = 0 * checkArray2D(T, &N, &N) * row_length = 0 # <<<<<<<<<<<<<< * row_count = 0 * checkArray1D(plan, &row_count) */ __pyx_v_row_length = 0; /* "cogent/align/_pairwise_seqs.pyx":77 * checkArray2D(T, &N, &N) * row_length = 0 * row_count = 0 # <<<<<<<<<<<<<< * checkArray1D(plan, &row_count) * */ __pyx_v_row_count = 0; /* "cogent/align/_pairwise_seqs.pyx":78 * row_length = 0 * row_count = 0 * checkArray1D(plan, &row_count) # <<<<<<<<<<<<<< * * dest_states = 0 */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray1D(__pyx_v_plan, (&__pyx_v_row_count)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":80 * checkArray1D(plan, &row_count) * * dest_states = 0 # <<<<<<<<<<<<<< * d4 = 4 * # Array of (state, bin, dx, dy) tuples describing the HMM states. */ __pyx_v_dest_states = 0; /* "cogent/align/_pairwise_seqs.pyx":81 * * dest_states = 0 * d4 = 4 # <<<<<<<<<<<<<< * # Array of (state, bin, dx, dy) tuples describing the HMM states. * checkArray2D(state_directions, &dest_states, &d4) */ __pyx_v_d4 = 4; /* "cogent/align/_pairwise_seqs.pyx":83 * d4 = 4 * # Array of (state, bin, dx, dy) tuples describing the HMM states. * checkArray2D(state_directions, &dest_states, &d4) # <<<<<<<<<<<<<< * * checkArray1D(seq1_index, &row_count) */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray2D(__pyx_v_state_directions, (&__pyx_v_dest_states), (&__pyx_v_d4)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":85 * checkArray2D(state_directions, &dest_states, &d4) * * checkArray1D(seq1_index, &row_count) # <<<<<<<<<<<<<< * checkArray1D(seq2_index, &row_length) * */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray1D(__pyx_v_seq1_index, (&__pyx_v_row_count)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":86 * * checkArray1D(seq1_index, &row_count) * checkArray1D(seq2_index, &row_length) # <<<<<<<<<<<<<< * * max_x = max_y = bin_count = 0 */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray1D(__pyx_v_seq2_index, (&__pyx_v_row_length)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":88 * checkArray1D(seq2_index, &row_length) * * max_x = max_y = bin_count = 0 # <<<<<<<<<<<<<< * checkArray3D(match_scores, &bin_count, &max_x, &max_y) * checkArray2D(xgap_scores, &bin_count, &max_x) */ __pyx_v_max_x = 0; __pyx_v_max_y = 0; __pyx_v_bin_count = 0; /* "cogent/align/_pairwise_seqs.pyx":89 * * max_x = max_y = bin_count = 0 * checkArray3D(match_scores, &bin_count, &max_x, &max_y) # <<<<<<<<<<<<<< * checkArray2D(xgap_scores, &bin_count, &max_x) * checkArray2D(ygap_scores, &bin_count, &max_y) */ __pyx_t_3 = __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray3D(__pyx_v_match_scores, (&__pyx_v_bin_count), (&__pyx_v_max_x), (&__pyx_v_max_y)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":90 * max_x = max_y = bin_count = 0 * checkArray3D(match_scores, &bin_count, &max_x, &max_y) * checkArray2D(xgap_scores, &bin_count, &max_x) # <<<<<<<<<<<<<< * checkArray2D(ygap_scores, &bin_count, &max_y) * */ __pyx_t_3 = __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray2D(__pyx_v_xgap_scores, (&__pyx_v_bin_count), (&__pyx_v_max_x)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":91 * checkArray3D(match_scores, &bin_count, &max_x, &max_y) * checkArray2D(xgap_scores, &bin_count, &max_x) * checkArray2D(ygap_scores, &bin_count, &max_y) # <<<<<<<<<<<<<< * * for i from 0 <= i < row_count: */ __pyx_t_3 = __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray2D(__pyx_v_ygap_scores, (&__pyx_v_bin_count), (&__pyx_v_max_y)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":93 * checkArray2D(ygap_scores, &bin_count, &max_y) * * for i from 0 <= i < row_count: # <<<<<<<<<<<<<< * assert 0 <= seq1_index[i] < max_x * for j from 0 <= j < row_length: */ __pyx_t_3 = __pyx_v_row_count; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { /* "cogent/align/_pairwise_seqs.pyx":94 * * for i from 0 <= i < row_count: * assert 0 <= seq1_index[i] < max_x # <<<<<<<<<<<<<< * for j from 0 <= j < row_length: * assert 0 <= seq2_index[j] < max_y */ #ifndef CYTHON_WITHOUT_ASSERTIONS __pyx_t_4 = __pyx_v_i; __pyx_t_5 = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_seq1_index.data) + __pyx_t_4)) ))); __pyx_t_1 = (0 <= __pyx_t_5); if (__pyx_t_1) { __pyx_t_1 = (__pyx_t_5 < __pyx_v_max_x); } if (unlikely(!__pyx_t_1)) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif } /* "cogent/align/_pairwise_seqs.pyx":95 * for i from 0 <= i < row_count: * assert 0 <= seq1_index[i] < max_x * for j from 0 <= j < row_length: # <<<<<<<<<<<<<< * assert 0 <= seq2_index[j] < max_y * */ __pyx_t_3 = __pyx_v_row_length; for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { /* "cogent/align/_pairwise_seqs.pyx":96 * assert 0 <= seq1_index[i] < max_x * for j from 0 <= j < row_length: * assert 0 <= seq2_index[j] < max_y # <<<<<<<<<<<<<< * * assert j_low >= 0 and j_high > j_low and j_high <= row_length */ #ifndef CYTHON_WITHOUT_ASSERTIONS __pyx_t_6 = __pyx_v_j; __pyx_t_5 = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_seq2_index.data) + __pyx_t_6)) ))); __pyx_t_1 = (0 <= __pyx_t_5); if (__pyx_t_1) { __pyx_t_1 = (__pyx_t_5 < __pyx_v_max_y); } if (unlikely(!__pyx_t_1)) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif } /* "cogent/align/_pairwise_seqs.pyx":98 * assert 0 <= seq2_index[j] < max_y * * assert j_low >= 0 and j_high > j_low and j_high <= row_length # <<<<<<<<<<<<<< * * (mantissas, exponents) = rows */ #ifndef CYTHON_WITHOUT_ASSERTIONS __pyx_t_1 = (__pyx_v_j_low >= 0); if (__pyx_t_1) { __pyx_t_2 = (__pyx_v_j_high > __pyx_v_j_low); if (__pyx_t_2) { __pyx_t_7 = (__pyx_v_j_high <= __pyx_v_row_length); __pyx_t_8 = __pyx_t_7; } else { __pyx_t_8 = __pyx_t_2; } __pyx_t_2 = __pyx_t_8; } else { __pyx_t_2 = __pyx_t_1; } if (unlikely(!__pyx_t_2)) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif /* "cogent/align/_pairwise_seqs.pyx":100 * assert j_low >= 0 and j_high > j_low and j_high <= row_length * * (mantissas, exponents) = rows # <<<<<<<<<<<<<< * tmp_rows = 0 * checkArray3D(mantissas, &tmp_rows, &row_length, &N) */ if ((likely(PyTuple_CheckExact(__pyx_v_rows))) || (PyList_CheckExact(__pyx_v_rows))) { PyObject* sequence = __pyx_v_rows; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_9 = PyList_GET_ITEM(sequence, 0); __pyx_t_10 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(__pyx_t_10); #else __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { Py_ssize_t index = -1; __pyx_t_11 = PyObject_GetIter(__pyx_v_rows); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __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_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L8_unpacking_done:; } __pyx_t_13 = __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_double(__pyx_t_9); if (unlikely(!__pyx_t_13.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_14 = __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_long(__pyx_t_10); if (unlikely(!__pyx_t_14.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_v_mantissas = __pyx_t_13; __pyx_t_13.memview = NULL; __pyx_t_13.data = NULL; __pyx_v_exponents = __pyx_t_14; __pyx_t_14.memview = NULL; __pyx_t_14.data = NULL; /* "cogent/align/_pairwise_seqs.pyx":101 * * (mantissas, exponents) = rows * tmp_rows = 0 # <<<<<<<<<<<<<< * checkArray3D(mantissas, &tmp_rows, &row_length, &N) * if use_scaling: */ __pyx_v_tmp_rows = 0; /* "cogent/align/_pairwise_seqs.pyx":102 * (mantissas, exponents) = rows * tmp_rows = 0 * checkArray3D(mantissas, &tmp_rows, &row_length, &N) # <<<<<<<<<<<<<< * if use_scaling: * checkArray3D(exponents, &tmp_rows, &row_length, &N) */ __pyx_t_3 = __pyx_fuse_0_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray3D(__pyx_v_mantissas, (&__pyx_v_tmp_rows), (&__pyx_v_row_length), (&__pyx_v_N)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":103 * tmp_rows = 0 * checkArray3D(mantissas, &tmp_rows, &row_length, &N) * if use_scaling: # <<<<<<<<<<<<<< * checkArray3D(exponents, &tmp_rows, &row_length, &N) * */ if (__pyx_v_use_scaling) { /* "cogent/align/_pairwise_seqs.pyx":104 * checkArray3D(mantissas, &tmp_rows, &row_length, &N) * if use_scaling: * checkArray3D(exponents, &tmp_rows, &row_length, &N) # <<<<<<<<<<<<<< * * cdef double impossible */ __pyx_t_3 = __pyx_fuse_1_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray3D(__pyx_v_exponents, (&__pyx_v_tmp_rows), (&__pyx_v_row_length), (&__pyx_v_N)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L9; } __pyx_L9:; /* "cogent/align/_pairwise_seqs.pyx":107 * * cdef double impossible * if use_logs: # <<<<<<<<<<<<<< * impossible = log(0.0) # -inf * else: */ if (__pyx_v_use_logs) { /* "cogent/align/_pairwise_seqs.pyx":108 * cdef double impossible * if use_logs: * impossible = log(0.0) # -inf # <<<<<<<<<<<<<< * else: * impossible = 0.0 */ __pyx_v_impossible = log(0.0); goto __pyx_L10; } /*else*/ { /* "cogent/align/_pairwise_seqs.pyx":110 * impossible = log(0.0) # -inf * else: * impossible = 0.0 # <<<<<<<<<<<<<< * * if viterbi and track is not None and track_enc is not None: */ __pyx_v_impossible = 0.0; } __pyx_L10:; /* "cogent/align/_pairwise_seqs.pyx":112 * impossible = 0.0 * * if viterbi and track is not None and track_enc is not None: # <<<<<<<<<<<<<< * checkArray3D(track, &row_count, &row_length, &N) * (tcode_x, tcode_y, tcode_s) = track_enc */ if (__pyx_v_viterbi) { __pyx_t_2 = (((PyObject *) __pyx_v_track.memview) != Py_None); if (__pyx_t_2) { __pyx_t_1 = (__pyx_v_track_enc != Py_None); __pyx_t_8 = __pyx_t_1; } else { __pyx_t_8 = __pyx_t_2; } __pyx_t_2 = __pyx_t_8; } else { __pyx_t_2 = __pyx_v_viterbi; } if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":113 * * if viterbi and track is not None and track_enc is not None: * checkArray3D(track, &row_count, &row_length, &N) # <<<<<<<<<<<<<< * (tcode_x, tcode_y, tcode_s) = track_enc * else: */ __pyx_t_3 = __pyx_fuse_2_2__pyx_f_6cogent_5align_14_pairwise_seqs_checkArray3D(__pyx_v_track, (&__pyx_v_row_count), (&__pyx_v_row_length), (&__pyx_v_N)); if (unlikely(__pyx_t_3 == 1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":114 * if viterbi and track is not None and track_enc is not None: * checkArray3D(track, &row_count, &row_length, &N) * (tcode_x, tcode_y, tcode_s) = track_enc # <<<<<<<<<<<<<< * else: * track = None */ if ((likely(PyTuple_CheckExact(__pyx_v_track_enc))) || (PyList_CheckExact(__pyx_v_track_enc))) { PyObject* sequence = __pyx_v_track_enc; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 3)) { if (size > 3) __Pyx_RaiseTooManyValuesError(3); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); __pyx_t_11 = PyTuple_GET_ITEM(sequence, 2); } else { __pyx_t_10 = PyList_GET_ITEM(sequence, 0); __pyx_t_9 = PyList_GET_ITEM(sequence, 1); __pyx_t_11 = PyList_GET_ITEM(sequence, 2); } __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(__pyx_t_11); #else __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_11 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { Py_ssize_t index = -1; __pyx_t_15 = PyObject_GetIter(__pyx_v_track_enc); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_15); __pyx_t_12 = Py_TYPE(__pyx_t_15)->tp_iternext; index = 0; __pyx_t_10 = __pyx_t_12(__pyx_t_15); if (unlikely(!__pyx_t_10)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_10); index = 1; __pyx_t_9 = __pyx_t_12(__pyx_t_15); if (unlikely(!__pyx_t_9)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_9); index = 2; __pyx_t_11 = __pyx_t_12(__pyx_t_15); if (unlikely(!__pyx_t_11)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_11); if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_15), 3) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_12 = NULL; __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; goto __pyx_L13_unpacking_done; __pyx_L12_unpacking_failed:; __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; __pyx_t_12 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L13_unpacking_done:; } __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_10); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_16 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_17 = __Pyx_PyInt_AsInt(__pyx_t_11); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_v_tcode_x = __pyx_t_3; __pyx_v_tcode_y = __pyx_t_16; __pyx_v_tcode_s = __pyx_t_17; goto __pyx_L11; } /*else*/ { /* "cogent/align/_pairwise_seqs.pyx":116 * (tcode_x, tcode_y, tcode_s) = track_enc * else: * track = None # <<<<<<<<<<<<<< * tcode_x = tcode_y = tcode_s = 0 * */ __pyx_t_18 = __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_unsigned_char(Py_None); if (unlikely(!__pyx_t_18.memview)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __PYX_XDEC_MEMVIEW(&__pyx_v_track, 1); __pyx_v_track = __pyx_t_18; __pyx_t_18.memview = NULL; __pyx_t_18.data = NULL; /* "cogent/align/_pairwise_seqs.pyx":117 * else: * track = None * tcode_x = tcode_y = tcode_s = 0 # <<<<<<<<<<<<<< * * # For local */ __pyx_v_tcode_x = 0; __pyx_v_tcode_y = 0; __pyx_v_tcode_s = 0; } __pyx_L11:; /* "cogent/align/_pairwise_seqs.pyx":120 * * # For local * overall_max_exponent = MIN_SCALE # <<<<<<<<<<<<<< * overall_max_mantissa = impossible * last_i = last_j = last_state = -1 */ __pyx_v_overall_max_exponent = __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_SCALE; /* "cogent/align/_pairwise_seqs.pyx":121 * # For local * overall_max_exponent = MIN_SCALE * overall_max_mantissa = impossible # <<<<<<<<<<<<<< * last_i = last_j = last_state = -1 * */ __pyx_v_overall_max_mantissa = __pyx_v_impossible; /* "cogent/align/_pairwise_seqs.pyx":122 * overall_max_exponent = MIN_SCALE * overall_max_mantissa = impossible * last_i = last_j = last_state = -1 # <<<<<<<<<<<<<< * * for i from i_low <= i < i_high: */ __pyx_v_last_i = -1; __pyx_v_last_j = -1; __pyx_v_last_state = -1; /* "cogent/align/_pairwise_seqs.pyx":124 * last_i = last_j = last_state = -1 * * for i from i_low <= i < i_high: # <<<<<<<<<<<<<< * x = seq1_index[i] * */ __pyx_t_17 = __pyx_v_i_high; for (__pyx_v_i = __pyx_v_i_low; __pyx_v_i < __pyx_t_17; __pyx_v_i++) { /* "cogent/align/_pairwise_seqs.pyx":125 * * for i from i_low <= i < i_high: * x = seq1_index[i] # <<<<<<<<<<<<<< * * if PyErr_CheckSignals(): */ __pyx_t_16 = __pyx_v_i; __pyx_v_x = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_seq1_index.data) + __pyx_t_16)) ))); /* "cogent/align/_pairwise_seqs.pyx":127 * x = seq1_index[i] * * if PyErr_CheckSignals(): # <<<<<<<<<<<<<< * raise PyErr_Occurred() * */ __pyx_t_3 = PyErr_CheckSignals(); if (__pyx_t_3) { /* "cogent/align/_pairwise_seqs.pyx":128 * * if PyErr_CheckSignals(): * raise PyErr_Occurred() # <<<<<<<<<<<<<< * * current_row_index = plan[i] */ __pyx_t_11 = PyErr_Occurred(); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[1]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L16; } __pyx_L16:; /* "cogent/align/_pairwise_seqs.pyx":130 * raise PyErr_Occurred() * * current_row_index = plan[i] # <<<<<<<<<<<<<< * * #for prev_state from 1 <= prev_state < N: */ __pyx_t_3 = __pyx_v_i; __pyx_v_current_row_index = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_plan.data) + __pyx_t_3)) ))); /* "cogent/align/_pairwise_seqs.pyx":135 * # current_row_data[0, prev_state] = impossible * * for j from j_low <= j < j_high: # <<<<<<<<<<<<<< * * for dest_state from 0 <= dest_state < dest_states: */ __pyx_t_19 = __pyx_v_j_high; for (__pyx_v_j = __pyx_v_j_low; __pyx_v_j < __pyx_t_19; __pyx_v_j++) { /* "cogent/align/_pairwise_seqs.pyx":137 * for j from j_low <= j < j_high: * * for dest_state from 0 <= dest_state < dest_states: # <<<<<<<<<<<<<< * state = state_directions[dest_state, 0] * bin = state_directions[dest_state, 1] */ __pyx_t_20 = __pyx_v_dest_states; for (__pyx_v_dest_state = 0; __pyx_v_dest_state < __pyx_t_20; __pyx_v_dest_state++) { /* "cogent/align/_pairwise_seqs.pyx":138 * * for dest_state from 0 <= dest_state < dest_states: * state = state_directions[dest_state, 0] # <<<<<<<<<<<<<< * bin = state_directions[dest_state, 1] * dx = state_directions[dest_state, 2] */ __pyx_t_21 = __pyx_v_dest_state; __pyx_t_22 = 0; __pyx_v_state = (*((long *) ( /* dim=1 */ ((char *) (((long *) ( /* dim=0 */ (__pyx_v_state_directions.data + __pyx_t_21 * __pyx_v_state_directions.strides[0]) )) + __pyx_t_22)) ))); /* "cogent/align/_pairwise_seqs.pyx":139 * for dest_state from 0 <= dest_state < dest_states: * state = state_directions[dest_state, 0] * bin = state_directions[dest_state, 1] # <<<<<<<<<<<<<< * dx = state_directions[dest_state, 2] * dy = state_directions[dest_state, 3] */ __pyx_t_23 = __pyx_v_dest_state; __pyx_t_24 = 1; __pyx_v_bin = (*((long *) ( /* dim=1 */ ((char *) (((long *) ( /* dim=0 */ (__pyx_v_state_directions.data + __pyx_t_23 * __pyx_v_state_directions.strides[0]) )) + __pyx_t_24)) ))); /* "cogent/align/_pairwise_seqs.pyx":140 * state = state_directions[dest_state, 0] * bin = state_directions[dest_state, 1] * dx = state_directions[dest_state, 2] # <<<<<<<<<<<<<< * dy = state_directions[dest_state, 3] * */ __pyx_t_25 = __pyx_v_dest_state; __pyx_t_26 = 2; __pyx_v_dx = (*((long *) ( /* dim=1 */ ((char *) (((long *) ( /* dim=0 */ (__pyx_v_state_directions.data + __pyx_t_25 * __pyx_v_state_directions.strides[0]) )) + __pyx_t_26)) ))); /* "cogent/align/_pairwise_seqs.pyx":141 * bin = state_directions[dest_state, 1] * dx = state_directions[dest_state, 2] * dy = state_directions[dest_state, 3] # <<<<<<<<<<<<<< * * max_mantissa = impossible */ __pyx_t_27 = __pyx_v_dest_state; __pyx_t_28 = 3; __pyx_v_dy = (*((long *) ( /* dim=1 */ ((char *) (((long *) ( /* dim=0 */ (__pyx_v_state_directions.data + __pyx_t_27 * __pyx_v_state_directions.strides[0]) )) + __pyx_t_28)) ))); /* "cogent/align/_pairwise_seqs.pyx":143 * dy = state_directions[dest_state, 3] * * max_mantissa = impossible # <<<<<<<<<<<<<< * max_exponent = MIN_SCALE * partial_sum = 0.0 */ __pyx_v_max_mantissa = __pyx_v_impossible; /* "cogent/align/_pairwise_seqs.pyx":144 * * max_mantissa = impossible * max_exponent = MIN_SCALE # <<<<<<<<<<<<<< * partial_sum = 0.0 * pointer_state = N # ie ERROR */ __pyx_v_max_exponent = __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_SCALE; /* "cogent/align/_pairwise_seqs.pyx":145 * max_mantissa = impossible * max_exponent = MIN_SCALE * partial_sum = 0.0 # <<<<<<<<<<<<<< * pointer_state = N # ie ERROR * */ __pyx_v_partial_sum = 0.0; /* "cogent/align/_pairwise_seqs.pyx":146 * max_exponent = MIN_SCALE * partial_sum = 0.0 * pointer_state = N # ie ERROR # <<<<<<<<<<<<<< * * source_i = i - dx */ __pyx_v_pointer_state = __pyx_v_N; /* "cogent/align/_pairwise_seqs.pyx":148 * pointer_state = N # ie ERROR * * source_i = i - dx # <<<<<<<<<<<<<< * if source_i < 0: * continue */ __pyx_v_source_i = (__pyx_v_i - __pyx_v_dx); /* "cogent/align/_pairwise_seqs.pyx":149 * * source_i = i - dx * if source_i < 0: # <<<<<<<<<<<<<< * continue * source_row_index = plan[source_i] */ __pyx_t_2 = (__pyx_v_source_i < 0); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":150 * source_i = i - dx * if source_i < 0: * continue # <<<<<<<<<<<<<< * source_row_index = plan[source_i] * */ goto __pyx_L19_continue; goto __pyx_L21; } __pyx_L21:; /* "cogent/align/_pairwise_seqs.pyx":151 * if source_i < 0: * continue * source_row_index = plan[source_i] # <<<<<<<<<<<<<< * * prev_j = j - dy */ __pyx_t_29 = __pyx_v_source_i; __pyx_v_source_row_index = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_plan.data) + __pyx_t_29)) ))); /* "cogent/align/_pairwise_seqs.pyx":153 * source_row_index = plan[source_i] * * prev_j = j - dy # <<<<<<<<<<<<<< * if prev_j < 0: * continue */ __pyx_v_prev_j = (__pyx_v_j - __pyx_v_dy); /* "cogent/align/_pairwise_seqs.pyx":154 * * prev_j = j - dy * if prev_j < 0: # <<<<<<<<<<<<<< * continue * */ __pyx_t_2 = (__pyx_v_prev_j < 0); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":155 * prev_j = j - dy * if prev_j < 0: * continue # <<<<<<<<<<<<<< * * min_prev_state = 1 */ goto __pyx_L19_continue; goto __pyx_L22; } __pyx_L22:; /* "cogent/align/_pairwise_seqs.pyx":157 * continue * * min_prev_state = 1 # <<<<<<<<<<<<<< * a = dx * b = dy */ __pyx_v_min_prev_state = 1; /* "cogent/align/_pairwise_seqs.pyx":158 * * min_prev_state = 1 * a = dx # <<<<<<<<<<<<<< * b = dy * */ __pyx_v_a = __pyx_v_dx; /* "cogent/align/_pairwise_seqs.pyx":159 * min_prev_state = 1 * a = dx * b = dy # <<<<<<<<<<<<<< * * if (local and dx and dy) or (prev_j == 0 and source_i == 0): */ __pyx_v_b = __pyx_v_dy; /* "cogent/align/_pairwise_seqs.pyx":161 * b = dy * * if (local and dx and dy) or (prev_j == 0 and source_i == 0): # <<<<<<<<<<<<<< * partial_sum = max_mantissa = T[0, state] * max_exponent = 0 */ if (__pyx_v_local) { if (__pyx_v_dx) { __pyx_t_2 = __pyx_v_dy; } else { __pyx_t_2 = __pyx_v_dx; } __pyx_t_8 = __pyx_t_2; } else { __pyx_t_8 = __pyx_v_local; } if (!__pyx_t_8) { __pyx_t_2 = (__pyx_v_prev_j == 0); if (__pyx_t_2) { __pyx_t_1 = (__pyx_v_source_i == 0); __pyx_t_7 = __pyx_t_1; } else { __pyx_t_7 = __pyx_t_2; } __pyx_t_2 = __pyx_t_7; } else { __pyx_t_2 = __pyx_t_8; } if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":162 * * if (local and dx and dy) or (prev_j == 0 and source_i == 0): * partial_sum = max_mantissa = T[0, state] # <<<<<<<<<<<<<< * max_exponent = 0 * pointer_state = 0 */ __pyx_t_30 = 0; __pyx_t_31 = __pyx_v_state; __pyx_t_32 = (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_T.data + __pyx_t_30 * __pyx_v_T.strides[0]) )) + __pyx_t_31)) ))); __pyx_v_partial_sum = __pyx_t_32; __pyx_v_max_mantissa = __pyx_t_32; /* "cogent/align/_pairwise_seqs.pyx":163 * if (local and dx and dy) or (prev_j == 0 and source_i == 0): * partial_sum = max_mantissa = T[0, state] * max_exponent = 0 # <<<<<<<<<<<<<< * pointer_state = 0 * pointer_a = a */ __pyx_v_max_exponent = 0; /* "cogent/align/_pairwise_seqs.pyx":164 * partial_sum = max_mantissa = T[0, state] * max_exponent = 0 * pointer_state = 0 # <<<<<<<<<<<<<< * pointer_a = a * pointer_b = b */ __pyx_v_pointer_state = 0; /* "cogent/align/_pairwise_seqs.pyx":165 * max_exponent = 0 * pointer_state = 0 * pointer_a = a # <<<<<<<<<<<<<< * pointer_b = b * */ __pyx_v_pointer_a = __pyx_v_a; /* "cogent/align/_pairwise_seqs.pyx":166 * pointer_state = 0 * pointer_a = a * pointer_b = b # <<<<<<<<<<<<<< * * if use_scaling: */ __pyx_v_pointer_b = __pyx_v_b; goto __pyx_L23; } __pyx_L23:; /* "cogent/align/_pairwise_seqs.pyx":168 * pointer_b = b * * if use_scaling: # <<<<<<<<<<<<<< * sub_partial_sum = 0.0 * for prev_state from min_prev_state <= prev_state < N: */ if (__pyx_v_use_scaling) { /* "cogent/align/_pairwise_seqs.pyx":169 * * if use_scaling: * sub_partial_sum = 0.0 # <<<<<<<<<<<<<< * for prev_state from min_prev_state <= prev_state < N: * exponent = exponents[source_row_index, prev_j, prev_state] */ __pyx_v_sub_partial_sum = 0.0; /* "cogent/align/_pairwise_seqs.pyx":170 * if use_scaling: * sub_partial_sum = 0.0 * for prev_state from min_prev_state <= prev_state < N: # <<<<<<<<<<<<<< * exponent = exponents[source_row_index, prev_j, prev_state] * if exponent == MIN_SCALE: */ __pyx_t_33 = __pyx_v_N; for (__pyx_v_prev_state = __pyx_v_min_prev_state; __pyx_v_prev_state < __pyx_t_33; __pyx_v_prev_state++) { /* "cogent/align/_pairwise_seqs.pyx":171 * sub_partial_sum = 0.0 * for prev_state from min_prev_state <= prev_state < N: * exponent = exponents[source_row_index, prev_j, prev_state] # <<<<<<<<<<<<<< * if exponent == MIN_SCALE: * continue */ __pyx_t_34 = __pyx_v_source_row_index; __pyx_t_35 = __pyx_v_prev_j; __pyx_t_36 = __pyx_v_prev_state; __pyx_v_exponent = (*((long *) ( /* dim=2 */ ((char *) (((long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_exponents.data + __pyx_t_34 * __pyx_v_exponents.strides[0]) ) + __pyx_t_35 * __pyx_v_exponents.strides[1]) )) + __pyx_t_36)) ))); /* "cogent/align/_pairwise_seqs.pyx":172 * for prev_state from min_prev_state <= prev_state < N: * exponent = exponents[source_row_index, prev_j, prev_state] * if exponent == MIN_SCALE: # <<<<<<<<<<<<<< * continue * */ __pyx_t_2 = (__pyx_v_exponent == __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_SCALE); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":173 * exponent = exponents[source_row_index, prev_j, prev_state] * if exponent == MIN_SCALE: * continue # <<<<<<<<<<<<<< * * mantissa = mantissas[source_row_index, prev_j, prev_state] */ goto __pyx_L25_continue; goto __pyx_L27; } __pyx_L27:; /* "cogent/align/_pairwise_seqs.pyx":175 * continue * * mantissa = mantissas[source_row_index, prev_j, prev_state] # <<<<<<<<<<<<<< * mantissa = mantissa * T[prev_state, state] * */ __pyx_t_37 = __pyx_v_source_row_index; __pyx_t_38 = __pyx_v_prev_j; __pyx_t_39 = __pyx_v_prev_state; __pyx_v_mantissa = (*((double *) ( /* dim=2 */ ((char *) (((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_mantissas.data + __pyx_t_37 * __pyx_v_mantissas.strides[0]) ) + __pyx_t_38 * __pyx_v_mantissas.strides[1]) )) + __pyx_t_39)) ))); /* "cogent/align/_pairwise_seqs.pyx":176 * * mantissa = mantissas[source_row_index, prev_j, prev_state] * mantissa = mantissa * T[prev_state, state] # <<<<<<<<<<<<<< * * if mantissa < MIN_FLOAT_VALUE: */ __pyx_t_40 = __pyx_v_prev_state; __pyx_t_41 = __pyx_v_state; __pyx_v_mantissa = (__pyx_v_mantissa * (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_T.data + __pyx_t_40 * __pyx_v_T.strides[0]) )) + __pyx_t_41)) )))); /* "cogent/align/_pairwise_seqs.pyx":178 * mantissa = mantissa * T[prev_state, state] * * if mantissa < MIN_FLOAT_VALUE: # <<<<<<<<<<<<<< * if mantissa == 0.0: * continue */ __pyx_t_2 = (__pyx_v_mantissa < __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_FLOAT_VALUE); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":179 * * if mantissa < MIN_FLOAT_VALUE: * if mantissa == 0.0: # <<<<<<<<<<<<<< * continue * if mantissa < 0.0: */ __pyx_t_2 = (__pyx_v_mantissa == 0.0); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":180 * if mantissa < MIN_FLOAT_VALUE: * if mantissa == 0.0: * continue # <<<<<<<<<<<<<< * if mantissa < 0.0: * if T[prev_state, state] < 0.0: */ goto __pyx_L25_continue; goto __pyx_L29; } __pyx_L29:; /* "cogent/align/_pairwise_seqs.pyx":181 * if mantissa == 0.0: * continue * if mantissa < 0.0: # <<<<<<<<<<<<<< * if T[prev_state, state] < 0.0: * raise ArithmeticError(fmpt(mantissa, exponent, */ __pyx_t_2 = (__pyx_v_mantissa < 0.0); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":182 * continue * if mantissa < 0.0: * if T[prev_state, state] < 0.0: # <<<<<<<<<<<<<< * raise ArithmeticError(fmpt(mantissa, exponent, * "transition is a negative probability")) */ __pyx_t_42 = __pyx_v_prev_state; __pyx_t_43 = __pyx_v_state; __pyx_t_2 = ((*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_T.data + __pyx_t_42 * __pyx_v_T.strides[0]) )) + __pyx_t_43)) ))) < 0.0); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":183 * if mantissa < 0.0: * if T[prev_state, state] < 0.0: * raise ArithmeticError(fmpt(mantissa, exponent, # <<<<<<<<<<<<<< * "transition is a negative probability")) * raise ArithmeticError(fmpt(mantissa, exponent, */ __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__fmpt); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __pyx_t_9 = PyFloat_FromDouble(__pyx_v_mantissa); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = PyInt_FromLong(__pyx_v_exponent); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); __Pyx_INCREF(((PyObject *)__pyx_kp_s_12)); PyTuple_SET_ITEM(__pyx_t_15, 2, ((PyObject *)__pyx_kp_s_12)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_12)); __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_builtin_ArithmeticError, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; __Pyx_Raise(__pyx_t_10, 0, 0, 0); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L31; } __pyx_L31:; /* "cogent/align/_pairwise_seqs.pyx":185 * raise ArithmeticError(fmpt(mantissa, exponent, * "transition is a negative probability")) * raise ArithmeticError(fmpt(mantissa, exponent, # <<<<<<<<<<<<<< * "product is a negative probability")) * while mantissa < MIN_FLOAT_VALUE: */ __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__fmpt); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_15 = PyFloat_FromDouble(__pyx_v_mantissa); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_15); __pyx_t_11 = PyInt_FromLong(__pyx_v_exponent); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_15); __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_11); __Pyx_GIVEREF(__pyx_t_11); __Pyx_INCREF(((PyObject *)__pyx_kp_s_13)); PyTuple_SET_ITEM(__pyx_t_9, 2, ((PyObject *)__pyx_kp_s_13)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13)); __pyx_t_15 = 0; __pyx_t_11 = 0; __pyx_t_11 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_11); __Pyx_GIVEREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_11 = PyObject_Call(__pyx_builtin_ArithmeticError, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; __Pyx_Raise(__pyx_t_11, 0, 0, 0); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L30; } __pyx_L30:; /* "cogent/align/_pairwise_seqs.pyx":187 * raise ArithmeticError(fmpt(mantissa, exponent, * "product is a negative probability")) * while mantissa < MIN_FLOAT_VALUE: # <<<<<<<<<<<<<< * mantissa *= SCALE_STEP * exponent += -1 */ while (1) { __pyx_t_2 = (__pyx_v_mantissa < __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_FLOAT_VALUE); if (!__pyx_t_2) break; /* "cogent/align/_pairwise_seqs.pyx":188 * "product is a negative probability")) * while mantissa < MIN_FLOAT_VALUE: * mantissa *= SCALE_STEP # <<<<<<<<<<<<<< * exponent += -1 * if exponent <= MIN_SCALE: */ __pyx_v_mantissa = (__pyx_v_mantissa * __pyx_v_6cogent_5align_14_pairwise_seqs_SCALE_STEP); /* "cogent/align/_pairwise_seqs.pyx":189 * while mantissa < MIN_FLOAT_VALUE: * mantissa *= SCALE_STEP * exponent += -1 # <<<<<<<<<<<<<< * if exponent <= MIN_SCALE: * raise ArithmeticError(fmpt(mantissa, exponent, */ __pyx_v_exponent = (__pyx_v_exponent + -1); /* "cogent/align/_pairwise_seqs.pyx":190 * mantissa *= SCALE_STEP * exponent += -1 * if exponent <= MIN_SCALE: # <<<<<<<<<<<<<< * raise ArithmeticError(fmpt(mantissa, exponent, * "underflows")) */ __pyx_t_2 = (__pyx_v_exponent <= __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_SCALE); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":191 * exponent += -1 * if exponent <= MIN_SCALE: * raise ArithmeticError(fmpt(mantissa, exponent, # <<<<<<<<<<<<<< * "underflows")) * */ __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__fmpt); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __pyx_t_9 = PyFloat_FromDouble(__pyx_v_mantissa); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = PyInt_FromLong(__pyx_v_exponent); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); __Pyx_INCREF(((PyObject *)__pyx_n_s__underflows)); PyTuple_SET_ITEM(__pyx_t_15, 2, ((PyObject *)__pyx_n_s__underflows)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__underflows)); __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_builtin_ArithmeticError, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; __Pyx_Raise(__pyx_t_10, 0, 0, 0); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L34; } __pyx_L34:; } goto __pyx_L28; } /* "cogent/align/_pairwise_seqs.pyx":194 * "underflows")) * * elif mantissa > 1.0: # <<<<<<<<<<<<<< * mantissa *= MIN_FLOAT_VALUE * exponent += 1 */ __pyx_t_2 = (__pyx_v_mantissa > 1.0); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":195 * * elif mantissa > 1.0: * mantissa *= MIN_FLOAT_VALUE # <<<<<<<<<<<<<< * exponent += 1 * if exponent > MAX_SCALE: */ __pyx_v_mantissa = (__pyx_v_mantissa * __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_FLOAT_VALUE); /* "cogent/align/_pairwise_seqs.pyx":196 * elif mantissa > 1.0: * mantissa *= MIN_FLOAT_VALUE * exponent += 1 # <<<<<<<<<<<<<< * if exponent > MAX_SCALE: * raise ArithmeticError(fmpt(mantissa, exponent, */ __pyx_v_exponent = (__pyx_v_exponent + 1); /* "cogent/align/_pairwise_seqs.pyx":197 * mantissa *= MIN_FLOAT_VALUE * exponent += 1 * if exponent > MAX_SCALE: # <<<<<<<<<<<<<< * raise ArithmeticError(fmpt(mantissa, exponent, * "is unexpectedly large")) */ __pyx_t_2 = (__pyx_v_exponent > __pyx_v_6cogent_5align_14_pairwise_seqs_MAX_SCALE); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":198 * exponent += 1 * if exponent > MAX_SCALE: * raise ArithmeticError(fmpt(mantissa, exponent, # <<<<<<<<<<<<<< * "is unexpectedly large")) * */ __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__fmpt); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_15 = PyFloat_FromDouble(__pyx_v_mantissa); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_15); __pyx_t_11 = PyInt_FromLong(__pyx_v_exponent); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_15); __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_11); __Pyx_GIVEREF(__pyx_t_11); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); PyTuple_SET_ITEM(__pyx_t_9, 2, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); __pyx_t_15 = 0; __pyx_t_11 = 0; __pyx_t_11 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_11); __Pyx_GIVEREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_11 = PyObject_Call(__pyx_builtin_ArithmeticError, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; __Pyx_Raise(__pyx_t_11, 0, 0, 0); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L35; } __pyx_L35:; goto __pyx_L28; } __pyx_L28:; /* "cogent/align/_pairwise_seqs.pyx":201 * "is unexpectedly large")) * * if exponent > max_exponent: # <<<<<<<<<<<<<< * if exponent == max_exponent + 1: * sub_partial_sum = partial_sum */ __pyx_t_2 = (__pyx_v_exponent > __pyx_v_max_exponent); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":202 * * if exponent > max_exponent: * if exponent == max_exponent + 1: # <<<<<<<<<<<<<< * sub_partial_sum = partial_sum * else: */ __pyx_t_2 = (__pyx_v_exponent == (__pyx_v_max_exponent + 1)); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":203 * if exponent > max_exponent: * if exponent == max_exponent + 1: * sub_partial_sum = partial_sum # <<<<<<<<<<<<<< * else: * sub_partial_sum = 0.0 */ __pyx_v_sub_partial_sum = __pyx_v_partial_sum; goto __pyx_L37; } /*else*/ { /* "cogent/align/_pairwise_seqs.pyx":205 * sub_partial_sum = partial_sum * else: * sub_partial_sum = 0.0 # <<<<<<<<<<<<<< * partial_sum = 0.0 * max_mantissa = 0.0 */ __pyx_v_sub_partial_sum = 0.0; } __pyx_L37:; /* "cogent/align/_pairwise_seqs.pyx":206 * else: * sub_partial_sum = 0.0 * partial_sum = 0.0 # <<<<<<<<<<<<<< * max_mantissa = 0.0 * max_exponent = exponent */ __pyx_v_partial_sum = 0.0; /* "cogent/align/_pairwise_seqs.pyx":207 * sub_partial_sum = 0.0 * partial_sum = 0.0 * max_mantissa = 0.0 # <<<<<<<<<<<<<< * max_exponent = exponent * */ __pyx_v_max_mantissa = 0.0; /* "cogent/align/_pairwise_seqs.pyx":208 * partial_sum = 0.0 * max_mantissa = 0.0 * max_exponent = exponent # <<<<<<<<<<<<<< * * if exponent == max_exponent: */ __pyx_v_max_exponent = __pyx_v_exponent; goto __pyx_L36; } __pyx_L36:; /* "cogent/align/_pairwise_seqs.pyx":210 * max_exponent = exponent * * if exponent == max_exponent: # <<<<<<<<<<<<<< * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: */ __pyx_t_2 = (__pyx_v_exponent == __pyx_v_max_exponent); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":211 * * if exponent == max_exponent: * partial_sum += mantissa # <<<<<<<<<<<<<< * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa */ __pyx_v_partial_sum = (__pyx_v_partial_sum + __pyx_v_mantissa); /* "cogent/align/_pairwise_seqs.pyx":212 * if exponent == max_exponent: * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: # <<<<<<<<<<<<<< * max_mantissa = mantissa * pointer_state = prev_state */ if (__pyx_v_viterbi) { __pyx_t_2 = (__pyx_v_mantissa > __pyx_v_max_mantissa); __pyx_t_8 = __pyx_t_2; } else { __pyx_t_8 = __pyx_v_viterbi; } if (__pyx_t_8) { /* "cogent/align/_pairwise_seqs.pyx":213 * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa # <<<<<<<<<<<<<< * pointer_state = prev_state * pointer_a = a */ __pyx_v_max_mantissa = __pyx_v_mantissa; /* "cogent/align/_pairwise_seqs.pyx":214 * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa * pointer_state = prev_state # <<<<<<<<<<<<<< * pointer_a = a * pointer_b = b */ __pyx_v_pointer_state = __pyx_v_prev_state; /* "cogent/align/_pairwise_seqs.pyx":215 * max_mantissa = mantissa * pointer_state = prev_state * pointer_a = a # <<<<<<<<<<<<<< * pointer_b = b * */ __pyx_v_pointer_a = __pyx_v_a; /* "cogent/align/_pairwise_seqs.pyx":216 * pointer_state = prev_state * pointer_a = a * pointer_b = b # <<<<<<<<<<<<<< * * elif exponent == max_exponent - 1: */ __pyx_v_pointer_b = __pyx_v_b; goto __pyx_L39; } __pyx_L39:; goto __pyx_L38; } /* "cogent/align/_pairwise_seqs.pyx":218 * pointer_b = b * * elif exponent == max_exponent - 1: # <<<<<<<<<<<<<< * sub_partial_sum += mantissa * */ __pyx_t_8 = (__pyx_v_exponent == (__pyx_v_max_exponent - 1)); if (__pyx_t_8) { /* "cogent/align/_pairwise_seqs.pyx":219 * * elif exponent == max_exponent - 1: * sub_partial_sum += mantissa # <<<<<<<<<<<<<< * * partial_sum += sub_partial_sum * MIN_FLOAT_VALUE */ __pyx_v_sub_partial_sum = (__pyx_v_sub_partial_sum + __pyx_v_mantissa); goto __pyx_L38; } __pyx_L38:; __pyx_L25_continue:; } /* "cogent/align/_pairwise_seqs.pyx":221 * sub_partial_sum += mantissa * * partial_sum += sub_partial_sum * MIN_FLOAT_VALUE # <<<<<<<<<<<<<< * else: * for prev_state from min_prev_state <= prev_state < N: */ __pyx_v_partial_sum = (__pyx_v_partial_sum + (__pyx_v_sub_partial_sum * __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_FLOAT_VALUE)); goto __pyx_L24; } /*else*/ { /* "cogent/align/_pairwise_seqs.pyx":223 * partial_sum += sub_partial_sum * MIN_FLOAT_VALUE * else: * for prev_state from min_prev_state <= prev_state < N: # <<<<<<<<<<<<<< * mantissa = mantissas[source_row_index, prev_j, prev_state] * if use_logs: */ __pyx_t_33 = __pyx_v_N; for (__pyx_v_prev_state = __pyx_v_min_prev_state; __pyx_v_prev_state < __pyx_t_33; __pyx_v_prev_state++) { /* "cogent/align/_pairwise_seqs.pyx":224 * else: * for prev_state from min_prev_state <= prev_state < N: * mantissa = mantissas[source_row_index, prev_j, prev_state] # <<<<<<<<<<<<<< * if use_logs: * mantissa = mantissa + T[prev_state, state] */ __pyx_t_44 = __pyx_v_source_row_index; __pyx_t_45 = __pyx_v_prev_j; __pyx_t_46 = __pyx_v_prev_state; __pyx_v_mantissa = (*((double *) ( /* dim=2 */ ((char *) (((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_mantissas.data + __pyx_t_44 * __pyx_v_mantissas.strides[0]) ) + __pyx_t_45 * __pyx_v_mantissas.strides[1]) )) + __pyx_t_46)) ))); /* "cogent/align/_pairwise_seqs.pyx":225 * for prev_state from min_prev_state <= prev_state < N: * mantissa = mantissas[source_row_index, prev_j, prev_state] * if use_logs: # <<<<<<<<<<<<<< * mantissa = mantissa + T[prev_state, state] * else: */ if (__pyx_v_use_logs) { /* "cogent/align/_pairwise_seqs.pyx":226 * mantissa = mantissas[source_row_index, prev_j, prev_state] * if use_logs: * mantissa = mantissa + T[prev_state, state] # <<<<<<<<<<<<<< * else: * mantissa = mantissa * T[prev_state, state] */ __pyx_t_47 = __pyx_v_prev_state; __pyx_t_48 = __pyx_v_state; __pyx_v_mantissa = (__pyx_v_mantissa + (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_T.data + __pyx_t_47 * __pyx_v_T.strides[0]) )) + __pyx_t_48)) )))); goto __pyx_L42; } /*else*/ { /* "cogent/align/_pairwise_seqs.pyx":228 * mantissa = mantissa + T[prev_state, state] * else: * mantissa = mantissa * T[prev_state, state] # <<<<<<<<<<<<<< * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: */ __pyx_t_49 = __pyx_v_prev_state; __pyx_t_50 = __pyx_v_state; __pyx_v_mantissa = (__pyx_v_mantissa * (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_T.data + __pyx_t_49 * __pyx_v_T.strides[0]) )) + __pyx_t_50)) )))); /* "cogent/align/_pairwise_seqs.pyx":229 * else: * mantissa = mantissa * T[prev_state, state] * partial_sum += mantissa # <<<<<<<<<<<<<< * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa */ __pyx_v_partial_sum = (__pyx_v_partial_sum + __pyx_v_mantissa); } __pyx_L42:; /* "cogent/align/_pairwise_seqs.pyx":230 * mantissa = mantissa * T[prev_state, state] * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: # <<<<<<<<<<<<<< * max_mantissa = mantissa * pointer_state = prev_state */ if (__pyx_v_viterbi) { __pyx_t_8 = (__pyx_v_mantissa > __pyx_v_max_mantissa); __pyx_t_2 = __pyx_t_8; } else { __pyx_t_2 = __pyx_v_viterbi; } if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":231 * partial_sum += mantissa * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa # <<<<<<<<<<<<<< * pointer_state = prev_state * pointer_a = a */ __pyx_v_max_mantissa = __pyx_v_mantissa; /* "cogent/align/_pairwise_seqs.pyx":232 * if viterbi and mantissa > max_mantissa: * max_mantissa = mantissa * pointer_state = prev_state # <<<<<<<<<<<<<< * pointer_a = a * pointer_b = b */ __pyx_v_pointer_state = __pyx_v_prev_state; /* "cogent/align/_pairwise_seqs.pyx":233 * max_mantissa = mantissa * pointer_state = prev_state * pointer_a = a # <<<<<<<<<<<<<< * pointer_b = b * */ __pyx_v_pointer_a = __pyx_v_a; /* "cogent/align/_pairwise_seqs.pyx":234 * pointer_state = prev_state * pointer_a = a * pointer_b = b # <<<<<<<<<<<<<< * * if viterbi: */ __pyx_v_pointer_b = __pyx_v_b; goto __pyx_L43; } __pyx_L43:; } } __pyx_L24:; /* "cogent/align/_pairwise_seqs.pyx":236 * pointer_b = b * * if viterbi: # <<<<<<<<<<<<<< * mantissa = max_mantissa * if track is not None: */ if (__pyx_v_viterbi) { /* "cogent/align/_pairwise_seqs.pyx":237 * * if viterbi: * mantissa = max_mantissa # <<<<<<<<<<<<<< * if track is not None: * track[i, j, state] = ( */ __pyx_v_mantissa = __pyx_v_max_mantissa; /* "cogent/align/_pairwise_seqs.pyx":238 * if viterbi: * mantissa = max_mantissa * if track is not None: # <<<<<<<<<<<<<< * track[i, j, state] = ( * (pointer_a << tcode_x) | */ __pyx_t_2 = (((PyObject *) __pyx_v_track.memview) != Py_None); if (__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":239 * mantissa = max_mantissa * if track is not None: * track[i, j, state] = ( # <<<<<<<<<<<<<< * (pointer_a << tcode_x) | * (pointer_b << tcode_y) | */ __pyx_t_33 = __pyx_v_i; __pyx_t_51 = __pyx_v_j; __pyx_t_52 = __pyx_v_state; *((unsigned char *) ( /* dim=2 */ ((char *) (((unsigned char *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_track.data + __pyx_t_33 * __pyx_v_track.strides[0]) ) + __pyx_t_51 * __pyx_v_track.strides[1]) )) + __pyx_t_52)) )) = (((__pyx_v_pointer_a << __pyx_v_tcode_x) | (__pyx_v_pointer_b << __pyx_v_tcode_y)) | (__pyx_v_pointer_state << __pyx_v_tcode_s)); goto __pyx_L45; } __pyx_L45:; goto __pyx_L44; } /*else*/ { /* "cogent/align/_pairwise_seqs.pyx":244 * (pointer_state << tcode_s)) * else: * mantissa = partial_sum # <<<<<<<<<<<<<< * * if dy: */ __pyx_v_mantissa = __pyx_v_partial_sum; } __pyx_L44:; /* "cogent/align/_pairwise_seqs.pyx":246 * mantissa = partial_sum * * if dy: # <<<<<<<<<<<<<< * y = seq2_index[j] * if dx: */ if (__pyx_v_dy) { /* "cogent/align/_pairwise_seqs.pyx":247 * * if dy: * y = seq2_index[j] # <<<<<<<<<<<<<< * if dx: * d_score = match_scores[bin, x, y] */ __pyx_t_53 = __pyx_v_j; __pyx_v_y = (*((long *) ( /* dim=0 */ ((char *) (((long *) __pyx_v_seq2_index.data) + __pyx_t_53)) ))); /* "cogent/align/_pairwise_seqs.pyx":248 * if dy: * y = seq2_index[j] * if dx: # <<<<<<<<<<<<<< * d_score = match_scores[bin, x, y] * else: */ if (__pyx_v_dx) { /* "cogent/align/_pairwise_seqs.pyx":249 * y = seq2_index[j] * if dx: * d_score = match_scores[bin, x, y] # <<<<<<<<<<<<<< * else: * d_score = ygap_scores[bin, y] */ __pyx_t_54 = __pyx_v_bin; __pyx_t_55 = __pyx_v_x; __pyx_t_56 = __pyx_v_y; __pyx_v_d_score = (*((double *) ( /* dim=2 */ ((char *) (((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_match_scores.data + __pyx_t_54 * __pyx_v_match_scores.strides[0]) ) + __pyx_t_55 * __pyx_v_match_scores.strides[1]) )) + __pyx_t_56)) ))); goto __pyx_L47; } /*else*/ { /* "cogent/align/_pairwise_seqs.pyx":251 * d_score = match_scores[bin, x, y] * else: * d_score = ygap_scores[bin, y] # <<<<<<<<<<<<<< * elif dx: * d_score = xgap_scores[bin, x] */ __pyx_t_57 = __pyx_v_bin; __pyx_t_58 = __pyx_v_y; __pyx_v_d_score = (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_ygap_scores.data + __pyx_t_57 * __pyx_v_ygap_scores.strides[0]) )) + __pyx_t_58)) ))); } __pyx_L47:; goto __pyx_L46; } /* "cogent/align/_pairwise_seqs.pyx":252 * else: * d_score = ygap_scores[bin, y] * elif dx: # <<<<<<<<<<<<<< * d_score = xgap_scores[bin, x] * elif use_logs: */ if (__pyx_v_dx) { /* "cogent/align/_pairwise_seqs.pyx":253 * d_score = ygap_scores[bin, y] * elif dx: * d_score = xgap_scores[bin, x] # <<<<<<<<<<<<<< * elif use_logs: * d_score = 0.0 */ __pyx_t_59 = __pyx_v_bin; __pyx_t_60 = __pyx_v_x; __pyx_v_d_score = (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_xgap_scores.data + __pyx_t_59 * __pyx_v_xgap_scores.strides[0]) )) + __pyx_t_60)) ))); goto __pyx_L46; } /* "cogent/align/_pairwise_seqs.pyx":254 * elif dx: * d_score = xgap_scores[bin, x] * elif use_logs: # <<<<<<<<<<<<<< * d_score = 0.0 * else: */ if (__pyx_v_use_logs) { /* "cogent/align/_pairwise_seqs.pyx":255 * d_score = xgap_scores[bin, x] * elif use_logs: * d_score = 0.0 # <<<<<<<<<<<<<< * else: * d_score = 1.0 */ __pyx_v_d_score = 0.0; goto __pyx_L46; } /*else*/ { /* "cogent/align/_pairwise_seqs.pyx":257 * d_score = 0.0 * else: * d_score = 1.0 # <<<<<<<<<<<<<< * * if use_logs: */ __pyx_v_d_score = 1.0; } __pyx_L46:; /* "cogent/align/_pairwise_seqs.pyx":259 * d_score = 1.0 * * if use_logs: # <<<<<<<<<<<<<< * mantissa += d_score * else: */ if (__pyx_v_use_logs) { /* "cogent/align/_pairwise_seqs.pyx":260 * * if use_logs: * mantissa += d_score # <<<<<<<<<<<<<< * else: * mantissa *= d_score */ __pyx_v_mantissa = (__pyx_v_mantissa + __pyx_v_d_score); goto __pyx_L48; } /*else*/ { /* "cogent/align/_pairwise_seqs.pyx":262 * mantissa += d_score * else: * mantissa *= d_score # <<<<<<<<<<<<<< * * mantissas[current_row_index, j, state] = mantissa */ __pyx_v_mantissa = (__pyx_v_mantissa * __pyx_v_d_score); } __pyx_L48:; /* "cogent/align/_pairwise_seqs.pyx":264 * mantissa *= d_score * * mantissas[current_row_index, j, state] = mantissa # <<<<<<<<<<<<<< * if use_scaling: * exponents[current_row_index, j, state] = max_exponent */ __pyx_t_61 = __pyx_v_current_row_index; __pyx_t_62 = __pyx_v_j; __pyx_t_63 = __pyx_v_state; *((double *) ( /* dim=2 */ ((char *) (((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_mantissas.data + __pyx_t_61 * __pyx_v_mantissas.strides[0]) ) + __pyx_t_62 * __pyx_v_mantissas.strides[1]) )) + __pyx_t_63)) )) = __pyx_v_mantissa; /* "cogent/align/_pairwise_seqs.pyx":265 * * mantissas[current_row_index, j, state] = mantissa * if use_scaling: # <<<<<<<<<<<<<< * exponents[current_row_index, j, state] = max_exponent * */ if (__pyx_v_use_scaling) { /* "cogent/align/_pairwise_seqs.pyx":266 * mantissas[current_row_index, j, state] = mantissa * if use_scaling: * exponents[current_row_index, j, state] = max_exponent # <<<<<<<<<<<<<< * * if local and dx and dy: */ __pyx_t_64 = __pyx_v_current_row_index; __pyx_t_65 = __pyx_v_j; __pyx_t_66 = __pyx_v_state; *((long *) ( /* dim=2 */ ((char *) (((long *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_exponents.data + __pyx_t_64 * __pyx_v_exponents.strides[0]) ) + __pyx_t_65 * __pyx_v_exponents.strides[1]) )) + __pyx_t_66)) )) = __pyx_v_max_exponent; goto __pyx_L49; } __pyx_L49:; /* "cogent/align/_pairwise_seqs.pyx":268 * exponents[current_row_index, j, state] = max_exponent * * if local and dx and dy: # <<<<<<<<<<<<<< * if (use_scaling and max_exponent > overall_max_exponent) or ( * (not use_scaling or max_exponent == overall_max_exponent) and ( */ if (__pyx_v_local) { if (__pyx_v_dx) { __pyx_t_2 = __pyx_v_dy; } else { __pyx_t_2 = __pyx_v_dx; } __pyx_t_8 = __pyx_t_2; } else { __pyx_t_8 = __pyx_v_local; } if (__pyx_t_8) { /* "cogent/align/_pairwise_seqs.pyx":269 * * if local and dx and dy: * if (use_scaling and max_exponent > overall_max_exponent) or ( # <<<<<<<<<<<<<< * (not use_scaling or max_exponent == overall_max_exponent) and ( * mantissa > overall_max_mantissa)): */ if (__pyx_v_use_scaling) { __pyx_t_8 = (__pyx_v_max_exponent > __pyx_v_overall_max_exponent); __pyx_t_2 = __pyx_t_8; } else { __pyx_t_2 = __pyx_v_use_scaling; } if (!__pyx_t_2) { /* "cogent/align/_pairwise_seqs.pyx":270 * if local and dx and dy: * if (use_scaling and max_exponent > overall_max_exponent) or ( * (not use_scaling or max_exponent == overall_max_exponent) and ( # <<<<<<<<<<<<<< * mantissa > overall_max_mantissa)): * overall_max_exponent = max_exponent */ __pyx_t_8 = (!__pyx_v_use_scaling); if (!__pyx_t_8) { __pyx_t_7 = (__pyx_v_max_exponent == __pyx_v_overall_max_exponent); __pyx_t_1 = __pyx_t_7; } else { __pyx_t_1 = __pyx_t_8; } if (__pyx_t_1) { /* "cogent/align/_pairwise_seqs.pyx":271 * if (use_scaling and max_exponent > overall_max_exponent) or ( * (not use_scaling or max_exponent == overall_max_exponent) and ( * mantissa > overall_max_mantissa)): # <<<<<<<<<<<<<< * overall_max_exponent = max_exponent * overall_max_mantissa = mantissa */ __pyx_t_8 = (__pyx_v_mantissa > __pyx_v_overall_max_mantissa); __pyx_t_7 = __pyx_t_8; } else { __pyx_t_7 = __pyx_t_1; } __pyx_t_1 = __pyx_t_7; } else { __pyx_t_1 = __pyx_t_2; } if (__pyx_t_1) { /* "cogent/align/_pairwise_seqs.pyx":272 * (not use_scaling or max_exponent == overall_max_exponent) and ( * mantissa > overall_max_mantissa)): * overall_max_exponent = max_exponent # <<<<<<<<<<<<<< * overall_max_mantissa = mantissa * last_i = i */ __pyx_v_overall_max_exponent = __pyx_v_max_exponent; /* "cogent/align/_pairwise_seqs.pyx":273 * mantissa > overall_max_mantissa)): * overall_max_exponent = max_exponent * overall_max_mantissa = mantissa # <<<<<<<<<<<<<< * last_i = i * last_j = j */ __pyx_v_overall_max_mantissa = __pyx_v_mantissa; /* "cogent/align/_pairwise_seqs.pyx":274 * overall_max_exponent = max_exponent * overall_max_mantissa = mantissa * last_i = i # <<<<<<<<<<<<<< * last_j = j * last_state = state */ __pyx_v_last_i = __pyx_v_i; /* "cogent/align/_pairwise_seqs.pyx":275 * overall_max_mantissa = mantissa * last_i = i * last_j = j # <<<<<<<<<<<<<< * last_state = state * if not local: */ __pyx_v_last_j = __pyx_v_j; /* "cogent/align/_pairwise_seqs.pyx":276 * last_i = i * last_j = j * last_state = state # <<<<<<<<<<<<<< * if not local: * last_i = i_high - 1 */ __pyx_v_last_state = __pyx_v_state; goto __pyx_L51; } __pyx_L51:; goto __pyx_L50; } __pyx_L50:; __pyx_L19_continue:; } } } /* "cogent/align/_pairwise_seqs.pyx":277 * last_j = j * last_state = state * if not local: # <<<<<<<<<<<<<< * last_i = i_high - 1 * last_j = j_high - 1 */ __pyx_t_1 = (!__pyx_v_local); if (__pyx_t_1) { /* "cogent/align/_pairwise_seqs.pyx":278 * last_state = state * if not local: * last_i = i_high - 1 # <<<<<<<<<<<<<< * last_j = j_high - 1 * last_state = state */ __pyx_v_last_i = (__pyx_v_i_high - 1); /* "cogent/align/_pairwise_seqs.pyx":279 * if not local: * last_i = i_high - 1 * last_j = j_high - 1 # <<<<<<<<<<<<<< * last_state = state * else: */ __pyx_v_last_j = (__pyx_v_j_high - 1); /* "cogent/align/_pairwise_seqs.pyx":280 * last_i = i_high - 1 * last_j = j_high - 1 * last_state = state # <<<<<<<<<<<<<< * else: * mantissa = overall_max_mantissa */ __pyx_v_last_state = __pyx_v_state; goto __pyx_L52; } /*else*/ { /* "cogent/align/_pairwise_seqs.pyx":282 * last_state = state * else: * mantissa = overall_max_mantissa # <<<<<<<<<<<<<< * max_exponent = overall_max_exponent * */ __pyx_v_mantissa = __pyx_v_overall_max_mantissa; /* "cogent/align/_pairwise_seqs.pyx":283 * else: * mantissa = overall_max_mantissa * max_exponent = overall_max_exponent # <<<<<<<<<<<<<< * * if use_scaling: */ __pyx_v_max_exponent = __pyx_v_overall_max_exponent; } __pyx_L52:; /* "cogent/align/_pairwise_seqs.pyx":285 * max_exponent = overall_max_exponent * * if use_scaling: # <<<<<<<<<<<<<< * score = log(mantissa) + log(SCALE_STEP) * max_exponent * elif use_logs: */ if (__pyx_v_use_scaling) { /* "cogent/align/_pairwise_seqs.pyx":286 * * if use_scaling: * score = log(mantissa) + log(SCALE_STEP) * max_exponent # <<<<<<<<<<<<<< * elif use_logs: * score = mantissa */ __pyx_v_score = (log(__pyx_v_mantissa) + (log(__pyx_v_6cogent_5align_14_pairwise_seqs_SCALE_STEP) * __pyx_v_max_exponent)); goto __pyx_L53; } /* "cogent/align/_pairwise_seqs.pyx":287 * if use_scaling: * score = log(mantissa) + log(SCALE_STEP) * max_exponent * elif use_logs: # <<<<<<<<<<<<<< * score = mantissa * else: */ if (__pyx_v_use_logs) { /* "cogent/align/_pairwise_seqs.pyx":288 * score = log(mantissa) + log(SCALE_STEP) * max_exponent * elif use_logs: * score = mantissa # <<<<<<<<<<<<<< * else: * score = log(mantissa) */ __pyx_v_score = __pyx_v_mantissa; goto __pyx_L53; } /*else*/ { /* "cogent/align/_pairwise_seqs.pyx":290 * score = mantissa * else: * score = log(mantissa) # <<<<<<<<<<<<<< * return ((last_i, last_j), last_state, score) */ __pyx_v_score = log(__pyx_v_mantissa); } __pyx_L53:; /* "cogent/align/_pairwise_seqs.pyx":291 * else: * score = log(mantissa) * return ((last_i, last_j), last_state, score) # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); __pyx_t_11 = PyInt_FromLong(__pyx_v_last_i); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __pyx_t_9 = PyInt_FromLong(__pyx_v_last_j); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_11 = 0; __pyx_t_9 = 0; __pyx_t_9 = PyInt_FromLong(__pyx_v_last_state); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_11 = PyFloat_FromDouble(__pyx_v_score); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_t_10)); __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_11); __Pyx_GIVEREF(__pyx_t_11); __pyx_t_10 = 0; __pyx_t_9 = 0; __pyx_t_11 = 0; __pyx_r = ((PyObject *)__pyx_t_15); __pyx_t_15 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_11); __PYX_XDEC_MEMVIEW(&__pyx_t_13, 1); __PYX_XDEC_MEMVIEW(&__pyx_t_14, 1); __Pyx_XDECREF(__pyx_t_15); __PYX_XDEC_MEMVIEW(&__pyx_t_18, 1); __Pyx_AddTraceback("cogent.align._pairwise_seqs.calc_rows", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __PYX_XDEC_MEMVIEW(&__pyx_v_mantissas, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_exponents, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_plan, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_seq1_index, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_seq2_index, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_state_directions, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_T, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_xgap_scores, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_ygap_scores, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_match_scores, 1); __PYX_XDEC_MEMVIEW(&__pyx_v_track, 1); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_u__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); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__shape)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__itemsize)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__format)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mode); if (value) { values[3] = value; kw_args--; } } case 4: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); 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_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { /* "View.MemoryView":114 * * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, * mode=u"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_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (unlikely(((PyObject *)__pyx_v_format) == Py_None)) { PyErr_Format(PyExc_TypeError, "Argument 'format' must not be None"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_r = __pyx_array_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); goto __pyx_L0; __pyx_L1_error:; __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":113 * cdef bint dtype_is_object * * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< * mode=u"c", bint allocate_buffer=True): * */ static int __pyx_array_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; PyObject **__pyx_v_p; PyObject *__pyx_v_encode = NULL; PyObject *__pyx_v_dim = NULL; char __pyx_v_order; PyObject *__pyx_v_decode = NULL; int __pyx_r; __Pyx_RefNannyDeclarations Py_ssize_t __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; int __pyx_t_7; int __pyx_t_8; int __pyx_t_9; Py_ssize_t __pyx_t_10; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); __Pyx_INCREF(__pyx_v_format); __Pyx_INCREF(__pyx_v_mode); /* "View.MemoryView":120 * cdef PyObject **p * * self.ndim = len(shape) # <<<<<<<<<<<<<< * self.itemsize = itemsize * */ if (unlikely(((PyObject *)__pyx_v_shape) == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_1 = PyTuple_GET_SIZE(((PyObject *)__pyx_v_shape)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->ndim = __pyx_t_1; /* "View.MemoryView":121 * * self.ndim = len(shape) * self.itemsize = itemsize # <<<<<<<<<<<<<< * * if not self.ndim: */ __pyx_v_self->itemsize = __pyx_v_itemsize; /* "View.MemoryView":123 * self.itemsize = itemsize * * if not self.ndim: # <<<<<<<<<<<<<< * raise ValueError("Empty shape tuple for cython.array") * */ __pyx_t_2 = (!__pyx_v_self->ndim); if (__pyx_t_2) { /* "View.MemoryView":124 * * if not self.ndim: * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< * * if self.itemsize <= 0: */ __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_16), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":126 * raise ValueError("Empty shape tuple for cython.array") * * if self.itemsize <= 0: # <<<<<<<<<<<<<< * raise ValueError("itemsize <= 0 for cython.array") * */ __pyx_t_2 = (__pyx_v_self->itemsize <= 0); if (__pyx_t_2) { /* "View.MemoryView":127 * * if self.itemsize <= 0: * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< * * encode = getattr(format, 'encode', None) */ __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_18), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; /* "View.MemoryView":129 * raise ValueError("itemsize <= 0 for cython.array") * * encode = getattr(format, 'encode', None) # <<<<<<<<<<<<<< * if encode: * format = encode('ASCII') */ __pyx_t_3 = ((PyObject *)__pyx_n_s__encode); __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = Py_None; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = __Pyx_GetAttr3(__pyx_v_format, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __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_v_encode = __pyx_t_5; __pyx_t_5 = 0; /* "View.MemoryView":130 * * encode = getattr(format, 'encode', None) * if encode: # <<<<<<<<<<<<<< * format = encode('ASCII') * self._format = format */ __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_encode); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_2) { /* "View.MemoryView":131 * encode = getattr(format, 'encode', None) * if encode: * format = encode('ASCII') # <<<<<<<<<<<<<< * self._format = format * self.format = self._format */ __pyx_t_5 = PyObject_Call(__pyx_v_encode, ((PyObject *)__pyx_k_tuple_19), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_v_format); __pyx_v_format = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L5; } __pyx_L5:; /* "View.MemoryView":132 * if encode: * format = encode('ASCII') * self._format = format # <<<<<<<<<<<<<< * self.format = self._format * */ if (!(likely(PyBytes_CheckExact(__pyx_v_format))||((__pyx_v_format) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_format)->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_INCREF(__pyx_v_format); __Pyx_GIVEREF(__pyx_v_format); __Pyx_GOTREF(__pyx_v_self->_format); __Pyx_DECREF(((PyObject *)__pyx_v_self->_format)); __pyx_v_self->_format = ((PyObject*)__pyx_v_format); /* "View.MemoryView":133 * format = encode('ASCII') * self._format = format * self.format = self._format # <<<<<<<<<<<<<< * * self._shape = malloc(sizeof(Py_ssize_t)*self.ndim) */ __pyx_t_6 = PyBytes_AsString(((PyObject *)__pyx_v_self->_format)); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->format = __pyx_t_6; /* "View.MemoryView":135 * self.format = self._format * * self._shape = malloc(sizeof(Py_ssize_t)*self.ndim) # <<<<<<<<<<<<<< * self._strides = malloc(sizeof(Py_ssize_t)*self.ndim) * */ __pyx_v_self->_shape = ((Py_ssize_t *)malloc(((sizeof(Py_ssize_t)) * __pyx_v_self->ndim))); /* "View.MemoryView":136 * * self._shape = malloc(sizeof(Py_ssize_t)*self.ndim) * self._strides = malloc(sizeof(Py_ssize_t)*self.ndim) # <<<<<<<<<<<<<< * * if not self._shape or not self._strides: */ __pyx_v_self->_strides = ((Py_ssize_t *)malloc(((sizeof(Py_ssize_t)) * __pyx_v_self->ndim))); /* "View.MemoryView":138 * self._strides = malloc(sizeof(Py_ssize_t)*self.ndim) * * if not self._shape or not self._strides: # <<<<<<<<<<<<<< * free(self._shape) * free(self._strides) */ __pyx_t_2 = (!(__pyx_v_self->_shape != 0)); if (!__pyx_t_2) { __pyx_t_7 = (!(__pyx_v_self->_strides != 0)); __pyx_t_8 = __pyx_t_7; } else { __pyx_t_8 = __pyx_t_2; } if (__pyx_t_8) { /* "View.MemoryView":139 * * if not self._shape or not self._strides: * free(self._shape) # <<<<<<<<<<<<<< * free(self._strides) * raise MemoryError("unable to allocate shape or strides.") */ free(__pyx_v_self->_shape); /* "View.MemoryView":140 * if not self._shape or not self._strides: * free(self._shape) * free(self._strides) # <<<<<<<<<<<<<< * raise MemoryError("unable to allocate shape or strides.") * */ free(__pyx_v_self->_strides); /* "View.MemoryView":141 * free(self._shape) * free(self._strides) * raise MemoryError("unable to allocate shape or strides.") # <<<<<<<<<<<<<< * * */ __pyx_t_5 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; /* "View.MemoryView":144 * * * idx = 0 # <<<<<<<<<<<<<< * for idx, dim in enumerate(shape): * if dim <= 0: */ __pyx_v_idx = 0; /* "View.MemoryView":145 * * idx = 0 * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<< * if dim <= 0: * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) */ __pyx_t_9 = 0; __pyx_t_5 = ((PyObject *)__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_COMPILING_IN_CPYTHON __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif __Pyx_XDECREF(__pyx_v_dim); __pyx_v_dim = __pyx_t_4; __pyx_t_4 = 0; __pyx_v_idx = __pyx_t_9; __pyx_t_9 = (__pyx_t_9 + 1); /* "View.MemoryView":146 * idx = 0 * for idx, dim in enumerate(shape): * if dim <= 0: # <<<<<<<<<<<<<< * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) * */ __pyx_t_4 = PyObject_RichCompare(__pyx_v_dim, __pyx_int_0, Py_LE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_8) { /* "View.MemoryView":147 * 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 = PyInt_FromLong(__pyx_v_idx); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_dim); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_dim); __Pyx_GIVEREF(__pyx_v_dim); __pyx_t_4 = 0; __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_4)); __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L9; } __pyx_L9:; /* "View.MemoryView":149 * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) * * self._shape[idx] = dim # <<<<<<<<<<<<<< * idx += 1 * */ __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_dim); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} (__pyx_v_self->_shape[__pyx_v_idx]) = __pyx_t_10; /* "View.MemoryView":150 * * self._shape[idx] = dim * idx += 1 # <<<<<<<<<<<<<< * * if mode not in ("fortran", "c"): */ __pyx_v_idx = (__pyx_v_idx + 1); } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; /* "View.MemoryView":152 * idx += 1 * * if mode not in ("fortran", "c"): # <<<<<<<<<<<<<< * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) * */ __Pyx_INCREF(__pyx_v_mode); __pyx_t_5 = __pyx_v_mode; __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__fortran), Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (((int)__pyx_t_8)) { __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__c), Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = ((int)__pyx_t_2); } else { __pyx_t_7 = ((int)__pyx_t_8); } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_8 = __pyx_t_7; if (__pyx_t_8) { /* "View.MemoryView":153 * * if mode not in ("fortran", "c"): * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) # <<<<<<<<<<<<<< * * cdef char order */ __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_23), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_5)); __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L10; } __pyx_L10:; /* "View.MemoryView":156 * * cdef char order * if mode == 'fortran': # <<<<<<<<<<<<<< * order = 'F' * else: */ __pyx_t_5 = PyObject_RichCompare(__pyx_v_mode, ((PyObject *)__pyx_n_s__fortran), Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_8) { /* "View.MemoryView":157 * cdef char order * if mode == 'fortran': * order = 'F' # <<<<<<<<<<<<<< * else: * order = 'C' */ __pyx_v_order = 'F'; goto __pyx_L11; } /*else*/ { /* "View.MemoryView":159 * order = 'F' * else: * order = 'C' # <<<<<<<<<<<<<< * * self.len = fill_contig_strides_array(self._shape, self._strides, */ __pyx_v_order = 'C'; } __pyx_L11:; /* "View.MemoryView":161 * order = 'C' * * 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); /* "View.MemoryView":164 * itemsize, self.ndim, order) * * decode = getattr(mode, 'decode', None) # <<<<<<<<<<<<<< * if decode: * mode = decode('ASCII') */ __pyx_t_5 = ((PyObject *)__pyx_n_s__decode); __Pyx_INCREF(__pyx_t_5); __pyx_t_4 = Py_None; __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = __Pyx_GetAttr3(__pyx_v_mode, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_decode = __pyx_t_3; __pyx_t_3 = 0; /* "View.MemoryView":165 * * decode = getattr(mode, 'decode', None) * if decode: # <<<<<<<<<<<<<< * mode = decode('ASCII') * self.mode = mode */ __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_decode); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_8) { /* "View.MemoryView":166 * decode = getattr(mode, 'decode', None) * if decode: * mode = decode('ASCII') # <<<<<<<<<<<<<< * self.mode = mode * */ __pyx_t_3 = PyObject_Call(__pyx_v_decode, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_v_mode); __pyx_v_mode = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L12; } __pyx_L12:; /* "View.MemoryView":167 * if decode: * mode = decode('ASCII') * self.mode = mode # <<<<<<<<<<<<<< * * self.free_data = allocate_buffer */ if (!(likely(PyUnicode_CheckExact(__pyx_v_mode))||((__pyx_v_mode) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected unicode, got %.200s", Py_TYPE(__pyx_v_mode)->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_INCREF(__pyx_v_mode); __Pyx_GIVEREF(__pyx_v_mode); __Pyx_GOTREF(__pyx_v_self->mode); __Pyx_DECREF(((PyObject *)__pyx_v_self->mode)); __pyx_v_self->mode = ((PyObject*)__pyx_v_mode); /* "View.MemoryView":169 * self.mode = mode * * 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":170 * * self.free_data = allocate_buffer * self.dtype_is_object = format == b'O' # <<<<<<<<<<<<<< * if allocate_buffer: * self.data = malloc(self.len) */ __pyx_t_3 = PyObject_RichCompare(__pyx_v_format, ((PyObject *)__pyx_n_b__O), Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_self->dtype_is_object = __pyx_t_8; /* "View.MemoryView":171 * self.free_data = allocate_buffer * self.dtype_is_object = format == b'O' * if allocate_buffer: # <<<<<<<<<<<<<< * self.data = malloc(self.len) * if not self.data: */ if (__pyx_v_allocate_buffer) { /* "View.MemoryView":172 * self.dtype_is_object = format == b'O' * if allocate_buffer: * 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)); /* "View.MemoryView":173 * if allocate_buffer: * self.data = malloc(self.len) * if not self.data: # <<<<<<<<<<<<<< * raise MemoryError("unable to allocate array data.") * */ __pyx_t_8 = (!(__pyx_v_self->data != 0)); if (__pyx_t_8) { /* "View.MemoryView":174 * self.data = malloc(self.len) * if not self.data: * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< * * if self.dtype_is_object: */ __pyx_t_3 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L14; } __pyx_L14:; /* "View.MemoryView":176 * raise MemoryError("unable to allocate array data.") * * if self.dtype_is_object: # <<<<<<<<<<<<<< * p = self.data * for i in range(self.len / itemsize): */ if (__pyx_v_self->dtype_is_object) { /* "View.MemoryView":177 * * 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":178 * 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_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else if (sizeof(Py_ssize_t) == sizeof(long) && unlikely(__pyx_v_itemsize == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_self->len))) { PyErr_Format(PyExc_OverflowError, "value too large to perform division"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_1 = __Pyx_div_Py_ssize_t(__pyx_v_self->len, __pyx_v_itemsize); for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_1; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; /* "View.MemoryView":179 * p = self.data * for i in range(self.len / itemsize): * p[i] = Py_None # <<<<<<<<<<<<<< * Py_INCREF(Py_None) * */ (__pyx_v_p[__pyx_v_i]) = Py_None; /* "View.MemoryView":180 * for i in range(self.len / itemsize): * p[i] = Py_None * Py_INCREF(Py_None) # <<<<<<<<<<<<<< * * @cname('getbuffer') */ Py_INCREF(Py_None); } goto __pyx_L15; } __pyx_L15:; goto __pyx_L13; } __pyx_L13:; __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("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_encode); __Pyx_XDECREF(__pyx_v_dim); __Pyx_XDECREF(__pyx_v_decode); __Pyx_XDECREF(__pyx_v_format); __Pyx_XDECREF(__pyx_v_mode); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ static int __pyx_array_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_array_getbuffer_MemoryView_5array_2__getbuffer__(((struct __pyx_array_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":183 * * @cname('getbuffer') * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< * cdef int bufmode = -1 * if self.mode == b"c": */ static int __pyx_array_getbuffer_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_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getbuffer__", 0); if (__pyx_v_info != NULL) { __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); __Pyx_GIVEREF(__pyx_v_info->obj); } /* "View.MemoryView":184 * @cname('getbuffer') * def __getbuffer__(self, Py_buffer *info, int flags): * cdef int bufmode = -1 # <<<<<<<<<<<<<< * if self.mode == b"c": * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS */ __pyx_v_bufmode = -1; /* "View.MemoryView":185 * def __getbuffer__(self, Py_buffer *info, int flags): * cdef int bufmode = -1 * if self.mode == b"c": # <<<<<<<<<<<<<< * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS * elif self.mode == b"fortran": */ __pyx_t_1 = (__Pyx_PyUnicode_Equals(((PyObject *)__pyx_v_self->mode), ((PyObject *)__pyx_n_b__c), Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { /* "View.MemoryView":186 * cdef int bufmode = -1 * if self.mode == b"c": * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<< * elif self.mode == b"fortran": * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS */ __pyx_v_bufmode = (PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS); goto __pyx_L3; } /* "View.MemoryView":187 * if self.mode == b"c": * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS * elif self.mode == b"fortran": # <<<<<<<<<<<<<< * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS * if not (flags & bufmode): */ __pyx_t_1 = (__Pyx_PyUnicode_Equals(((PyObject *)__pyx_v_self->mode), ((PyObject *)__pyx_n_b__fortran), Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { /* "View.MemoryView":188 * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS * elif self.mode == b"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); goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":189 * elif self.mode == b"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)); if (__pyx_t_1) { /* "View.MemoryView":190 * 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_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_28), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; /* "View.MemoryView":191 * 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_v_info->buf = __pyx_v_self->data; /* "View.MemoryView":192 * 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_v_info->len = __pyx_v_self->len; /* "View.MemoryView":193 * info.buf = self.data * info.len = self.len * info.ndim = self.ndim # <<<<<<<<<<<<<< * info.shape = self._shape * info.strides = self._strides */ __pyx_v_info->ndim = __pyx_v_self->ndim; /* "View.MemoryView":194 * info.len = self.len * info.ndim = self.ndim * info.shape = self._shape # <<<<<<<<<<<<<< * info.strides = self._strides * info.suboffsets = NULL */ __pyx_v_info->shape = __pyx_v_self->_shape; /* "View.MemoryView":195 * info.ndim = self.ndim * info.shape = self._shape * info.strides = self._strides # <<<<<<<<<<<<<< * info.suboffsets = NULL * info.itemsize = self.itemsize */ __pyx_v_info->strides = __pyx_v_self->_strides; /* "View.MemoryView":196 * 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":197 * info.strides = self._strides * info.suboffsets = NULL * info.itemsize = self.itemsize # <<<<<<<<<<<<<< * info.readonly = 0 * */ __pyx_v_info->itemsize = __pyx_v_self->itemsize; /* "View.MemoryView":198 * info.suboffsets = NULL * info.itemsize = self.itemsize * info.readonly = 0 # <<<<<<<<<<<<<< * * if flags & PyBUF_FORMAT: */ __pyx_v_info->readonly = 0; /* "View.MemoryView":200 * info.readonly = 0 * * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< * info.format = self.format * else: */ __pyx_t_3 = (__pyx_v_flags & PyBUF_FORMAT); if (__pyx_t_3) { /* "View.MemoryView":201 * * if flags & PyBUF_FORMAT: * info.format = self.format # <<<<<<<<<<<<<< * else: * info.format = NULL */ __pyx_v_info->format = __pyx_v_self->format; goto __pyx_L5; } /*else*/ { /* "View.MemoryView":203 * info.format = self.format * else: * info.format = NULL # <<<<<<<<<<<<<< * * info.obj = self */ __pyx_v_info->format = NULL; } __pyx_L5:; /* "View.MemoryView":205 * 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); __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("View.MemoryView.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; if (__pyx_v_info != NULL && __pyx_v_info->obj != NULL) { __Pyx_GOTREF(__pyx_v_info->obj); __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL; } goto __pyx_L2; __pyx_L0:; if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) { __Pyx_GOTREF(Py_None); __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL; } __pyx_L2:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_5array_4__dealloc__(((struct __pyx_array_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":209 * __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) */ static void __pyx_array_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self) { __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); /* "View.MemoryView":210 * * def __dealloc__(array self): * if self.callback_free_data != NULL: # <<<<<<<<<<<<<< * self.callback_free_data(self.data) * elif self.free_data: */ __pyx_t_1 = (__pyx_v_self->callback_free_data != NULL); if (__pyx_t_1) { /* "View.MemoryView":211 * 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); goto __pyx_L3; } /* "View.MemoryView":212 * 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, */ if (__pyx_v_self->free_data) { /* "View.MemoryView":213 * 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) */ if (__pyx_v_self->dtype_is_object) { /* "View.MemoryView":215 * 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); goto __pyx_L4; } __pyx_L4:; /* "View.MemoryView":216 * refcount_objects_in_slice(self.data, self._shape, * self._strides, self.ndim, False) * free(self.data) # <<<<<<<<<<<<<< * * free(self._strides) */ free(__pyx_v_self->data); goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":218 * free(self.data) * * free(self._strides) # <<<<<<<<<<<<<< * free(self._shape) * */ free(__pyx_v_self->_strides); /* "View.MemoryView":219 * * free(self._strides) * free(self._shape) # <<<<<<<<<<<<<< * * property memview: */ free(__pyx_v_self->_shape); __Pyx_RefNannyFinishContext(); } /* Python wrapper */ static PyObject *get_memview(PyObject *__pyx_v_self); /*proto*/ static PyObject *get_memview(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = get_memview_MemoryView_5array_7memview___get__(((struct __pyx_array_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":223 * property memview: * @cname('get_memview') * def __get__(self): # <<<<<<<<<<<<<< * * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE */ static PyObject *get_memview_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self) { int __pyx_v_flags; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":225 * def __get__(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":226 * * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE * return memoryview(self, flags, self.dtype_is_object) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyInt_FromLong(__pyx_v_flags); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject *)__pyx_memoryview_type)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; __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_AddTraceback("View.MemoryView.array.memview.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_5array_6__getattr__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_attr)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":229 * * * def __getattr__(self, attr): # <<<<<<<<<<<<<< * return getattr(self.memview, attr) * */ static PyObject *__pyx_array_MemoryView_5array_6__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getattr__", 0); /* "View.MemoryView":230 * * def __getattr__(self, attr): * return getattr(self.memview, attr) # <<<<<<<<<<<<<< * * def __getitem__(self, item): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__memview); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_v_attr); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __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_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.array.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); __pyx_r = __pyx_array_MemoryView_5array_8__getitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":232 * return getattr(self.memview, attr) * * def __getitem__(self, item): # <<<<<<<<<<<<<< * return self.memview[item] * */ static PyObject *__pyx_array_MemoryView_5array_8__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); /* "View.MemoryView":233 * * def __getitem__(self, item): * return self.memview[item] # <<<<<<<<<<<<<< * * def __setitem__(self, item, value): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__memview); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetItem(__pyx_t_1, __pyx_v_item); if (!__pyx_t_2) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __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_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.array.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_5array_10__setitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item), ((PyObject *)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":235 * return self.memview[item] * * def __setitem__(self, item, value): # <<<<<<<<<<<<<< * self.memview[item] = value * */ static int __pyx_array_MemoryView_5array_10__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setitem__", 0); /* "View.MemoryView":236 * * def __setitem__(self, item, value): * self.memview[item] = value # <<<<<<<<<<<<<< * * */ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__memview); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetItem(__pyx_t_1, __pyx_v_item, __pyx_v_value) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __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_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":240 * * @cname("__pyx_array_new") * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<< * char *mode, char *buf): * cdef array result */ 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_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; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("array_cwrapper", 0); /* "View.MemoryView":244 * cdef array result * * if buf == NULL: # <<<<<<<<<<<<<< * result = array(shape, itemsize, format, mode.decode('ASCII')) * else: */ __pyx_t_1 = (__pyx_v_buf == NULL); if (__pyx_t_1) { /* "View.MemoryView":245 * * if buf == NULL: * result = array(shape, itemsize, format, mode.decode('ASCII')) # <<<<<<<<<<<<<< * else: * result = array(shape, itemsize, format, mode.decode('ASCII'), */ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_t_4 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(((PyObject *)__pyx_v_shape)); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_shape)); __Pyx_GIVEREF(((PyObject *)__pyx_v_shape)); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); PyTuple_SET_ITEM(__pyx_t_5, 3, ((PyObject *)__pyx_t_4)); __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject *)__pyx_array_type)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":247 * 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_4 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_t_3 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_shape)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_shape)); __Pyx_GIVEREF(((PyObject *)__pyx_v_shape)); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_t_5)); __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_4 = 0; __pyx_t_5 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); /* "View.MemoryView":248 * else: * result = array(shape, itemsize, format, mode.decode('ASCII'), * allocate_buffer=False) # <<<<<<<<<<<<<< * result.data = buf * */ __pyx_t_5 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__allocate_buffer), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject *)__pyx_array_type)), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_5); __pyx_t_5 = 0; /* "View.MemoryView":249 * 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":251 * result.data = buf * * return result # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(((PyObject *)__pyx_r)); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = __pyx_v_result; goto __pyx_L0; __pyx_r = ((struct __pyx_array_obj *)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("View.MemoryView.array_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__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_filename = __pyx_f[2]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __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_MemoryView_4Enum___init__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), __pyx_v_name); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":277 * cdef class Enum(object): * cdef object name * def __init__(self, name): # <<<<<<<<<<<<<< * self.name = name * def __repr__(self): */ static int __pyx_MemviewEnum_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__", 0); /* "View.MemoryView":278 * cdef object name * def __init__(self, name): * self.name = name # <<<<<<<<<<<<<< * def __repr__(self): * return self.name */ __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_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_4Enum_2__repr__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":279 * def __init__(self, name): * self.name = name * def __repr__(self): # <<<<<<<<<<<<<< * return self.name * */ static PyObject *__pyx_MemviewEnum_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__repr__", 0); /* "View.MemoryView":280 * 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; __pyx_r = Py_None; __Pyx_INCREF(Py_None); __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":294 * * @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; int __pyx_t_1; /* "View.MemoryView":296 * 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_v_aligned_p = ((Py_intptr_t)__pyx_v_memory); /* "View.MemoryView":300 * * with cython.cdivision(True): * offset = aligned_p % alignment # <<<<<<<<<<<<<< * * if offset > 0: */ __pyx_v_offset = (__pyx_v_aligned_p % __pyx_v_alignment); /* "View.MemoryView":302 * offset = aligned_p % alignment * * if offset > 0: # <<<<<<<<<<<<<< * aligned_p += alignment - offset * */ __pyx_t_1 = (__pyx_v_offset > 0); if (__pyx_t_1) { /* "View.MemoryView":303 * * if offset > 0: * aligned_p += alignment - offset # <<<<<<<<<<<<<< * * return aligned_p */ __pyx_v_aligned_p = (__pyx_v_aligned_p + (__pyx_v_alignment - __pyx_v_offset)); goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":305 * aligned_p += alignment - offset * * return aligned_p # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview') */ __pyx_r = ((void *)__pyx_v_aligned_p); goto __pyx_L0; __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* 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); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__obj)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__flags)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[2]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); 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_AsInt(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { /* "View.MemoryView":323 * 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_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_filename = __pyx_f[2]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __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_MemoryView_10memoryview___cinit__(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_obj, __pyx_v_flags, __pyx_v_dtype_is_object); __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_memoryview_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_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_t_4; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); /* "View.MemoryView":324 * * 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; /* "View.MemoryView":325 * 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_v_self->flags = __pyx_v_flags; /* "View.MemoryView":326 * 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_1 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)((PyObject *)__pyx_memoryview_type))); if (!__pyx_t_1) { __pyx_t_2 = (__pyx_v_obj != Py_None); __pyx_t_3 = __pyx_t_2; } else { __pyx_t_3 = __pyx_t_1; } if (__pyx_t_3) { /* "View.MemoryView":327 * 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 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":328 * 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_3 = (((PyObject *)__pyx_v_self->view.obj) == NULL); if (__pyx_t_3) { /* "View.MemoryView":329 * __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":330 * if self.view.obj == NULL: * (<__pyx_buffer *> &self.view).obj = Py_None * Py_INCREF(Py_None) # <<<<<<<<<<<<<< * * self.lock = PyThread_allocate_lock() */ Py_INCREF(Py_None); goto __pyx_L4; } __pyx_L4:; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":332 * Py_INCREF(Py_None) * * self.lock = PyThread_allocate_lock() # <<<<<<<<<<<<<< * if self.lock == NULL: * raise MemoryError */ __pyx_v_self->lock = PyThread_allocate_lock(); /* "View.MemoryView":333 * * self.lock = PyThread_allocate_lock() * if self.lock == NULL: # <<<<<<<<<<<<<< * raise MemoryError * */ __pyx_t_3 = (__pyx_v_self->lock == NULL); if (__pyx_t_3) { /* "View.MemoryView":334 * self.lock = PyThread_allocate_lock() * if self.lock == NULL: * raise MemoryError # <<<<<<<<<<<<<< * * if flags & PyBUF_FORMAT: */ PyErr_NoMemory(); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; /* "View.MemoryView":336 * raise MemoryError * * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< * self.dtype_is_object = self.view.format == b'O' * else: */ __pyx_t_4 = (__pyx_v_flags & PyBUF_FORMAT); if (__pyx_t_4) { /* "View.MemoryView":337 * * if flags & PyBUF_FORMAT: * self.dtype_is_object = self.view.format == b'O' # <<<<<<<<<<<<<< * else: * self.dtype_is_object = dtype_is_object */ __pyx_t_5 = PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_t_6 = PyObject_RichCompare(((PyObject *)__pyx_t_5), ((PyObject *)__pyx_n_b__O), Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_self->dtype_is_object = __pyx_t_3; goto __pyx_L6; } /*else*/ { /* "View.MemoryView":339 * self.dtype_is_object = self.view.format == b'O' * else: * self.dtype_is_object = dtype_is_object # <<<<<<<<<<<<<< * * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( */ __pyx_v_self->dtype_is_object = __pyx_v_dtype_is_object; } __pyx_L6:; /* "View.MemoryView":341 * 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":343 * 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_v_self->typeinfo = NULL; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_2__dealloc__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":345 * self.typeinfo = NULL * * def __dealloc__(memoryview self): # <<<<<<<<<<<<<< * if self.obj is not None: * __Pyx_ReleaseBuffer(&self.view) */ static void __pyx_memoryview_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self) { __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); /* "View.MemoryView":346 * * def __dealloc__(memoryview self): * if self.obj is not None: # <<<<<<<<<<<<<< * __Pyx_ReleaseBuffer(&self.view) * */ __pyx_t_1 = (__pyx_v_self->obj != Py_None); if (__pyx_t_1) { /* "View.MemoryView":347 * def __dealloc__(memoryview self): * if self.obj is not None: * __Pyx_ReleaseBuffer(&self.view) # <<<<<<<<<<<<<< * * if self.lock != NULL: */ __Pyx_ReleaseBuffer((&__pyx_v_self->view)); goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":349 * __Pyx_ReleaseBuffer(&self.view) * * if self.lock != NULL: # <<<<<<<<<<<<<< * PyThread_free_lock(self.lock) * */ __pyx_t_1 = (__pyx_v_self->lock != NULL); if (__pyx_t_1) { /* "View.MemoryView":350 * * if self.lock != NULL: * PyThread_free_lock(self.lock) # <<<<<<<<<<<<<< * * cdef char *get_item_pointer(memoryview self, object index) except NULL: */ PyThread_free_lock(__pyx_v_self->lock); goto __pyx_L4; } __pyx_L4:; __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":352 * 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 */ 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_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; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("get_item_pointer", 0); /* "View.MemoryView":354 * cdef char *get_item_pointer(memoryview self, object index) except NULL: * cdef Py_ssize_t dim * cdef char *itemp = self.view.buf # <<<<<<<<<<<<<< * * for dim, idx in enumerate(index): */ __pyx_v_itemp = ((char *)__pyx_v_self->view.buf); /* "View.MemoryView":356 * cdef char *itemp = self.view.buf * * for dim, idx in enumerate(index): # <<<<<<<<<<<<<< * itemp = pybuffer_index(&self.view, itemp, idx, dim) * */ __pyx_t_1 = 0; if (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_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; } for (;;) { if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) { if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) { if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { __pyx_t_5 = __pyx_t_4(__pyx_t_2); if (unlikely(!__pyx_t_5)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } __Pyx_GOTREF(__pyx_t_5); } __Pyx_XDECREF(__pyx_v_idx); __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":357 * * for dim, idx in enumerate(index): * itemp = pybuffer_index(&self.view, itemp, idx, dim) # <<<<<<<<<<<<<< * * return itemp */ __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __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 == NULL)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_itemp = __pyx_t_7; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "View.MemoryView":359 * itemp = pybuffer_index(&self.view, itemp, idx, dim) * * return itemp # <<<<<<<<<<<<<< * * */ __pyx_r = __pyx_v_itemp; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_4__getitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":362 * * * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<< * if index is Ellipsis: * return self */ static PyObject *__pyx_memoryview_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_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)(PyObject *); char *__pyx_t_7; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); /* "View.MemoryView":363 * * def __getitem__(memoryview self, object index): * if index is Ellipsis: # <<<<<<<<<<<<<< * return self * */ __pyx_t_1 = (__pyx_v_index == __pyx_builtin_Ellipsis); if (__pyx_t_1) { /* "View.MemoryView":364 * 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; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":366 * return self * * have_slices, indices = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< * * cdef char *itemp */ __pyx_t_2 = ((PyObject *)_unellipsify(__pyx_v_index, __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (likely(PyTuple_CheckExact(__pyx_t_2))) { PyObject* sequence = __pyx_t_2; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else if (1) { __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else { Py_ssize_t index = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext; index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_6 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L5_unpacking_done; __pyx_L4_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L5_unpacking_done:; } __pyx_v_have_slices = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_indices = __pyx_t_4; __pyx_t_4 = 0; /* "View.MemoryView":369 * * cdef char *itemp * if have_slices: # <<<<<<<<<<<<<< * return memview_slice(self, indices) * else: */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { /* "View.MemoryView":370 * cdef char *itemp * if have_slices: * return memview_slice(self, indices) # <<<<<<<<<<<<<< * else: * itemp = self.get_item_pointer(indices) */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = ((PyObject *)__pyx_memview_slice(__pyx_v_self, __pyx_v_indices)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; goto __pyx_L6; } /*else*/ { /* "View.MemoryView":372 * return memview_slice(self, indices) * else: * itemp = self.get_item_pointer(indices) # <<<<<<<<<<<<<< * return self.convert_item_to_object(itemp) * */ __pyx_t_7 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_indices); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_itemp = __pyx_t_7; /* "View.MemoryView":373 * 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_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->convert_item_to_object(__pyx_v_self, __pyx_v_itemp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } __pyx_L6:; __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("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_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_6__setitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index), ((PyObject *)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":375 * return self.convert_item_to_object(itemp) * * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<< * have_slices, index = _unellipsify(index, self.view.ndim) * */ static int __pyx_memoryview_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_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_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setitem__", 0); __Pyx_INCREF(__pyx_v_index); /* "View.MemoryView":376 * * def __setitem__(memoryview self, object index, object value): * have_slices, index = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< * * if have_slices: */ __pyx_t_1 = ((PyObject *)_unellipsify(__pyx_v_index, __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (likely(PyTuple_CheckExact(__pyx_t_1))) { PyObject* sequence = __pyx_t_1; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); #else __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else if (1) { __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else { Py_ssize_t index = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); 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_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L4_unpacking_done:; } __pyx_v_have_slices = __pyx_t_2; __pyx_t_2 = 0; __Pyx_DECREF(__pyx_v_index); __pyx_v_index = __pyx_t_3; __pyx_t_3 = 0; /* "View.MemoryView":378 * have_slices, index = _unellipsify(index, self.view.ndim) * * if have_slices: # <<<<<<<<<<<<<< * obj = self.is_slice(value) * if obj: */ __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_6) { /* "View.MemoryView":379 * * if have_slices: * obj = self.is_slice(value) # <<<<<<<<<<<<<< * if obj: * self.setitem_slice_assignment(self[index], obj) */ __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->is_slice(__pyx_v_self, __pyx_v_value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_obj = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":380 * if have_slices: * obj = self.is_slice(value) * if obj: # <<<<<<<<<<<<<< * self.setitem_slice_assignment(self[index], obj) * else: */ __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_obj); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_6) { /* "View.MemoryView":381 * obj = self.is_slice(value) * if obj: * self.setitem_slice_assignment(self[index], obj) # <<<<<<<<<<<<<< * else: * self.setitem_slice_assign_scalar(self[index], value) */ __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (!__pyx_t_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assignment(__pyx_v_self, __pyx_t_1, __pyx_v_obj); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L6; } /*else*/ { /* "View.MemoryView":383 * self.setitem_slice_assignment(self[index], obj) * else: * self.setitem_slice_assign_scalar(self[index], value) # <<<<<<<<<<<<<< * else: * self.setitem_indexed(index, value) */ __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assign_scalar(__pyx_v_self, ((struct __pyx_memoryview_obj *)__pyx_t_3), __pyx_v_value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __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_L6:; goto __pyx_L5; } /*else*/ { /* "View.MemoryView":385 * self.setitem_slice_assign_scalar(self[index], value) * else: * self.setitem_indexed(index, value) # <<<<<<<<<<<<<< * * cdef is_slice(self, obj): */ __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_indexed(__pyx_v_self, __pyx_v_index, __pyx_v_value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 385; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L5:; __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("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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":387 * self.setitem_indexed(index, value) * * cdef is_slice(self, obj): # <<<<<<<<<<<<<< * if not isinstance(obj, memoryview): * try: */ static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj) { PyObject *__pyx_r = NULL; __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; PyObject *__pyx_t_8 = NULL; int __pyx_t_9; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("is_slice", 0); __Pyx_INCREF(__pyx_v_obj); /* "View.MemoryView":388 * * cdef is_slice(self, obj): * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<< * try: * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, */ __pyx_t_1 = ((PyObject *)((PyObject *)__pyx_memoryview_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_obj, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = (!__pyx_t_2); if (__pyx_t_3) { /* "View.MemoryView":389 * cdef is_slice(self, obj): * if not isinstance(obj, memoryview): * try: # <<<<<<<<<<<<<< * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, * self.dtype_is_object) */ { __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:*/ { /* "View.MemoryView":390 * if not isinstance(obj, memoryview): * try: * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<< * self.dtype_is_object) * except TypeError: */ __pyx_t_1 = PyInt_FromLong((__pyx_v_self->flags | PyBUF_ANY_CONTIGUOUS)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L4_error;} __Pyx_GOTREF(__pyx_t_1); /* "View.MemoryView":391 * 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_filename = __pyx_f[2]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L4_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L4_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_INCREF(__pyx_v_obj); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_obj); __Pyx_GIVEREF(__pyx_v_obj); PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_7); __pyx_t_1 = 0; __pyx_t_7 = 0; __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject *)__pyx_memoryview_type)), ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L4_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_v_obj); __pyx_v_obj = __pyx_t_7; __pyx_t_7 = 0; } __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_L4_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; /* "View.MemoryView":392 * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, * self.dtype_is_object) * except TypeError: # <<<<<<<<<<<<<< * return None * */ __pyx_t_9 = 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_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_GOTREF(__pyx_t_8); __Pyx_GOTREF(__pyx_t_1); /* "View.MemoryView":393 * self.dtype_is_object) * except TypeError: * return None # <<<<<<<<<<<<<< * * return obj */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_None); __pyx_r = Py_None; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; goto __pyx_L7_except_return; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L5_exception_handled; } __pyx_L6_except_error:; __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_L7_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_L5_exception_handled:; __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); __pyx_L11_try_end:; } goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":395 * return None * * return obj # <<<<<<<<<<<<<< * * cdef setitem_slice_assignment(self, dst, src): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_obj); __pyx_r = __pyx_v_obj; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":397 * return obj * * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<< * cdef __Pyx_memviewslice dst_slice * cdef __Pyx_memviewslice src_slice */ 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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; int __pyx_t_5; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("setitem_slice_assignment", 0); /* "View.MemoryView":401 * 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) */ if (!(likely(((__pyx_v_src) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_src, __pyx_memoryview_type))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_src; __Pyx_INCREF(__pyx_t_1); /* "View.MemoryView":402 * * 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_filename = __pyx_f[2]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_2 = __pyx_v_dst; __Pyx_INCREF(__pyx_t_2); /* "View.MemoryView":403 * 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_3 = PyObject_GetAttr(__pyx_v_src, __pyx_n_s__ndim); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyObject_GetAttr(__pyx_v_dst, __pyx_n_s__ndim); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_6 = __pyx_memoryview_copy_contents((__pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_t_1), (&__pyx_v_src_slice))[0]), (__pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_t_2), (&__pyx_v_dst_slice))[0]), __pyx_t_4, __pyx_t_5, __pyx_v_self->dtype_is_object); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __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_AddTraceback("View.MemoryView.memoryview.setitem_slice_assignment", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":405 * 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 */ 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[128]; void *__pyx_v_tmp; void *__pyx_v_item; __Pyx_memviewslice __pyx_v_tmp_slice; __Pyx_memviewslice *__pyx_v_dst_slice; PyObject *__pyx_r = NULL; __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; PyObject *__pyx_t_7 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("setitem_slice_assign_scalar", 0); /* "View.MemoryView":407 * 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":411 * * cdef __Pyx_memviewslice tmp_slice, *dst_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)); /* "View.MemoryView":413 * dst_slice = get_slice_from_memview(dst, &tmp_slice) * * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<< * tmp = malloc(self.view.itemsize) * if tmp == NULL: */ __pyx_t_1 = (((size_t)__pyx_v_self->view.itemsize) > (sizeof(__pyx_v_array))); if (__pyx_t_1) { /* "View.MemoryView":414 * * if self.view.itemsize > sizeof(array): * tmp = malloc(self.view.itemsize) # <<<<<<<<<<<<<< * if tmp == NULL: * raise MemoryError */ __pyx_v_tmp = malloc(__pyx_v_self->view.itemsize); /* "View.MemoryView":415 * if self.view.itemsize > sizeof(array): * tmp = malloc(self.view.itemsize) * if tmp == NULL: # <<<<<<<<<<<<<< * raise MemoryError * item = tmp */ __pyx_t_1 = (__pyx_v_tmp == NULL); if (__pyx_t_1) { /* "View.MemoryView":416 * tmp = malloc(self.view.itemsize) * if tmp == NULL: * raise MemoryError # <<<<<<<<<<<<<< * item = tmp * else: */ PyErr_NoMemory(); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; /* "View.MemoryView":417 * if tmp == NULL: * raise MemoryError * item = tmp # <<<<<<<<<<<<<< * else: * item = array */ __pyx_v_item = __pyx_v_tmp; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":419 * item = tmp * else: * item = array # <<<<<<<<<<<<<< * * if self.dtype_is_object: */ __pyx_v_item = ((void *)__pyx_v_array); } __pyx_L3:; /* "View.MemoryView":421 * item = array * * if self.dtype_is_object: # <<<<<<<<<<<<<< * ( item)[0] = value * else: */ if (__pyx_v_self->dtype_is_object) { /* "View.MemoryView":422 * * if self.dtype_is_object: * ( item)[0] = value # <<<<<<<<<<<<<< * else: * try: */ (((PyObject **)__pyx_v_item)[0]) = ((PyObject *)__pyx_v_value); goto __pyx_L5; } /*else*/ { /* "View.MemoryView":424 * ( item)[0] = value * else: * try: # <<<<<<<<<<<<<< * self.assign_item_from_object( item, value) * except: */ { __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":425 * else: * try: * self.assign_item_from_object( item, value) # <<<<<<<<<<<<<< * except: * free(tmp) */ __pyx_t_5 = ((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_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L6_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L13_try_end; __pyx_L6_error:; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; /* "View.MemoryView":426 * try: * self.assign_item_from_object( item, value) * except: # <<<<<<<<<<<<<< * free(tmp) * raise */ /*except:*/ { __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L8_except_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); /* "View.MemoryView":427 * self.assign_item_from_object( item, value) * except: * free(tmp) # <<<<<<<<<<<<<< * raise * */ free(__pyx_v_tmp); /* "View.MemoryView":428 * except: * free(tmp) * raise # <<<<<<<<<<<<<< * * */ __Pyx_GIVEREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_7); __Pyx_ErrRestore(__pyx_t_5, __pyx_t_6, __pyx_t_7); __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0; {__pyx_filename = __pyx_f[2]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L8_except_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L7_exception_handled; } __pyx_L8_except_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_L7_exception_handled:; __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); __pyx_L13_try_end:; } } __pyx_L5:; /* "View.MemoryView":432 * * * 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); if (__pyx_t_1) { /* "View.MemoryView":433 * * 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) */ __pyx_t_7 = assert_direct_dimensions(__pyx_v_self->view.suboffsets, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L16; } __pyx_L16:; /* "View.MemoryView":435 * 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) # <<<<<<<<<<<<<< * free(tmp) * */ __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":436 * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, * item, self.dtype_is_object) * free(tmp) # <<<<<<<<<<<<<< * * cdef setitem_indexed(self, index, value): */ free(__pyx_v_tmp); __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_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":438 * free(tmp) * * 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; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations char *__pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("setitem_indexed", 0); /* "View.MemoryView":439 * * cdef setitem_indexed(self, index, value): * cdef char *itemp = self.get_item_pointer(index) # <<<<<<<<<<<<<< * self.assign_item_from_object(itemp, value) * */ __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 == NULL)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_itemp = __pyx_t_1; /* "View.MemoryView":440 * 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_filename = __pyx_f[2]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":442 * 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""" */ 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_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; size_t __pyx_t_7; int __pyx_t_8; int __pyx_t_9; PyObject *__pyx_t_10 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("convert_item_to_object", 0); /* "View.MemoryView":445 * """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_1 = __Pyx_Import(((PyObject *)__pyx_n_s__struct), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_struct = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":448 * cdef bytes bytesitem * * bytesitem = itemp[:self.view.itemsize] # <<<<<<<<<<<<<< * try: * result = struct.unpack(self.view.format, bytesitem) */ __pyx_t_1 = PyBytes_FromStringAndSize(((const char*)__pyx_v_itemp) + 0, __pyx_v_self->view.itemsize - 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_v_bytesitem = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":449 * * bytesitem = itemp[:self.view.itemsize] * try: # <<<<<<<<<<<<<< * result = struct.unpack(self.view.format, bytesitem) * except struct.error: */ { __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":450 * 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_1 = PyObject_GetAttr(__pyx_v_struct, __pyx_n_s__unpack); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); __Pyx_INCREF(((PyObject *)__pyx_v_bytesitem)); PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_v_bytesitem)); __Pyx_GIVEREF(((PyObject *)__pyx_v_bytesitem)); __pyx_t_5 = 0; __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; __pyx_v_result = __pyx_t_5; __pyx_t_5 = 0; } /*else:*/ { /* "View.MemoryView":454 * raise ValueError("Unable to convert item to object") * else: * if len(self.view.format) == 1: # <<<<<<<<<<<<<< * return result[0] * return result */ __pyx_t_7 = strlen(__pyx_v_self->view.format); __pyx_t_8 = (__pyx_t_7 == 1); if (__pyx_t_8) { /* "View.MemoryView":455 * else: * if len(self.view.format) == 1: * return result[0] # <<<<<<<<<<<<<< * return result * */ __Pyx_XDECREF(__pyx_r); __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_result, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;} __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L6_except_return; goto __pyx_L11; } __pyx_L11:; /* "View.MemoryView":456 * 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_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L10_try_end; __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; /* "View.MemoryView":451 * try: * result = struct.unpack(self.view.format, bytesitem) * except struct.error: # <<<<<<<<<<<<<< * raise ValueError("Unable to convert item to object") * else: */ __pyx_t_5 = PyObject_GetAttr(__pyx_v_struct, __pyx_n_s__error); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;} __Pyx_GOTREF(__pyx_t_5); __pyx_t_9 = PyErr_ExceptionMatches(__pyx_t_5); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_9) { __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_1); /* "View.MemoryView":452 * 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_10 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_30), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_Raise(__pyx_t_10, 0, 0, 0); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; {__pyx_filename = __pyx_f[2]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L4_exception_handled; } __pyx_L5_except_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; __pyx_L4_exception_handled:; __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); __pyx_L10_try_end:; } __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_10); __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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":458 * 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""" */ 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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; 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 = NULL; char *__pyx_t_8; char *__pyx_t_9; char *__pyx_t_10; char *__pyx_t_11; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("assign_item_from_object", 0); /* "View.MemoryView":461 * """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(((PyObject *)__pyx_n_s__struct), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_struct = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":466 * cdef Py_ssize_t i * * if isinstance(value, tuple): # <<<<<<<<<<<<<< * bytesvalue = struct.pack(self.view.format, *value) * else: */ __pyx_t_1 = ((PyObject *)((PyObject*)(&PyTuple_Type))); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_value, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "View.MemoryView":467 * * if isinstance(value, tuple): * bytesvalue = struct.pack(self.view.format, *value) # <<<<<<<<<<<<<< * else: * bytesvalue = struct.pack(self.view.format, value) */ __pyx_t_1 = PyObject_GetAttr(__pyx_v_struct, __pyx_n_s__pack); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PySequence_Tuple(__pyx_v_value); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_t_5 = PyNumber_Add(((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_bytesvalue = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":469 * bytesvalue = struct.pack(self.view.format, *value) * else: * bytesvalue = struct.pack(self.view.format, value) # <<<<<<<<<<<<<< * * for i, c in enumerate(bytesvalue): */ __pyx_t_3 = PyObject_GetAttr(__pyx_v_struct, __pyx_n_s__pack); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5)); __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); __Pyx_INCREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); __pyx_t_5 = 0; __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_bytesvalue = ((PyObject*)__pyx_t_5); __pyx_t_5 = 0; } __pyx_L3:; /* "View.MemoryView":471 * bytesvalue = struct.pack(self.view.format, value) * * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< * itemp[i] = c * */ __pyx_t_6 = 0; if (unlikely(((PyObject *)__pyx_v_bytesvalue) == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __Pyx_INCREF(((PyObject *)__pyx_v_bytesvalue)); __pyx_t_7 = __pyx_v_bytesvalue; __pyx_t_9 = PyBytes_AS_STRING(__pyx_t_7); __pyx_t_10 = (__pyx_t_9 + PyBytes_GET_SIZE(__pyx_t_7)); for (__pyx_t_11 = __pyx_t_9; __pyx_t_11 < __pyx_t_10; __pyx_t_11++) { __pyx_t_8 = __pyx_t_11; __pyx_v_c = (__pyx_t_8[0]); /* "View.MemoryView":472 * * for i, c in enumerate(bytesvalue): * itemp[i] = c # <<<<<<<<<<<<<< * * @cname('getbuffer') */ __pyx_v_i = __pyx_t_6; /* "View.MemoryView":471 * bytesvalue = struct.pack(self.view.format, value) * * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< * itemp[i] = c * */ __pyx_t_6 = (__pyx_t_6 + 1); /* "View.MemoryView":472 * * for i, c in enumerate(bytesvalue): * itemp[i] = c # <<<<<<<<<<<<<< * * @cname('getbuffer') */ (__pyx_v_itemp[__pyx_v_i]) = __pyx_v_c; } __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; __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_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(((PyObject *)__pyx_t_7)); __Pyx_AddTraceback("View.MemoryView.memoryview.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_struct); __Pyx_XDECREF(__pyx_v_bytesvalue); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ static 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_getbuffer_MemoryView_10memoryview_8__getbuffer__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":475 * * @cname('getbuffer') * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< * if flags & PyBUF_STRIDES: * info.shape = self.view.shape */ static int __pyx_memoryview_getbuffer_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__getbuffer__", 0); if (__pyx_v_info != NULL) { __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); __Pyx_GIVEREF(__pyx_v_info->obj); } /* "View.MemoryView":476 * @cname('getbuffer') * def __getbuffer__(self, Py_buffer *info, int flags): * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< * info.shape = self.view.shape * else: */ __pyx_t_1 = (__pyx_v_flags & PyBUF_STRIDES); if (__pyx_t_1) { /* "View.MemoryView":477 * def __getbuffer__(self, Py_buffer *info, int flags): * if flags & PyBUF_STRIDES: * info.shape = self.view.shape # <<<<<<<<<<<<<< * else: * info.shape = NULL */ __pyx_v_info->shape = __pyx_v_self->view.shape; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":479 * info.shape = self.view.shape * else: * info.shape = NULL # <<<<<<<<<<<<<< * * if flags & PyBUF_STRIDES: */ __pyx_v_info->shape = NULL; } __pyx_L3:; /* "View.MemoryView":481 * info.shape = NULL * * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< * info.strides = self.view.strides * else: */ __pyx_t_1 = (__pyx_v_flags & PyBUF_STRIDES); if (__pyx_t_1) { /* "View.MemoryView":482 * * if flags & PyBUF_STRIDES: * info.strides = self.view.strides # <<<<<<<<<<<<<< * else: * info.strides = NULL */ __pyx_v_info->strides = __pyx_v_self->view.strides; goto __pyx_L4; } /*else*/ { /* "View.MemoryView":484 * info.strides = self.view.strides * else: * info.strides = NULL # <<<<<<<<<<<<<< * * if flags & PyBUF_INDIRECT: */ __pyx_v_info->strides = NULL; } __pyx_L4:; /* "View.MemoryView":486 * info.strides = NULL * * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<< * info.suboffsets = self.view.suboffsets * else: */ __pyx_t_1 = (__pyx_v_flags & PyBUF_INDIRECT); if (__pyx_t_1) { /* "View.MemoryView":487 * * if flags & PyBUF_INDIRECT: * info.suboffsets = self.view.suboffsets # <<<<<<<<<<<<<< * else: * info.suboffsets = NULL */ __pyx_v_info->suboffsets = __pyx_v_self->view.suboffsets; goto __pyx_L5; } /*else*/ { /* "View.MemoryView":489 * info.suboffsets = self.view.suboffsets * else: * info.suboffsets = NULL # <<<<<<<<<<<<<< * * if flags & PyBUF_FORMAT: */ __pyx_v_info->suboffsets = NULL; } __pyx_L5:; /* "View.MemoryView":491 * info.suboffsets = NULL * * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< * info.format = self.view.format * else: */ __pyx_t_1 = (__pyx_v_flags & PyBUF_FORMAT); if (__pyx_t_1) { /* "View.MemoryView":492 * * if flags & PyBUF_FORMAT: * info.format = self.view.format # <<<<<<<<<<<<<< * else: * info.format = NULL */ __pyx_v_info->format = __pyx_v_self->view.format; goto __pyx_L6; } /*else*/ { /* "View.MemoryView":494 * info.format = self.view.format * else: * info.format = NULL # <<<<<<<<<<<<<< * * info.buf = self.view.buf */ __pyx_v_info->format = NULL; } __pyx_L6:; /* "View.MemoryView":496 * info.format = NULL * * info.buf = self.view.buf # <<<<<<<<<<<<<< * info.ndim = self.view.ndim * info.itemsize = self.view.itemsize */ __pyx_v_info->buf = __pyx_v_self->view.buf; /* "View.MemoryView":497 * * info.buf = self.view.buf * info.ndim = self.view.ndim # <<<<<<<<<<<<<< * info.itemsize = self.view.itemsize * info.len = self.view.len */ __pyx_v_info->ndim = __pyx_v_self->view.ndim; /* "View.MemoryView":498 * info.buf = self.view.buf * info.ndim = self.view.ndim * info.itemsize = self.view.itemsize # <<<<<<<<<<<<<< * info.len = self.view.len * info.readonly = 0 */ __pyx_v_info->itemsize = __pyx_v_self->view.itemsize; /* "View.MemoryView":499 * info.ndim = self.view.ndim * info.itemsize = self.view.itemsize * info.len = self.view.len # <<<<<<<<<<<<<< * info.readonly = 0 * info.obj = self */ __pyx_v_info->len = __pyx_v_self->view.len; /* "View.MemoryView":500 * info.itemsize = self.view.itemsize * info.len = self.view.len * info.readonly = 0 # <<<<<<<<<<<<<< * info.obj = self * */ __pyx_v_info->readonly = 0; /* "View.MemoryView":501 * info.len = self.view.len * info.readonly = 0 * info.obj = self # <<<<<<<<<<<<<< * * __pyx_getbuffer = capsule( &__pyx_memoryview_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); __pyx_r = 0; if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) { __Pyx_GOTREF(Py_None); __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL; } __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_transpose(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_transpose(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_transpose_MemoryView_10memoryview_1T___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":508 * property T: * @cname('__pyx_memoryview_transpose') * def __get__(self): # <<<<<<<<<<<<<< * cdef _memoryviewslice result = memoryview_copy(self) * transpose_memslice(&result.from_slice) */ static PyObject *__pyx_memoryview_transpose_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self) { struct __pyx_memoryviewslice_obj *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":509 * @cname('__pyx_memoryview_transpose') * def __get__(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_filename = __pyx_f[2]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_1); __pyx_t_1 = 0; /* "View.MemoryView":510 * def __get__(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 == 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":511 * cdef _memoryviewslice result = memoryview_copy(self) * transpose_memslice(&result.from_slice) * return result # <<<<<<<<<<<<<< * * property base: */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview__get__base(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview__get__base(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview__get__base_MemoryView_10memoryview_4base___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":515 * property base: * @cname('__pyx_memoryview__get__base') * def __get__(self): # <<<<<<<<<<<<<< * return self.obj * */ static PyObject *__pyx_memoryview__get__base_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":516 * @cname('__pyx_memoryview__get__base') * def __get__(self): * return self.obj # <<<<<<<<<<<<<< * * property shape: */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->obj); __pyx_r = __pyx_v_self->obj; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_shape(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_shape(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_shape_MemoryView_10memoryview_5shape___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":520 * property shape: * @cname('__pyx_memoryview_get_shape') * def __get__(self): # <<<<<<<<<<<<<< * return tuple([self.view.shape[i] for i in xrange(self.view.ndim)]) * */ static PyObject *__pyx_memoryview_get_shape_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self) { int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":521 * @cname('__pyx_memoryview_get_shape') * def __get__(self): * return tuple([self.view.shape[i] for i in xrange(self.view.ndim)]) # <<<<<<<<<<<<<< * * property strides: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_v_self->view.ndim; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; __pyx_t_4 = PyInt_FromSsize_t((__pyx_v_self->view.shape[__pyx_v_i])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); if (unlikely(__Pyx_PyList_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_t_4 = ((PyObject *)PyList_AsTuple(__pyx_t_1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_r = ((PyObject *)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L0; __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("View.MemoryView.memoryview.shape.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_strides(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_strides(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_strides_MemoryView_10memoryview_7strides___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":525 * property strides: * @cname('__pyx_memoryview_get_strides') * def __get__(self): # <<<<<<<<<<<<<< * if self.view.strides == NULL: * */ static PyObject *__pyx_memoryview_get_strides_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self) { int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_t_4; PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":526 * @cname('__pyx_memoryview_get_strides') * def __get__(self): * if self.view.strides == NULL: # <<<<<<<<<<<<<< * * raise ValueError("Buffer view does not expose strides") */ __pyx_t_1 = (__pyx_v_self->view.strides == NULL); if (__pyx_t_1) { /* "View.MemoryView":528 * if self.view.strides == NULL: * * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< * * return tuple([self.view.strides[i] for i in xrange(self.view.ndim)]) */ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_32), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":530 * raise ValueError("Buffer view does not expose strides") * * return tuple([self.view.strides[i] for i in xrange(self.view.ndim)]) # <<<<<<<<<<<<<< * * property suboffsets: */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_v_self->view.ndim; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; __pyx_t_5 = PyInt_FromSsize_t((__pyx_v_self->view.strides[__pyx_v_i])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); if (unlikely(__Pyx_PyList_Append(__pyx_t_2, (PyObject*)__pyx_t_5))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __pyx_t_5 = ((PyObject *)PyList_AsTuple(__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = ((PyObject *)__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L0; __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_AddTraceback("View.MemoryView.memoryview.strides.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_suboffsets(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_suboffsets(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_suboffsets_MemoryView_10memoryview_10suboffsets___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":534 * property suboffsets: * @cname('__pyx_memoryview_get_suboffsets') * def __get__(self): # <<<<<<<<<<<<<< * if self.view.suboffsets == NULL: * return [-1] * self.view.ndim */ static PyObject *__pyx_memoryview_get_suboffsets_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self) { int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_t_4; PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":535 * @cname('__pyx_memoryview_get_suboffsets') * def __get__(self): * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<< * return [-1] * self.view.ndim * */ __pyx_t_1 = (__pyx_v_self->view.suboffsets == NULL); if (__pyx_t_1) { /* "View.MemoryView":536 * def __get__(self): * if self.view.suboffsets == NULL: * return [-1] * self.view.ndim # <<<<<<<<<<<<<< * * return tuple([self.view.suboffsets[i] for i in xrange(self.view.ndim)]) */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyList_New(1 * ((__pyx_v_self->view.ndim<0) ? 0:__pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < __pyx_v_self->view.ndim; __pyx_temp++) { __Pyx_INCREF(__pyx_int_neg_1); PyList_SET_ITEM(__pyx_t_2, __pyx_temp, __pyx_int_neg_1); __Pyx_GIVEREF(__pyx_int_neg_1); } } __pyx_r = ((PyObject *)__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L0; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":538 * return [-1] * self.view.ndim * * return tuple([self.view.suboffsets[i] for i in xrange(self.view.ndim)]) # <<<<<<<<<<<<<< * * property ndim: */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_v_self->view.ndim; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; __pyx_t_5 = PyInt_FromSsize_t((__pyx_v_self->view.suboffsets[__pyx_v_i])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); if (unlikely(__Pyx_PyList_Append(__pyx_t_2, (PyObject*)__pyx_t_5))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __pyx_t_5 = ((PyObject *)PyList_AsTuple(__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = ((PyObject *)__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L0; __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_AddTraceback("View.MemoryView.memoryview.suboffsets.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_ndim(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_ndim(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_ndim_MemoryView_10memoryview_4ndim___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":542 * property ndim: * @cname('__pyx_memoryview_get_ndim') * def __get__(self): # <<<<<<<<<<<<<< * return self.view.ndim * */ static PyObject *__pyx_memoryview_get_ndim_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":543 * @cname('__pyx_memoryview_get_ndim') * def __get__(self): * return self.view.ndim # <<<<<<<<<<<<<< * * property itemsize: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyInt_FromLong(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_itemsize(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_itemsize(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_itemsize_MemoryView_10memoryview_8itemsize___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":547 * property itemsize: * @cname('__pyx_memoryview_get_itemsize') * def __get__(self): # <<<<<<<<<<<<<< * return self.view.itemsize * */ static PyObject *__pyx_memoryview_get_itemsize_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":548 * @cname('__pyx_memoryview_get_itemsize') * def __get__(self): * return self.view.itemsize # <<<<<<<<<<<<<< * * property nbytes: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 548; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_nbytes(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_nbytes(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_nbytes_MemoryView_10memoryview_6nbytes___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":552 * property nbytes: * @cname('__pyx_memoryview_get_nbytes') * def __get__(self): # <<<<<<<<<<<<<< * return self.size * self.view.itemsize * */ static PyObject *__pyx_memoryview_get_nbytes_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":553 * @cname('__pyx_memoryview_get_nbytes') * def __get__(self): * return self.size * self.view.itemsize # <<<<<<<<<<<<<< * * property size: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __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_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_AddTraceback("View.MemoryView.memoryview.nbytes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryview_get_size(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryview_get_size(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryview_get_size_MemoryView_10memoryview_4size___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":557 * property size: * @cname('__pyx_memoryview_get_size') * def __get__(self): # <<<<<<<<<<<<<< * if self._size is None: * result = 1 */ static PyObject *__pyx_memoryview_get_size_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_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_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":558 * @cname('__pyx_memoryview_get_size') * def __get__(self): * if self._size is None: # <<<<<<<<<<<<<< * result = 1 * */ __pyx_t_1 = (__pyx_v_self->_size == Py_None); if (__pyx_t_1) { /* "View.MemoryView":559 * def __get__(self): * if self._size is None: * result = 1 # <<<<<<<<<<<<<< * * for length in self.shape: */ __Pyx_INCREF(__pyx_int_1); __pyx_v_result = __pyx_int_1; /* "View.MemoryView":561 * result = 1 * * for length in self.shape: # <<<<<<<<<<<<<< * result *= length * */ __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (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_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_3)) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_3)) { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { __pyx_t_2 = __pyx_t_5(__pyx_t_3); if (unlikely(!__pyx_t_2)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } __Pyx_GOTREF(__pyx_t_2); } __Pyx_XDECREF(__pyx_v_length); __pyx_v_length = __pyx_t_2; __pyx_t_2 = 0; /* "View.MemoryView":562 * * for length in self.shape: * result *= length # <<<<<<<<<<<<<< * * self._size = result */ __pyx_t_2 = PyNumber_InPlaceMultiply(__pyx_v_result, __pyx_v_length); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_v_result); __pyx_v_result = __pyx_t_2; __pyx_t_2 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "View.MemoryView":564 * result *= length * * 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; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":566 * self._size = result * * return self._size # <<<<<<<<<<<<<< * * def __len__(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_size); __pyx_r = __pyx_v_self->_size; goto __pyx_L0; __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.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_RefNannyFinishContext(); return __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_MemoryView_10memoryview_10__len__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":568 * return self._size * * def __len__(self): # <<<<<<<<<<<<<< * if self.view.ndim >= 1: * return self.view.shape[0] */ static Py_ssize_t __pyx_memoryview_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self) { Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__len__", 0); /* "View.MemoryView":569 * * def __len__(self): * if self.view.ndim >= 1: # <<<<<<<<<<<<<< * return self.view.shape[0] * */ __pyx_t_1 = (__pyx_v_self->view.ndim >= 1); if (__pyx_t_1) { /* "View.MemoryView":570 * def __len__(self): * if self.view.ndim >= 1: * return self.view.shape[0] # <<<<<<<<<<<<<< * * return 0 */ __pyx_r = (__pyx_v_self->view.shape[0]); goto __pyx_L0; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":572 * return self.view.shape[0] * * return 0 # <<<<<<<<<<<<<< * * def __repr__(self): */ __pyx_r = 0; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_12__repr__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":574 * return 0 * * def __repr__(self): # <<<<<<<<<<<<<< * return "" % (self.base.__class__.__name__, * id(self)) */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__repr__", 0); /* "View.MemoryView":575 * * def __repr__(self): * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<< * id(self)) * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__base); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____class__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____name__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "View.MemoryView":576 * def __repr__(self): * return "" % (self.base.__class__.__name__, * id(self)) # <<<<<<<<<<<<<< * * def __str__(self): */ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); __pyx_t_3 = PyObject_Call(__pyx_builtin_id, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_33), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = ((PyObject *)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; __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_AddTraceback("View.MemoryView.memoryview.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_14__str__(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":578 * id(self)) * * def __str__(self): # <<<<<<<<<<<<<< * return "" % (self.base.__class__.__name__,) * */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__str__", 0); /* "View.MemoryView":579 * * def __str__(self): * return "" % (self.base.__class__.__name__,) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__base); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____class__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____name__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_34), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; __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.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_16is_c_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":582 * * * def is_c_contig(self): # <<<<<<<<<<<<<< * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) */ static PyObject *__pyx_memoryview_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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("is_c_contig", 0); /* "View.MemoryView":584 * def is_c_contig(self): * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< * return slice_is_contig(mslice, 'C', self.view.ndim) * */ __pyx_v_mslice = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); /* "View.MemoryView":585 * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) * return slice_is_contig(mslice, 'C', self.view.ndim) # <<<<<<<<<<<<<< * * def is_f_contig(self): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig(__pyx_v_mslice, 'C', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 585; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); 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_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_18is_f_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":587 * return slice_is_contig(mslice, 'C', self.view.ndim) * * def is_f_contig(self): # <<<<<<<<<<<<<< * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) */ static PyObject *__pyx_memoryview_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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("is_f_contig", 0); /* "View.MemoryView":589 * def is_f_contig(self): * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< * return slice_is_contig(mslice, 'F', self.view.ndim) * */ __pyx_v_mslice = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); /* "View.MemoryView":590 * cdef __Pyx_memviewslice *mslice, tmp * mslice = get_slice_from_memview(self, &tmp) * return slice_is_contig(mslice, 'F', self.view.ndim) # <<<<<<<<<<<<<< * * def copy(self): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig(__pyx_v_mslice, 'F', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __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_RefNannyFinishContext(); return __pyx_r; } /* 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_MemoryView_10memoryview_20copy(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":592 * return slice_is_contig(mslice, 'F', self.view.ndim) * * def copy(self): # <<<<<<<<<<<<<< * cdef __Pyx_memviewslice mslice * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS */ static PyObject *__pyx_memoryview_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self) { __Pyx_memviewslice __pyx_v_mslice; int __pyx_v_flags; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_memviewslice __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("copy", 0); /* "View.MemoryView":594 * def copy(self): * cdef __Pyx_memviewslice mslice * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS # <<<<<<<<<<<<<< * * slice_copy(self, &mslice) */ __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_F_CONTIGUOUS)); /* "View.MemoryView":596 * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS * * 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":600 * self.view.itemsize, * flags|PyBUF_C_CONTIGUOUS, * self.dtype_is_object) # <<<<<<<<<<<<<< * * return memoryview_copy_from_slice(self, &mslice) */ __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_mslice), __pyx_k__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_filename = __pyx_f[2]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_mslice = __pyx_t_1; /* "View.MemoryView":602 * self.dtype_is_object) * * return memoryview_copy_from_slice(self, &mslice) # <<<<<<<<<<<<<< * * 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_filename = __pyx_f[2]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("View.MemoryView.memoryview.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __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_MemoryView_10memoryview_22copy_fortran(((struct __pyx_memoryview_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":604 * return memoryview_copy_from_slice(self, &mslice) * * def copy_fortran(self): # <<<<<<<<<<<<<< * cdef __Pyx_memviewslice src, dst * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS */ static PyObject *__pyx_memoryview_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_RefNannyDeclarations __Pyx_memviewslice __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("copy_fortran", 0); /* "View.MemoryView":606 * def copy_fortran(self): * cdef __Pyx_memviewslice src, dst * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS # <<<<<<<<<<<<<< * * slice_copy(self, &src) */ __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_C_CONTIGUOUS)); /* "View.MemoryView":608 * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS * * 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":612 * self.view.itemsize, * flags|PyBUF_F_CONTIGUOUS, * self.dtype_is_object) # <<<<<<<<<<<<<< * * return memoryview_copy_from_slice(self, &dst) */ __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_src), __pyx_k__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_filename = __pyx_f[2]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_dst = __pyx_t_1; /* "View.MemoryView":614 * self.dtype_is_object) * * return memoryview_copy_from_slice(self, &dst) # <<<<<<<<<<<<<< * * */ __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_filename = __pyx_f[2]; __pyx_lineno = 614; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); 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_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":618 * * @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 */ 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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("memoryview_cwrapper", 0); /* "View.MemoryView":619 * @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_t_1 = PyInt_FromLong(__pyx_v_flags); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_o); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_o); __Pyx_GIVEREF(__pyx_v_o); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject *)__pyx_memoryview_type)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_v_result = ((struct __pyx_memoryview_obj *)__pyx_t_2); __pyx_t_2 = 0; /* "View.MemoryView":620 * 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_v_result->typeinfo = __pyx_v_typeinfo; /* "View.MemoryView":621 * cdef memoryview result = memoryview(o, flags, dtype_is_object) * result.typeinfo = typeinfo * return result # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_check') */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0; __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_AddTraceback("View.MemoryView.memoryview_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":624 * * @cname('__pyx_memoryview_check') * cdef bint memoryview_check(object o): # <<<<<<<<<<<<<< * return isinstance(o, memoryview) * */ static int __pyx_memoryview_check(PyObject *__pyx_v_o) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; __Pyx_RefNannySetupContext("memoryview_check", 0); /* "View.MemoryView":625 * @cname('__pyx_memoryview_check') * cdef bint memoryview_check(object o): * return isinstance(o, memoryview) # <<<<<<<<<<<<<< * * cdef tuple _unellipsify(object index, int ndim): */ __pyx_t_1 = ((PyObject *)((PyObject *)__pyx_memoryview_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_o, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":627 * return isinstance(o, memoryview) * * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<< * """ * Replace all ellipses with full slices and fill incomplete indices with */ static PyObject *_unellipsify(PyObject *__pyx_v_index, int __pyx_v_ndim) { PyObject *__pyx_v_tup = NULL; PyObject *__pyx_v_result = NULL; PyObject *__pyx_v_have_slices = NULL; int __pyx_v_seen_ellipsis; CYTHON_UNUSED PyObject *__pyx_v_idx = NULL; PyObject *__pyx_v_item = NULL; PyObject *__pyx_v_nslices = NULL; PyObject *__pyx_r = NULL; __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; Py_ssize_t __pyx_t_9; PyObject *__pyx_t_10 = NULL; int __pyx_t_11; int __pyx_t_12; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("_unellipsify", 0); /* "View.MemoryView":632 * full slices. * """ * if not isinstance(index, tuple): # <<<<<<<<<<<<<< * tup = (index,) * else: */ __pyx_t_1 = ((PyObject *)((PyObject*)(&PyTuple_Type))); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_index, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = (!__pyx_t_2); if (__pyx_t_3) { /* "View.MemoryView":633 * """ * if not isinstance(index, tuple): * tup = (index,) # <<<<<<<<<<<<<< * else: * tup = index */ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_index); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_index); __Pyx_GIVEREF(__pyx_v_index); __pyx_v_tup = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":635 * tup = (index,) * else: * tup = index # <<<<<<<<<<<<<< * * result = [] */ __Pyx_INCREF(__pyx_v_index); __pyx_v_tup = __pyx_v_index; } __pyx_L3:; /* "View.MemoryView":637 * tup = index * * result = [] # <<<<<<<<<<<<<< * have_slices = False * seen_ellipsis = False */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":638 * * result = [] * have_slices = False # <<<<<<<<<<<<<< * seen_ellipsis = False * for idx, item in enumerate(tup): */ __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_have_slices = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":639 * result = [] * have_slices = False * seen_ellipsis = False # <<<<<<<<<<<<<< * for idx, item in enumerate(tup): * if item is Ellipsis: */ __pyx_v_seen_ellipsis = 0; /* "View.MemoryView":640 * have_slices = False * seen_ellipsis = False * for idx, item in enumerate(tup): # <<<<<<<<<<<<<< * if item is Ellipsis: * if not seen_ellipsis: */ __Pyx_INCREF(__pyx_int_0); __pyx_t_1 = __pyx_int_0; if (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_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; } for (;;) { if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_4)) { if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_4)) { if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; #if CYTHON_COMPILING_IN_CPYTHON __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_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { __pyx_t_7 = __pyx_t_6(__pyx_t_4); if (unlikely(!__pyx_t_7)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } __Pyx_GOTREF(__pyx_t_7); } __Pyx_XDECREF(__pyx_v_item); __pyx_v_item = __pyx_t_7; __pyx_t_7 = 0; __Pyx_INCREF(__pyx_t_1); __Pyx_XDECREF(__pyx_v_idx); __pyx_v_idx = __pyx_t_1; __pyx_t_7 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = __pyx_t_7; __pyx_t_7 = 0; /* "View.MemoryView":641 * 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)) */ __pyx_t_3 = (__pyx_v_item == __pyx_builtin_Ellipsis); if (__pyx_t_3) { /* "View.MemoryView":642 * 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_3 = (!__pyx_v_seen_ellipsis); if (__pyx_t_3) { /* "View.MemoryView":643 * if item is Ellipsis: * if not seen_ellipsis: * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<< * seen_ellipsis = True * else: */ __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_result), __pyx_n_s__extend); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = PyObject_Call(((PyObject *)((PyObject*)(&PySlice_Type))), ((PyObject *)__pyx_k_tuple_35), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = PyObject_Length(__pyx_v_tup); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_10 = PyList_New(1 * ((((__pyx_v_ndim - __pyx_t_9) + 1)<0) ? 0:((__pyx_v_ndim - __pyx_t_9) + 1))); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < ((__pyx_v_ndim - __pyx_t_9) + 1); __pyx_temp++) { __Pyx_INCREF(__pyx_t_8); PyList_SET_ITEM(__pyx_t_10, __pyx_temp, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); } } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_10)); __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; /* "View.MemoryView":644 * 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; goto __pyx_L7; } /*else*/ { /* "View.MemoryView":646 * seen_ellipsis = True * else: * result.append(slice(None)) # <<<<<<<<<<<<<< * have_slices = True * else: */ __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)(&PySlice_Type))), ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_11 = PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } __pyx_L7:; /* "View.MemoryView":647 * else: * result.append(slice(None)) * have_slices = True # <<<<<<<<<<<<<< * else: * if not isinstance(item, slice) and not PyIndex_Check(item): */ __pyx_t_10 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_v_have_slices); __pyx_v_have_slices = __pyx_t_10; __pyx_t_10 = 0; goto __pyx_L6; } /*else*/ { /* "View.MemoryView":649 * have_slices = True * else: * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<< * raise TypeError("Cannot index with type '%s'" % type(item)) * */ __pyx_t_10 = ((PyObject *)((PyObject*)(&PySlice_Type))); __Pyx_INCREF(__pyx_t_10); __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_item, __pyx_t_10); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_2 = (!__pyx_t_3); if (__pyx_t_2) { __pyx_t_3 = (!PyIndex_Check(__pyx_v_item)); __pyx_t_12 = __pyx_t_3; } else { __pyx_t_12 = __pyx_t_2; } if (__pyx_t_12) { /* "View.MemoryView":650 * else: * if not isinstance(item, slice) and not PyIndex_Check(item): * raise TypeError("Cannot index with type '%s'" % type(item)) # <<<<<<<<<<<<<< * * have_slices = have_slices or isinstance(item, slice) */ __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_37), ((PyObject *)Py_TYPE(__pyx_v_item))); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_10)); __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_10)); __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; __pyx_t_10 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; __Pyx_Raise(__pyx_t_10, 0, 0, 0); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; {__pyx_filename = __pyx_f[2]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L8; } __pyx_L8:; /* "View.MemoryView":652 * raise TypeError("Cannot index with type '%s'" % type(item)) * * have_slices = have_slices or isinstance(item, slice) # <<<<<<<<<<<<<< * result.append(item) * */ __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (!__pyx_t_12) { __pyx_t_10 = ((PyObject *)((PyObject*)(&PySlice_Type))); __Pyx_INCREF(__pyx_t_10); __pyx_t_12 = __Pyx_TypeCheck(__pyx_v_item, __pyx_t_10); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyBool_FromLong(__pyx_t_12); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_8 = __pyx_t_10; __pyx_t_10 = 0; } else { __Pyx_INCREF(__pyx_v_have_slices); __pyx_t_8 = __pyx_v_have_slices; } __Pyx_DECREF(__pyx_v_have_slices); __pyx_v_have_slices = __pyx_t_8; __pyx_t_8 = 0; /* "View.MemoryView":653 * * have_slices = have_slices or isinstance(item, slice) * result.append(item) # <<<<<<<<<<<<<< * * nslices = ndim - len(result) */ __pyx_t_11 = PyList_Append(__pyx_v_result, __pyx_v_item); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L6:; } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "View.MemoryView":655 * result.append(item) * * nslices = ndim - len(result) # <<<<<<<<<<<<<< * if nslices: * result.extend([slice(None)] * nslices) */ __pyx_t_5 = PyList_GET_SIZE(((PyObject *)__pyx_v_result)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = PyInt_FromSsize_t((__pyx_v_ndim - __pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_nslices = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":656 * * nslices = ndim - len(result) * if nslices: # <<<<<<<<<<<<<< * result.extend([slice(None)] * nslices) * */ __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_nslices); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_12) { /* "View.MemoryView":657 * nslices = ndim - len(result) * if nslices: * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<< * * return have_slices or nslices, tuple(result) */ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_result), __pyx_n_s__extend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PySlice_Type))), ((PyObject *)__pyx_k_tuple_38), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); PyList_SET_ITEM(__pyx_t_8, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); { PyObject* __pyx_temp = PyNumber_InPlaceMultiply(__pyx_t_8, __pyx_v_nslices); if (unlikely(!__pyx_temp)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_temp); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = __pyx_temp; } __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_8)); __Pyx_GIVEREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; __pyx_t_8 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; goto __pyx_L9; } __pyx_L9:; /* "View.MemoryView":659 * result.extend([slice(None)] * nslices) * * return have_slices or nslices, tuple(result) # <<<<<<<<<<<<<< * * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): */ __Pyx_XDECREF(((PyObject *)__pyx_r)); __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (!__pyx_t_12) { __Pyx_INCREF(__pyx_v_nslices); __pyx_t_8 = __pyx_v_nslices; } else { __Pyx_INCREF(__pyx_v_have_slices); __pyx_t_8 = __pyx_v_have_slices; } __pyx_t_4 = ((PyObject *)PyList_AsTuple(__pyx_v_result)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_t_4)); __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); __pyx_t_8 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = ((PyObject*)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_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_10); __Pyx_AddTraceback("View.MemoryView._unellipsify", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_tup); __Pyx_XDECREF(__pyx_v_result); __Pyx_XDECREF(__pyx_v_have_slices); __Pyx_XDECREF(__pyx_v_idx); __Pyx_XDECREF(__pyx_v_item); __Pyx_XDECREF(__pyx_v_nslices); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":661 * return have_slices or nslices, tuple(result) * * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<< * cdef int i * for i in range(ndim): */ static PyObject *assert_direct_dimensions(Py_ssize_t *__pyx_v_suboffsets, int __pyx_v_ndim) { int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("assert_direct_dimensions", 0); /* "View.MemoryView":663 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): * cdef int i * for i in range(ndim): # <<<<<<<<<<<<<< * if suboffsets[i] >= 0: * raise ValueError("Indirect dimensions not supported") */ __pyx_t_1 = __pyx_v_ndim; for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":664 * cdef int i * for i in range(ndim): * if suboffsets[i] >= 0: # <<<<<<<<<<<<<< * raise ValueError("Indirect dimensions not supported") * */ __pyx_t_3 = ((__pyx_v_suboffsets[__pyx_v_i]) >= 0); if (__pyx_t_3) { /* "View.MemoryView":665 * for i in range(ndim): * if suboffsets[i] >= 0: * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< * * */ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; } __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("View.MemoryView.assert_direct_dimensions", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":672 * * @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 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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_t_3; Py_ssize_t __pyx_t_4; PyObject *(*__pyx_t_5)(PyObject *); PyObject *__pyx_t_6 = NULL; int __pyx_t_7; Py_ssize_t __pyx_t_8; PyObject *__pyx_t_9 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("memview_slice", 0); /* "View.MemoryView":673 * @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_v_new_ndim = 0; __pyx_v_suboffset_dim = -1; /* "View.MemoryView":680 * * * memset(&dst, 0, sizeof(dst)) # <<<<<<<<<<<<<< * * cdef _memoryviewslice memviewsliceobj */ memset((&__pyx_v_dst), 0, (sizeof(__pyx_v_dst))); /* "View.MemoryView":684 * cdef _memoryviewslice memviewsliceobj * * assert memview.view.ndim > 0 # <<<<<<<<<<<<<< * * if isinstance(memview, _memoryviewslice): */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!(__pyx_v_memview->view.ndim > 0))) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #endif /* "View.MemoryView":686 * assert memview.view.ndim > 0 * * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< * memviewsliceobj = memview * p_src = &memviewsliceobj.from_slice */ __pyx_t_1 = ((PyObject *)((PyObject *)__pyx_memoryviewslice_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "View.MemoryView":687 * * 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_filename = __pyx_f[2]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_INCREF(((PyObject *)__pyx_v_memview)); __pyx_v_memviewsliceobj = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview); /* "View.MemoryView":688 * if isinstance(memview, _memoryviewslice): * memviewsliceobj = memview * p_src = &memviewsliceobj.from_slice # <<<<<<<<<<<<<< * else: * slice_copy(memview, &src) */ __pyx_v_p_src = (&__pyx_v_memviewsliceobj->from_slice); goto __pyx_L3; } /*else*/ { /* "View.MemoryView":690 * p_src = &memviewsliceobj.from_slice * else: * slice_copy(memview, &src) # <<<<<<<<<<<<<< * p_src = &src * */ __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_src)); /* "View.MemoryView":691 * else: * slice_copy(memview, &src) * p_src = &src # <<<<<<<<<<<<<< * * */ __pyx_v_p_src = (&__pyx_v_src); } __pyx_L3:; /* "View.MemoryView":697 * * * dst.memview = p_src.memview # <<<<<<<<<<<<<< * dst.data = p_src.data * */ __pyx_v_dst.memview = __pyx_v_p_src->memview; /* "View.MemoryView":698 * * dst.memview = p_src.memview * dst.data = p_src.data # <<<<<<<<<<<<<< * * */ __pyx_v_dst.data = __pyx_v_p_src->data; /* "View.MemoryView":703 * * * 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":704 * * 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_p_suboffset_dim = (&__pyx_v_suboffset_dim); /* "View.MemoryView":708 * cdef bint have_start, have_stop, have_step * * for dim, index in enumerate(indices): # <<<<<<<<<<<<<< * if PyIndex_Check(index): * slice_memviewslice( */ __pyx_t_3 = 0; if (PyList_CheckExact(__pyx_v_indices) || PyTuple_CheckExact(__pyx_v_indices)) { __pyx_t_1 = __pyx_v_indices; __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_indices); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; } for (;;) { if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_1)) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_1)) { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { __pyx_t_6 = __pyx_t_5(__pyx_t_1); if (unlikely(!__pyx_t_6)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } __Pyx_GOTREF(__pyx_t_6); } __Pyx_XDECREF(__pyx_v_index); __pyx_v_index = __pyx_t_6; __pyx_t_6 = 0; __pyx_v_dim = __pyx_t_3; __pyx_t_3 = (__pyx_t_3 + 1); /* "View.MemoryView":709 * * 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_7 = PyIndex_Check(__pyx_v_index); if (__pyx_t_7) { /* "View.MemoryView":713 * 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_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":715 * index, 0, 0, # start, stop, step * 0, 0, 0, # have_{start,stop,step} * False) # <<<<<<<<<<<<<< * elif index is None: * p_dst.shape[new_ndim] = 1 */ __pyx_t_7 = __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_8, 0, 0, 0, 0, 0, 0); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } /* "View.MemoryView":716 * 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); if (__pyx_t_2) { /* "View.MemoryView":717 * 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":718 * 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":719 * 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]) = -1; /* "View.MemoryView":720 * 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); goto __pyx_L6; } /*else*/ { /* "View.MemoryView":722 * new_ndim += 1 * else: * start = index.start or 0 # <<<<<<<<<<<<<< * stop = index.stop or 0 * step = index.step or 0 */ __pyx_t_6 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__start); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 722; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 722; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (!__pyx_t_2) { __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_INCREF(__pyx_int_0); __pyx_t_9 = __pyx_int_0; } else { __pyx_t_9 = __pyx_t_6; __pyx_t_6 = 0; } __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 722; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_start = __pyx_t_8; /* "View.MemoryView":723 * else: * start = index.start or 0 * stop = index.stop or 0 # <<<<<<<<<<<<<< * step = index.step or 0 * */ __pyx_t_9 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__stop); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (!__pyx_t_2) { __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_INCREF(__pyx_int_0); __pyx_t_6 = __pyx_int_0; } else { __pyx_t_6 = __pyx_t_9; __pyx_t_9 = 0; } __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_6); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_stop = __pyx_t_8; /* "View.MemoryView":724 * start = index.start or 0 * stop = index.stop or 0 * step = index.step or 0 # <<<<<<<<<<<<<< * * have_start = index.start is not None */ __pyx_t_6 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__step); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (!__pyx_t_2) { __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_INCREF(__pyx_int_0); __pyx_t_9 = __pyx_int_0; } else { __pyx_t_9 = __pyx_t_6; __pyx_t_6 = 0; } __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_step = __pyx_t_8; /* "View.MemoryView":726 * 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 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__start); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = (__pyx_t_9 != Py_None); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_have_start = __pyx_t_2; /* "View.MemoryView":727 * * have_start = index.start is not None * have_stop = index.stop is not None # <<<<<<<<<<<<<< * have_step = index.step is not None * */ __pyx_t_9 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__stop); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = (__pyx_t_9 != Py_None); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_have_stop = __pyx_t_2; /* "View.MemoryView":728 * 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 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__step); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = (__pyx_t_9 != Py_None); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_have_step = __pyx_t_2; /* "View.MemoryView":735 * start, stop, step, * have_start, have_stop, have_step, * True) # <<<<<<<<<<<<<< * new_ndim += 1 * */ __pyx_t_7 = __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_7 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 730; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":736 * 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:; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "View.MemoryView":738 * new_ndim += 1 * * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< * return memoryview_fromslice(dst, new_ndim, * memviewsliceobj.to_object_func, */ __pyx_t_1 = ((PyObject *)((PyObject *)__pyx_memoryviewslice_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "View.MemoryView":739 * * 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":740 * 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_filename = __pyx_f[2]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "View.MemoryView":742 * memviewsliceobj.to_object_func, * memviewsliceobj.to_dtype_func, * memview.dtype_is_object) # <<<<<<<<<<<<<< * else: * return memoryview_fromslice(dst, new_ndim, NULL, NULL, */ __pyx_t_1 = __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_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryview_type))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; goto __pyx_L7; } /*else*/ { /* "View.MemoryView":744 * memview.dtype_is_object) * else: * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<< * memview.dtype_is_object) * */ __Pyx_XDECREF(((PyObject *)__pyx_r)); /* "View.MemoryView":745 * else: * return memoryview_fromslice(dst, new_ndim, NULL, NULL, * memview.dtype_is_object) # <<<<<<<<<<<<<< * * */ __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, NULL, NULL, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryview_type))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; } __pyx_L7:; __pyx_r = ((struct __pyx_memoryview_obj *)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_9); __Pyx_AddTraceback("View.MemoryView.memview_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_memviewsliceobj); __Pyx_XDECREF(__pyx_v_index); __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":769 * * @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_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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_t_4; Py_ssize_t __pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* "View.MemoryView":789 * cdef bint negative_step * * if not is_slice: # <<<<<<<<<<<<<< * * if start < 0: */ __pyx_t_1 = (!__pyx_v_is_slice); if (__pyx_t_1) { /* "View.MemoryView":791 * if not is_slice: * * if start < 0: # <<<<<<<<<<<<<< * start += shape * if not 0 <= start < shape: */ __pyx_t_1 = (__pyx_v_start < 0); if (__pyx_t_1) { /* "View.MemoryView":792 * * 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); goto __pyx_L4; } __pyx_L4:; /* "View.MemoryView":793 * 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_2 = (!__pyx_t_1); if (__pyx_t_2) { /* "View.MemoryView":794 * 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, __pyx_k_41, __pyx_v_dim); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":797 * else: * * negative_step = have_step != 0 and step < 0 # <<<<<<<<<<<<<< * * if have_step and step == 0: */ __pyx_t_2 = (__pyx_v_have_step != 0); if (__pyx_t_2) { __pyx_t_1 = (__pyx_v_step < 0); __pyx_t_4 = __pyx_t_1; } else { __pyx_t_4 = __pyx_t_2; } __pyx_v_negative_step = __pyx_t_4; /* "View.MemoryView":799 * 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) * */ if (__pyx_v_have_step) { __pyx_t_4 = (__pyx_v_step == 0); __pyx_t_2 = __pyx_t_4; } else { __pyx_t_2 = __pyx_v_have_step; } if (__pyx_t_2) { /* "View.MemoryView":800 * * 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, __pyx_k_42, __pyx_v_dim); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; /* "View.MemoryView":803 * * * if have_start: # <<<<<<<<<<<<<< * if start < 0: * start += shape */ if (__pyx_v_have_start) { /* "View.MemoryView":804 * * if have_start: * if start < 0: # <<<<<<<<<<<<<< * start += shape * if start < 0: */ __pyx_t_2 = (__pyx_v_start < 0); if (__pyx_t_2) { /* "View.MemoryView":805 * if have_start: * if start < 0: * start += shape # <<<<<<<<<<<<<< * if start < 0: * start = 0 */ __pyx_v_start = (__pyx_v_start + __pyx_v_shape); /* "View.MemoryView":806 * if start < 0: * start += shape * if start < 0: # <<<<<<<<<<<<<< * start = 0 * elif start >= shape: */ __pyx_t_2 = (__pyx_v_start < 0); if (__pyx_t_2) { /* "View.MemoryView":807 * start += shape * if start < 0: * start = 0 # <<<<<<<<<<<<<< * elif start >= shape: * if negative_step: */ __pyx_v_start = 0; goto __pyx_L9; } __pyx_L9:; goto __pyx_L8; } /* "View.MemoryView":808 * if start < 0: * start = 0 * elif start >= shape: # <<<<<<<<<<<<<< * if negative_step: * start = shape - 1 */ __pyx_t_2 = (__pyx_v_start >= __pyx_v_shape); if (__pyx_t_2) { /* "View.MemoryView":809 * start = 0 * elif start >= shape: * if negative_step: # <<<<<<<<<<<<<< * start = shape - 1 * else: */ if (__pyx_v_negative_step) { /* "View.MemoryView":810 * elif start >= shape: * if negative_step: * start = shape - 1 # <<<<<<<<<<<<<< * else: * start = shape */ __pyx_v_start = (__pyx_v_shape - 1); goto __pyx_L10; } /*else*/ { /* "View.MemoryView":812 * start = shape - 1 * else: * start = shape # <<<<<<<<<<<<<< * else: * if negative_step: */ __pyx_v_start = __pyx_v_shape; } __pyx_L10:; goto __pyx_L8; } __pyx_L8:; goto __pyx_L7; } /*else*/ { /* "View.MemoryView":814 * start = shape * else: * if negative_step: # <<<<<<<<<<<<<< * start = shape - 1 * else: */ if (__pyx_v_negative_step) { /* "View.MemoryView":815 * else: * if negative_step: * start = shape - 1 # <<<<<<<<<<<<<< * else: * start = 0 */ __pyx_v_start = (__pyx_v_shape - 1); goto __pyx_L11; } /*else*/ { /* "View.MemoryView":817 * start = shape - 1 * else: * start = 0 # <<<<<<<<<<<<<< * * if have_stop: */ __pyx_v_start = 0; } __pyx_L11:; } __pyx_L7:; /* "View.MemoryView":819 * start = 0 * * if have_stop: # <<<<<<<<<<<<<< * if stop < 0: * stop += shape */ if (__pyx_v_have_stop) { /* "View.MemoryView":820 * * if have_stop: * if stop < 0: # <<<<<<<<<<<<<< * stop += shape * if stop < 0: */ __pyx_t_2 = (__pyx_v_stop < 0); if (__pyx_t_2) { /* "View.MemoryView":821 * if have_stop: * if stop < 0: * stop += shape # <<<<<<<<<<<<<< * if stop < 0: * stop = 0 */ __pyx_v_stop = (__pyx_v_stop + __pyx_v_shape); /* "View.MemoryView":822 * if stop < 0: * stop += shape * if stop < 0: # <<<<<<<<<<<<<< * stop = 0 * elif stop > shape: */ __pyx_t_2 = (__pyx_v_stop < 0); if (__pyx_t_2) { /* "View.MemoryView":823 * stop += shape * if stop < 0: * stop = 0 # <<<<<<<<<<<<<< * elif stop > shape: * stop = shape */ __pyx_v_stop = 0; goto __pyx_L14; } __pyx_L14:; goto __pyx_L13; } /* "View.MemoryView":824 * if stop < 0: * stop = 0 * elif stop > shape: # <<<<<<<<<<<<<< * stop = shape * else: */ __pyx_t_2 = (__pyx_v_stop > __pyx_v_shape); if (__pyx_t_2) { /* "View.MemoryView":825 * stop = 0 * elif stop > shape: * stop = shape # <<<<<<<<<<<<<< * else: * if negative_step: */ __pyx_v_stop = __pyx_v_shape; goto __pyx_L13; } __pyx_L13:; goto __pyx_L12; } /*else*/ { /* "View.MemoryView":827 * stop = shape * else: * if negative_step: # <<<<<<<<<<<<<< * stop = -1 * else: */ if (__pyx_v_negative_step) { /* "View.MemoryView":828 * else: * if negative_step: * stop = -1 # <<<<<<<<<<<<<< * else: * stop = shape */ __pyx_v_stop = -1; goto __pyx_L15; } /*else*/ { /* "View.MemoryView":830 * stop = -1 * else: * stop = shape # <<<<<<<<<<<<<< * * if not have_step: */ __pyx_v_stop = __pyx_v_shape; } __pyx_L15:; } __pyx_L12:; /* "View.MemoryView":832 * stop = shape * * if not have_step: # <<<<<<<<<<<<<< * step = 1 * */ __pyx_t_2 = (!__pyx_v_have_step); if (__pyx_t_2) { /* "View.MemoryView":833 * * if not have_step: * step = 1 # <<<<<<<<<<<<<< * * */ __pyx_v_step = 1; goto __pyx_L16; } __pyx_L16:; /* "View.MemoryView":837 * * with cython.cdivision(True): * new_shape = (stop - start) // step # <<<<<<<<<<<<<< * * if (stop - start) % step: */ __pyx_v_new_shape = ((__pyx_v_stop - __pyx_v_start) / __pyx_v_step); /* "View.MemoryView":839 * new_shape = (stop - start) // step * * if (stop - start) % step: # <<<<<<<<<<<<<< * new_shape += 1 * */ __pyx_t_5 = ((__pyx_v_stop - __pyx_v_start) % __pyx_v_step); if (__pyx_t_5) { /* "View.MemoryView":840 * * if (stop - start) % step: * new_shape += 1 # <<<<<<<<<<<<<< * * if new_shape < 0: */ __pyx_v_new_shape = (__pyx_v_new_shape + 1); goto __pyx_L17; } __pyx_L17:; /* "View.MemoryView":842 * new_shape += 1 * * if new_shape < 0: # <<<<<<<<<<<<<< * new_shape = 0 * */ __pyx_t_2 = (__pyx_v_new_shape < 0); if (__pyx_t_2) { /* "View.MemoryView":843 * * if new_shape < 0: * new_shape = 0 # <<<<<<<<<<<<<< * * */ __pyx_v_new_shape = 0; goto __pyx_L18; } __pyx_L18:; /* "View.MemoryView":846 * * * dst.strides[new_ndim] = stride * step # <<<<<<<<<<<<<< * dst.shape[new_ndim] = new_shape * dst.suboffsets[new_ndim] = suboffset */ (__pyx_v_dst->strides[__pyx_v_new_ndim]) = (__pyx_v_stride * __pyx_v_step); /* "View.MemoryView":847 * * 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":848 * dst.strides[new_ndim] = stride * step * dst.shape[new_ndim] = new_shape * dst.suboffsets[new_ndim] = suboffset # <<<<<<<<<<<<<< * * */ (__pyx_v_dst->suboffsets[__pyx_v_new_ndim]) = __pyx_v_suboffset; } __pyx_L3:; /* "View.MemoryView":851 * * * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<< * dst.data += start * stride * else: */ __pyx_t_2 = ((__pyx_v_suboffset_dim[0]) < 0); if (__pyx_t_2) { /* "View.MemoryView":852 * * if suboffset_dim[0] < 0: * dst.data += start * stride # <<<<<<<<<<<<<< * else: * dst.suboffsets[suboffset_dim[0]] += start * stride */ __pyx_v_dst->data = (__pyx_v_dst->data + (__pyx_v_start * __pyx_v_stride)); goto __pyx_L19; } /*else*/ { /* "View.MemoryView":854 * dst.data += start * stride * else: * dst.suboffsets[suboffset_dim[0]] += start * stride # <<<<<<<<<<<<<< * * if suboffset >= 0: */ __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_L19:; /* "View.MemoryView":856 * 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); if (__pyx_t_2) { /* "View.MemoryView":857 * * if suboffset >= 0: * if not is_slice: # <<<<<<<<<<<<<< * if new_ndim == 0: * dst.data = ( dst.data)[0] + suboffset */ __pyx_t_2 = (!__pyx_v_is_slice); if (__pyx_t_2) { /* "View.MemoryView":858 * 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); if (__pyx_t_2) { /* "View.MemoryView":859 * 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); goto __pyx_L22; } /*else*/ { /* "View.MemoryView":862 * 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, __pyx_k_43, __pyx_v_dim); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L22:; goto __pyx_L21; } /*else*/ { /* "View.MemoryView":864 * "must be indexed and not sliced", dim) * else: * suboffset_dim[0] = new_ndim # <<<<<<<<<<<<<< * * return 0 */ (__pyx_v_suboffset_dim[0]) = __pyx_v_new_ndim; } __pyx_L21:; goto __pyx_L20; } __pyx_L20:; /* "View.MemoryView":866 * suboffset_dim[0] = new_ndim * * return 0 # <<<<<<<<<<<<<< * * */ __pyx_r = 0; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; { #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_AddTraceback("View.MemoryView.slice_memviewslice", __pyx_clineno, __pyx_lineno, __pyx_filename); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif } __pyx_r = -1; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":872 * * @cname('__pyx_pybuffer_index') * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<< * int dim) except NULL: * cdef Py_ssize_t shape, stride, suboffset = -1 */ static char *__pyx_pybuffer_index(Py_buffer *__pyx_v_view, char *__pyx_v_bufp, Py_ssize_t __pyx_v_index, int __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_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("pybuffer_index", 0); /* "View.MemoryView":874 * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, * int dim) except NULL: * cdef Py_ssize_t shape, stride, suboffset = -1 # <<<<<<<<<<<<<< * cdef Py_ssize_t itemsize = view.itemsize * cdef char *resultp */ __pyx_v_suboffset = -1; /* "View.MemoryView":875 * int dim) except NULL: * cdef Py_ssize_t shape, stride, suboffset = -1 * cdef Py_ssize_t itemsize = view.itemsize # <<<<<<<<<<<<<< * cdef char *resultp * */ __pyx_v_itemsize = __pyx_v_view->itemsize; /* "View.MemoryView":878 * cdef char *resultp * * if view.ndim == 0: # <<<<<<<<<<<<<< * shape = view.len / itemsize * stride = itemsize */ __pyx_t_1 = (__pyx_v_view->ndim == 0); if (__pyx_t_1) { /* "View.MemoryView":879 * * if view.ndim == 0: * shape = view.len / itemsize # <<<<<<<<<<<<<< * stride = itemsize * else: */ if (unlikely(__pyx_v_itemsize == 0)) { PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else if (sizeof(Py_ssize_t) == sizeof(long) && unlikely(__pyx_v_itemsize == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_view->len))) { PyErr_Format(PyExc_OverflowError, "value too large to perform division"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_v_shape = __Pyx_div_Py_ssize_t(__pyx_v_view->len, __pyx_v_itemsize); /* "View.MemoryView":880 * if view.ndim == 0: * shape = view.len / itemsize * stride = itemsize # <<<<<<<<<<<<<< * else: * shape = view.shape[dim] */ __pyx_v_stride = __pyx_v_itemsize; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":882 * stride = itemsize * else: * shape = view.shape[dim] # <<<<<<<<<<<<<< * stride = view.strides[dim] * if view.suboffsets != NULL: */ __pyx_v_shape = (__pyx_v_view->shape[__pyx_v_dim]); /* "View.MemoryView":883 * 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]); /* "View.MemoryView":884 * shape = view.shape[dim] * stride = view.strides[dim] * if view.suboffsets != NULL: # <<<<<<<<<<<<<< * suboffset = view.suboffsets[dim] * */ __pyx_t_1 = (__pyx_v_view->suboffsets != NULL); if (__pyx_t_1) { /* "View.MemoryView":885 * 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]); goto __pyx_L4; } __pyx_L4:; } __pyx_L3:; /* "View.MemoryView":887 * suboffset = view.suboffsets[dim] * * if index < 0: # <<<<<<<<<<<<<< * index += view.shape[dim] * if index < 0: */ __pyx_t_1 = (__pyx_v_index < 0); if (__pyx_t_1) { /* "View.MemoryView":888 * * 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":889 * if index < 0: * index += view.shape[dim] * if index < 0: # <<<<<<<<<<<<<< * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) * */ __pyx_t_1 = (__pyx_v_index < 0); if (__pyx_t_1) { /* "View.MemoryView":890 * index += view.shape[dim] * if index < 0: * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< * * if index >= shape: */ __pyx_t_2 = PyInt_FromLong(__pyx_v_dim); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_44), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; goto __pyx_L5; } __pyx_L5:; /* "View.MemoryView":892 * 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) * */ __pyx_t_1 = (__pyx_v_index >= __pyx_v_shape); if (__pyx_t_1) { /* "View.MemoryView":893 * * if index >= shape: * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< * * resultp = bufp + index * stride */ __pyx_t_3 = PyInt_FromLong(__pyx_v_dim); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_44), __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L7; } __pyx_L7:; /* "View.MemoryView":895 * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) * * resultp = bufp + index * stride # <<<<<<<<<<<<<< * if suboffset >= 0: * resultp = ( resultp)[0] + suboffset */ __pyx_v_resultp = (__pyx_v_bufp + (__pyx_v_index * __pyx_v_stride)); /* "View.MemoryView":896 * * resultp = bufp + index * stride * if suboffset >= 0: # <<<<<<<<<<<<<< * resultp = ( resultp)[0] + suboffset * */ __pyx_t_1 = (__pyx_v_suboffset >= 0); if (__pyx_t_1) { /* "View.MemoryView":897 * resultp = bufp + index * stride * if suboffset >= 0: * resultp = ( resultp)[0] + suboffset # <<<<<<<<<<<<<< * * return resultp */ __pyx_v_resultp = ((((char **)__pyx_v_resultp)[0]) + __pyx_v_suboffset); goto __pyx_L8; } __pyx_L8:; /* "View.MemoryView":899 * resultp = ( resultp)[0] + suboffset * * return resultp # <<<<<<<<<<<<<< * * */ __pyx_r = __pyx_v_resultp; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("View.MemoryView.pybuffer_index", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":905 * * @cname('__pyx_memslice_transpose') * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<< * cdef int ndim = memslice.memview.view.ndim * */ 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; long __pyx_t_1; int __pyx_t_2; Py_ssize_t __pyx_t_3; Py_ssize_t __pyx_t_4; int __pyx_t_5; int __pyx_t_6; int __pyx_t_7; int __pyx_t_8; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* "View.MemoryView":906 * @cname('__pyx_memslice_transpose') * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: * cdef int ndim = memslice.memview.view.ndim # <<<<<<<<<<<<<< * * cdef Py_ssize_t *shape = memslice.shape */ __pyx_v_ndim = __pyx_v_memslice->memview->view.ndim; /* "View.MemoryView":908 * cdef int ndim = memslice.memview.view.ndim * * cdef Py_ssize_t *shape = memslice.shape # <<<<<<<<<<<<<< * cdef Py_ssize_t *strides = memslice.strides * */ __pyx_v_shape = __pyx_v_memslice->shape; /* "View.MemoryView":909 * * cdef Py_ssize_t *shape = memslice.shape * cdef Py_ssize_t *strides = memslice.strides # <<<<<<<<<<<<<< * * */ __pyx_v_strides = __pyx_v_memslice->strides; /* "View.MemoryView":913 * * cdef int i, j * for i in range(ndim / 2): # <<<<<<<<<<<<<< * j = ndim - 1 - i * strides[i], strides[j] = strides[j], strides[i] */ __pyx_t_1 = __Pyx_div_long(__pyx_v_ndim, 2); for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":914 * 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] */ __pyx_v_j = ((__pyx_v_ndim - 1) - __pyx_v_i); /* "View.MemoryView":915 * 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] * */ __pyx_t_3 = (__pyx_v_strides[__pyx_v_j]); __pyx_t_4 = (__pyx_v_strides[__pyx_v_i]); (__pyx_v_strides[__pyx_v_i]) = __pyx_t_3; (__pyx_v_strides[__pyx_v_j]) = __pyx_t_4; /* "View.MemoryView":916 * j = ndim - 1 - i * strides[i], strides[j] = strides[j], strides[i] * shape[i], shape[j] = shape[j], shape[i] # <<<<<<<<<<<<<< * * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: */ __pyx_t_4 = (__pyx_v_shape[__pyx_v_j]); __pyx_t_3 = (__pyx_v_shape[__pyx_v_i]); (__pyx_v_shape[__pyx_v_i]) = __pyx_t_4; (__pyx_v_shape[__pyx_v_j]) = __pyx_t_3; /* "View.MemoryView":918 * 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_5 = ((__pyx_v_memslice->suboffsets[__pyx_v_i]) >= 0); if (!__pyx_t_5) { __pyx_t_6 = ((__pyx_v_memslice->suboffsets[__pyx_v_j]) >= 0); __pyx_t_7 = __pyx_t_6; } else { __pyx_t_7 = __pyx_t_5; } if (__pyx_t_7) { /* "View.MemoryView":919 * * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") # <<<<<<<<<<<<<< * * return 1 */ __pyx_t_8 = __pyx_memoryview_err(__pyx_builtin_ValueError, __pyx_k_45); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; } /* "View.MemoryView":921 * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") * * return 1 # <<<<<<<<<<<<<< * * */ __pyx_r = 1; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; { #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_AddTraceback("View.MemoryView.transpose_memslice", __pyx_clineno, __pyx_lineno, __pyx_filename); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif } __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* 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_MemoryView_16_memoryviewslice___dealloc__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":938 * cdef int (*to_dtype_func)(char *, object) except 0 * * def __dealloc__(self): # <<<<<<<<<<<<<< * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) * */ static void __pyx_memoryviewslice_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); /* "View.MemoryView":939 * * def __dealloc__(self): * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) # <<<<<<<<<<<<<< * * cdef convert_item_to_object(self, char *itemp): */ __PYX_XDEC_MEMVIEW((&__pyx_v_self->from_slice), 1); __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":941 * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) * * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< * if self.to_object_func != NULL: * return self.to_object_func(itemp) */ static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("convert_item_to_object", 0); /* "View.MemoryView":942 * * 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_self->to_object_func != NULL); if (__pyx_t_1) { /* "View.MemoryView":943 * 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_XDECREF(__pyx_r); __pyx_t_2 = __pyx_v_self->to_object_func(__pyx_v_itemp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":945 * 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_XDECREF(__pyx_r); __pyx_t_2 = __pyx_vtabptr_memoryview->convert_item_to_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 945; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } __pyx_L3:; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":947 * 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) */ 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_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("assign_item_from_object", 0); /* "View.MemoryView":948 * * 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_self->to_dtype_func != NULL); if (__pyx_t_1) { /* "View.MemoryView":949 * 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_v_self->to_dtype_func(__pyx_v_itemp, __pyx_v_value); if (unlikely(__pyx_t_2 == 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } /*else*/ { /* "View.MemoryView":951 * self.to_dtype_func(itemp, value) * else: * memoryview.assign_item_from_object(self, itemp, value) # <<<<<<<<<<<<<< * * property base: */ __pyx_t_3 = __pyx_vtabptr_memoryview->assign_item_from_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L3:; __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_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_memoryviewslice__get__base(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_memoryviewslice__get__base(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_memoryviewslice__get__base_MemoryView_16_memoryviewslice_4base___get__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":955 * property base: * @cname('__pyx_memoryviewslice__get__base') * def __get__(self): # <<<<<<<<<<<<<< * return self.from_object * */ static PyObject *__pyx_memoryviewslice__get__base_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); /* "View.MemoryView":956 * @cname('__pyx_memoryviewslice__get__base') * def __get__(self): * return self.from_object # <<<<<<<<<<<<<< * * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->from_object); __pyx_r = __pyx_v_self->from_object; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":962 * * @cname('__pyx_memoryview_fromslice') * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice, # <<<<<<<<<<<<<< * int ndim, * object (*to_object_func)(char *), */ 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; int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; int __pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("memoryview_fromslice", 0); /* "View.MemoryView":971 * cdef int i * * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<< * return None * */ __pyx_t_1 = (((PyObject *)__pyx_v_memviewslice.memview) == Py_None); if (__pyx_t_1) { /* "View.MemoryView":972 * * if memviewslice.memview == Py_None: * return None # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_None); __pyx_r = Py_None; goto __pyx_L0; goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":977 * * * 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_filename = __pyx_f[2]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(Py_None); PyTuple_SET_ITEM(__pyx_t_3, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(__pyx_int_0); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject *)__pyx_memoryviewslice_type)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_2); __pyx_t_2 = 0; /* "View.MemoryView":979 * result = _memoryviewslice(None, 0, dtype_is_object) * * result.from_slice = memviewslice # <<<<<<<<<<<<<< * __PYX_INC_MEMVIEW(&memviewslice, 1) * */ __pyx_v_result->from_slice = __pyx_v_memviewslice; /* "View.MemoryView":980 * * result.from_slice = memviewslice * __PYX_INC_MEMVIEW(&memviewslice, 1) # <<<<<<<<<<<<<< * * result.from_object = ( memviewslice.memview).base */ __PYX_INC_MEMVIEW((&__pyx_v_memviewslice), 1); /* "View.MemoryView":982 * __PYX_INC_MEMVIEW(&memviewslice, 1) * * result.from_object = ( memviewslice.memview).base # <<<<<<<<<<<<<< * result.typeinfo = memviewslice.memview.typeinfo * */ __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_memviewslice.memview), __pyx_n_s__base); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 982; __pyx_clineno = __LINE__; goto __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; /* "View.MemoryView":983 * * result.from_object = ( memviewslice.memview).base * result.typeinfo = memviewslice.memview.typeinfo # <<<<<<<<<<<<<< * * result.view = memviewslice.memview.view */ __pyx_v_result->__pyx_base.typeinfo = __pyx_v_memviewslice.memview->typeinfo; /* "View.MemoryView":985 * result.typeinfo = memviewslice.memview.typeinfo * * result.view = memviewslice.memview.view # <<<<<<<<<<<<<< * result.view.buf = memviewslice.data * result.view.ndim = ndim */ __pyx_v_result->__pyx_base.view = __pyx_v_memviewslice.memview->view; /* "View.MemoryView":986 * * 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":987 * 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; /* "View.MemoryView":988 * 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; /* "View.MemoryView":989 * result.view.ndim = ndim * (<__pyx_buffer *> &result.view).obj = Py_None * Py_INCREF(Py_None) # <<<<<<<<<<<<<< * * result.flags = PyBUF_RECORDS */ Py_INCREF(Py_None); /* "View.MemoryView":991 * Py_INCREF(Py_None) * * result.flags = PyBUF_RECORDS # <<<<<<<<<<<<<< * * result.view.shape = result.from_slice.shape */ __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS; /* "View.MemoryView":993 * result.flags = PyBUF_RECORDS * * result.view.shape = result.from_slice.shape # <<<<<<<<<<<<<< * result.view.strides = result.from_slice.strides * result.view.suboffsets = result.from_slice.suboffsets */ __pyx_v_result->__pyx_base.view.shape = ((Py_ssize_t *)__pyx_v_result->from_slice.shape); /* "View.MemoryView":994 * * result.view.shape = result.from_slice.shape * result.view.strides = result.from_slice.strides # <<<<<<<<<<<<<< * result.view.suboffsets = result.from_slice.suboffsets * */ __pyx_v_result->__pyx_base.view.strides = ((Py_ssize_t *)__pyx_v_result->from_slice.strides); /* "View.MemoryView":995 * result.view.shape = result.from_slice.shape * result.view.strides = result.from_slice.strides * result.view.suboffsets = result.from_slice.suboffsets # <<<<<<<<<<<<<< * * result.view.len = result.view.itemsize */ __pyx_v_result->__pyx_base.view.suboffsets = ((Py_ssize_t *)__pyx_v_result->from_slice.suboffsets); /* "View.MemoryView":997 * result.view.suboffsets = result.from_slice.suboffsets * * result.view.len = result.view.itemsize # <<<<<<<<<<<<<< * for i in range(ndim): * result.view.len *= result.view.shape[i] */ __pyx_v_result->__pyx_base.view.len = __pyx_v_result->__pyx_base.view.itemsize; /* "View.MemoryView":998 * * result.view.len = result.view.itemsize * for i in range(ndim): # <<<<<<<<<<<<<< * result.view.len *= result.view.shape[i] * */ __pyx_t_4 = __pyx_v_ndim; for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_v_i = __pyx_t_5; /* "View.MemoryView":999 * result.view.len = result.view.itemsize * for i in range(ndim): * result.view.len *= result.view.shape[i] # <<<<<<<<<<<<<< * * result.to_object_func = to_object_func */ __pyx_v_result->__pyx_base.view.len = (__pyx_v_result->__pyx_base.view.len * (__pyx_v_result->__pyx_base.view.shape[__pyx_v_i])); } /* "View.MemoryView":1001 * result.view.len *= result.view.shape[i] * * 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; /* "View.MemoryView":1002 * * 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; /* "View.MemoryView":1004 * 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; __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_fromslice", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":1007 * * @cname('__pyx_memoryview_get_slice_from_memoryview') * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview, # <<<<<<<<<<<<<< * __Pyx_memviewslice *mslice): * cdef _memoryviewslice obj */ 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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("get_slice_from_memview", 0); /* "View.MemoryView":1010 * __Pyx_memviewslice *mslice): * cdef _memoryviewslice obj * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< * obj = memview * return &obj.from_slice */ __pyx_t_1 = ((PyObject *)((PyObject *)__pyx_memoryviewslice_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "View.MemoryView":1011 * 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_filename = __pyx_f[2]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_INCREF(((PyObject *)__pyx_v_memview)); __pyx_v_obj = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview); /* "View.MemoryView":1012 * 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; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1014 * return &obj.from_slice * else: * slice_copy(memview, mslice) # <<<<<<<<<<<<<< * return mslice * */ __pyx_memoryview_slice_copy(__pyx_v_memview, __pyx_v_mslice); /* "View.MemoryView":1015 * else: * slice_copy(memview, mslice) * return mslice # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_slice_copy') */ __pyx_r = __pyx_v_mslice; goto __pyx_L0; } __pyx_L3:; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_WriteUnraisable("View.MemoryView.get_slice_from_memview", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_obj); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":1018 * * @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 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_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; __Pyx_RefNannySetupContext("slice_copy", 0); /* "View.MemoryView":1022 * cdef Py_ssize_t *shape, *strides, *suboffsets * * shape = memview.view.shape # <<<<<<<<<<<<<< * strides = memview.view.strides * suboffsets = memview.view.suboffsets */ __pyx_v_shape = __pyx_v_memview->view.shape; /* "View.MemoryView":1023 * * shape = memview.view.shape * strides = memview.view.strides # <<<<<<<<<<<<<< * suboffsets = memview.view.suboffsets * */ __pyx_v_strides = __pyx_v_memview->view.strides; /* "View.MemoryView":1024 * shape = memview.view.shape * strides = memview.view.strides * suboffsets = memview.view.suboffsets # <<<<<<<<<<<<<< * * dst.memview = <__pyx_memoryview *> memview */ __pyx_v_suboffsets = __pyx_v_memview->view.suboffsets; /* "View.MemoryView":1026 * 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); /* "View.MemoryView":1027 * * 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); /* "View.MemoryView":1029 * dst.data = memview.view.buf * * for dim in range(memview.view.ndim): # <<<<<<<<<<<<<< * dst.shape[dim] = shape[dim] * dst.strides[dim] = strides[dim] */ __pyx_t_1 = __pyx_v_memview->view.ndim; for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_dim = __pyx_t_2; /* "View.MemoryView":1030 * * for dim in range(memview.view.ndim): * dst.shape[dim] = shape[dim] # <<<<<<<<<<<<<< * dst.strides[dim] = strides[dim] * if suboffsets == NULL: */ (__pyx_v_dst->shape[__pyx_v_dim]) = (__pyx_v_shape[__pyx_v_dim]); /* "View.MemoryView":1031 * for dim in range(memview.view.ndim): * dst.shape[dim] = shape[dim] * dst.strides[dim] = strides[dim] # <<<<<<<<<<<<<< * if suboffsets == NULL: * dst.suboffsets[dim] = -1 */ (__pyx_v_dst->strides[__pyx_v_dim]) = (__pyx_v_strides[__pyx_v_dim]); /* "View.MemoryView":1032 * dst.shape[dim] = shape[dim] * dst.strides[dim] = strides[dim] * if suboffsets == NULL: # <<<<<<<<<<<<<< * dst.suboffsets[dim] = -1 * else: */ __pyx_t_3 = (__pyx_v_suboffsets == NULL); if (__pyx_t_3) { /* "View.MemoryView":1033 * dst.strides[dim] = strides[dim] * if suboffsets == NULL: * dst.suboffsets[dim] = -1 # <<<<<<<<<<<<<< * else: * dst.suboffsets[dim] = suboffsets[dim] */ (__pyx_v_dst->suboffsets[__pyx_v_dim]) = -1; goto __pyx_L5; } /*else*/ { /* "View.MemoryView":1035 * dst.suboffsets[dim] = -1 * else: * dst.suboffsets[dim] = suboffsets[dim] # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_copy_object') */ (__pyx_v_dst->suboffsets[__pyx_v_dim]) = (__pyx_v_suboffsets[__pyx_v_dim]); } __pyx_L5:; } __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":1038 * * @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; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("memoryview_copy", 0); /* "View.MemoryView":1041 * "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)); /* "View.MemoryView":1042 * 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_filename = __pyx_f[2]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __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_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":1045 * * @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_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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("memoryview_copy_from_slice", 0); /* "View.MemoryView":1052 * 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 = ((PyObject *)((PyObject *)__pyx_memoryviewslice_type)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "View.MemoryView":1053 * * if isinstance(memview, _memoryviewslice): * to_object_func = (<_memoryviewslice> memview).to_object_func # <<<<<<<<<<<<<< * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func * else: */ __pyx_v_to_object_func = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_object_func; /* "View.MemoryView":1054 * 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_v_to_dtype_func = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_dtype_func; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1056 * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func * else: * to_object_func = NULL # <<<<<<<<<<<<<< * to_dtype_func = NULL * */ __pyx_v_to_object_func = NULL; /* "View.MemoryView":1057 * else: * to_object_func = NULL * to_dtype_func = NULL # <<<<<<<<<<<<<< * * return memoryview_fromslice(memviewslice[0], memview.view.ndim, */ __pyx_v_to_dtype_func = NULL; } __pyx_L3:; /* "View.MemoryView":1059 * 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); /* "View.MemoryView":1061 * return memoryview_fromslice(memviewslice[0], memview.view.ndim, * to_object_func, to_dtype_func, * memview.dtype_is_object) # <<<<<<<<<<<<<< * * */ __pyx_t_1 = __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_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("View.MemoryView.memoryview_copy_from_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "View.MemoryView":1067 * * * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: # <<<<<<<<<<<<<< * if arg < 0: * return -arg */ static Py_ssize_t abs_py_ssize_t(Py_ssize_t __pyx_v_arg) { Py_ssize_t __pyx_r; int __pyx_t_1; /* "View.MemoryView":1068 * * 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); if (__pyx_t_1) { /* "View.MemoryView":1069 * 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; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1071 * return -arg * else: * return arg # <<<<<<<<<<<<<< * * @cname('__pyx_get_best_slice_order') */ __pyx_r = __pyx_v_arg; goto __pyx_L0; } __pyx_L3:; __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1074 * * @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 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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; /* "View.MemoryView":1079 * """ * cdef int i * cdef Py_ssize_t c_stride = 0 # <<<<<<<<<<<<<< * cdef Py_ssize_t f_stride = 0 * */ __pyx_v_c_stride = 0; /* "View.MemoryView":1080 * 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; /* "View.MemoryView":1082 * 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; /* "View.MemoryView":1083 * * 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); if (__pyx_t_2) { /* "View.MemoryView":1084 * 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]); /* "View.MemoryView":1085 * if mslice.shape[i] > 1: * c_stride = mslice.strides[i] * break # <<<<<<<<<<<<<< * * for i in range(ndim): */ goto __pyx_L4_break; goto __pyx_L5; } __pyx_L5:; } __pyx_L4_break:; /* "View.MemoryView":1087 * break * * for i in range(ndim): # <<<<<<<<<<<<<< * if mslice.shape[i] > 1: * f_stride = mslice.strides[i] */ __pyx_t_1 = __pyx_v_ndim; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_1; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; /* "View.MemoryView":1088 * * 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); if (__pyx_t_2) { /* "View.MemoryView":1089 * 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]); /* "View.MemoryView":1090 * 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; goto __pyx_L8; } __pyx_L8:; } __pyx_L7_break:; /* "View.MemoryView":1092 * 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)); if (__pyx_t_2) { /* "View.MemoryView":1093 * * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): * return 'C' # <<<<<<<<<<<<<< * else: * return 'F' */ __pyx_r = 'C'; goto __pyx_L0; goto __pyx_L9; } /*else*/ { /* "View.MemoryView":1095 * return 'C' * else: * return 'F' # <<<<<<<<<<<<<< * * @cython.cdivision(True) */ __pyx_r = 'F'; goto __pyx_L0; } __pyx_L9:; __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1098 * * @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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_t_4; Py_ssize_t __pyx_t_5; Py_ssize_t __pyx_t_6; /* "View.MemoryView":1105 * * 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]); /* "View.MemoryView":1106 * 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":1107 * 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]); /* "View.MemoryView":1108 * 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]); /* "View.MemoryView":1110 * 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); if (__pyx_t_1) { /* "View.MemoryView":1111 * * 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_1 = (__pyx_v_src_stride > 0); if (__pyx_t_1) { __pyx_t_2 = (__pyx_v_dst_stride > 0); if (__pyx_t_2) { /* "View.MemoryView":1112 * 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_3 = (((size_t)__pyx_v_src_stride) == __pyx_v_itemsize); if (__pyx_t_3) { __pyx_t_3 = (__pyx_v_itemsize == ((size_t)__pyx_v_dst_stride)); } __pyx_t_4 = __pyx_t_3; } else { __pyx_t_4 = __pyx_t_2; } __pyx_t_2 = __pyx_t_4; } else { __pyx_t_2 = __pyx_t_1; } if (__pyx_t_2) { /* "View.MemoryView":1113 * 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): */ memcpy(__pyx_v_dst_data, __pyx_v_src_data, (__pyx_v_itemsize * __pyx_v_dst_extent)); goto __pyx_L4; } /*else*/ { /* "View.MemoryView":1115 * 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 */ __pyx_t_5 = __pyx_v_dst_extent; for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; /* "View.MemoryView":1116 * else: * for i in range(dst_extent): * memcpy(dst_data, src_data, itemsize) # <<<<<<<<<<<<<< * src_data += src_stride * dst_data += dst_stride */ memcpy(__pyx_v_dst_data, __pyx_v_src_data, __pyx_v_itemsize); /* "View.MemoryView":1117 * 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); /* "View.MemoryView":1118 * 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:; goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1120 * 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, */ __pyx_t_5 = __pyx_v_dst_extent; for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; /* "View.MemoryView":1124 * dst_data, dst_strides + 1, * src_shape + 1, dst_shape + 1, * ndim - 1, itemsize) # <<<<<<<<<<<<<< * src_data += src_stride * dst_data += dst_stride */ _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); /* "View.MemoryView":1125 * 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); /* "View.MemoryView":1126 * 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); } } __pyx_L3:; } /* "View.MemoryView":1128 * dst_data += dst_stride * * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< * __Pyx_memviewslice *dst, * int ndim, size_t itemsize) nogil: */ 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) { /* "View.MemoryView":1132 * int ndim, size_t itemsize) nogil: * _copy_strided_to_strided(src.data, src.strides, dst.data, dst.strides, * src.shape, dst.shape, ndim, itemsize) # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_slice_get_size') */ _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); } /* "View.MemoryView":1135 * * @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; int __pyx_t_1; int __pyx_t_2; /* "View.MemoryView":1138 * "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_v_size = __pyx_v_src->memview->view.itemsize; /* "View.MemoryView":1140 * cdef Py_ssize_t size = src.memview.view.itemsize * * for i in range(ndim): # <<<<<<<<<<<<<< * size *= src.shape[i] * */ __pyx_t_1 = __pyx_v_ndim; for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":1141 * * for i in range(ndim): * size *= src.shape[i] # <<<<<<<<<<<<<< * * return size */ __pyx_v_size = (__pyx_v_size * (__pyx_v_src->shape[__pyx_v_i])); } /* "View.MemoryView":1143 * size *= src.shape[i] * * return size # <<<<<<<<<<<<<< * * @cname('__pyx_fill_contig_strides_array') */ __pyx_r = __pyx_v_size; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1146 * * @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 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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; /* "View.MemoryView":1155 * cdef int idx * * if order == 'F': # <<<<<<<<<<<<<< * for idx in range(ndim): * strides[idx] = stride */ __pyx_t_1 = (__pyx_v_order == 'F'); if (__pyx_t_1) { /* "View.MemoryView":1156 * * if order == 'F': * for idx in range(ndim): # <<<<<<<<<<<<<< * strides[idx] = stride * stride = stride * shape[idx] */ __pyx_t_2 = __pyx_v_ndim; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_idx = __pyx_t_3; /* "View.MemoryView":1157 * 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":1158 * 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])); } goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1160 * stride = stride * shape[idx] * else: * for idx in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< * strides[idx] = stride * stride = stride * shape[idx] */ for (__pyx_t_2 = (__pyx_v_ndim - 1); __pyx_t_2 > -1; __pyx_t_2-=1) { __pyx_v_idx = __pyx_t_2; /* "View.MemoryView":1161 * 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; /* "View.MemoryView":1162 * 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:; /* "View.MemoryView":1164 * stride = stride * shape[idx] * * return stride # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_copy_data_to_temp') */ __pyx_r = __pyx_v_stride; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1167 * * @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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* "View.MemoryView":1178 * cdef void *result * * cdef size_t itemsize = src.memview.view.itemsize # <<<<<<<<<<<<<< * cdef size_t size = slice_get_size(src, ndim) * */ __pyx_v_itemsize = __pyx_v_src->memview->view.itemsize; /* "View.MemoryView":1179 * * 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":1181 * 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":1182 * * result = malloc(size) * if not result: # <<<<<<<<<<<<<< * _err(MemoryError, NULL) * */ __pyx_t_1 = (!(__pyx_v_result != 0)); if (__pyx_t_1) { /* "View.MemoryView":1183 * result = malloc(size) * if not result: * _err(MemoryError, NULL) # <<<<<<<<<<<<<< * * */ __pyx_t_2 = __pyx_memoryview_err(__pyx_builtin_MemoryError, NULL); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":1186 * * * tmpslice.data = result # <<<<<<<<<<<<<< * tmpslice.memview = src.memview * for i in range(ndim): */ __pyx_v_tmpslice->data = ((char *)__pyx_v_result); /* "View.MemoryView":1187 * * tmpslice.data = result * tmpslice.memview = src.memview # <<<<<<<<<<<<<< * for i in range(ndim): * tmpslice.shape[i] = src.shape[i] */ __pyx_v_tmpslice->memview = __pyx_v_src->memview; /* "View.MemoryView":1188 * tmpslice.data = result * tmpslice.memview = src.memview * for i in range(ndim): # <<<<<<<<<<<<<< * tmpslice.shape[i] = src.shape[i] * tmpslice.suboffsets[i] = -1 */ __pyx_t_2 = __pyx_v_ndim; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; /* "View.MemoryView":1189 * 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":1190 * 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]) = -1; } /* "View.MemoryView":1193 * * fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize, * ndim, order) # <<<<<<<<<<<<<< * * */ __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":1196 * * * for i in range(ndim): # <<<<<<<<<<<<<< * if tmpslice.shape[i] == 1: * tmpslice.strides[i] = 0 */ __pyx_t_2 = __pyx_v_ndim; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; /* "View.MemoryView":1197 * * for i in range(ndim): * if tmpslice.shape[i] == 1: # <<<<<<<<<<<<<< * tmpslice.strides[i] = 0 * */ __pyx_t_1 = ((__pyx_v_tmpslice->shape[__pyx_v_i]) == 1); if (__pyx_t_1) { /* "View.MemoryView":1198 * for i in range(ndim): * if tmpslice.shape[i] == 1: * tmpslice.strides[i] = 0 # <<<<<<<<<<<<<< * * if slice_is_contig(src, order, ndim): */ (__pyx_v_tmpslice->strides[__pyx_v_i]) = 0; goto __pyx_L8; } __pyx_L8:; } /* "View.MemoryView":1200 * tmpslice.strides[i] = 0 * * if slice_is_contig(src, order, ndim): # <<<<<<<<<<<<<< * memcpy(result, src.data, size) * else: */ __pyx_t_1 = __pyx_memviewslice_is_contig(__pyx_v_src, __pyx_v_order, __pyx_v_ndim); if (__pyx_t_1) { /* "View.MemoryView":1201 * * if slice_is_contig(src, order, ndim): * memcpy(result, src.data, size) # <<<<<<<<<<<<<< * else: * copy_strided_to_strided(src, tmpslice, ndim, itemsize) */ memcpy(__pyx_v_result, __pyx_v_src->data, __pyx_v_size); goto __pyx_L9; } /*else*/ { /* "View.MemoryView":1203 * memcpy(result, src.data, size) * else: * copy_strided_to_strided(src, tmpslice, ndim, itemsize) # <<<<<<<<<<<<<< * * return result */ copy_strided_to_strided(__pyx_v_src, __pyx_v_tmpslice, __pyx_v_ndim, __pyx_v_itemsize); } __pyx_L9:; /* "View.MemoryView":1205 * copy_strided_to_strided(src, tmpslice, ndim, itemsize) * * return result # <<<<<<<<<<<<<< * * */ __pyx_r = __pyx_v_result; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; { #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_AddTraceback("View.MemoryView.copy_data_to_temp", __pyx_clineno, __pyx_lineno, __pyx_filename); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif } __pyx_r = NULL; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1210 * * @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_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_RefNannySetupContext("_err_extents", 0); /* "View.MemoryView":1213 * 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 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_extent1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_extent2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_46), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __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("View.MemoryView._err_extents", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif return __pyx_r; } /* "View.MemoryView":1216 * * @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 int __pyx_memoryview_err_dim(PyObject *__pyx_v_error, char *__pyx_v_msg, int __pyx_v_dim) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_RefNannySetupContext("_err_dim", 0); __Pyx_INCREF(__pyx_v_error); /* "View.MemoryView":1217 * @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_1 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_t_2 = PyInt_FromLong(__pyx_v_dim); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_t_1), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_v_error, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __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._err_dim", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_error); __Pyx_RefNannyFinishContext(); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif return __pyx_r; } /* "View.MemoryView":1220 * * @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_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_RefNannySetupContext("_err", 0); __Pyx_INCREF(__pyx_v_error); /* "View.MemoryView":1221 * @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); if (__pyx_t_1) { /* "View.MemoryView":1222 * cdef int _err(object error, char *msg) except -1 with gil: * if msg != NULL: * raise error(msg.decode('ascii')) # <<<<<<<<<<<<<< * else: * raise error */ __pyx_t_2 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_v_error, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[2]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1224 * raise error(msg.decode('ascii')) * else: * raise error # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_copy_contents') */ __Pyx_Raise(__pyx_v_error, 0, 0, 0); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("View.MemoryView._err", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_error); __Pyx_RefNannyFinishContext(); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif return __pyx_r; } /* "View.MemoryView":1227 * * @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; int __pyx_t_1; int __pyx_t_2; int __pyx_t_3; int __pyx_t_4; void *__pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* "View.MemoryView":1235 * 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":1236 * """ * 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_v_itemsize = __pyx_v_src.memview->view.itemsize; /* "View.MemoryView":1238 * 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":1239 * 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":1240 * 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":1243 * cdef __Pyx_memviewslice tmp * * if src_ndim < dst_ndim: # <<<<<<<<<<<<<< * broadcast_leading(&src, src_ndim, dst_ndim) * elif dst_ndim < src_ndim: */ __pyx_t_1 = (__pyx_v_src_ndim < __pyx_v_dst_ndim); if (__pyx_t_1) { /* "View.MemoryView":1244 * * 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); goto __pyx_L3; } /* "View.MemoryView":1245 * 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_1 = (__pyx_v_dst_ndim < __pyx_v_src_ndim); if (__pyx_t_1) { /* "View.MemoryView":1246 * 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); goto __pyx_L3; } __pyx_L3:; /* "View.MemoryView":1248 * broadcast_leading(&dst, dst_ndim, src_ndim) * * cdef int ndim = max(src_ndim, dst_ndim) # <<<<<<<<<<<<<< * * for i in range(ndim): */ __pyx_t_2 = __pyx_v_dst_ndim; __pyx_t_3 = __pyx_v_src_ndim; if ((__pyx_t_2 > __pyx_t_3)) { __pyx_t_4 = __pyx_t_2; } else { __pyx_t_4 = __pyx_t_3; } __pyx_v_ndim = __pyx_t_4; /* "View.MemoryView":1250 * 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_4 = __pyx_v_ndim; for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_4; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":1251 * * for i in range(ndim): * if src.shape[i] != dst.shape[i]: # <<<<<<<<<<<<<< * if src.shape[i] == 1: * broadcasting = True */ __pyx_t_1 = ((__pyx_v_src.shape[__pyx_v_i]) != (__pyx_v_dst.shape[__pyx_v_i])); if (__pyx_t_1) { /* "View.MemoryView":1252 * 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_1 = ((__pyx_v_src.shape[__pyx_v_i]) == 1); if (__pyx_t_1) { /* "View.MemoryView":1253 * 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":1254 * 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; goto __pyx_L7; } /*else*/ { /* "View.MemoryView":1256 * src.strides[i] = 0 * else: * _err_extents(i, dst.shape[i], src.shape[i]) # <<<<<<<<<<<<<< * * if src.suboffsets[i] >= 0: */ __pyx_t_3 = __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_3 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L7:; goto __pyx_L6; } __pyx_L6:; /* "View.MemoryView":1258 * _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_1 = ((__pyx_v_src.suboffsets[__pyx_v_i]) >= 0); if (__pyx_t_1) { /* "View.MemoryView":1259 * * if src.suboffsets[i] >= 0: * _err_dim(ValueError, "Dimension %d is not direct", i) # <<<<<<<<<<<<<< * * if slices_overlap(&src, &dst, ndim, itemsize): */ __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, __pyx_k_47, __pyx_v_i); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L8; } __pyx_L8:; } /* "View.MemoryView":1261 * _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_1 = __pyx_slices_overlap((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize); if (__pyx_t_1) { /* "View.MemoryView":1263 * if slices_overlap(&src, &dst, ndim, itemsize): * * if not slice_is_contig(&src, order, ndim): # <<<<<<<<<<<<<< * order = get_best_order(&dst, ndim) * */ __pyx_t_1 = (!__pyx_memviewslice_is_contig((&__pyx_v_src), __pyx_v_order, __pyx_v_ndim)); if (__pyx_t_1) { /* "View.MemoryView":1264 * * 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); goto __pyx_L10; } __pyx_L10:; /* "View.MemoryView":1266 * order = get_best_order(&dst, ndim) * * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) # <<<<<<<<<<<<<< * src = tmp * */ __pyx_t_5 = __pyx_memoryview_copy_data_to_temp((&__pyx_v_src), (&__pyx_v_tmp), __pyx_v_order, __pyx_v_ndim); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_tmpdata = __pyx_t_5; /* "View.MemoryView":1267 * * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) * src = tmp # <<<<<<<<<<<<<< * * if not broadcasting: */ __pyx_v_src = __pyx_v_tmp; goto __pyx_L9; } __pyx_L9:; /* "View.MemoryView":1269 * src = tmp * * if not broadcasting: # <<<<<<<<<<<<<< * * */ __pyx_t_1 = (!__pyx_v_broadcasting); if (__pyx_t_1) { /* "View.MemoryView":1272 * * * if slice_is_contig(&src, 'C', ndim): # <<<<<<<<<<<<<< * direct_copy = slice_is_contig(&dst, 'C', ndim) * elif slice_is_contig(&src, 'F', ndim): */ __pyx_t_1 = __pyx_memviewslice_is_contig((&__pyx_v_src), 'C', __pyx_v_ndim); if (__pyx_t_1) { /* "View.MemoryView":1273 * * 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); goto __pyx_L12; } /* "View.MemoryView":1274 * 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_1 = __pyx_memviewslice_is_contig((&__pyx_v_src), 'F', __pyx_v_ndim); if (__pyx_t_1) { /* "View.MemoryView":1275 * 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); goto __pyx_L12; } __pyx_L12:; /* "View.MemoryView":1277 * direct_copy = slice_is_contig(&dst, 'F', ndim) * * if direct_copy: # <<<<<<<<<<<<<< * * refcount_copying(&dst, dtype_is_object, ndim, False) */ if (__pyx_v_direct_copy) { /* "View.MemoryView":1279 * 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":1280 * * 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) * return 0 */ memcpy(__pyx_v_dst.data, __pyx_v_src.data, __pyx_memoryview_slice_get_size((&__pyx_v_src), __pyx_v_ndim)); /* "View.MemoryView":1281 * 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) # <<<<<<<<<<<<<< * return 0 * */ __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1); /* "View.MemoryView":1282 * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) * refcount_copying(&dst, dtype_is_object, ndim, True) * return 0 # <<<<<<<<<<<<<< * * if order == 'F' == get_best_order(&dst, ndim): */ __pyx_r = 0; goto __pyx_L0; goto __pyx_L13; } __pyx_L13:; goto __pyx_L11; } __pyx_L11:; /* "View.MemoryView":1284 * return 0 * * if order == 'F' == get_best_order(&dst, ndim): # <<<<<<<<<<<<<< * * */ __pyx_t_1 = (__pyx_v_order == 'F'); if (__pyx_t_1) { __pyx_t_1 = ('F' == __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim)); } if (__pyx_t_1) { /* "View.MemoryView":1287 * * * transpose_memslice(&src) # <<<<<<<<<<<<<< * transpose_memslice(&dst) * */ __pyx_t_4 = __pyx_memslice_transpose((&__pyx_v_src)); if (unlikely(__pyx_t_4 == 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":1288 * * transpose_memslice(&src) * transpose_memslice(&dst) # <<<<<<<<<<<<<< * * refcount_copying(&dst, dtype_is_object, ndim, False) */ __pyx_t_4 = __pyx_memslice_transpose((&__pyx_v_dst)); if (unlikely(__pyx_t_4 == 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 1288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L14; } __pyx_L14:; /* "View.MemoryView":1290 * 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":1291 * * 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":1292 * 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":1294 * refcount_copying(&dst, dtype_is_object, ndim, True) * * free(tmpdata) # <<<<<<<<<<<<<< * return 0 * */ free(__pyx_v_tmpdata); /* "View.MemoryView":1295 * * free(tmpdata) * return 0 # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_broadcast_leading') */ __pyx_r = 0; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; { #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_AddTraceback("View.MemoryView.memoryview_copy_contents", __pyx_clineno, __pyx_lineno, __pyx_filename); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif } __pyx_r = -1; __pyx_L0:; return __pyx_r; } /* "View.MemoryView":1298 * * @cname('__pyx_memoryview_broadcast_leading') * cdef void broadcast_leading(__Pyx_memviewslice *slice, # <<<<<<<<<<<<<< * int ndim, * int ndim_other) nogil: */ static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *__pyx_v_slice, int __pyx_v_ndim, int __pyx_v_ndim_other) { int __pyx_v_i; int __pyx_v_offset; int __pyx_t_1; int __pyx_t_2; /* "View.MemoryView":1302 * 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":1304 * cdef int offset = ndim_other - ndim * * for i in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< * slice.shape[i + offset] = slice.shape[i] * slice.strides[i + offset] = slice.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":1305 * * for i in range(ndim - 1, -1, -1): * slice.shape[i + offset] = slice.shape[i] # <<<<<<<<<<<<<< * slice.strides[i + offset] = slice.strides[i] * slice.suboffsets[i + offset] = slice.suboffsets[i] */ (__pyx_v_slice->shape[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_slice->shape[__pyx_v_i]); /* "View.MemoryView":1306 * for i in range(ndim - 1, -1, -1): * slice.shape[i + offset] = slice.shape[i] * slice.strides[i + offset] = slice.strides[i] # <<<<<<<<<<<<<< * slice.suboffsets[i + offset] = slice.suboffsets[i] * */ (__pyx_v_slice->strides[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_slice->strides[__pyx_v_i]); /* "View.MemoryView":1307 * slice.shape[i + offset] = slice.shape[i] * slice.strides[i + offset] = slice.strides[i] * slice.suboffsets[i + offset] = slice.suboffsets[i] # <<<<<<<<<<<<<< * * for i in range(offset): */ (__pyx_v_slice->suboffsets[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_slice->suboffsets[__pyx_v_i]); } /* "View.MemoryView":1309 * slice.suboffsets[i + offset] = slice.suboffsets[i] * * for i in range(offset): # <<<<<<<<<<<<<< * slice.shape[i] = 1 * slice.strides[i] = slice.strides[0] */ __pyx_t_1 = __pyx_v_offset; for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":1310 * * for i in range(offset): * slice.shape[i] = 1 # <<<<<<<<<<<<<< * slice.strides[i] = slice.strides[0] * slice.suboffsets[i] = -1 */ (__pyx_v_slice->shape[__pyx_v_i]) = 1; /* "View.MemoryView":1311 * for i in range(offset): * slice.shape[i] = 1 * slice.strides[i] = slice.strides[0] # <<<<<<<<<<<<<< * slice.suboffsets[i] = -1 * */ (__pyx_v_slice->strides[__pyx_v_i]) = (__pyx_v_slice->strides[0]); /* "View.MemoryView":1312 * slice.shape[i] = 1 * slice.strides[i] = slice.strides[0] * slice.suboffsets[i] = -1 # <<<<<<<<<<<<<< * * */ (__pyx_v_slice->suboffsets[__pyx_v_i]) = -1; } } /* "View.MemoryView":1320 * * @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) { /* "View.MemoryView":1324 * * * if dtype_is_object: # <<<<<<<<<<<<<< * refcount_objects_in_slice_with_gil(dst.data, dst.shape, * dst.strides, ndim, inc) */ if (__pyx_v_dtype_is_object) { /* "View.MemoryView":1326 * if dtype_is_object: * refcount_objects_in_slice_with_gil(dst.data, dst.shape, * dst.strides, ndim, inc) # <<<<<<<<<<<<<< * * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil') */ __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); goto __pyx_L3; } __pyx_L3:; } /* "View.MemoryView":1329 * * @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_RefNannyDeclarations #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); #endif __Pyx_RefNannySetupContext("refcount_objects_in_slice_with_gil", 0); /* "View.MemoryView":1332 * 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); __Pyx_RefNannyFinishContext(); #ifdef WITH_THREAD PyGILState_Release(__pyx_gilstate_save); #endif } /* "View.MemoryView":1335 * * @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_RefNannyDeclarations Py_ssize_t __pyx_t_1; Py_ssize_t __pyx_t_2; int __pyx_t_3; __Pyx_RefNannySetupContext("refcount_objects_in_slice", 0); /* "View.MemoryView":1339 * cdef Py_ssize_t i * * for i in range(shape[0]): # <<<<<<<<<<<<<< * if ndim == 1: * if inc: */ __pyx_t_1 = (__pyx_v_shape[0]); for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; /* "View.MemoryView":1340 * * for i in range(shape[0]): * if ndim == 1: # <<<<<<<<<<<<<< * if inc: * Py_INCREF(( data)[0]) */ __pyx_t_3 = (__pyx_v_ndim == 1); if (__pyx_t_3) { /* "View.MemoryView":1341 * for i in range(shape[0]): * if ndim == 1: * if inc: # <<<<<<<<<<<<<< * Py_INCREF(( data)[0]) * else: */ if (__pyx_v_inc) { /* "View.MemoryView":1342 * if ndim == 1: * if inc: * Py_INCREF(( data)[0]) # <<<<<<<<<<<<<< * else: * Py_DECREF(( data)[0]) */ Py_INCREF((((PyObject **)__pyx_v_data)[0])); goto __pyx_L6; } /*else*/ { /* "View.MemoryView":1344 * Py_INCREF(( data)[0]) * else: * Py_DECREF(( data)[0]) # <<<<<<<<<<<<<< * else: * refcount_objects_in_slice(data, shape + 1, strides + 1, */ Py_DECREF((((PyObject **)__pyx_v_data)[0])); } __pyx_L6:; goto __pyx_L5; } /*else*/ { /* "View.MemoryView":1347 * 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":1349 * ndim - 1, inc) * * data += strides[0] # <<<<<<<<<<<<<< * * */ __pyx_v_data = (__pyx_v_data + (__pyx_v_strides[0])); } __Pyx_RefNannyFinishContext(); } /* "View.MemoryView":1355 * * @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) { /* "View.MemoryView":1358 * 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":1360 * 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":1361 * _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":1365 * * @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; int __pyx_t_1; Py_ssize_t __pyx_t_2; Py_ssize_t __pyx_t_3; /* "View.MemoryView":1369 * 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":1370 * 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":1372 * 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); if (__pyx_t_1) { /* "View.MemoryView":1373 * * if ndim == 1: * for i in range(extent): # <<<<<<<<<<<<<< * memcpy(data, item, itemsize) * data += stride */ __pyx_t_2 = __pyx_v_extent; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; /* "View.MemoryView":1374 * if ndim == 1: * for i in range(extent): * memcpy(data, item, itemsize) # <<<<<<<<<<<<<< * data += stride * else: */ memcpy(__pyx_v_data, __pyx_v_item, __pyx_v_itemsize); /* "View.MemoryView":1375 * 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); } goto __pyx_L3; } /*else*/ { /* "View.MemoryView":1377 * data += stride * else: * for i in range(extent): # <<<<<<<<<<<<<< * _slice_assign_scalar(data, shape + 1, strides + 1, * ndim - 1, itemsize, item) */ __pyx_t_2 = __pyx_v_extent; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; /* "View.MemoryView":1379 * 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":1380 * _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:; } static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_array_obj *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; p = ((struct __pyx_array_obj *)o); p->mode = ((PyObject*)Py_None); Py_INCREF(Py_None); p->_format = ((PyObject*)Py_None); Py_INCREF(Py_None); if (__pyx_array___cinit__(o, a, k) < 0) { Py_DECREF(o); o = 0; } return o; } static void __pyx_tp_dealloc_array(PyObject *o) { struct __pyx_array_obj *p = (struct __pyx_array_obj *)o; { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); __pyx_array___dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } Py_CLEAR(p->mode); Py_CLEAR(p->_format); (*Py_TYPE(o)->tp_free)(o); } static int __pyx_tp_traverse_array(PyObject *o, visitproc v, void *a) { int e; struct __pyx_array_obj *p = (struct __pyx_array_obj *)o; if (p->mode) { e = (*v)(p->mode, a); if (e) return e; } if (p->_format) { e = (*v)(p->_format, a); if (e) return e; } return 0; } static int __pyx_tp_clear_array(PyObject *o) { struct __pyx_array_obj *p = (struct __pyx_array_obj *)o; PyObject* tmp; tmp = ((PyObject*)p->mode); p->mode = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->_format); p->_format = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } 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 %s", Py_TYPE(o)->tp_name); return -1; } } static PyObject *__pyx_tp_getattro_array(PyObject *o, PyObject *n) { PyObject *v = 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 get_memview(o); } static PyMethodDef __pyx_methods_array[] = { {__Pyx_NAMESTR("__getattr__"), (PyCFunction)__pyx_array___getattr__, METH_O|METH_COEXIST, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets_array[] = { {(char *)"memview", __pyx_getprop___pyx_array_memview, 0, 0, 0}, {0, 0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_array = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*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 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 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 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*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_array = { 0, /*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 = { 0, /*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 #if PY_VERSION_HEX >= 0x02060000 __pyx_array_getbuffer, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type___pyx_array = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("cogent.align._pairwise_seqs.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*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ &__pyx_tp_as_number_array, /*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_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ __pyx_tp_traverse_array, /*tp_traverse*/ __pyx_tp_clear_array, /*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*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_MemviewEnum_obj *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!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; 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) { struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; PyObject* tmp; tmp = ((PyObject*)p->name); p->name = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyMethodDef __pyx_methods_Enum[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_Enum = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*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 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 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 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*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_Enum = { 0, /*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_Enum = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_Enum = { #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 #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type___pyx_MemviewEnum = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("cogent.align._pairwise_seqs.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*/ #else 0, /*reserved*/ #endif __pyx_MemviewEnum___repr__, /*tp_repr*/ &__pyx_tp_as_number_Enum, /*tp_as_number*/ &__pyx_tp_as_sequence_Enum, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Enum, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Enum, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|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*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #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 = (*t->tp_alloc)(t, 0); if (!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 (__pyx_memoryview___cinit__(o, a, k) < 0) { Py_DECREF(o); o = 0; } return o; } static void __pyx_tp_dealloc_memoryview(PyObject *o) { struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); __pyx_memoryview___dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(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) { struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; PyObject* tmp; 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 %s", Py_TYPE(o)->tp_name); return -1; } } static PyObject *__pyx_getprop___pyx_memoryview_T(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_transpose(o); } static PyObject *__pyx_getprop___pyx_memoryview_base(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview__get__base(o); } static PyObject *__pyx_getprop___pyx_memoryview_shape(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_shape(o); } static PyObject *__pyx_getprop___pyx_memoryview_strides(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_strides(o); } static PyObject *__pyx_getprop___pyx_memoryview_suboffsets(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_suboffsets(o); } static PyObject *__pyx_getprop___pyx_memoryview_ndim(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_ndim(o); } static PyObject *__pyx_getprop___pyx_memoryview_itemsize(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_itemsize(o); } static PyObject *__pyx_getprop___pyx_memoryview_nbytes(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_nbytes(o); } static PyObject *__pyx_getprop___pyx_memoryview_size(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_memoryview_get_size(o); } static PyMethodDef __pyx_methods_memoryview[] = { {__Pyx_NAMESTR("is_c_contig"), (PyCFunction)__pyx_memoryview_is_c_contig, METH_NOARGS, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("is_f_contig"), (PyCFunction)__pyx_memoryview_is_f_contig, METH_NOARGS, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_memoryview_copy, METH_NOARGS, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("copy_fortran"), (PyCFunction)__pyx_memoryview_copy_fortran, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets_memoryview[] = { {(char *)"T", __pyx_getprop___pyx_memoryview_T, 0, 0, 0}, {(char *)"base", __pyx_getprop___pyx_memoryview_base, 0, 0, 0}, {(char *)"shape", __pyx_getprop___pyx_memoryview_shape, 0, 0, 0}, {(char *)"strides", __pyx_getprop___pyx_memoryview_strides, 0, 0, 0}, {(char *)"suboffsets", __pyx_getprop___pyx_memoryview_suboffsets, 0, 0, 0}, {(char *)"ndim", __pyx_getprop___pyx_memoryview_ndim, 0, 0, 0}, {(char *)"itemsize", __pyx_getprop___pyx_memoryview_itemsize, 0, 0, 0}, {(char *)"nbytes", __pyx_getprop___pyx_memoryview_nbytes, 0, 0, 0}, {(char *)"size", __pyx_getprop___pyx_memoryview_size, 0, 0, 0}, {0, 0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_memoryview = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*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 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 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 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*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; 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 #if PY_VERSION_HEX >= 0x02060000 __pyx_memoryview_getbuffer, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type___pyx_memoryview = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("cogent.align._pairwise_seqs.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*/ #else 0, /*reserved*/ #endif __pyx_memoryview___repr__, /*tp_repr*/ &__pyx_tp_as_number_memoryview, /*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_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*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #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 (!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; { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); __pyx_memoryviewslice___dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } Py_CLEAR(p->from_object); __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) { struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; PyObject* tmp; __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_memoryviewslice__get__base(o); } static PyMethodDef __pyx_methods__memoryviewslice[] = { {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets__memoryviewslice[] = { {(char *)"base", __pyx_getprop___pyx_memoryviewslice_base, 0, 0, 0}, {0, 0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number__memoryviewslice = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*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 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 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 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*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence__memoryviewslice = { #if CYTHON_COMPILING_IN_PYPY __pyx_memoryview___len__, /*sq_length*/ #else 0, /*sq_length*/ #endif 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__memoryviewslice = { #if CYTHON_COMPILING_IN_PYPY __pyx_memoryview___len__, /*mp_length*/ #else 0, /*mp_length*/ #endif #if CYTHON_COMPILING_IN_PYPY __pyx_memoryview___getitem__, /*mp_subscript*/ #else 0, /*mp_subscript*/ #endif 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer__memoryviewslice = { #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 #if CYTHON_COMPILING_IN_PYPY __pyx_memoryview_getbuffer, /*bf_getbuffer*/ #else #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type___pyx_memoryviewslice = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("cogent.align._pairwise_seqs._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*/ #else 0, /*reserved*/ #endif #if CYTHON_COMPILING_IN_PYPY __pyx_memoryview___repr__, /*tp_repr*/ #else 0, /*tp_repr*/ #endif &__pyx_tp_as_number__memoryviewslice, /*tp_as_number*/ &__pyx_tp_as_sequence__memoryviewslice, /*tp_as_sequence*/ &__pyx_tp_as_mapping__memoryviewslice, /*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*/ &__pyx_tp_as_buffer__memoryviewslice, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("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*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef __pyx_moduledef = { PyModuleDef_HEAD_INIT, __Pyx_NAMESTR("_pairwise_seqs"), 0, /* m_doc */ -1, /* m_size */ __pyx_methods /* m_methods */, NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0}, {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0}, {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0}, {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0}, {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 0}, {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0}, {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0}, {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 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_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 0, 1, 0}, {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0}, {&__pyx_kp_s_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 1, 0}, {&__pyx_kp_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 0}, {&__pyx_kp_s_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 1, 0}, {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0}, {&__pyx_kp_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 0}, {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0}, {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0}, {&__pyx_kp_s_52, __pyx_k_52, sizeof(__pyx_k_52), 0, 0, 1, 0}, {&__pyx_n_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 1}, {&__pyx_n_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 1}, {&__pyx_n_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 1}, {&__pyx_kp_s_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 1, 0}, {&__pyx_kp_s_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 0, 1, 0}, {&__pyx_kp_s_63, __pyx_k_63, sizeof(__pyx_k_63), 0, 0, 1, 0}, {&__pyx_kp_s_65, __pyx_k_65, sizeof(__pyx_k_65), 0, 0, 1, 0}, {&__pyx_kp_s_67, __pyx_k_67, sizeof(__pyx_k_67), 0, 0, 1, 0}, {&__pyx_kp_s__1st, __pyx_k__1st, sizeof(__pyx_k__1st), 0, 0, 1, 0}, {&__pyx_kp_s__2nd, __pyx_k__2nd, sizeof(__pyx_k__2nd), 0, 0, 1, 0}, {&__pyx_kp_s__3rd, __pyx_k__3rd, sizeof(__pyx_k__3rd), 0, 0, 1, 0}, {&__pyx_n_s__ASCII, __pyx_k__ASCII, sizeof(__pyx_k__ASCII), 0, 0, 1, 1}, {&__pyx_n_s__ArithmeticError, __pyx_k__ArithmeticError, sizeof(__pyx_k__ArithmeticError), 0, 0, 1, 1}, {&__pyx_n_s__Ellipsis, __pyx_k__Ellipsis, sizeof(__pyx_k__Ellipsis), 0, 0, 1, 1}, {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 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_b__O, __pyx_k__O, sizeof(__pyx_k__O), 0, 0, 0, 1}, {&__pyx_n_s__T, __pyx_k__T, sizeof(__pyx_k__T), 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_n_s____class__, __pyx_k____class__, sizeof(__pyx_k____class__), 0, 0, 1, 1}, {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, {&__pyx_n_s____name__, __pyx_k____name__, sizeof(__pyx_k____name__), 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____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, {&__pyx_n_s____version__, __pyx_k____version__, sizeof(__pyx_k____version__), 0, 0, 1, 1}, {&__pyx_n_s__a, __pyx_k__a, sizeof(__pyx_k__a), 0, 0, 1, 1}, {&__pyx_n_s__a_count, __pyx_k__a_count, sizeof(__pyx_k__a_count), 0, 0, 1, 1}, {&__pyx_n_s__a_high, __pyx_k__a_high, sizeof(__pyx_k__a_high), 0, 0, 1, 1}, {&__pyx_n_s__a_low, __pyx_k__a_low, sizeof(__pyx_k__a_low), 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__b, __pyx_k__b, sizeof(__pyx_k__b), 0, 0, 1, 1}, {&__pyx_n_s__b_count, __pyx_k__b_count, sizeof(__pyx_k__b_count), 0, 0, 1, 1}, {&__pyx_n_s__b_high, __pyx_k__b_high, sizeof(__pyx_k__b_high), 0, 0, 1, 1}, {&__pyx_n_s__b_low, __pyx_k__b_low, sizeof(__pyx_k__b_low), 0, 0, 1, 1}, {&__pyx_n_s__base, __pyx_k__base, sizeof(__pyx_k__base), 0, 0, 1, 1}, {&__pyx_n_s__bin, __pyx_k__bin, sizeof(__pyx_k__bin), 0, 0, 1, 1}, {&__pyx_n_s__bin_count, __pyx_k__bin_count, sizeof(__pyx_k__bin_count), 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_n_s__calc_rows, __pyx_k__calc_rows, sizeof(__pyx_k__calc_rows), 0, 0, 1, 1}, {&__pyx_n_s__current_row_index, __pyx_k__current_row_index, sizeof(__pyx_k__current_row_index), 0, 0, 1, 1}, {&__pyx_n_s__d4, __pyx_k__d4, sizeof(__pyx_k__d4), 0, 0, 1, 1}, {&__pyx_n_s__d_score, __pyx_k__d_score, sizeof(__pyx_k__d_score), 0, 0, 1, 1}, {&__pyx_n_s__decode, __pyx_k__decode, sizeof(__pyx_k__decode), 0, 0, 1, 1}, {&__pyx_n_s__dest_state, __pyx_k__dest_state, sizeof(__pyx_k__dest_state), 0, 0, 1, 1}, {&__pyx_n_s__dest_states, __pyx_k__dest_states, sizeof(__pyx_k__dest_states), 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__dx, __pyx_k__dx, sizeof(__pyx_k__dx), 0, 0, 1, 1}, {&__pyx_n_s__dy, __pyx_k__dy, sizeof(__pyx_k__dy), 0, 0, 1, 1}, {&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 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__exponent, __pyx_k__exponent, sizeof(__pyx_k__exponent), 0, 0, 1, 1}, {&__pyx_n_s__exponents, __pyx_k__exponents, sizeof(__pyx_k__exponents), 0, 0, 1, 1}, {&__pyx_n_s__extend, __pyx_k__extend, sizeof(__pyx_k__extend), 0, 0, 1, 1}, {&__pyx_n_s__flags, __pyx_k__flags, sizeof(__pyx_k__flags), 0, 0, 1, 1}, {&__pyx_n_s__fmpt, __pyx_k__fmpt, sizeof(__pyx_k__fmpt), 0, 0, 1, 1}, {&__pyx_n_s__format, __pyx_k__format, sizeof(__pyx_k__format), 0, 0, 1, 1}, {&__pyx_n_b__fortran, __pyx_k__fortran, sizeof(__pyx_k__fortran), 0, 0, 0, 1}, {&__pyx_n_s__fortran, __pyx_k__fortran, sizeof(__pyx_k__fortran), 0, 0, 1, 1}, {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1}, {&__pyx_n_s__i_high, __pyx_k__i_high, sizeof(__pyx_k__i_high), 0, 0, 1, 1}, {&__pyx_n_s__i_low, __pyx_k__i_low, sizeof(__pyx_k__i_low), 0, 0, 1, 1}, {&__pyx_n_s__id, __pyx_k__id, sizeof(__pyx_k__id), 0, 0, 1, 1}, {&__pyx_n_s__impossible, __pyx_k__impossible, sizeof(__pyx_k__impossible), 0, 0, 1, 1}, {&__pyx_n_s__itemsize, __pyx_k__itemsize, sizeof(__pyx_k__itemsize), 0, 0, 1, 1}, {&__pyx_n_s__j, __pyx_k__j, sizeof(__pyx_k__j), 0, 0, 1, 1}, {&__pyx_n_s__j_high, __pyx_k__j_high, sizeof(__pyx_k__j_high), 0, 0, 1, 1}, {&__pyx_n_s__j_low, __pyx_k__j_low, sizeof(__pyx_k__j_low), 0, 0, 1, 1}, {&__pyx_n_s__last_i, __pyx_k__last_i, sizeof(__pyx_k__last_i), 0, 0, 1, 1}, {&__pyx_n_s__last_j, __pyx_k__last_j, sizeof(__pyx_k__last_j), 0, 0, 1, 1}, {&__pyx_n_s__last_state, __pyx_k__last_state, sizeof(__pyx_k__last_state), 0, 0, 1, 1}, {&__pyx_n_s__local, __pyx_k__local, sizeof(__pyx_k__local), 0, 0, 1, 1}, {&__pyx_n_s__mantissa, __pyx_k__mantissa, sizeof(__pyx_k__mantissa), 0, 0, 1, 1}, {&__pyx_n_s__mantissas, __pyx_k__mantissas, sizeof(__pyx_k__mantissas), 0, 0, 1, 1}, {&__pyx_n_s__match_scores, __pyx_k__match_scores, sizeof(__pyx_k__match_scores), 0, 0, 1, 1}, {&__pyx_n_s__max_exponent, __pyx_k__max_exponent, sizeof(__pyx_k__max_exponent), 0, 0, 1, 1}, {&__pyx_n_s__max_mantissa, __pyx_k__max_mantissa, sizeof(__pyx_k__max_mantissa), 0, 0, 1, 1}, {&__pyx_n_s__max_x, __pyx_k__max_x, sizeof(__pyx_k__max_x), 0, 0, 1, 1}, {&__pyx_n_s__max_y, __pyx_k__max_y, sizeof(__pyx_k__max_y), 0, 0, 1, 1}, {&__pyx_n_s__memview, __pyx_k__memview, sizeof(__pyx_k__memview), 0, 0, 1, 1}, {&__pyx_n_s__min_prev_state, __pyx_k__min_prev_state, sizeof(__pyx_k__min_prev_state), 0, 0, 1, 1}, {&__pyx_n_s__mode, __pyx_k__mode, sizeof(__pyx_k__mode), 0, 0, 1, 1}, {&__pyx_n_s__msg, __pyx_k__msg, sizeof(__pyx_k__msg), 0, 0, 1, 1}, {&__pyx_n_s__name, __pyx_k__name, sizeof(__pyx_k__name), 0, 0, 1, 1}, {&__pyx_n_s__ndim, __pyx_k__ndim, sizeof(__pyx_k__ndim), 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__partial_sum, __pyx_k__partial_sum, sizeof(__pyx_k__partial_sum), 0, 0, 1, 1}, {&__pyx_n_s__plan, __pyx_k__plan, sizeof(__pyx_k__plan), 0, 0, 1, 1}, {&__pyx_n_s__pointer_a, __pyx_k__pointer_a, sizeof(__pyx_k__pointer_a), 0, 0, 1, 1}, {&__pyx_n_s__pointer_b, __pyx_k__pointer_b, sizeof(__pyx_k__pointer_b), 0, 0, 1, 1}, {&__pyx_n_s__pointer_state, __pyx_k__pointer_state, sizeof(__pyx_k__pointer_state), 0, 0, 1, 1}, {&__pyx_n_s__preds, __pyx_k__preds, sizeof(__pyx_k__preds), 0, 0, 1, 1}, {&__pyx_n_s__prev_i, __pyx_k__prev_i, sizeof(__pyx_k__prev_i), 0, 0, 1, 1}, {&__pyx_n_s__prev_j, __pyx_k__prev_j, sizeof(__pyx_k__prev_j), 0, 0, 1, 1}, {&__pyx_n_s__prev_state, __pyx_k__prev_state, sizeof(__pyx_k__prev_state), 0, 0, 1, 1}, {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, {&__pyx_n_s__row_count, __pyx_k__row_count, sizeof(__pyx_k__row_count), 0, 0, 1, 1}, {&__pyx_n_s__row_count1, __pyx_k__row_count1, sizeof(__pyx_k__row_count1), 0, 0, 1, 1}, {&__pyx_n_s__row_length, __pyx_k__row_length, sizeof(__pyx_k__row_length), 0, 0, 1, 1}, {&__pyx_n_s__row_length1, __pyx_k__row_length1, sizeof(__pyx_k__row_length1), 0, 0, 1, 1}, {&__pyx_n_s__rows, __pyx_k__rows, sizeof(__pyx_k__rows), 0, 0, 1, 1}, {&__pyx_n_s__score, __pyx_k__score, sizeof(__pyx_k__score), 0, 0, 1, 1}, {&__pyx_n_s__seq1_index, __pyx_k__seq1_index, sizeof(__pyx_k__seq1_index), 0, 0, 1, 1}, {&__pyx_n_s__seq2_index, __pyx_k__seq2_index, sizeof(__pyx_k__seq2_index), 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__source_i, __pyx_k__source_i, sizeof(__pyx_k__source_i), 0, 0, 1, 1}, {&__pyx_n_s__source_row_index, __pyx_k__source_row_index, sizeof(__pyx_k__source_row_index), 0, 0, 1, 1}, {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1}, {&__pyx_n_s__state, __pyx_k__state, sizeof(__pyx_k__state), 0, 0, 1, 1}, {&__pyx_n_s__state_directions, __pyx_k__state_directions, sizeof(__pyx_k__state_directions), 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__struct, __pyx_k__struct, sizeof(__pyx_k__struct), 0, 0, 1, 1}, {&__pyx_n_s__sub_partial_sum, __pyx_k__sub_partial_sum, sizeof(__pyx_k__sub_partial_sum), 0, 0, 1, 1}, {&__pyx_n_s__tcode_s, __pyx_k__tcode_s, sizeof(__pyx_k__tcode_s), 0, 0, 1, 1}, {&__pyx_n_s__tcode_x, __pyx_k__tcode_x, sizeof(__pyx_k__tcode_x), 0, 0, 1, 1}, {&__pyx_n_s__tcode_y, __pyx_k__tcode_y, sizeof(__pyx_k__tcode_y), 0, 0, 1, 1}, {&__pyx_n_s__tmp_rows, __pyx_k__tmp_rows, sizeof(__pyx_k__tmp_rows), 0, 0, 1, 1}, {&__pyx_n_s__track, __pyx_k__track, sizeof(__pyx_k__track), 0, 0, 1, 1}, {&__pyx_n_s__track_enc, __pyx_k__track_enc, sizeof(__pyx_k__track_enc), 0, 0, 1, 1}, {&__pyx_n_s__underflows, __pyx_k__underflows, sizeof(__pyx_k__underflows), 0, 0, 1, 1}, {&__pyx_n_s__unpack, __pyx_k__unpack, sizeof(__pyx_k__unpack), 0, 0, 1, 1}, {&__pyx_n_s__use_logs, __pyx_k__use_logs, sizeof(__pyx_k__use_logs), 0, 0, 1, 1}, {&__pyx_n_s__use_scaling, __pyx_k__use_scaling, sizeof(__pyx_k__use_scaling), 0, 0, 1, 1}, {&__pyx_n_s__version_info, __pyx_k__version_info, sizeof(__pyx_k__version_info), 0, 0, 1, 1}, {&__pyx_n_s__viterbi, __pyx_k__viterbi, sizeof(__pyx_k__viterbi), 0, 0, 1, 1}, {&__pyx_n_s__x, __pyx_k__x, sizeof(__pyx_k__x), 0, 0, 1, 1}, {&__pyx_n_s__xgap_scores, __pyx_k__xgap_scores, sizeof(__pyx_k__xgap_scores), 0, 0, 1, 1}, {&__pyx_n_s__xrange, __pyx_k__xrange, sizeof(__pyx_k__xrange), 0, 0, 1, 1}, {&__pyx_n_s__y, __pyx_k__y, sizeof(__pyx_k__y), 0, 0, 1, 1}, {&__pyx_n_s__ygap_scores, __pyx_k__ygap_scores, sizeof(__pyx_k__ygap_scores), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_ArithmeticError = __Pyx_GetName(__pyx_b, __pyx_n_s__ArithmeticError); if (!__pyx_builtin_ArithmeticError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_Ellipsis = __Pyx_GetName(__pyx_b, __pyx_n_s__Ellipsis); if (!__pyx_builtin_Ellipsis) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if PY_MAJOR_VERSION >= 3 __pyx_builtin_xrange = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else __pyx_builtin_xrange = __Pyx_GetName(__pyx_b, __pyx_n_s__xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif __pyx_builtin_id = __Pyx_GetName(__pyx_b, __pyx_n_s__id); if (!__pyx_builtin_id) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; } static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":64 * cdef int checkArray1D(num[::1] a, dim *x) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * */ __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_4); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4)); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":69 * cdef int checkArray2D(num[:, ::1] a, dim *x, dim *y) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_5); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_6); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6)); /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":75 * cdef int checkArray3D(num[:, :, ::1] a, dim *x, dim *y, dim *z) except 1: * if a is None: * raise ValueError('Array required, got None') # <<<<<<<<<<<<<< * checkDim('1st', a.shape[0], x) * checkDim('2nd', a.shape[1], y) */ __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_7); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7)); __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_8); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_8, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8)); __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_9); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_9)); /* "View.MemoryView":124 * * if not self.ndim: * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< * * if self.itemsize <= 0: */ __pyx_k_tuple_16 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_16); __Pyx_INCREF(((PyObject *)__pyx_kp_s_15)); PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, ((PyObject *)__pyx_kp_s_15)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_15)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16)); /* "View.MemoryView":127 * * if self.itemsize <= 0: * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< * * encode = getattr(format, 'encode', None) */ __pyx_k_tuple_18 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_18)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_18); __Pyx_INCREF(((PyObject *)__pyx_kp_s_17)); PyTuple_SET_ITEM(__pyx_k_tuple_18, 0, ((PyObject *)__pyx_kp_s_17)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18)); /* "View.MemoryView":131 * encode = getattr(format, 'encode', None) * if encode: * format = encode('ASCII') # <<<<<<<<<<<<<< * self._format = format * self.format = self._format */ __pyx_k_tuple_19 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_19); __Pyx_INCREF(((PyObject *)__pyx_n_s__ASCII)); PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_n_s__ASCII)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ASCII)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19)); /* "View.MemoryView":141 * free(self._shape) * free(self._strides) * raise MemoryError("unable to allocate shape or strides.") # <<<<<<<<<<<<<< * * */ __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_21); __Pyx_INCREF(((PyObject *)__pyx_kp_s_20)); PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_20)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_20)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); /* "View.MemoryView":166 * decode = getattr(mode, 'decode', None) * if decode: * mode = decode('ASCII') # <<<<<<<<<<<<<< * self.mode = mode * */ __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_24); __Pyx_INCREF(((PyObject *)__pyx_n_s__ASCII)); PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_n_s__ASCII)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ASCII)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); /* "View.MemoryView":174 * self.data = malloc(self.len) * if not self.data: * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< * * if self.dtype_is_object: */ __pyx_k_tuple_26 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_26); __Pyx_INCREF(((PyObject *)__pyx_kp_s_25)); PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, ((PyObject *)__pyx_kp_s_25)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_25)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26)); /* "View.MemoryView":190 * 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_k_tuple_28 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_28)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_28); __Pyx_INCREF(((PyObject *)__pyx_kp_s_27)); PyTuple_SET_ITEM(__pyx_k_tuple_28, 0, ((PyObject *)__pyx_kp_s_27)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_27)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_28)); /* "View.MemoryView":452 * 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_k_tuple_30 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_30); __Pyx_INCREF(((PyObject *)__pyx_kp_s_29)); PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, ((PyObject *)__pyx_kp_s_29)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_29)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30)); /* "View.MemoryView":528 * if self.view.strides == NULL: * * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< * * return tuple([self.view.strides[i] for i in xrange(self.view.ndim)]) */ __pyx_k_tuple_32 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_32); __Pyx_INCREF(((PyObject *)__pyx_kp_s_31)); PyTuple_SET_ITEM(__pyx_k_tuple_32, 0, ((PyObject *)__pyx_kp_s_31)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32)); /* "View.MemoryView":643 * if item is Ellipsis: * if not seen_ellipsis: * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<< * seen_ellipsis = True * else: */ __pyx_k_tuple_35 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_35); __Pyx_INCREF(Py_None); PyTuple_SET_ITEM(__pyx_k_tuple_35, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35)); /* "View.MemoryView":646 * seen_ellipsis = True * else: * result.append(slice(None)) # <<<<<<<<<<<<<< * have_slices = True * else: */ __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_36); __Pyx_INCREF(Py_None); PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); /* "View.MemoryView":657 * nslices = ndim - len(result) * if nslices: * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<< * * return have_slices or nslices, tuple(result) */ __pyx_k_tuple_38 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_38)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_38); __Pyx_INCREF(Py_None); PyTuple_SET_ITEM(__pyx_k_tuple_38, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_38)); /* "View.MemoryView":665 * for i in range(ndim): * if suboffsets[i] >= 0: * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< * * */ __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_40); __Pyx_INCREF(((PyObject *)__pyx_kp_s_39)); PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, ((PyObject *)__pyx_kp_s_39)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_39)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40)); /* "cogent/align/_pairwise_seqs.pyx":16 * double log (double x) * * version_info = (3, 2) # <<<<<<<<<<<<<< * __version__ = "('1', '5', '3-dev')" * */ __pyx_k_tuple_49 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_49)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_49); __Pyx_INCREF(__pyx_int_3); PyTuple_SET_ITEM(__pyx_k_tuple_49, 0, __pyx_int_3); __Pyx_GIVEREF(__pyx_int_3); __Pyx_INCREF(__pyx_int_2); PyTuple_SET_ITEM(__pyx_k_tuple_49, 1, __pyx_int_2); __Pyx_GIVEREF(__pyx_int_2); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_49)); /* "cogent/align/_pairwise_seqs.pyx":30 * MAX_SCALE = +10000 # or 0 if all numbers should be probabilities * * def fmpt(mantissa, exponent, msg=''): # <<<<<<<<<<<<<< * return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) * */ __pyx_k_tuple_50 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_50); __Pyx_INCREF(((PyObject *)__pyx_n_s__mantissa)); PyTuple_SET_ITEM(__pyx_k_tuple_50, 0, ((PyObject *)__pyx_n_s__mantissa)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mantissa)); __Pyx_INCREF(((PyObject *)__pyx_n_s__exponent)); PyTuple_SET_ITEM(__pyx_k_tuple_50, 1, ((PyObject *)__pyx_n_s__exponent)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__exponent)); __Pyx_INCREF(((PyObject *)__pyx_n_s__msg)); PyTuple_SET_ITEM(__pyx_k_tuple_50, 2, ((PyObject *)__pyx_n_s__msg)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50)); __pyx_k_codeobj_51 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_50, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_52, __pyx_n_s__fmpt, 30, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_51)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":35 * ctypedef unsigned char [:,:,::1] UChar3D * * def calc_rows(Long1D plan, Long1D seq1_index, Long1D seq2_index, # <<<<<<<<<<<<<< * int i_low, int i_high, int j_low, int j_high, preds, * Long2D state_directions, Double2D T, */ __pyx_k_tuple_56 = PyTuple_New(77); if (unlikely(!__pyx_k_tuple_56)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_56); __Pyx_INCREF(((PyObject *)__pyx_n_s__plan)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 0, ((PyObject *)__pyx_n_s__plan)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__plan)); __Pyx_INCREF(((PyObject *)__pyx_n_s__seq1_index)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 1, ((PyObject *)__pyx_n_s__seq1_index)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__seq1_index)); __Pyx_INCREF(((PyObject *)__pyx_n_s__seq2_index)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 2, ((PyObject *)__pyx_n_s__seq2_index)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__seq2_index)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i_low)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 3, ((PyObject *)__pyx_n_s__i_low)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_low)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i_high)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 4, ((PyObject *)__pyx_n_s__i_high)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_high)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j_low)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 5, ((PyObject *)__pyx_n_s__j_low)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j_low)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j_high)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 6, ((PyObject *)__pyx_n_s__j_high)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j_high)); __Pyx_INCREF(((PyObject *)__pyx_n_s__preds)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 7, ((PyObject *)__pyx_n_s__preds)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__preds)); __Pyx_INCREF(((PyObject *)__pyx_n_s__state_directions)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 8, ((PyObject *)__pyx_n_s__state_directions)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__state_directions)); __Pyx_INCREF(((PyObject *)__pyx_n_s__T)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 9, ((PyObject *)__pyx_n_s__T)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__T)); __Pyx_INCREF(((PyObject *)__pyx_n_s__xgap_scores)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 10, ((PyObject *)__pyx_n_s__xgap_scores)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__xgap_scores)); __Pyx_INCREF(((PyObject *)__pyx_n_s__ygap_scores)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 11, ((PyObject *)__pyx_n_s__ygap_scores)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ygap_scores)); __Pyx_INCREF(((PyObject *)__pyx_n_s__match_scores)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 12, ((PyObject *)__pyx_n_s__match_scores)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__match_scores)); __Pyx_INCREF(((PyObject *)__pyx_n_s__rows)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 13, ((PyObject *)__pyx_n_s__rows)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rows)); __Pyx_INCREF(((PyObject *)__pyx_n_s__track)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 14, ((PyObject *)__pyx_n_s__track)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__track)); __Pyx_INCREF(((PyObject *)__pyx_n_s__track_enc)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 15, ((PyObject *)__pyx_n_s__track_enc)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__track_enc)); __Pyx_INCREF(((PyObject *)__pyx_n_s__viterbi)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 16, ((PyObject *)__pyx_n_s__viterbi)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__viterbi)); __Pyx_INCREF(((PyObject *)__pyx_n_s__use_logs)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 17, ((PyObject *)__pyx_n_s__use_logs)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__use_logs)); __Pyx_INCREF(((PyObject *)__pyx_n_s__local)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 18, ((PyObject *)__pyx_n_s__local)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__local)); __Pyx_INCREF(((PyObject *)__pyx_n_s__use_scaling)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 19, ((PyObject *)__pyx_n_s__use_scaling)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__use_scaling)); __Pyx_INCREF(((PyObject *)__pyx_n_s__prev_i)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 20, ((PyObject *)__pyx_n_s__prev_i)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__prev_i)); __Pyx_INCREF(((PyObject *)__pyx_n_s__prev_j)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 21, ((PyObject *)__pyx_n_s__prev_j)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__prev_j)); __Pyx_INCREF(((PyObject *)__pyx_n_s__state)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 22, ((PyObject *)__pyx_n_s__state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__prev_state)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 23, ((PyObject *)__pyx_n_s__prev_state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__prev_state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__min_prev_state)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 24, ((PyObject *)__pyx_n_s__min_prev_state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__min_prev_state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__N)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 25, ((PyObject *)__pyx_n_s__N)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__N)); __Pyx_INCREF(((PyObject *)__pyx_n_s__row_length)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 26, ((PyObject *)__pyx_n_s__row_length)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__row_length)); __Pyx_INCREF(((PyObject *)__pyx_n_s__row_length1)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 27, ((PyObject *)__pyx_n_s__row_length1)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__row_length1)); __Pyx_INCREF(((PyObject *)__pyx_n_s__row_count)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 28, ((PyObject *)__pyx_n_s__row_count)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__row_count)); __Pyx_INCREF(((PyObject *)__pyx_n_s__row_count1)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 29, ((PyObject *)__pyx_n_s__row_count1)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__row_count1)); __Pyx_INCREF(((PyObject *)__pyx_n_s__tmp_rows)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 30, ((PyObject *)__pyx_n_s__tmp_rows)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tmp_rows)); __Pyx_INCREF(((PyObject *)__pyx_n_s__a_count)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 31, ((PyObject *)__pyx_n_s__a_count)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__a_count)); __Pyx_INCREF(((PyObject *)__pyx_n_s__b_count)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 32, ((PyObject *)__pyx_n_s__b_count)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__b_count)); __Pyx_INCREF(((PyObject *)__pyx_n_s__a)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 33, ((PyObject *)__pyx_n_s__a)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__a)); __Pyx_INCREF(((PyObject *)__pyx_n_s__b)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 34, ((PyObject *)__pyx_n_s__b)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__b)); __Pyx_INCREF(((PyObject *)__pyx_n_s__a_low)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 35, ((PyObject *)__pyx_n_s__a_low)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__a_low)); __Pyx_INCREF(((PyObject *)__pyx_n_s__a_high)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 36, ((PyObject *)__pyx_n_s__a_high)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__a_high)); __Pyx_INCREF(((PyObject *)__pyx_n_s__b_low)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 37, ((PyObject *)__pyx_n_s__b_low)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__b_low)); __Pyx_INCREF(((PyObject *)__pyx_n_s__b_high)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 38, ((PyObject *)__pyx_n_s__b_high)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__b_high)); __Pyx_INCREF(((PyObject *)__pyx_n_s__dest_states)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 39, ((PyObject *)__pyx_n_s__dest_states)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dest_states)); __Pyx_INCREF(((PyObject *)__pyx_n_s__dest_state)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 40, ((PyObject *)__pyx_n_s__dest_state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dest_state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__d4)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 41, ((PyObject *)__pyx_n_s__d4)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__d4)); __Pyx_INCREF(((PyObject *)__pyx_n_s__j)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 42, ((PyObject *)__pyx_n_s__j)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j)); __Pyx_INCREF(((PyObject *)__pyx_n_s__i)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 43, ((PyObject *)__pyx_n_s__i)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i)); __Pyx_INCREF(((PyObject *)__pyx_n_s__last_i)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 44, ((PyObject *)__pyx_n_s__last_i)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__last_i)); __Pyx_INCREF(((PyObject *)__pyx_n_s__last_j)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 45, ((PyObject *)__pyx_n_s__last_j)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__last_j)); __Pyx_INCREF(((PyObject *)__pyx_n_s__last_state)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 46, ((PyObject *)__pyx_n_s__last_state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__last_state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__bin)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 47, ((PyObject *)__pyx_n_s__bin)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bin)); __Pyx_INCREF(((PyObject *)__pyx_n_s__x)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 48, ((PyObject *)__pyx_n_s__x)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__x)); __Pyx_INCREF(((PyObject *)__pyx_n_s__y)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 49, ((PyObject *)__pyx_n_s__y)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__y)); __Pyx_INCREF(((PyObject *)__pyx_n_s__bin_count)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 50, ((PyObject *)__pyx_n_s__bin_count)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bin_count)); __Pyx_INCREF(((PyObject *)__pyx_n_s__max_x)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 51, ((PyObject *)__pyx_n_s__max_x)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_x)); __Pyx_INCREF(((PyObject *)__pyx_n_s__max_y)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 52, ((PyObject *)__pyx_n_s__max_y)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_y)); __Pyx_INCREF(((PyObject *)__pyx_n_s__current_row_index)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 53, ((PyObject *)__pyx_n_s__current_row_index)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__current_row_index)); __Pyx_INCREF(((PyObject *)__pyx_n_s__source_row_index)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 54, ((PyObject *)__pyx_n_s__source_row_index)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__source_row_index)); __Pyx_INCREF(((PyObject *)__pyx_n_s__source_i)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 55, ((PyObject *)__pyx_n_s__source_i)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__source_i)); __Pyx_INCREF(((PyObject *)__pyx_n_s__dx)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 56, ((PyObject *)__pyx_n_s__dx)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dx)); __Pyx_INCREF(((PyObject *)__pyx_n_s__dy)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 57, ((PyObject *)__pyx_n_s__dy)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dy)); __Pyx_INCREF(((PyObject *)__pyx_n_s__tcode_x)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 58, ((PyObject *)__pyx_n_s__tcode_x)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tcode_x)); __Pyx_INCREF(((PyObject *)__pyx_n_s__tcode_y)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 59, ((PyObject *)__pyx_n_s__tcode_y)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tcode_y)); __Pyx_INCREF(((PyObject *)__pyx_n_s__tcode_s)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 60, ((PyObject *)__pyx_n_s__tcode_s)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tcode_s)); __Pyx_INCREF(((PyObject *)__pyx_n_s__d_score)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 61, ((PyObject *)__pyx_n_s__d_score)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__d_score)); __Pyx_INCREF(((PyObject *)__pyx_n_s__mantissa)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 62, ((PyObject *)__pyx_n_s__mantissa)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mantissa)); __Pyx_INCREF(((PyObject *)__pyx_n_s__partial_sum)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 63, ((PyObject *)__pyx_n_s__partial_sum)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__partial_sum)); __Pyx_INCREF(((PyObject *)__pyx_n_s__sub_partial_sum)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 64, ((PyObject *)__pyx_n_s__sub_partial_sum)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sub_partial_sum)); __Pyx_INCREF(((PyObject *)__pyx_n_s__max_mantissa)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 65, ((PyObject *)__pyx_n_s__max_mantissa)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_mantissa)); __Pyx_INCREF(((PyObject *)__pyx_n_s_54)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 66, ((PyObject *)__pyx_n_s_54)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s_54)); __Pyx_INCREF(((PyObject *)__pyx_n_s__exponent)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 67, ((PyObject *)__pyx_n_s__exponent)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__exponent)); __Pyx_INCREF(((PyObject *)__pyx_n_s__max_exponent)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 68, ((PyObject *)__pyx_n_s__max_exponent)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_exponent)); __Pyx_INCREF(((PyObject *)__pyx_n_s_55)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 69, ((PyObject *)__pyx_n_s_55)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s_55)); __Pyx_INCREF(((PyObject *)__pyx_n_s__mantissas)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 70, ((PyObject *)__pyx_n_s__mantissas)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mantissas)); __Pyx_INCREF(((PyObject *)__pyx_n_s__exponents)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 71, ((PyObject *)__pyx_n_s__exponents)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__exponents)); __Pyx_INCREF(((PyObject *)__pyx_n_s__pointer_a)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 72, ((PyObject *)__pyx_n_s__pointer_a)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pointer_a)); __Pyx_INCREF(((PyObject *)__pyx_n_s__pointer_b)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 73, ((PyObject *)__pyx_n_s__pointer_b)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pointer_b)); __Pyx_INCREF(((PyObject *)__pyx_n_s__pointer_state)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 74, ((PyObject *)__pyx_n_s__pointer_state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pointer_state)); __Pyx_INCREF(((PyObject *)__pyx_n_s__impossible)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 75, ((PyObject *)__pyx_n_s__impossible)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__impossible)); __Pyx_INCREF(((PyObject *)__pyx_n_s__score)); PyTuple_SET_ITEM(__pyx_k_tuple_56, 76, ((PyObject *)__pyx_n_s__score)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__score)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_56)); __pyx_k_codeobj_57 = (PyObject*)__Pyx_PyCode_New(20, 0, 77, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_56, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_52, __pyx_n_s__calc_rows, 35, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_57)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":282 * return self.name * * cdef generic = Enum("") # <<<<<<<<<<<<<< * cdef strided = Enum("") # default * cdef indirect = Enum("") */ __pyx_k_tuple_60 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_60); __Pyx_INCREF(((PyObject *)__pyx_kp_s_59)); PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_kp_s_59)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_59)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60)); /* "View.MemoryView":283 * * cdef generic = Enum("") * cdef strided = Enum("") # default # <<<<<<<<<<<<<< * cdef indirect = Enum("") * */ __pyx_k_tuple_62 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_62)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_62); __Pyx_INCREF(((PyObject *)__pyx_kp_s_61)); PyTuple_SET_ITEM(__pyx_k_tuple_62, 0, ((PyObject *)__pyx_kp_s_61)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_61)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_62)); /* "View.MemoryView":284 * cdef generic = Enum("") * cdef strided = Enum("") # default * cdef indirect = Enum("") # <<<<<<<<<<<<<< * * */ __pyx_k_tuple_64 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_64)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_64); __Pyx_INCREF(((PyObject *)__pyx_kp_s_63)); PyTuple_SET_ITEM(__pyx_k_tuple_64, 0, ((PyObject *)__pyx_kp_s_63)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_63)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_64)); /* "View.MemoryView":287 * * * cdef contiguous = Enum("") # <<<<<<<<<<<<<< * cdef indirect_contiguous = Enum("") * */ __pyx_k_tuple_66 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_66)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_66); __Pyx_INCREF(((PyObject *)__pyx_kp_s_65)); PyTuple_SET_ITEM(__pyx_k_tuple_66, 0, ((PyObject *)__pyx_kp_s_65)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_65)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_66)); /* "View.MemoryView":288 * * cdef contiguous = Enum("") * cdef indirect_contiguous = Enum("") # <<<<<<<<<<<<<< * * */ __pyx_k_tuple_68 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_68)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_68); __Pyx_INCREF(((PyObject *)__pyx_kp_s_67)); PyTuple_SET_ITEM(__pyx_k_tuple_68, 0, ((PyObject *)__pyx_kp_s_67)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_67)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_68)); __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; return 0; __pyx_L1_error:; return -1; } #if PY_MAJOR_VERSION < 3 PyMODINIT_FUNC init_pairwise_seqs(void); /*proto*/ PyMODINIT_FUNC init_pairwise_seqs(void) #else PyMODINIT_FUNC PyInit__pairwise_seqs(void); /*proto*/ PyMODINIT_FUNC PyInit__pairwise_seqs(void) #endif { PyObject *__pyx_t_1 = NULL; __Pyx_RefNannyDeclarations #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("PyMODINIT_FUNC PyInit__pairwise_seqs(void)", 0); if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #ifdef __Pyx_CyFunction_USED if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif #ifdef __Pyx_FusedFunction_USED if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif #ifdef __Pyx_Generator_USED if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __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 PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_pairwise_seqs"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if CYTHON_COMPILING_IN_PYPY Py_INCREF(__pyx_b); #endif if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; /*--- Initialize various global constants etc. ---*/ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_module_is_main_cogent__align___pairwise_seqs) { if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; } /*--- Builtin init code ---*/ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Constants init code ---*/ if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- 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); /*--- Variable export code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ if (PyType_Ready(&__pyx_type___pyx_array) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "array", (PyObject *)&__pyx_type___pyx_array) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_array_type = &__pyx_type___pyx_array; if (PyType_Ready(&__pyx_type___pyx_MemviewEnum) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Enum", (PyObject *)&__pyx_type___pyx_MemviewEnum) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type___pyx_memoryview.tp_dict, __pyx_vtabptr_memoryview) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "memoryview", (PyObject *)&__pyx_type___pyx_memoryview) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type___pyx_memoryviewslice.tp_dict, __pyx_vtabptr__memoryviewslice) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "_memoryviewslice", (PyObject *)&__pyx_type___pyx_memoryviewslice) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_memoryviewslice_type = &__pyx_type___pyx_memoryviewslice; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ /* "/Users/maxwell/Documents/Work/Cogent/cogent/align/../../include/numerical_pyrex.pyx":13 * # * * __version__ = "('1', '5', '3-dev')" # <<<<<<<<<<<<<< * * cdef extern from "limits.h": */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____version__, ((PyObject *)__pyx_kp_s_48)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":16 * double log (double x) * * version_info = (3, 2) # <<<<<<<<<<<<<< * __version__ = "('1', '5', '3-dev')" * */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__version_info, ((PyObject *)__pyx_k_tuple_49)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":17 * * version_info = (3, 2) * __version__ = "('1', '5', '3-dev')" # <<<<<<<<<<<<<< * * cdef double SCALE_STEP, MIN_FLOAT_VALUE */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____version__, ((PyObject *)__pyx_kp_s_48)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "cogent/align/_pairwise_seqs.pyx":20 * * cdef double SCALE_STEP, MIN_FLOAT_VALUE * SCALE_STEP = 2.0**50 # <<<<<<<<<<<<<< * MIN_FLOAT_VALUE = 1.0 / SCALE_STEP * */ __pyx_v_6cogent_5align_14_pairwise_seqs_SCALE_STEP = pow(2.0, 50.0); /* "cogent/align/_pairwise_seqs.pyx":21 * cdef double SCALE_STEP, MIN_FLOAT_VALUE * SCALE_STEP = 2.0**50 * MIN_FLOAT_VALUE = 1.0 / SCALE_STEP # <<<<<<<<<<<<<< * * cdef int MAX_XCOUNT */ if (unlikely(__pyx_v_6cogent_5align_14_pairwise_seqs_SCALE_STEP == 0)) { PyErr_Format(PyExc_ZeroDivisionError, "float division"); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_FLOAT_VALUE = (1.0 / __pyx_v_6cogent_5align_14_pairwise_seqs_SCALE_STEP); /* "cogent/align/_pairwise_seqs.pyx":24 * * cdef int MAX_XCOUNT * MAX_XCOUNT = 256 # <<<<<<<<<<<<<< * * cdef long MIN_SCALE, MAX_SCALE */ __pyx_v_6cogent_5align_14_pairwise_seqs_MAX_XCOUNT = 256; /* "cogent/align/_pairwise_seqs.pyx":27 * * cdef long MIN_SCALE, MAX_SCALE * MIN_SCALE = -10000 # <<<<<<<<<<<<<< * MAX_SCALE = +10000 # or 0 if all numbers should be probabilities * */ __pyx_v_6cogent_5align_14_pairwise_seqs_MIN_SCALE = -10000; /* "cogent/align/_pairwise_seqs.pyx":28 * cdef long MIN_SCALE, MAX_SCALE * MIN_SCALE = -10000 * MAX_SCALE = +10000 # or 0 if all numbers should be probabilities # <<<<<<<<<<<<<< * * def fmpt(mantissa, exponent, msg=''): */ __pyx_v_6cogent_5align_14_pairwise_seqs_MAX_SCALE = 10000; /* "cogent/align/_pairwise_seqs.pyx":30 * MAX_SCALE = +10000 # or 0 if all numbers should be probabilities * * def fmpt(mantissa, exponent, msg=''): # <<<<<<<<<<<<<< * return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) * */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6cogent_5align_14_pairwise_seqs_1fmpt, NULL, __pyx_n_s_53); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__fmpt, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "cogent/align/_pairwise_seqs.pyx":35 * ctypedef unsigned char [:,:,::1] UChar3D * * def calc_rows(Long1D plan, Long1D seq1_index, Long1D seq2_index, # <<<<<<<<<<<<<< * int i_low, int i_high, int j_low, int j_high, preds, * Long2D state_directions, Double2D T, */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6cogent_5align_14_pairwise_seqs_3calc_rows, NULL, __pyx_n_s_53); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__calc_rows, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "cogent/align/_pairwise_seqs.pyx":1 * #cython: boundscheck=False # <<<<<<<<<<<<<< * #cython: wraparound=False * */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; /* "View.MemoryView":207 * info.obj = self * * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< * * def __dealloc__(array self): */ __pyx_t_1 = __pyx_capsule_create(((void *)(&__pyx_array_getbuffer)), __pyx_k_58); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_array_type->tp_dict, __pyx_n_s____pyx_getbuffer, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyType_Modified(__pyx_array_type); /* "View.MemoryView":282 * return self.name * * cdef generic = Enum("") # <<<<<<<<<<<<<< * cdef strided = Enum("") # default * cdef indirect = Enum("") */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject *)__pyx_MemviewEnum_type)), ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(generic); __Pyx_DECREF(generic); __Pyx_GIVEREF(__pyx_t_1); generic = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":283 * * cdef generic = Enum("") * cdef strided = Enum("") # default # <<<<<<<<<<<<<< * cdef indirect = Enum("") * */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject *)__pyx_MemviewEnum_type)), ((PyObject *)__pyx_k_tuple_62), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(strided); __Pyx_DECREF(strided); __Pyx_GIVEREF(__pyx_t_1); strided = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":284 * cdef generic = Enum("") * cdef strided = Enum("") # default * cdef indirect = Enum("") # <<<<<<<<<<<<<< * * */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject *)__pyx_MemviewEnum_type)), ((PyObject *)__pyx_k_tuple_64), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(indirect); __Pyx_DECREF(indirect); __Pyx_GIVEREF(__pyx_t_1); indirect = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":287 * * * cdef contiguous = Enum("") # <<<<<<<<<<<<<< * cdef indirect_contiguous = Enum("") * */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject *)__pyx_MemviewEnum_type)), ((PyObject *)__pyx_k_tuple_66), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(contiguous); __Pyx_DECREF(contiguous); __Pyx_GIVEREF(__pyx_t_1); contiguous = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":288 * * cdef contiguous = Enum("") * cdef indirect_contiguous = Enum("") # <<<<<<<<<<<<<< * * */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject *)__pyx_MemviewEnum_type)), ((PyObject *)__pyx_k_tuple_68), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(indirect_contiguous); __Pyx_DECREF(indirect_contiguous); __Pyx_GIVEREF(__pyx_t_1); indirect_contiguous = __pyx_t_1; __pyx_t_1 = 0; /* "View.MemoryView":503 * info.obj = self * * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< * * */ __pyx_t_1 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), __pyx_k_58); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_memoryview_type->tp_dict, __pyx_n_s____pyx_getbuffer, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyType_Modified(__pyx_memoryview_type); /* "View.MemoryView":958 * return self.from_object * * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< * * */ __pyx_t_1 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), __pyx_k_58); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_memoryviewslice_type->tp_dict, __pyx_n_s____pyx_getbuffer, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyType_Modified(__pyx_memoryviewslice_type); /* "View.MemoryView":1365 * * @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: */ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); if (__pyx_m) { __Pyx_AddTraceback("init cogent.align._pairwise_seqs", __pyx_clineno, __pyx_lineno, __pyx_filename); Py_DECREF(__pyx_m); __pyx_m = 0; } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init cogent.align._pairwise_seqs"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); #if PY_MAJOR_VERSION < 3 return; #else return __pyx_m; #endif } /* Runtime support code */ #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 /* CYTHON_REFNANNY */ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { PyObject *result; result = PyObject_GetAttr(dict, name); if (!result) { if (dict != __pyx_b) { PyErr_Clear(); result = PyObject_GetAttr(__pyx_b, name); } if (!result) { PyErr_SetObject(PyExc_NameError, name); } } return result; } static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { #if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); 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); #else PyErr_Restore(type, value, tb); #endif } static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { #if CYTHON_COMPILING_IN_CPYTHON PyThreadState *tstate = PyThreadState_GET(); *type = tstate->curexc_type; *value = tstate->curexc_value; *tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; #else PyErr_Fetch(type, value, tb); #endif } #if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, CYTHON_UNUSED PyObject *cause) { 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 PY_VERSION_HEX < 0x02050000 if (PyClass_Check(type)) { #else if (PyType_Check(type)) { #endif #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; #if PY_VERSION_HEX < 0x02050000 if (PyInstance_Check(type)) { type = (PyObject*) ((PyInstanceObject*)type)->in_class; Py_INCREF(type); } else { type = 0; PyErr_SetString(PyExc_TypeError, "raise: exception must be an old-style class or instance"); goto raise_error; } #else 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; } #endif } __Pyx_ErrRestore(type, value, tb); return; raise_error: Py_XDECREF(value); Py_XDECREF(type); Py_XDECREF(tb); return; } #else /* Python 3+ */ 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 *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 = PyEval_CallObject(type, args); 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 && cause != Py_None) { PyObject *fixed_cause; 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) { PyThreadState *tstate = PyThreadState_GET(); PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { Py_INCREF(tb); tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } } bad: Py_XDECREF(owned_instance); return; } #endif 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, "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } 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 } 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++; } 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; } } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 "%s() got an unexpected keyword argument '%s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", function_name, key); #endif bad: return -1; } 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); } static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, "need more than %" CYTHON_FORMAT_SSIZE_T "d value%s to unpack", index, (index == 1) ? "" : "s"); } static CYTHON_INLINE int __Pyx_IterFinish(void) { #if CYTHON_COMPILING_IN_CPYTHON PyThreadState *tstate = PyThreadState_GET(); PyObject* exc_type = tstate->curexc_type; if (unlikely(exc_type)) { if (likely(exc_type == PyExc_StopIteration) || 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 } 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; } static CYTHON_INLINE int __Pyx_IsLittleEndian(void) { unsigned int n = 1; return *(unsigned char*)(&n) != 0; } static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx, __Pyx_BufFmt_StackElem* stack, __Pyx_TypeInfo* type) { stack[0].field = &ctx->root; stack[0].parent_offset = 0; ctx->root.type = type; ctx->root.name = "buffer dtype"; ctx->root.offset = 0; ctx->head = stack; ctx->head->field = &ctx->root; ctx->fmt_offset = 0; ctx->head->parent_offset = 0; ctx->new_packmode = '@'; ctx->enc_packmode = '@'; ctx->new_count = 1; ctx->enc_count = 0; ctx->enc_type = 0; ctx->is_complex = 0; ctx->is_valid_array = 0; ctx->struct_alignment = 0; while (type->typegroup == 'S') { ++ctx->head; ctx->head->field = type->fields; ctx->head->parent_offset = 0; type = type->fields->type; } } static int __Pyx_BufFmt_ParseNumber(const char** ts) { int count; const char* t = *ts; if (*t < '0' || *t > '9') { return -1; } else { count = *t++ - '0'; while (*t >= '0' && *t < '9') { count *= 10; count += *t++ - '0'; } } *ts = t; return count; } static int __Pyx_BufFmt_ExpectNumber(const char **ts) { int number = __Pyx_BufFmt_ParseNumber(ts); if (number == -1) /* First char was not a digit */ PyErr_Format(PyExc_ValueError,\ "Does not understand character buffer dtype format string ('%c')", **ts); return number; } static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) { PyErr_Format(PyExc_ValueError, "Unexpected format string character: '%c'", ch); } static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) { switch (ch) { case 'c': return "'char'"; case 'b': return "'signed char'"; case 'B': return "'unsigned char'"; case 'h': return "'short'"; case 'H': return "'unsigned short'"; case 'i': return "'int'"; case 'I': return "'unsigned int'"; case 'l': return "'long'"; case 'L': return "'unsigned long'"; case 'q': return "'long long'"; case 'Q': return "'unsigned long long'"; case 'f': return (is_complex ? "'complex float'" : "'float'"); case 'd': return (is_complex ? "'complex double'" : "'double'"); case 'g': return (is_complex ? "'complex long double'" : "'long double'"); case 'T': return "a struct"; case 'O': return "Python object"; case 'P': return "a pointer"; case 's': case 'p': return "a string"; case 0: return "end"; default: return "unparseable format string"; } } static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) { switch (ch) { case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; case 'h': case 'H': return 2; case 'i': case 'I': case 'l': case 'L': return 4; case 'q': case 'Q': return 8; case 'f': return (is_complex ? 8 : 4); case 'd': return (is_complex ? 16 : 8); case 'g': { PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g').."); return 0; } case 'O': case 'P': return sizeof(void*); default: __Pyx_BufFmt_RaiseUnexpectedChar(ch); return 0; } } static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) { switch (ch) { case 'c': case 'b': case 'B': case 's': case 'p': return 1; case 'h': case 'H': return sizeof(short); case 'i': case 'I': return sizeof(int); case 'l': case 'L': return sizeof(long); #ifdef HAVE_LONG_LONG case 'q': case 'Q': return sizeof(PY_LONG_LONG); #endif case 'f': return sizeof(float) * (is_complex ? 2 : 1); case 'd': return sizeof(double) * (is_complex ? 2 : 1); case 'g': return sizeof(long double) * (is_complex ? 2 : 1); case 'O': case 'P': return sizeof(void*); default: { __Pyx_BufFmt_RaiseUnexpectedChar(ch); return 0; } } } typedef struct { char c; short x; } __Pyx_st_short; typedef struct { char c; int x; } __Pyx_st_int; typedef struct { char c; long x; } __Pyx_st_long; typedef struct { char c; float x; } __Pyx_st_float; typedef struct { char c; double x; } __Pyx_st_double; typedef struct { char c; long double x; } __Pyx_st_longdouble; typedef struct { char c; void *x; } __Pyx_st_void_p; #ifdef HAVE_LONG_LONG typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong; #endif static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, CYTHON_UNUSED int is_complex) { switch (ch) { case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short); case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int); case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long); #ifdef HAVE_LONG_LONG case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG); #endif case 'f': return sizeof(__Pyx_st_float) - sizeof(float); case 'd': return sizeof(__Pyx_st_double) - sizeof(double); case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double); case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*); default: __Pyx_BufFmt_RaiseUnexpectedChar(ch); return 0; } } /* These are for computing the padding at the end of the struct to align on the first member of the struct. This will probably the same as above, but we don't have any guarantees. */ typedef struct { short x; char c; } __Pyx_pad_short; typedef struct { int x; char c; } __Pyx_pad_int; typedef struct { long x; char c; } __Pyx_pad_long; typedef struct { float x; char c; } __Pyx_pad_float; typedef struct { double x; char c; } __Pyx_pad_double; typedef struct { long double x; char c; } __Pyx_pad_longdouble; typedef struct { void *x; char c; } __Pyx_pad_void_p; #ifdef HAVE_LONG_LONG typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong; #endif static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int is_complex) { switch (ch) { case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short); case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int); case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long); #ifdef HAVE_LONG_LONG case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG); #endif case 'f': return sizeof(__Pyx_pad_float) - sizeof(float); case 'd': return sizeof(__Pyx_pad_double) - sizeof(double); case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double); case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*); default: __Pyx_BufFmt_RaiseUnexpectedChar(ch); return 0; } } static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) { switch (ch) { case 'c': return 'H'; case 'b': case 'h': case 'i': case 'l': case 'q': case 's': case 'p': return 'I'; case 'B': case 'H': case 'I': case 'L': case 'Q': return 'U'; case 'f': case 'd': case 'g': return (is_complex ? 'C' : 'R'); case 'O': return 'O'; case 'P': return 'P'; default: { __Pyx_BufFmt_RaiseUnexpectedChar(ch); return 0; } } } static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) { if (ctx->head == NULL || ctx->head->field == &ctx->root) { const char* expected; const char* quote; if (ctx->head == NULL) { expected = "end"; quote = ""; } else { expected = ctx->head->field->type->name; quote = "'"; } PyErr_Format(PyExc_ValueError, "Buffer dtype mismatch, expected %s%s%s but got %s", quote, expected, quote, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex)); } else { __Pyx_StructField* field = ctx->head->field; __Pyx_StructField* parent = (ctx->head - 1)->field; PyErr_Format(PyExc_ValueError, "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'", field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex), parent->type->name, field->name); } } static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) { char group; size_t size, offset, arraysize = 1; if (ctx->enc_type == 0) return 0; if (ctx->head->field->type->arraysize[0]) { int i, ndim = 0; if (ctx->enc_type == 's' || ctx->enc_type == 'p') { ctx->is_valid_array = ctx->head->field->type->ndim == 1; ndim = 1; if (ctx->enc_count != ctx->head->field->type->arraysize[0]) { PyErr_Format(PyExc_ValueError, "Expected a dimension of size %zu, got %zu", ctx->head->field->type->arraysize[0], ctx->enc_count); return -1; } } if (!ctx->is_valid_array) { PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d", ctx->head->field->type->ndim, ndim); return -1; } for (i = 0; i < ctx->head->field->type->ndim; i++) { arraysize *= ctx->head->field->type->arraysize[i]; } ctx->is_valid_array = 0; ctx->enc_count = 1; } group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex); do { __Pyx_StructField* field = ctx->head->field; __Pyx_TypeInfo* type = field->type; if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') { size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex); } else { size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex); } if (ctx->enc_packmode == '@') { size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex); size_t align_mod_offset; if (align_at == 0) return -1; align_mod_offset = ctx->fmt_offset % align_at; if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset; if (ctx->struct_alignment == 0) ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type, ctx->is_complex); } if (type->size != size || type->typegroup != group) { if (type->typegroup == 'C' && type->fields != NULL) { size_t parent_offset = ctx->head->parent_offset + field->offset; ++ctx->head; ctx->head->field = type->fields; ctx->head->parent_offset = parent_offset; continue; } if ((type->typegroup == 'H' || group == 'H') && type->size == size) { } else { __Pyx_BufFmt_RaiseExpected(ctx); return -1; } } offset = ctx->head->parent_offset + field->offset; if (ctx->fmt_offset != offset) { PyErr_Format(PyExc_ValueError, "Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected", (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset); return -1; } ctx->fmt_offset += size; if (arraysize) ctx->fmt_offset += (arraysize - 1) * size; --ctx->enc_count; /* Consume from buffer string */ while (1) { if (field == &ctx->root) { ctx->head = NULL; if (ctx->enc_count != 0) { __Pyx_BufFmt_RaiseExpected(ctx); return -1; } break; /* breaks both loops as ctx->enc_count == 0 */ } ctx->head->field = ++field; if (field->type == NULL) { --ctx->head; field = ctx->head->field; continue; } else if (field->type->typegroup == 'S') { size_t parent_offset = ctx->head->parent_offset + field->offset; if (field->type->fields->type == NULL) continue; /* empty struct */ field = field->type->fields; ++ctx->head; ctx->head->field = field; ctx->head->parent_offset = parent_offset; break; } else { break; } } } while (ctx->enc_count); ctx->enc_type = 0; ctx->is_complex = 0; return 0; } static CYTHON_INLINE PyObject * __pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp) { const char *ts = *tsp; int i = 0, number; int ndim = ctx->head->field->type->ndim; ; ++ts; if (ctx->new_count != 1) { PyErr_SetString(PyExc_ValueError, "Cannot handle repeated arrays in format string"); return NULL; } if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; while (*ts && *ts != ')') { if (isspace(*ts)) continue; number = __Pyx_BufFmt_ExpectNumber(&ts); if (number == -1) return NULL; if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i]) return PyErr_Format(PyExc_ValueError, "Expected a dimension of size %zu, got %d", ctx->head->field->type->arraysize[i], number); if (*ts != ',' && *ts != ')') return PyErr_Format(PyExc_ValueError, "Expected a comma in format string, got '%c'", *ts); if (*ts == ',') ts++; i++; } if (i != ndim) return PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d", ctx->head->field->type->ndim, i); if (!*ts) { PyErr_SetString(PyExc_ValueError, "Unexpected end of format string, expected ')'"); return NULL; } ctx->is_valid_array = 1; ctx->new_count = 1; *tsp = ++ts; return Py_None; } static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) { int got_Z = 0; while (1) { switch(*ts) { case 0: if (ctx->enc_type != 0 && ctx->head == NULL) { __Pyx_BufFmt_RaiseExpected(ctx); return NULL; } if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; if (ctx->head != NULL) { __Pyx_BufFmt_RaiseExpected(ctx); return NULL; } return ts; case ' ': case 10: case 13: ++ts; break; case '<': if (!__Pyx_IsLittleEndian()) { PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler"); return NULL; } ctx->new_packmode = '='; ++ts; break; case '>': case '!': if (__Pyx_IsLittleEndian()) { PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler"); return NULL; } ctx->new_packmode = '='; ++ts; break; case '=': case '@': case '^': ctx->new_packmode = *ts++; break; case 'T': /* substruct */ { const char* ts_after_sub; size_t i, struct_count = ctx->new_count; size_t struct_alignment = ctx->struct_alignment; ctx->new_count = 1; ++ts; if (*ts != '{') { PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'"); return NULL; } if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; ctx->enc_type = 0; /* Erase processed last struct element */ ctx->enc_count = 0; ctx->struct_alignment = 0; ++ts; ts_after_sub = ts; for (i = 0; i != struct_count; ++i) { ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts); if (!ts_after_sub) return NULL; } ts = ts_after_sub; if (struct_alignment) ctx->struct_alignment = struct_alignment; } break; case '}': /* end of substruct; either repeat or move on */ { size_t alignment = ctx->struct_alignment; ++ts; if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; ctx->enc_type = 0; /* Erase processed last struct element */ if (alignment && ctx->fmt_offset % alignment) { ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment); } } return ts; case 'x': if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; ctx->fmt_offset += ctx->new_count; ctx->new_count = 1; ctx->enc_count = 0; ctx->enc_type = 0; ctx->enc_packmode = ctx->new_packmode; ++ts; break; case 'Z': got_Z = 1; ++ts; if (*ts != 'f' && *ts != 'd' && *ts != 'g') { __Pyx_BufFmt_RaiseUnexpectedChar('Z'); return NULL; } /* fall through */ case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I': case 'l': case 'L': case 'q': case 'Q': case 'f': case 'd': case 'g': case 'O': case 's': case 'p': if (ctx->enc_type == *ts && got_Z == ctx->is_complex && ctx->enc_packmode == ctx->new_packmode) { ctx->enc_count += ctx->new_count; } else { if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; ctx->enc_count = ctx->new_count; ctx->enc_packmode = ctx->new_packmode; ctx->enc_type = *ts; ctx->is_complex = got_Z; } ++ts; ctx->new_count = 1; got_Z = 0; break; case ':': ++ts; while(*ts != ':') ++ts; ++ts; break; case '(': if (!__pyx_buffmt_parse_array(ctx, &ts)) return NULL; break; default: { int number = __Pyx_BufFmt_ExpectNumber(&ts); if (number == -1) return NULL; ctx->new_count = (size_t)number; } } } } static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) { buf->buf = NULL; buf->obj = NULL; buf->strides = __Pyx_zeros; buf->shape = __Pyx_zeros; buf->suboffsets = __Pyx_minusones; } static CYTHON_INLINE int __Pyx_GetBufferAndValidate( Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack) { if (obj == Py_None || obj == NULL) { __Pyx_ZeroBuffer(buf); return 0; } buf->buf = NULL; if (__Pyx_GetBuffer(obj, buf, flags) == -1) goto fail; if (buf->ndim != nd) { PyErr_Format(PyExc_ValueError, "Buffer has wrong number of dimensions (expected %d, got %d)", nd, buf->ndim); goto fail; } if (!cast) { __Pyx_BufFmt_Context ctx; __Pyx_BufFmt_Init(&ctx, stack, dtype); if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail; } if ((unsigned)buf->itemsize != dtype->size) { PyErr_Format(PyExc_ValueError, "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)", buf->itemsize, (buf->itemsize > 1) ? "s" : "", dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : ""); goto fail; } if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones; return 0; fail:; __Pyx_ZeroBuffer(buf); return -1; } static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) { if (info->buf == NULL) return; if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL; __Pyx_ReleaseBuffer(info); } static int __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b) { int i; if (!a || !b) return 0; if (a == b) return 1; if (a->size != b->size || a->typegroup != b->typegroup || a->is_unsigned != b->is_unsigned || a->ndim != b->ndim) { if (a->typegroup == 'H' || b->typegroup == 'H') { return a->size == b->size; } else { return 0; } } if (a->ndim) { for (i = 0; i < a->ndim; i++) if (a->arraysize[i] != b->arraysize[i]) return 0; } if (a->typegroup == 'S') { if (a->flags != b->flags) return 0; if (a->fields || b->fields) { if (!(a->fields && b->fields)) return 0; for (i = 0; a->fields[i].type && b->fields[i].type; i++) { __Pyx_StructField *field_a = a->fields + i; __Pyx_StructField *field_b = b->fields + i; if (field_a->offset != field_b->offset || !__pyx_typeinfo_cmp(field_a->type, field_b->type)) return 0; } return !a->fields[i].type && !b->fields[i].type; } } return 1; } static int __Pyx_ValidateAndInit_memviewslice( int *axes_specs, int c_or_f_flag, int buf_flags, int ndim, __Pyx_TypeInfo *dtype, __Pyx_BufFmt_StackElem stack[], __Pyx_memviewslice *memviewslice, PyObject *original_obj) { struct __pyx_memoryview_obj *memview, *new_memview; __Pyx_RefNannyDeclarations Py_buffer *buf; int i, spec = 0, retval = -1; __Pyx_BufFmt_Context ctx; int from_memoryview = __pyx_memoryview_check(original_obj); __Pyx_RefNannySetupContext("ValidateAndInit_memviewslice", 0); if (from_memoryview && __pyx_typeinfo_cmp(dtype, ((struct __pyx_memoryview_obj *) original_obj)->typeinfo)) { memview = (struct __pyx_memoryview_obj *) original_obj; new_memview = NULL; } else { memview = (struct __pyx_memoryview_obj *) __pyx_memoryview_new( original_obj, buf_flags, 0, dtype); new_memview = memview; if (unlikely(!memview)) goto fail; } buf = &memview->view; if (buf->ndim != ndim) { PyErr_Format(PyExc_ValueError, "Buffer has wrong number of dimensions (expected %d, got %d)", ndim, buf->ndim); goto fail; } if (new_memview) { __Pyx_BufFmt_Init(&ctx, stack, dtype); if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail; } if ((unsigned)buf->itemsize != dtype->size) { PyErr_Format(PyExc_ValueError, "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "u byte%s) " "does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "u byte%s)", buf->itemsize, (buf->itemsize > 1) ? "s" : "", dtype->name, dtype->size, (dtype->size > 1) ? "s" : ""); goto fail; } for (i = 0; i < ndim; i++) { spec = axes_specs[i]; if (buf->strides) { if (spec & __Pyx_MEMVIEW_CONTIG) { if (spec & (__Pyx_MEMVIEW_PTR|__Pyx_MEMVIEW_FULL)) { if (buf->strides[i] != sizeof(void *)) { PyErr_Format(PyExc_ValueError, "Buffer is not indirectly contiguous in dimension %d.", i); goto fail; } } else if (buf->strides[i] != buf->itemsize) { PyErr_SetString(PyExc_ValueError, "Buffer and memoryview are not contiguous in the same dimension."); goto fail; } } if (spec & __Pyx_MEMVIEW_FOLLOW) { Py_ssize_t stride = buf->strides[i]; if (stride < 0) stride = -stride; if (stride < buf->itemsize) { PyErr_SetString(PyExc_ValueError, "Buffer and memoryview are not contiguous in the same dimension."); goto fail; } } } else { if (spec & __Pyx_MEMVIEW_CONTIG && i != ndim - 1) { PyErr_Format(PyExc_ValueError, "C-contiguous buffer is not contiguous in " "dimension %d", i); goto fail; } else if (spec & (__Pyx_MEMVIEW_PTR)) { PyErr_Format(PyExc_ValueError, "C-contiguous buffer is not indirect in " "dimension %d", i); goto fail; } else if (buf->suboffsets) { PyErr_SetString(PyExc_ValueError, "Buffer exposes suboffsets but no strides"); goto fail; } } /* Todo: without PyBUF_INDIRECT we may not have suboffset information, i.e., the ptr may not be set to NULL but may be uninitialized? */ if (spec & __Pyx_MEMVIEW_DIRECT) { if (buf->suboffsets && buf->suboffsets[i] >= 0) { PyErr_Format(PyExc_ValueError, "Buffer not compatible with direct access in dimension %d.", i); goto fail; } } if (spec & __Pyx_MEMVIEW_PTR) { if (!buf->suboffsets || (buf->suboffsets && buf->suboffsets[i] < 0)) { PyErr_Format(PyExc_ValueError, "Buffer is not indirectly accessisble in dimension %d.", i); goto fail; } } } if (buf->strides) { if (c_or_f_flag & __Pyx_IS_F_CONTIG) { Py_ssize_t stride = 1; for (i=0; iitemsize != buf->strides[i]) { PyErr_SetString(PyExc_ValueError, "Buffer not fortran contiguous."); goto fail; } stride = stride * buf->shape[i]; } } else if (c_or_f_flag & __Pyx_IS_C_CONTIG) { Py_ssize_t stride = 1; for (i = ndim-1; i>-1; i--) { if(stride * buf->itemsize != buf->strides[i]) { PyErr_SetString(PyExc_ValueError, "Buffer not C contiguous."); goto fail; } stride = stride * buf->shape[i]; } } } if (unlikely(__Pyx_init_memviewslice(memview, ndim, memviewslice, new_memview != NULL) == -1)) { goto fail; } retval = 0; goto no_fail; fail: Py_XDECREF(new_memview); retval = -1; no_fail: __Pyx_RefNannyFinishContext(); return retval; } static int __Pyx_init_memviewslice(struct __pyx_memoryview_obj *memview, int ndim, __Pyx_memviewslice *memviewslice, int memview_is_new_reference) { __Pyx_RefNannyDeclarations int i, retval=-1; Py_buffer *buf = &memview->view; __Pyx_RefNannySetupContext("init_memviewslice", 0); if (!buf) { PyErr_SetString(PyExc_ValueError, "buf is NULL."); goto fail; } else if (memviewslice->memview || memviewslice->data) { PyErr_SetString(PyExc_ValueError, "memviewslice is already initialized!"); goto fail; } if (buf->strides) { for (i = 0; i < ndim; i++) { memviewslice->strides[i] = buf->strides[i]; } } else { Py_ssize_t stride = buf->itemsize; for (i = ndim - 1; i >= 0; i--) { memviewslice->strides[i] = stride; stride *= buf->shape[i]; } } for (i = 0; i < ndim; i++) { memviewslice->shape[i] = buf->shape[i]; if (buf->suboffsets) { memviewslice->suboffsets[i] = buf->suboffsets[i]; } else { memviewslice->suboffsets[i] = -1; } } memviewslice->memview = memview; memviewslice->data = (char *)buf->buf; if (__pyx_add_acquisition_count(memview) == 0 && !memview_is_new_reference) { Py_INCREF(memview); } retval = 0; goto no_fail; fail: memviewslice->memview = 0; memviewslice->data = 0; retval = -1; no_fail: __Pyx_RefNannyFinishContext(); return retval; } static CYTHON_INLINE void __pyx_fatalerror(const char *fmt, ...) { va_list vargs; char msg[200]; va_start(vargs, fmt); #ifdef HAVE_STDARG_PROTOTYPES va_start(vargs, fmt); #else va_start(vargs); #endif vsnprintf(msg, 200, fmt, vargs); Py_FatalError(msg); va_end(vargs); } static CYTHON_INLINE int __pyx_add_acquisition_count_locked(__pyx_atomic_int *acquisition_count, PyThread_type_lock lock) { int result; PyThread_acquire_lock(lock, 1); result = (*acquisition_count)++; PyThread_release_lock(lock); return result; } static CYTHON_INLINE int __pyx_sub_acquisition_count_locked(__pyx_atomic_int *acquisition_count, PyThread_type_lock lock) { int result; PyThread_acquire_lock(lock, 1); result = (*acquisition_count)--; PyThread_release_lock(lock); return result; } static CYTHON_INLINE void __Pyx_INC_MEMVIEW(__Pyx_memviewslice *memslice, int have_gil, int lineno) { int first_time; struct __pyx_memoryview_obj *memview = memslice->memview; if (!memview || (PyObject *) memview == Py_None) return; /* allow uninitialized memoryview assignment */ if (__pyx_get_slice_count(memview) < 0) __pyx_fatalerror("Acquisition count is %d (line %d)", __pyx_get_slice_count(memview), lineno); first_time = __pyx_add_acquisition_count(memview) == 0; if (first_time) { if (have_gil) { Py_INCREF((PyObject *) memview); } else { PyGILState_STATE _gilstate = PyGILState_Ensure(); Py_INCREF((PyObject *) memview); PyGILState_Release(_gilstate); } } } static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *memslice, int have_gil, int lineno) { int last_time; struct __pyx_memoryview_obj *memview = memslice->memview; if (!memview ) { return; } else if ((PyObject *) memview == Py_None) { memslice->memview = NULL; return; } if (__pyx_get_slice_count(memview) <= 0) __pyx_fatalerror("Acquisition count is %d (line %d)", __pyx_get_slice_count(memview), lineno); last_time = __pyx_sub_acquisition_count(memview) == 1; memslice->data = NULL; if (last_time) { if (have_gil) { Py_CLEAR(memslice->memview); } else { PyGILState_STATE _gilstate = PyGILState_Ensure(); Py_CLEAR(memslice->memview); PyGILState_Release(_gilstate); } } else { memslice->memview = NULL; } } static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact) { if (!type) { PyErr_Format(PyExc_SystemError, "Missing type object"); return 0; } if (none_allowed && obj == Py_None) return 1; else if (exact) { if (Py_TYPE(obj) == type) return 1; } else { if (PyObject_TypeCheck(obj, type)) return 1; } PyErr_Format(PyExc_TypeError, "Argument '%s' has incorrect type (expected %s, got %s)", name, type->tp_name, Py_TYPE(obj)->tp_name); return 0; } static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { PyObject *r = PyObject_GetAttr(o, n); if (!r) { if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; PyErr_Clear(); r = d; Py_INCREF(d); } return r; bad: return NULL; } static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t a, Py_ssize_t b) { Py_ssize_t q = a / b; Py_ssize_t r = a - q*b; q -= ((r != 0) & ((r ^ b) < 0)); return q; } 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 (s1 == s2) { return (equals == Py_EQ); } else if (PyUnicode_CheckExact(s1) & PyUnicode_CheckExact(s2)) { #if CYTHON_PEP393_ENABLED if ((PyUnicode_READY(s1) < 0) || (PyUnicode_READY(s2) < 0)) return -1; if (PyUnicode_GET_LENGTH(s1) != PyUnicode_GET_LENGTH(s2)) { return (equals == Py_NE); } else if (PyUnicode_GET_LENGTH(s1) == 1) { Py_UCS4 ch1 = PyUnicode_READ_CHAR(s1, 0); Py_UCS4 ch2 = PyUnicode_READ_CHAR(s2, 0); return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2); #else if (PyUnicode_GET_SIZE(s1) != PyUnicode_GET_SIZE(s2)) { return (equals == Py_NE); } else if (PyUnicode_GET_SIZE(s1) == 1) { Py_UNICODE ch1 = PyUnicode_AS_UNICODE(s1)[0]; Py_UNICODE ch2 = PyUnicode_AS_UNICODE(s2)[0]; return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2); #endif } else { int result = PyUnicode_Compare(s1, s2); if ((result == -1) && unlikely(PyErr_Occurred())) return -1; return (equals == Py_EQ) ? (result == 0) : (result != 0); } } else if ((s1 == Py_None) & PyUnicode_CheckExact(s2)) { return (equals == Py_NE); } else if ((s2 == Py_None) & PyUnicode_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 } static CYTHON_INLINE PyObject* __Pyx_decode_c_string( const char* cstring, Py_ssize_t start, Py_ssize_t stop, const char* encoding, const char* errors, PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) { Py_ssize_t length; if (unlikely((start < 0) | (stop < 0))) { length = strlen(cstring); if (start < 0) { start += length; if (start < 0) start = 0; } if (stop < 0) stop += length; } length = stop - start; if (unlikely(length <= 0)) return PyUnicode_FromUnicode(NULL, 0); cstring += start; if (decode_func) { return decode_func(cstring, length, errors); } else { return PyUnicode_Decode(cstring, length, encoding, errors); } } static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); } static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { if (unlikely(!type)) { PyErr_Format(PyExc_SystemError, "Missing type object"); return 0; } if (likely(PyObject_TypeCheck(obj, type))) return 1; PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", Py_TYPE(obj)->tp_name, type->tp_name); return 0; } static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { PyObject *local_type, *local_value, *local_tb; #if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); 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_COMPILING_IN_CPYTHON if (unlikely(tstate->curexc_type)) #else if (unlikely(PyErr_Occurred())) #endif goto bad; #if PY_MAJOR_VERSION >= 3 if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) goto bad; #endif Py_INCREF(local_type); Py_INCREF(local_value); Py_INCREF(local_tb); *type = local_type; *value = local_value; *tb = local_tb; #if CYTHON_COMPILING_IN_CPYTHON 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; /* Make sure tstate is in a consistent state when we XDECREF these objects (DECREF may run arbitrary code). */ 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; } static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); } 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; } #if PY_MAJOR_VERSION < 3 static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { CYTHON_UNUSED PyObject *getbuffer_cobj; #if PY_VERSION_HEX >= 0x02060000 if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags); #endif if (PyObject_TypeCheck(obj, __pyx_array_type)) return __pyx_array_getbuffer(obj, view, flags); if (PyObject_TypeCheck(obj, __pyx_memoryview_type)) return __pyx_memoryview_getbuffer(obj, view, flags); #if PY_VERSION_HEX < 0x02060000 if (obj->ob_type->tp_dict && (getbuffer_cobj = PyMapping_GetItemString(obj->ob_type->tp_dict, "__pyx_getbuffer"))) { getbufferproc func; #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 0) func = (getbufferproc) PyCapsule_GetPointer(getbuffer_cobj, "getbuffer(obj, view, flags)"); #else func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj); #endif Py_DECREF(getbuffer_cobj); if (!func) goto fail; return func(obj, view, flags); } else { PyErr_Clear(); } #endif PyErr_Format(PyExc_TypeError, "'%100s' does not have the buffer interface", Py_TYPE(obj)->tp_name); #if PY_VERSION_HEX < 0x02060000 fail: #endif return -1; } static void __Pyx_ReleaseBuffer(Py_buffer *view) { PyObject *obj = view->obj; CYTHON_UNUSED PyObject *releasebuffer_cobj; if (!obj) return; #if PY_VERSION_HEX >= 0x02060000 if (PyObject_CheckBuffer(obj)) { PyBuffer_Release(view); return; } #endif #if PY_VERSION_HEX < 0x02060000 if (obj->ob_type->tp_dict && (releasebuffer_cobj = PyMapping_GetItemString(obj->ob_type->tp_dict, "__pyx_releasebuffer"))) { releasebufferproc func; #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 0) func = (releasebufferproc) PyCapsule_GetPointer(releasebuffer_cobj, "releasebuffer(obj, view)"); #else func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj); #endif Py_DECREF(releasebuffer_cobj); if (!func) goto fail; func(obj, view); return; } else { PyErr_Clear(); } #endif goto nofail; #if PY_VERSION_HEX < 0x02060000 fail: #endif PyErr_WriteUnraisable(obj); nofail: Py_DECREF(obj); view->obj = NULL; } #endif /* PY_MAJOR_VERSION < 3 */ static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dc_long(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 1, &__Pyx_TypeInfo_long, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_dc_long(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 2, &__Pyx_TypeInfo_long, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 2, &__Pyx_TypeInfo_double, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_double(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 3, &__Pyx_TypeInfo_double, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_unsigned_char(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 3, &__Pyx_TypeInfo_unsigned_char, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static int __pyx_memviewslice_is_contig(const __Pyx_memviewslice *mvs, char order, int ndim) { int i, index, step, start; Py_ssize_t itemsize = mvs->memview->view.itemsize; if (order == 'F') { step = 1; start = 0; } else { step = -1; start = ndim - 1; } for (i = 0; i < ndim; i++) { index = start + step * i; if (mvs->suboffsets[index] >= 0 || mvs->strides[index] != itemsize) return 0; itemsize *= mvs->shape[index]; } return 1; } static void __pyx_get_array_memory_extents(__Pyx_memviewslice *slice, void **out_start, void **out_end, int ndim, size_t itemsize) { char *start, *end; int i; start = end = slice->data; for (i = 0; i < ndim; i++) { Py_ssize_t stride = slice->strides[i]; Py_ssize_t extent = slice->shape[i]; if (extent == 0) { *out_start = *out_end = start; return; } else { if (stride > 0) end += stride * (extent - 1); else start += stride * (extent - 1); } } *out_start = start; *out_end = end + itemsize; } static int __pyx_slices_overlap(__Pyx_memviewslice *slice1, __Pyx_memviewslice *slice2, int ndim, size_t itemsize) { void *start1, *end1, *start2, *end2; __pyx_get_array_memory_extents(slice1, &start1, &end1, ndim, itemsize); __pyx_get_array_memory_extents(slice2, &start2, &end2, ndim, itemsize); return (start1 < end2) && (start2 < end1); } 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, int dtype_is_object) { __Pyx_RefNannyDeclarations int i; __Pyx_memviewslice new_mvs = { 0, 0, { 0 }, { 0 }, { 0 } }; struct __pyx_memoryview_obj *from_memview = from_mvs->memview; Py_buffer *buf = &from_memview->view; PyObject *shape_tuple = NULL; PyObject *temp_int = NULL; struct __pyx_array_obj *array_obj = NULL; struct __pyx_memoryview_obj *memview_obj = NULL; __Pyx_RefNannySetupContext("__pyx_memoryview_copy_new_contig", 0); for (i = 0; i < ndim; i++) { if (from_mvs->suboffsets[i] >= 0) { PyErr_Format(PyExc_ValueError, "Cannot copy memoryview slice with " "indirect dimensions (axis %d)", i); goto fail; } } shape_tuple = PyTuple_New(ndim); if (unlikely(!shape_tuple)) { goto fail; } __Pyx_GOTREF(shape_tuple); for(i = 0; i < ndim; i++) { temp_int = PyInt_FromLong(from_mvs->shape[i]); if(unlikely(!temp_int)) { goto fail; } else { PyTuple_SET_ITEM(shape_tuple, i, temp_int); temp_int = NULL; } } array_obj = __pyx_array_new(shape_tuple, sizeof_dtype, buf->format, (char *) mode, NULL); if (unlikely(!array_obj)) { goto fail; } __Pyx_GOTREF(array_obj); memview_obj = (struct __pyx_memoryview_obj *) __pyx_memoryview_new( (PyObject *) array_obj, contig_flag, dtype_is_object, from_mvs->memview->typeinfo); if (unlikely(!memview_obj)) goto fail; if (unlikely(__Pyx_init_memviewslice(memview_obj, ndim, &new_mvs, 1) < 0)) goto fail; if (unlikely(__pyx_memoryview_copy_contents(*from_mvs, new_mvs, ndim, ndim, dtype_is_object) < 0)) goto fail; goto no_fail; fail: __Pyx_XDECREF(new_mvs.memview); new_mvs.memview = NULL; new_mvs.data = NULL; no_fail: __Pyx_XDECREF(shape_tuple); __Pyx_XDECREF(temp_int); __Pyx_XDECREF(array_obj); __Pyx_RefNannyFinishContext(); return new_mvs; } static CYTHON_INLINE PyObject * __pyx_capsule_create(void *p, const char *sig) { PyObject *cobj; #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 0) cobj = PyCapsule_New(p, sig, NULL); #else cobj = PyCObject_FromVoidPtr(p, NULL); #endif return cobj; } static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) { #if CYTHON_COMPILING_IN_CPYTHON PyThreadState *tstate = PyThreadState_GET(); *type = tstate->exc_type; *value = tstate->exc_value; *tb = tstate->exc_traceback; Py_XINCREF(*type); Py_XINCREF(*value); Py_XINCREF(*tb); #else PyErr_GetExcInfo(type, value, tb); #endif } static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) { #if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); 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; Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); #else PyErr_SetExcInfo(type, value, tb); #endif } static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { PyObject *py_import = 0; PyObject *empty_list = 0; PyObject *module = 0; PyObject *global_dict = 0; PyObject *empty_dict = 0; PyObject *list; py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); if (!py_import) goto bad; if (from_list) list = from_list; else { empty_list = PyList_New(0); if (!empty_list) goto bad; list = empty_list; } global_dict = PyModule_GetDict(__pyx_m); if (!global_dict) goto bad; empty_dict = PyDict_New(); if (!empty_dict) goto bad; #if PY_VERSION_HEX >= 0x02050000 { #if PY_MAJOR_VERSION >= 3 if (level == -1) { if (strchr(__Pyx_MODULE_NAME, '.')) { /* try package relative import first */ PyObject *py_level = PyInt_FromLong(1); if (!py_level) goto bad; module = PyObject_CallFunctionObjArgs(py_import, name, global_dict, empty_dict, list, py_level, NULL); Py_DECREF(py_level); if (!module) { if (!PyErr_ExceptionMatches(PyExc_ImportError)) goto bad; PyErr_Clear(); } } level = 0; /* try absolute import on failure */ } #endif if (!module) { 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 if (level>0) { PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); goto bad; } module = PyObject_CallFunctionObjArgs(py_import, name, global_dict, empty_dict, list, NULL); #endif bad: Py_XDECREF(empty_list); Py_XDECREF(py_import); Py_XDECREF(empty_dict); return module; } static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { const unsigned char neg_one = (unsigned char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned char" : "value too large to convert to unsigned char"); } return (unsigned char)-1; } return (unsigned char)val; } return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { const unsigned short neg_one = (unsigned short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned short" : "value too large to convert to unsigned short"); } return (unsigned short)-1; } return (unsigned short)val; } return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { const unsigned int neg_one = (unsigned int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned int" : "value too large to convert to unsigned int"); } return (unsigned int)-1; } return (unsigned int)val; } return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { const char neg_one = (char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to char" : "value too large to convert to char"); } return (char)-1; } return (char)val; } return (char)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { const short neg_one = (short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to short" : "value too large to convert to short"); } return (short)-1; } return (short)val; } return (short)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { const int neg_one = (int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to int" : "value too large to convert to int"); } return (int)-1; } return (int)val; } return (int)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { const signed char neg_one = (signed char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed char" : "value too large to convert to signed char"); } return (signed char)-1; } return (signed char)val; } return (signed char)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { const signed short neg_one = (signed short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed short" : "value too large to convert to signed short"); } return (signed short)-1; } return (signed short)val; } return (signed short)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { const signed int neg_one = (signed int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed int" : "value too large to convert to signed int"); } return (signed int)-1; } return (signed int)val; } return (signed int)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { const int neg_one = (int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to int" : "value too large to convert to int"); } return (int)-1; } return (int)val; } return (int)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { const unsigned long neg_one = (unsigned long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned long"); return (unsigned long)-1; } return (unsigned long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned long"); return (unsigned long)-1; } return (unsigned long)PyLong_AsUnsignedLong(x); } else { return (unsigned long)PyLong_AsLong(x); } } else { unsigned long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (unsigned long)-1; val = __Pyx_PyInt_AsUnsignedLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG)-1; } return (unsigned PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG)-1; } return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); } else { return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); } } else { unsigned PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (unsigned PY_LONG_LONG)-1; val = __Pyx_PyInt_AsUnsignedLongLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { const long neg_one = (long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long)-1; } return (long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long)-1; } return (long)PyLong_AsUnsignedLong(x); } else { return (long)PyLong_AsLong(x); } } else { long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (long)-1; val = __Pyx_PyInt_AsLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to PY_LONG_LONG"); return (PY_LONG_LONG)-1; } return (PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to PY_LONG_LONG"); return (PY_LONG_LONG)-1; } return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); } else { return (PY_LONG_LONG)PyLong_AsLongLong(x); } } else { PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (PY_LONG_LONG)-1; val = __Pyx_PyInt_AsLongLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { const signed long neg_one = (signed long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed long"); return (signed long)-1; } return (signed long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed long"); return (signed long)-1; } return (signed long)PyLong_AsUnsignedLong(x); } else { return (signed long)PyLong_AsLong(x); } } else { signed long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (signed long)-1; val = __Pyx_PyInt_AsSignedLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed PY_LONG_LONG"); return (signed PY_LONG_LONG)-1; } return (signed PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed PY_LONG_LONG"); return (signed PY_LONG_LONG)-1; } return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); } else { return (signed PY_LONG_LONG)PyLong_AsLongLong(x); } } else { signed PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (signed PY_LONG_LONG)-1; val = __Pyx_PyInt_AsSignedLongLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_d_d_dc_long(PyObject *obj) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG) }; int retcode; if (obj == Py_None) { result.memview = (struct __pyx_memoryview_obj *) Py_None; return result; } retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_C_CONTIG, (PyBUF_C_CONTIGUOUS | PyBUF_FORMAT | PyBUF_WRITABLE), 3, &__Pyx_TypeInfo_long, stack, &result, obj); if (unlikely(retcode == -1)) goto __pyx_fail; return result; __pyx_fail: result.memview = NULL; result.data = NULL; return result; } static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename) { PyObject *old_exc, *old_val, *old_tb; PyObject *ctx; __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); #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); } } 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); #if PY_VERSION_HEX < 0x02050000 return PyErr_Warn(NULL, message); #else return PyErr_WarnEx(NULL, message, 1); #endif } return 0; } static int __Pyx_SetVtable(PyObject *dict, void *vtable) { #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) PyObject *ob = PyCapsule_New(vtable, 0, 0); #else PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); #endif if (!ob) goto bad; if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0) goto bad; Py_DECREF(ob); return 0; bad: Py_XDECREF(ob); return -1; } 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) / 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, 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); } #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, /*int argcount,*/ 0, /*int kwonlyargcount,*/ 0, /*int nlocals,*/ 0, /*int stacksize,*/ 0, /*int flags,*/ __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, /*int firstlineno,*/ __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; PyObject *py_globals = 0; PyFrameObject *py_frame = 0; 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_globals = PyModule_GetDict(__pyx_m); if (!py_globals) goto bad; py_frame = PyFrame_New( PyThreadState_GET(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ py_globals, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; py_frame->f_lineno = py_line; PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_code); Py_XDECREF(py_frame); } 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 /* Python 3+ has unicode identifiers */ 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; ++t; } return 0; } /* Type Conversion Functions */ 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 CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { PyNumberMethods *m; const char *name = NULL; PyObject *res = NULL; #if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(x) || PyLong_Check(x)) #else if (PyLong_Check(x)) #endif return Py_INCREF(x), x; m = Py_TYPE(x)->tp_as_number; #if PY_VERSION_HEX < 0x03000000 if (m && m->nb_int) { name = "int"; res = PyNumber_Int(x); } else if (m && m->nb_long) { name = "long"; res = PyNumber_Long(x); } #else if (m && m->nb_int) { name = "int"; res = PyNumber_Long(x); } #endif if (res) { #if PY_VERSION_HEX < 0x03000000 if (!PyInt_Check(res) && !PyLong_Check(res)) { #else if (!PyLong_Check(res)) { #endif PyErr_Format(PyExc_TypeError, "__%s__ returned non-%s (type %.200s)", name, name, Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } } 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 = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); return ival; } static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { #if PY_VERSION_HEX < 0x02050000 if (ival <= LONG_MAX) return PyInt_FromLong((long)ival); else { unsigned char *bytes = (unsigned char *) &ival; int one = 1; int little = (int)*(unsigned char*)&one; return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); } #else return PyInt_FromSize_t(ival); #endif } static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { return (size_t)-1; } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { PyErr_SetString(PyExc_OverflowError, "value too large to convert to size_t"); return (size_t)-1; } return (size_t)val; } #endif /* Py_PYTHON_H */ pycogent-1.9/cogent/align/_pairwise_seqs.pyx000066400000000000000000000270321273014367000213520ustar00rootroot00000000000000#cython: boundscheck=False #cython: wraparound=False include "../../include/numerical_pyrex.pyx" # The weird indentation in this file is to match the POG version. cdef extern from "Python.h": PyErr_Occurred() int PyErr_CheckSignals() double Py_HUGE_VAL cdef extern from "math.h": double log (double x) version_info = (3, 2) __version__ = "('1', '9')" cdef double SCALE_STEP, MIN_FLOAT_VALUE SCALE_STEP = 2.0**50 MIN_FLOAT_VALUE = 1.0 / SCALE_STEP cdef int MAX_XCOUNT MAX_XCOUNT = 256 cdef long MIN_SCALE, MAX_SCALE MIN_SCALE = -10000 MAX_SCALE = +10000 # or 0 if all numbers should be probabilities def fmpt(mantissa, exponent, msg=''): return "%s * SCALE_STEP ** %s %s" % (mantissa, exponent, msg) ctypedef unsigned char [:,:,::1] UChar3D def calc_rows(Long1D plan, Long1D seq1_index, Long1D seq2_index, int i_low, int i_high, int j_low, int j_high, preds, Long2D state_directions, Double2D T, Double2D xgap_scores, Double2D ygap_scores, Double3D match_scores, rows, UChar3D track, track_enc, int viterbi, int use_logs=0, int local=False, int use_scaling=True): """The faster, sequence only (no POG) version. Forward or Viterbi algorithm, with doubles or with slower but practically unoverflowable (double, long) GMP-like numbers. Viterbi is also available in the ever popular addition-of-logs version. All this with any possible pair HMM transition matrix. Limitations - HMM states must be in a sensible order: M and X, then Y, then END. """ # These are array lengths/indicies and so could be Py_ssize_t cdef int prev_i, prev_j, state, prev_state, min_prev_state, N cdef int row_length, row_length1, row_count, row_count1, tmp_rows cdef int a_count, b_count, a, b, a_low, a_high, b_low, b_high cdef int dest_states, dest_state, d4, j, i cdef int last_i, last_j, last_state cdef int bin, x, y, bin_count, max_x, max_y cdef int current_row_index, source_row_index cdef int source_i cdef int dx, dy cdef int tcode_x, tcode_y, tcode_s cdef double d_score, mantissa, partial_sum, sub_partial_sum, max_mantissa, overall_max_mantissa cdef long exponent, max_exponent, overall_max_exponent cdef Double3D mantissas cdef Long3D exponents cdef long pointer_a, pointer_b, pointer_state assert not (use_logs and not viterbi) assert not (use_logs and use_scaling) assert not (local and not viterbi) N = 0 checkArray2D(T, &N, &N) row_length = 0 row_count = 0 checkArray1D(plan, &row_count) dest_states = 0 d4 = 4 # Array of (state, bin, dx, dy) tuples describing the HMM states. checkArray2D(state_directions, &dest_states, &d4) checkArray1D(seq1_index, &row_count) checkArray1D(seq2_index, &row_length) max_x = max_y = bin_count = 0 checkArray3D(match_scores, &bin_count, &max_x, &max_y) checkArray2D(xgap_scores, &bin_count, &max_x) checkArray2D(ygap_scores, &bin_count, &max_y) for i from 0 <= i < row_count: assert 0 <= seq1_index[i] < max_x for j from 0 <= j < row_length: assert 0 <= seq2_index[j] < max_y assert j_low >= 0 and j_high > j_low and j_high <= row_length (mantissas, exponents) = rows tmp_rows = 0 checkArray3D(mantissas, &tmp_rows, &row_length, &N) if use_scaling: checkArray3D(exponents, &tmp_rows, &row_length, &N) cdef double impossible if use_logs: impossible = log(0.0) # -inf else: impossible = 0.0 if viterbi and track is not None and track_enc is not None: checkArray3D(track, &row_count, &row_length, &N) (tcode_x, tcode_y, tcode_s) = track_enc else: track = None tcode_x = tcode_y = tcode_s = 0 # For local overall_max_exponent = MIN_SCALE overall_max_mantissa = impossible last_i = last_j = last_state = -1 for i from i_low <= i < i_high: x = seq1_index[i] if PyErr_CheckSignals(): raise PyErr_Occurred() current_row_index = plan[i] #for prev_state from 1 <= prev_state < N: # current_row_data[0, prev_state] = impossible for j from j_low <= j < j_high: for dest_state from 0 <= dest_state < dest_states: state = state_directions[dest_state, 0] bin = state_directions[dest_state, 1] dx = state_directions[dest_state, 2] dy = state_directions[dest_state, 3] max_mantissa = impossible max_exponent = MIN_SCALE partial_sum = 0.0 pointer_state = N # ie ERROR source_i = i - dx if source_i < 0: continue source_row_index = plan[source_i] prev_j = j - dy if prev_j < 0: continue min_prev_state = 1 a = dx b = dy if (local and dx and dy) or (prev_j == 0 and source_i == 0): partial_sum = max_mantissa = T[0, state] max_exponent = 0 pointer_state = 0 pointer_a = a pointer_b = b if use_scaling: sub_partial_sum = 0.0 for prev_state from min_prev_state <= prev_state < N: exponent = exponents[source_row_index, prev_j, prev_state] if exponent == MIN_SCALE: continue mantissa = mantissas[source_row_index, prev_j, prev_state] mantissa = mantissa * T[prev_state, state] if mantissa < MIN_FLOAT_VALUE: if mantissa == 0.0: continue if mantissa < 0.0: if T[prev_state, state] < 0.0: raise ArithmeticError(fmpt(mantissa, exponent, "transition is a negative probability")) raise ArithmeticError(fmpt(mantissa, exponent, "product is a negative probability")) while mantissa < MIN_FLOAT_VALUE: mantissa *= SCALE_STEP exponent += -1 if exponent <= MIN_SCALE: raise ArithmeticError(fmpt(mantissa, exponent, "underflows")) elif mantissa > 1.0: mantissa *= MIN_FLOAT_VALUE exponent += 1 if exponent > MAX_SCALE: raise ArithmeticError(fmpt(mantissa, exponent, "is unexpectedly large")) if exponent > max_exponent: if exponent == max_exponent + 1: sub_partial_sum = partial_sum else: sub_partial_sum = 0.0 partial_sum = 0.0 max_mantissa = 0.0 max_exponent = exponent if exponent == max_exponent: partial_sum += mantissa if viterbi and mantissa > max_mantissa: max_mantissa = mantissa pointer_state = prev_state pointer_a = a pointer_b = b elif exponent == max_exponent - 1: sub_partial_sum += mantissa partial_sum += sub_partial_sum * MIN_FLOAT_VALUE else: for prev_state from min_prev_state <= prev_state < N: mantissa = mantissas[source_row_index, prev_j, prev_state] if use_logs: mantissa = mantissa + T[prev_state, state] else: mantissa = mantissa * T[prev_state, state] partial_sum += mantissa if viterbi and mantissa > max_mantissa: max_mantissa = mantissa pointer_state = prev_state pointer_a = a pointer_b = b if viterbi: mantissa = max_mantissa if track is not None: track[i, j, state] = ( (pointer_a << tcode_x) | (pointer_b << tcode_y) | (pointer_state << tcode_s)) else: mantissa = partial_sum if dy: y = seq2_index[j] if dx: d_score = match_scores[bin, x, y] else: d_score = ygap_scores[bin, y] elif dx: d_score = xgap_scores[bin, x] elif use_logs: d_score = 0.0 else: d_score = 1.0 if use_logs: mantissa += d_score else: mantissa *= d_score mantissas[current_row_index, j, state] = mantissa if use_scaling: exponents[current_row_index, j, state] = max_exponent if local and dx and dy: if (use_scaling and max_exponent > overall_max_exponent) or ( (not use_scaling or max_exponent == overall_max_exponent) and ( mantissa > overall_max_mantissa)): overall_max_exponent = max_exponent overall_max_mantissa = mantissa last_i = i last_j = j last_state = state if not local: last_i = i_high - 1 last_j = j_high - 1 last_state = state else: mantissa = overall_max_mantissa max_exponent = overall_max_exponent if use_scaling: score = log(mantissa) + log(SCALE_STEP) * max_exponent elif use_logs: score = mantissa else: score = log(mantissa) return ((last_i, last_j), last_state, score) pycogent-1.9/cogent/align/algorithm.py000066400000000000000000000307611273014367000201360ustar00rootroot00000000000000#!/usr/bin/env python """Code for performing alignments by Needleman-Wunsch and Smith-Waterman. """ __author__ = "Rob Knight" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Rob Knight", "Jeremy Widmann"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Rob Knight" __email__ = "rob@spot.colorado.edu" __status__ = "Development" class ScoreCell(object): """Cell in a ScoreMatrix object. Contains score and pointer.""" __slots__ = ['Score', 'Pointer'] def __init__(self, Score=0, Pointer=None): """Returns new ScoreCell object. Score should be a number. Pointer should be a direction (typically None, "up", "diag", or "left") """ self.Score = Score self.Pointer = Pointer def update(self, diag, up, left): """Updates the ScoreCell object with scores for its three neighbors. Finds max of (diag, up, and left), and sets the score and pointer accordingly. In case of tie, picks up (i.e. tries to minimize gaps since the first sequence is the shortest), then diag, then left. """ best = max(diag, up, left) if best == up: self.Score = up self.Pointer = "up" elif best == diag: self.Score = diag self.Pointer = "diag" else: self.Score = left self.Pointer = "left" def MatchScorer(match, mismatch): """Factory function that returns a score function set to match and mismatch. match and mismatch should both be numbers. Typically, match should be positive and mismatch should be negative. Resulting function has signature f(x,y) -> number. """ def scorer(x, y): if x == y: return match else: return mismatch return scorer equality_scorer = MatchScorer(1, -1) default_gap = -1 default_gap_symbol = '-' class ScoreMatrix(list): """Matrix that contains (score, pointer) pairs for sequence alignment.""" def __init__(self, First, Second, Score=equality_scorer, \ GapScore=default_gap, GapSymbol=default_gap_symbol): """Returns new ScoreMatrix object, initialized but not filled. Calls internal methods to initialize first row, column and cell. First and Second are the two sequences that will be aligned. Columns correspond to positions in First; rows correspond to positions in Second. Score is a scoring function that takes two corresponding items in First and Second, and returns a number that can be compared and added. Gap is the score for inserting a gap. Note that the matrix is one row and one column bigger than the lengths of the sequences, since the first row and first column contain initialization data. """ self.First = First #first sequence self.Second = Second #second sequence self.Cols = len(First) + 1 #need to add 1 for the start col self.Rows = len(Second) + 1 #need to add 1 for the start row self.Score = Score #scoring function: f(x,y) = num self.GapScore = GapScore #gap penalty self.GapSymbol = GapSymbol #symbol for gaps self.Filled = False #whether the matrix has been filled self.FirstAlign = [] #first sequence, aligned, as list self.SecondAlign = [] #second sequence, aligned, as list for r in range(self.Rows): self.append([ScoreCell() for c in range(self.Cols)]) self._init_first_row() self._init_first_col() self._init_first_cell() #print "INITIALIZED WITH:" #print self def __str__(self): """Prints score matrix, including labels for row and column.""" first = self.First second = self.Second if not first or not second: return "Empty Score Matrix" #add first sequence as first row: skip 2 positions for row label and #for the first column, which is initialized to default values rows = ['\t\t' + '\t'.join(self.First)] for index, row in enumerate(self): #if it's not the first row, add the appropriate char from the seq if index: curr = second[index-1] else: curr = '' #add the row containing the char and the data rows.append('%s\t'%curr + '\t'.join([str(i.Score) for i in row])) return '\n'.join(rows) def _init_first_row(self): """Hook for matrices that need to initialize the first row.""" pass def _init_first_col(self): """Hook for matrices that need to initialize the first column.""" pass def _init_first_cell(self): """Hook for matrices that need to initialize the first cell.""" pass def alignment(self): """Returns alignment of first and second sequences. Calls fill() and traceback() if necessary. Converts the aligned versions to the same class as the originals. """ seq1, seq2 = self.First, self.Second aln1, aln2 = self.FirstAlign, self.SecondAlign if not aln1 or not aln2: self.fill() self.traceback() aln1, aln2 = self.FirstAlign, self.SecondAlign #Remember to return sequences that are the correct class. If the class #subclasses str, you probably want ''.join rather than str to feed into #the constructor, since str() on a list prints the brackets and commas. if isinstance(seq1, str): first_result = seq1.__class__(''.join(aln1)) else: first_result = seq1.__class__(aln1) if isinstance(seq2, str): second_result = seq2.__class__(''.join(aln2)) else: second_result = seq2.__class__(aln2) return first_result, second_result class NeedlemanWunschMatrix(ScoreMatrix): """Score matrix for global alignment using Needleman-Wunsch.""" def _init_first_row(self): """First row initialized with index * gap penalty.""" gap = self.GapScore self[0] = [ScoreCell(gap * i, 'left') for i in range(self.Cols)] #print "AFTER FIRST ROW:" #print self def _init_first_col(self): """First column initialized with index * gap penalty.""" gap = self.GapScore for index, row in enumerate(self): row[0] = ScoreCell(gap * index, 'up') #print "AFTER FIRST COL:" #print self def _init_first_cell(self): """First cell initialized to 0 with no pointer.""" self[0][0] = ScoreCell(0) #print "AFTER FIRST CELL:" #print self def fill(self): """Fills each cell with its best score and the direction of the next. For moving up or left, calculates the gap penalty plus the score of the cell. For moving diagonally, calculates the match/mismatch score for the corresponding positions in the sequence plus the score of the cell. Performs all calculations in place. """ score = self.Score gap = self.GapScore seq_1, seq_2 = self.First, self.Second curr_row = self[0] for row_i in range(1, self.Rows): prev_row = curr_row curr_row = self[row_i] curr_cell = curr_row[0] for col_i in range(1, self.Cols): prev_cell = curr_cell curr_cell = curr_row[col_i] #remember to subtract 1 to find corresponding pos in seq diag_score = score(seq_1[col_i-1], seq_2[row_i-1]) + \ prev_row[col_i-1].Score up_score = gap + prev_row[col_i].Score left_score = gap + prev_cell.Score #print 'row: %s col: %s '%(row_i,col_i), \ # diag_score,up_score,left_score curr_cell.update(diag_score, up_score, left_score) self.Filled = True self.MaxScore = (self[-1][-1].Score, len(self)-1, len(self[0])-1) #print "FINISHED FILL" #print self def traceback(self): """Returns the optimal alignment as a (first, second) tuple w/ gaps. Follows the pointers assigned in fill(), inserting gaps whenever the movement is not diagonal. """ if not self.Filled: self.fill() align_1 = [] align_2 = [] seq_1 = self.First seq_2 = self.Second curr_row = self.Rows - 1 #subtract 1 to use length as index curr_col = self.Cols - 1 #subtract 1 to use length as index p = self[curr_row][curr_col].Pointer while 1: #print "ROW: %s, COL: %s" % (curr_row, curr_col),p if p == 'diag': align_1.append(seq_1[curr_col-1]) align_2.append(seq_2[curr_row-1]) curr_row -= 1 curr_col -= 1 elif p == 'left': align_1.append(seq_1[curr_col-1]) align_2.append('-') curr_col -= 1 elif p == 'up': align_1.append('-') align_2.append(seq_2[curr_row-1]) curr_row -= 1 else: break p = self[curr_row][curr_col].Pointer align_1.reverse() align_2.reverse() self.FirstAlign, self.SecondAlign = align_1, align_2 class SmithWatermanMatrix(ScoreMatrix): def fill(self): max_row, max_col, max_score = 0, 0, 0 score = self.Score gap = self.GapScore seq_1, seq_2 = self.First, self.Second curr_row = self[0] for row_i in range(1, self.Rows): prev_row = curr_row curr_row = self[row_i] curr_cell = curr_row[0] for col_i in range(1, self.Cols): prev_cell = curr_cell curr_cell = curr_row[col_i] #remember to subtract 1 to find corresponding pos in seq diag_score = score(seq_1[col_i-1], seq_2[row_i-1]) + \ prev_row[col_i-1].Score up_score = gap + prev_row[col_i].Score left_score = gap + prev_cell.Score if max(up_score, left_score, diag_score) <= 0: continue #leave uninitialized if scores all below threshold curr_cell.update(diag_score, up_score, left_score) if curr_cell.Score > max_score: max_score = curr_cell.Score max_row = row_i max_col = col_i self.MaxScore = (max_score, max_row, max_col) #print "FINISHED FILL" #print self def traceback(self): align_1 = [] align_2 = [] seq_1 = self.First seq_2 = self.Second max_score, curr_row, curr_col = self.MaxScore p = self[curr_row][curr_col].Pointer while 1: #print "ROW: %s, COL: %s" % (curr_row, curr_col) if p == 'diag': align_1.append(seq_1[curr_col-1]) align_2.append(seq_2[curr_row-1]) curr_row -= 1 curr_col -= 1 elif p == 'left': align_1.append(seq_1[curr_col-1]) align_2.append('-') curr_col -= 1 elif p == 'up': align_1.append('-') align_2.append(seq_2[curr_row-1]) curr_row -= 1 else: break p = self[curr_row][curr_col].Pointer align_1.reverse() align_2.reverse() self.FirstAlign, self.SecondAlign = align_1, align_2 def nw_align(seq1, seq2, scorer=equality_scorer, gap=default_gap, return_score=False): """Returns globally optimal alignment of seq1 and seq2.""" N = NeedlemanWunschMatrix(seq1, seq2, scorer, gap) if return_score: return N.alignment(), N.MaxScore[0] else: return N.alignment() def sw_align(seq1, seq2, scorer=equality_scorer, gap=default_gap, return_score=False): """Returns locally optimal alignment of seq1 and seq2.""" S = SmithWatermanMatrix(seq1, seq2, scorer, gap) if return_score: return S.alignment(), S.MaxScore[0] else: return S.alignment() def demo(seq1, seq2): result = [] result.append("Global alignment:") result.extend(nw_align(seq1, seq2)) result.append("Local alignment:") result.extend(sw_align(seq1, seq2)) return "\n".join(result) #initialization if __name__ == '__main__': from sys import argv print demo(argv[1], argv[2]) pycogent-1.9/cogent/align/align.py000066400000000000000000000054561273014367000172450ustar00rootroot00000000000000#!/usr/bin/env python import numpy Float = numpy.core.numerictypes.sctype2char(float) from cogent.align import pairwise, indel_model, pycompare from cogent.evolve.likelihood_tree import makeLikelihoodTreeLeaf __author__ = "Peter Maxwell" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Peter Maxwell", "Gavin Huttley"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Peter Maxwell" __email__ = "pm67nz@gmail.com" __status__ = "Production" def dotplot(seq1, seq2, window, threshold, min_gap_length=0, band=None, **kw): #warnings.warn("cogent.align.align.dotplot moved to cogent.align.compare.dotplot", # DeprecationWarning) return pycompare.dotplot(seq1, seq2, window, threshold, min_gap_length, band, **kw) def make_dna_scoring_dict(match, transition, transversion): DNA = {} for a in 'ATCG': ar = a in 'AG' for b in 'ATCG': br = b in 'AG' if a == b: score = match elif ar == br: score = transition else: score = transversion DNA[a,b] = score return DNA def _align_pairwise(s1, s2, mprobs, psub, TM, local, return_alignment=True, return_score=False, **kw): """Generic alignment with any substitution model and indel model""" [p1, p2] = [makeLikelihoodTreeLeaf(seq) for seq in [s1, s2]] [p1, p2] = [pairwise.AlignableSeq(leaf) for leaf in [p1, p2]] pair = pairwise.Pair(p1, p2) EP = pair.makeSimpleEmissionProbs(mprobs, [psub]) hmm = EP.makePairHMM(TM) vpath = hmm.getViterbiPath(local=local, **kw) score = vpath.getScore() if return_alignment: alignment = vpath.getAlignment() if return_score: return (alignment, score) else: return alignment else: return score def classic_align_pairwise(s1, s2, Sd, d, e, local, return_score=False, **kw): """Alignment specified by gap costs and a score matrix""" TM = indel_model.ClassicGapScores(d, e) a1 = s1.MolType.Alphabet a2 = s2.MolType.Alphabet S = numpy.zeros([len(a1), len(a2)], Float) for (i,m1) in enumerate(a1): for (j,m2) in enumerate(a2): S[i, j] = Sd[m1, m2] psub = numpy.exp(S) mprobs = numpy.ones(len(psub), Float) / len(psub) return _align_pairwise(s1, s2, mprobs, psub, TM, local, return_score=return_score, **kw) # these can't do codon sequences # they could be replaced with something more sophisticated, like the HMM # may not give same answers as algorithm def local_pairwise(s1, s2, S, d, e, return_score=False): return classic_align_pairwise(s1, s2, S, d, e, True, return_score=return_score) def global_pairwise(s1, s2, S, d, e, return_score=False): return classic_align_pairwise(s1, s2, S, d, e, False, return_score=return_score) pycogent-1.9/cogent/align/dp_calculation.py000066400000000000000000000134311273014367000211240ustar00rootroot00000000000000#!/usr/bin/env/python from cogent.maths.markov import SiteClassTransitionMatrix from cogent.recalculation.definition import PositiveParamDefn, \ ProbabilityParamDefn, CalculationDefn, CalcDefn, NonParamDefn, \ PartitionDefn from cogent.align import indel_model, pairwise import numpy __author__ = "Gavin Huttley and Peter Maxwell" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Peter Maxwell", "Gavin Huttley"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Gavin Huttleuy" __email__ = "gavin.huttley@anu.edu.au" __status__ = "Production" class IndelParameterDefn(ProbabilityParamDefn): # locus means allowed to vary by loci valid_dimensions = ('edge', 'bin', 'locus') independent_by_default = False default_value = default = 0.4 lower = 0.0001 def makeIndelModelDefn(with_indel_params=True, kn=True): if kn: klass = indel_model.KnudsenMiyamotoIndelModel else: klass = indel_model.SimpleIndelModel if with_indel_params: a = IndelParameterDefn('indel_length') # P(extend indel) r = IndelParameterDefn('indel_rate') # indels per substitution return CalcDefn(klass, name='indels')(r, a) else: # not optimisable parameter, a constant. Another example is the alignment in an LikFunc return NonParamDefn('indel_model') class FloatWithAttrs(float): def __new__(cls, value, **kw): return float.__new__(cls, value) def __init__(self, value, **kw): float.__init__(self) for (n,v) in kw.items(): setattr(self, n, v) def Edge(seq1, seq2, length, bin_data, switch=1.0, bprobs=None): # one sequence pair in, potentialy, a tree bins = len(bin_data) pair = pairwise.Pair(seq1, seq2) EP = pair.makeReversibleEmissionProbs([(bin.mprobs, bin.Qd) for bin in bin_data], length) tms = [bin.indel.calcTransitionMatrix(length) for bin in bin_data] if bins == 1: TM = tms[0] else: assert bprobs R = SiteClassTransitionMatrix(switch, bprobs) TM = R.nestTransitionMatricies(tms) assert min(TM.Matrix.flat) >=0, bin_data return EP.makePairHMM(TM) class BinData(object): def __init__(self, mprobs, indel, Qd, rate=1.0): self.mprobs = mprobs self.indel = indel self.Qd = Qd self.rate = rate def __repr__(self): return 'Bin(Pi, Qd, %s, %s)' % (self.rate, vars(self.indel)) class AnnotateFloatDefn(CalculationDefn): name = 'annot' def calc(self, value, edge): return FloatWithAttrs(value, edge=edge) class ViterbiPogDefn(CalculationDefn): name = 'align' def calc(self, edge): return edge.getaln() class FwdDefn(CalculationDefn): name = 'fwd' def calc(self, edge): return edge.getForwardScore(use_cost_function=False) class EdgeSumAndAlignDefn(CalculationDefn): name = 'pair' def calc(self, pog1, pog2, length1, length2, bin): edge = Edge(pog1, pog2, length1+length2, [bin]) def _getaln(): try: ratio = length1/(length1+length2) except (ZeroDivisionError, FloatingPointError): ratio = 1. return edge.getViterbiPath().getAlignable(ratio) edge.getaln = _getaln return edge class EdgeSumAndAlignDefnWithBins(CalculationDefn): name = 'pair' def calc(self, pog1, pog2, length1, length2, switch, bprobs, *bin_data): edge = Edge(pog1, pog2, length1+length2, bin_data, switch, bprobs) def _getaln(): ratio = length1/(length1+length2) (vtScore, result) = edge.getViterbiScoreAndAlignable(ratio) return result edge.getaln = _getaln return edge def _recursive_defns(edge, subst, leaf, edge_defn_constructor, bin_args): """A defn which calculates a fwd score with an .edge attribute which can provide a viterbi alignment which can be provided to a similar defn""" scores = [] args = [] for child in edge.Children: if child.istip(): args.append(leaf.selectFromDimension('edge', child.Name)) else: (child_defn, scores2) = _recursive_defns( child, subst, leaf, edge_defn_constructor, bin_args) child_defn = ViterbiPogDefn(child_defn) scores.extend(scores2) args.append(child_defn) child_names = [child.Name for child in edge.Children] assert len(child_names) == 2, child_names child_lengths = subst['length'].acrossDimension('edge', child_names) args.extend(child_lengths) args.extend(bin_args) edge_defn = edge_defn_constructor(*args) #fwd = FwdDefn(edge_defn) #scores.append(fwd) return (edge_defn, scores) def makeForwardTreeDefn(subst_model, tree, bin_names, with_indel_params=True, kn=True): """Pairwise Fwd""" indel = makeIndelModelDefn(with_indel_params, kn) subst = subst_model.makeFundamentalParamControllerDefns(bin_names) leaf = NonParamDefn('leaf', dimensions=('edge',)) if len(bin_names) > 1: switch = ProbabilityParamDefn('bin_switch', dimensions=['locus']) bprobs = PartitionDefn( [1.0/len(bin_names) for bin in bin_names], name = "bprobs", dimensions=['locus'], dimension=('bin', bin_names)) edge_args = [switch, bprobs] edge_defn_constructor = EdgeSumAndAlignDefnWithBins else: edge_args = [] edge_defn_constructor = EdgeSumAndAlignDefn mprobs = subst['word_probs'] bin_data = CalcDefn(BinData)(mprobs, indel, subst['Qd']) bin_data = bin_data.acrossDimension('bin', bin_names) edge_args.extend(bin_data) (top, scores) = _recursive_defns(tree, subst, leaf, edge_defn_constructor, edge_args) defn = FwdDefn(top) #defn = SumDefn(*scores) return AnnotateFloatDefn(defn, top) pycogent-1.9/cogent/align/indel_model.py000066400000000000000000000076201273014367000204210ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import division import numpy from cogent.maths.markov import TransitionMatrix __author__ = "Peter Maxwell" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Peter Maxwell"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Peter Maxwell" __email__ = "pm67nz@gmail.com" __status__ = "Production" def PairTransitionMatrix(order, a): """A matrix for Pair HMMs with gap states X and Y, match state M, and optionally a silent wait state W""" size = len(order) assert a.shape == (size, size) directions = {'W':(0,0), 'X':(1,0), 'Y':(0, 1), 'M':(1,1)} emits = [directions[state.upper()] for state in order] return TransitionMatrix(a, emits).withoutSilentStates() def ClassicGapScores(d, e): """Gap open / gap extend costs. No X to Y transitions""" _ = numpy.inf C = numpy.array([ [e, _, 0], [_, e, 0], [d, d, 0]]) T = numpy.exp(-1.0 * C) T = T / numpy.sum(T, axis=1)[..., numpy.newaxis] return PairTransitionMatrix('XYM', T) class _SimpleIndelParams(object): def __init__(self, indel_rate, indel_length): assert 0.0 < indel_length < 1.0, indel_length assert 0.0 < indel_rate < 1.0, indel_rate self.indel_rate = indel_rate self.indel_length = indel_length class SimpleIndelModel(_SimpleIndelParams): """P(gap open), P(gap extend) with const P(extend match)""" def calcTransitionMatrix(self, distance): d = 1.0 - numpy.exp(-self.indel_rate * distance) e = self.indel_length g = 0.0 T = numpy.array([ [0, d, d, 1-2*d], [1-e, e, 0, 0], [1-e, 0, e, 0], [1-g, 0, 0, g], ]) return PairTransitionMatrix('WXYM', T).withoutSilentStates() class KnudsenMiyamotoIndelModel(_SimpleIndelParams): """Sequence Alignments and Pair HMMs Using Evolutionary History Bjarne Knudsen and Michael M. Miyamoto Journal of Molecular Biology Volume 333, Issue 2 , 17 October 2003, Pages 453-460""" def calcTransitionMatrix(self, distance): distance = distance * self.indel_rate extend = self.indel_length close = 1.0 - extend # First indel event indel = 1.0 - numpy.exp(-distance) insert = deletion = indel / 2.0 # Second indel event if distance < 0.0001: secondary_indel = distance/2 else: x = numpy.exp(-distance - numpy.log(distance)) secondary_indel = 1 - 1/distance + x assert 0.0 <= secondary_indel <= 1.0 secondary_deletion = secondary_insert = secondary_indel / 2.0 same_len = (1 - extend)/(1 + extend) longer = shorted = (1.0 - same_len) / 2 eMX = insert * (1 - secondary_deletion*(1 - longer)) eMY = deletion + insert * secondary_deletion * longer eMZ = (eMX + eMY) eXM = extend * secondary_deletion * same_len + \ close * (deletion/4 + (1.0-indel)) eXX = extend * (secondary_insert*extend/close + secondary_deletion*shorted) + \ close * insert + extend #eXX = a + a**2/(1-a**2)*secondary_indel + (1-a)*insert eXY = extend * secondary_deletion * longer + \ close * deletion*3/4 #e = 1 + ( extend * secondary_indel/2 / close) #print e, (eXM + eXX + eXY) e = eXM + eXX + eXY #assert eMM + eMX + eMY == 1.0, (eMM + eMX + eMY) tMX = tMY = eMZ / 2 tMM = 1.0 - eMZ tXM = tYM = eXM / e tXX = tYY = eXX / e tXY = tYX = eXY / e tm = numpy.array([ [tMM, tMX, tMY], [tXM, tXX, tXY], [tYM, tYX, tYY]]) if(min(tm.flat)<0): raise ValueError return PairTransitionMatrix('MXY', tm) pycogent-1.9/cogent/align/indel_positions.py000066400000000000000000000200171273014367000213430ustar00rootroot00000000000000#!/usr/bin/env python __author__ = "Peter Maxwell" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Peter Maxwell", "Gavin Huttley"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Peter Maxwell" __email__ = "pm67nz@gmail.com" __status__ = "Production" def pog_traceback(pogs, aligned_positions): upto = [0, 0] align_builder = POGBuilder(pogs) for posn in aligned_positions: assert len(posn) == 2 for (dim, pos) in enumerate(posn): if pos is not None: align_builder.addSkipped(dim, upto[dim], pos) upto[dim] = pos+1 align_builder.addAligned(posn) for dim in [0,1]: align_builder.addSkipped(dim, upto[dim], len(pogs[dim])) result_pog = align_builder.getPOG() return result_pog class POGBuilder(object): def __init__(self, children): self.children = children self.remap = [{} for child in children] self.started = [False, False] self.last = [None, None] self.result = [[]] self.origins = [[]] self.aligned_positions = [] self.states = [] def addSkipped(self, dim, start, end, old_gap=True): for p in range(start, end): fp = [None, None] fp[dim] = p fp = tuple(fp) self.addAligned(fp, old_gap=old_gap) def addAligned(self, posn, old_gap=False): pre_merged = set() assert len(posn) == 2 for (dim, pos) in enumerate(posn): if pos is None: continue self.remap[dim][pos] = len(self.aligned_positions) self.last[dim] = pos self.result.append(pre_merged) self.aligned_positions.append(posn) if None not in posn: state = 'm' elif posn[0] is None: state = 'x' else: state = 'y' if not old_gap: state = state.upper() self.states.append(state) def getPOG(self): jumps = [] gapmap = {} ingap = False # Build a list of gaps (ie: segments of X or Y state) in # the alignment and a dict which maps from seq posn to the # start of the surrounding gap. for (i, state) in enumerate(self.states+['.']): gap = state in 'XYxy' if gap and not ingap: start = i ingap = True elif ingap and not gap: jumps.append((start, i)) ingap = False if ingap: gapmap[i] = start # in case of tail gap for (dim, child) in enumerate(self.children): pos = len(child) self.remap[dim][pos] = len(self.aligned_positions) # Keep only those child gaps which sit entirely within a gap # in this alignment child_jumps = [] for (dim,pog) in enumerate(self.children): r = self.remap[dim] for (i, j) in pog.jumps: (i, j) = (r[i], r[j]) if i in gapmap and j in gapmap and gapmap[i] == gapmap[j]: child_jumps.append((i,j)) pog = POG(len(self.aligned_positions), jumps, child_jumps) pog.aligned_positions = self.aligned_positions pog.states = ''.join(self.states) return pog class POG(object): """A representation of the indel positions in a pairwise alignment, ie: those segments of the consensus sequence which may be inserts and so absent from the common ancestor. Nearly equivalent to a generic Partial Order Graph. Indels are represented as tuples of (1st posn in indel, 1st posn after indel) Two lists of indels are kept, one for indels in the alignment, and one for indels in its two children in case they are also alignments. This data structure largely inspired by: Loytynoja A, Goldman N. 2005. An algorithm for progressive multiple alignment of sequences with insertions. PNAS 102:10557-10562 """ def __init__(self, length, jumps, child_jumps): self.jumps = jumps self.child_jumps = child_jumps self.all_jumps = self.jumps + self.child_jumps self.all_jumps.sort(key=lambda (i,j):j) self.length = length for (i, j) in self.all_jumps: assert i <= j, (length, jumps, child_jumps) assert 0 <= i <= length, (length, jumps, child_jumps) assert 0 <= j <= length, (length, jumps, child_jumps) def traceback(self, other, aligned_positions): return pog_traceback([self, other], aligned_positions) def asListOfPredLists(self): """A representation of the POG as a list of predecessor positions, a simple way to represent DAGs eg: [], [0], [1] would be a simple sequence of length 3. Extra start and end positions are added, so the length is len(self)+2 and the positions are all offset by 1""" result = [[]] # First the regular, linear sequence relationships for i in range(self.length+1): pre = [i] result.append(pre) # Then add in the indel jumps. Given an indel from i to j # j could have been ajacent to one of i's predecessors in # the ancestral sequence. This depends on all_jumps being sorted # by j. for (i,j) in self.all_jumps: if i == j: continue assert i < j result[j+1].extend(result[i+1]) return result def getAlignedPositions(self): return self.aligned_positions def getFullAlignedPositions(self): return self.aligned_positions def __len__(self): return self.length def midlinks(self): # for the hirchberg algorithm. half = self.length // 2 jumps = [(i,j) for (i,j) in self.all_jumps if i<=half and j>=half] return [(half, half)] + jumps def __getitem__(self, index): # POGs need to be sliceable for the hirchberg algorithm. if index.start is None: start = 0 else: start = index.start if index.stop is None: end = self.length else: end = index.stop assert end >= start, (start, end, index, self.length) def moved(i,j): i2 = max(min(i, end), start)-start j2 = max(min(j, end), start)-start return (i2, j2) jumps = [moved(i,j) for (i,j) in self.jumps if istart] cjumps = [moved(i,j) for (i,j) in self.child_jumps if istart] return POG(end-start, jumps, cjumps) def backward(self): # Switches predecessors / successors # POGs need to be reversable for the hirchberg algorithm. length = self.length jumps = [(length-j, length-i) for (i,j) in self.jumps] cjumps = [(length-j, length-i) for (i,j) in self.child_jumps] return POG(length, jumps, cjumps) def writeToDot(self, dot): pred_sets = self.asListOfPredLists() print >>dot, 'digraph POG {' for (i, preds) in enumerate(pred_sets): #print i, preds for pred in preds: print >>dot, ' ', ('node%s -> node%s' % (pred, i)) if i == 0: label = 'START' elif i == len(pred_sets) - 1: label = 'END' else: label = str(i) print >>dot, ' ', ('node%s' % i), '[label="%s"]' % label print >>dot, '}' print >>dot, '' class LeafPOG(POG): """The POG for a known sequence contains no indels.""" def __init__(self, length): self.length = length self.all_jumps = [] self.jumps = [] def asListOfPredLists(self): pog = [ [[i]] for i in range(self.length)] return [[]] + pog + [[len(pog)]] def __len__(self): return self.length def backward(self): return LeafPOG(self.length) def leaf2pog(leaf): return LeafPOG(len(leaf)) pycogent-1.9/cogent/align/pairwise.py000066400000000000000000001123401273014367000177650ustar00rootroot00000000000000#!/usr/bin/env python """Align two Alignables, each of which can be a sequence or a subalignment produced by the same code.""" # How many cells before using linear space alignment algorithm. # Should probably set to about half of physical memory / PointerEncoder.bytes HIRSCHBERG_LIMIT = 10**8 import numpy # setting global state on module load is bad practice and can be ineffective, # and this setting matches the defaults anyway, but left here as reference # in case it needs to be put back in a more runtime way. #numpy.seterr(all='ignore') import warnings from cogent.align.traceback import alignment_traceback from cogent.evolve.likelihood_tree import LikelihoodTreeEdge from indel_positions import leaf2pog from cogent import LoadSeqs from cogent.core.alignment import Aligned from cogent.align.traceback import map_traceback from cogent.util import parallel from cogent.util.modules import importVersionedModule, ExpectedImportError def _importedPyrexAligningModule(name): try: return importVersionedModule(name, globals(), (3, 1), "slow Python alignment implementation") except ExpectedImportError: return None pyrex_align_module = _importedPyrexAligningModule('_pairwise_pogs') pyrex_seq_align_module = _importedPyrexAligningModule('_pairwise_seqs') # Deal with minor API change between _pairwise_*.pyx versions 3.1 and 3.2 # rather than forcing everyone to recompile immediately. # After 1.6 release this can be replaced by (3, 2) requirement above. versions = [m.version_info for m in [pyrex_seq_align_module, pyrex_align_module] if m is not None] if len(versions) == 0 or min(versions) >= (3, 2): TRACK_INT_TYPE = numpy.uint8 elif max(versions) < (3, 2): TRACK_INT_TYPE = numpy.int8 else: raise ImportError('Incompatible _pairwise_*.pyx module versions. Recompile them') __author__ = "Peter Maxwell" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Peter Maxwell", "Gavin Huttley", "Rob Knight"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Peter Maxwell" __email__ = "pm67nz@gmail.com" __status__ = "Production" class PointerEncoding(object): """Pack very small ints into a byte. The last field, state, is assigned whatever bits are left over after the x and y pointers have claimed what they need, which is expected to be only 2 bits each at most""" dtype = TRACK_INT_TYPE bytes = 1 def __init__(self, x, y): assert x > 0 and y > 0, (x,y) (x, y) = (numpy.ceil(numpy.log2([x+1,y+1]))).astype(int) s = 8 * self.bytes - sum([x, y]) assert s**2 >= 4+1, (x,y,s) # min states required self.widths = numpy.array([x,y,s]).astype(int) self.limits = 2 ** self.widths self.max_states = self.limits[-1] if DEBUG: print self.max_states, "states allowed in viterbi traceback" self.positions = numpy.array([0, x, x+y], int) #a.flags.writeable = False def encode(self, x, y, s): parts = numpy.asarray([x, y, s], int) assert all(parts < self.limits), (parts, self.limits) return (parts << self.positions).sum() def decode(self, coded): return (coded >> self.positions) % self.limits def getEmptyArray(self, shape): return numpy.zeros(shape, self.dtype) DEBUG = False def py_calc_rows(plan, x_index, y_index, i_low, i_high, j_low, j_high, preds, state_directions, T, xgap_scores, ygap_scores, match_scores, rows, track, track_enc, viterbi, local=False, use_scaling=False, use_logs=False): """Pure python version of the dynamic programming algorithms Forward and Viterbi. Works on sequences and POGs. Unli""" if use_scaling: warnings.warn("Pure python version of DP code can suffer underflows") # because it ignores 'exponents', the Pyrex version doesn't. source_states = range(len(T)) BEGIN = 0 ERROR = len(T) (rows, exponents) = rows if use_logs: neutral_score = 0.0 impossible = -numpy.inf else: neutral_score = 1.0 impossible = 0.0 best_score = impossible for i in range(i_low, i_high): x = x_index[i] i_sources = preds[0][i] current_row = rows[plan[i]] #current_row[:] = 0.0 current_row[:,0] = impossible if i == 0 and not local: current_row[0,0] = neutral_score for j in range(j_low, j_high): y = y_index[j] j_sources = preds[1][j] for (state, bin, dx, dy) in state_directions: if (local and dx and dy): cumulative_score = T[BEGIN, state] pointer = (dx, dy, BEGIN) else: cumulative_score = impossible pointer = (0, 0, ERROR) for (a, prev_i) in enumerate([[i], i_sources][dx]): source_row = rows[plan[prev_i]] for (b, prev_j) in enumerate([[j], j_sources][dy]): source_posn = source_row[prev_j] for prev_state in source_states: prev_value = source_posn[prev_state] transition = T[prev_state, state] if viterbi: if use_logs: candidate = prev_value + transition else: candidate = prev_value * transition #if DEBUG: # print prev_state, prev_value, state if candidate > cumulative_score: cumulative_score = candidate pointer = (a+dx, b+dy, prev_state) else: cumulative_score += prev_value * transition if dx and dy: d_score = match_scores[bin, x, y] elif dx: d_score = xgap_scores[bin, x] elif dy: d_score = ygap_scores[bin, y] else: d_score = neutral_score #if DEBUG: # print (dx, dy), d_score, cumulative_score if use_logs: current_row[j, state] = cumulative_score + d_score else: current_row[j, state] = cumulative_score * d_score if track is not None: track[i,j,state] = (numpy.array(pointer) << track_enc).sum() if (i==i_high-1 and j==j_high-1 and not local) or ( local and dx and dy and current_row[j, state] > best_score): (best, best_score) = (((i, j), state), current_row[j, state]) #if DEBUG: # print i_low, i_high, j_low, j_high # print 'best_score %5.1f at %s' % (numpy.log(best_score), best) if not use_logs: best_score = numpy.log(best_score) return best + (best_score,) class TrackBack(object): def __init__(self, tlist): self.tlist = tlist def __str__(self): return ''.join('(%s,%s)%s' % (x,y, '.xym'[dx+2*dy]) for (state, (x,y), (dx,dy)) in self.tlist) def offset(self, X, Y): tlist = [(state, (x+X, y+Y), dxy) for (state, (x,y), dxy) in self.tlist] return TrackBack(tlist) def __add__(self, other): return TrackBack(self.tlist + other.tlist) def asStatePosnTuples(self): return [(s,p) for (s,p,d) in self.tlist] def asBinPosTuples(self, state_directions): bin_map = dict((state, bin) for (state, bin, dx, dy) in state_directions) result = [] for (state, posn, (dx, dy)) in self.tlist: pos = [[None, i-1][d] for (i,d) in zip( posn, [dx, dy])] result.append((bin_map.get(int(state), None), pos)) return result class Pair(object): def __init__(self, alignable1, alignable2, backward=False): alignables = [alignable1, alignable2] assert alignable1.alphabet == alignable2.alphabet self.alphabet = alignable1.alphabet for alignable in alignables: assert isinstance(alignable, _Alignable), type(alignable) if not isinstance(alignable, AlignableSeq): some_pogs = True break else: some_pogs = False if some_pogs and pyrex_align_module is not None: aligner = pyrex_align_module.calc_rows elif (not some_pogs) and pyrex_seq_align_module is not None: aligner = pyrex_seq_align_module.calc_rows else: aligner = py_calc_rows self.both_seqs = not some_pogs self.aligner = aligner if backward: alignables = [a.backward() for a in alignables] self.children = [alignable1, alignable2] = alignables self.max_preds = [alignable.max_preds for alignable in alignables] self.pointer_encoding = PointerEncoding(*self.max_preds) self.size = [len(alignable1), len(alignable2)] self.uniq_size = [len(alignable1.plh), len(alignable2.plh)] self.plan = numpy.array(alignable1.getRowAssignmentPlan()) self.x_index = alignable1.index self.y_index = alignable2.index def getSeqNamePairs(self): return [(a.leaf.edge_name, a.leaf.sequence) for a in self.children] def makeSimpleEmissionProbs(self, mprobs, psubs1): psubs2 = [numpy.identity(len(psub)) for psub in psubs1] bins = [PairBinData(mprobs, *ppsubs) for ppsubs in zip( psubs1, psubs2) ] return PairEmissionProbs(self, bins) def makeEmissionProbs(self, bins): bins = [PairBinData(*args) for args in bins] return PairEmissionProbs(self, bins) def makeReversibleEmissionProbs(self, bins, length): bins = [BinData(*bin) for bin in bins] return ReversiblePairEmissionProbs(self, bins, length) def backward(self): return Pair(*self.children, **dict(backward=True)) def __getitem__(self, index): assert len(index) == 2, index children = [child[dim_index] for (child, dim_index) in zip( self.children, index)] return Pair(*children) def _decode_state(self, track, encoding, posn, pstate): coded = int(track[posn[0], posn[1], pstate]) (a, b, state) = encoding.decode(coded) if state >= track.shape[-1]: raise ArithmeticError('Error state in traceback') (x, y) = posn if state == -1: next = (x, y) else: if a: x = self.children[0][x][a-1] if b: y = self.children[1][y][b-1] next = numpy.array([x,y], int) return (next, (a, b), state) def traceback(self, track, encoding, posn, state, skip_last=False): result = [] started = False while 1: (nposn, (a, b), nstate) = self._decode_state(track, encoding, posn, state) if state: result.append((state, posn, (a>0, b>0))) if started and state == 0: break (posn, state) = (nposn, nstate) started = True result.reverse() if skip_last: result.pop() return TrackBack(result) def edge2plh(self, edge, plhs): bins = plhs[0].shape[0] plh = [edge.sumInputLikelihoods(*[p[bin][1:-1] for p in plhs]) for bin in range(bins)] return plh def getPOG(self, aligned_positions): (pog1, pog2) = [child.getPOG() for child in self.children] return pog1.traceback(pog2, aligned_positions) def getPointerEncoding(self, n_states): assert n_states <= self.pointer_encoding.max_states, ( n_states, self.pointer_encoding.max_states) return self.pointer_encoding def getScoreArraysShape(self): needed = max(self.plan) + 1 N = self.size[1] return (needed, N) def getEmptyScoreArrays(self, n_states, dp_options): shape = self.getScoreArraysShape() + (n_states,) mantissas = numpy.zeros(shape, float) if dp_options.use_logs: mantissas[:] = numpy.log(0.0) if dp_options.use_scaling: exponents = numpy.ones(shape, int) * -10000 else: exponents = None return (mantissas, exponents) def calcRows(self, i_low, i_high, j_low, j_high, state_directions, T, scores, rows, track, track_encoding, viterbi, **kw): (match_scores, (xscores, yscores)) = scores track_enc = track_encoding and track_encoding.positions #print T return self.aligner(self.plan, self.x_index, self.y_index, i_low, i_high, j_low, j_high, self.children, state_directions, T, xscores, yscores, match_scores, rows, track, track_enc, viterbi, **kw) class _Alignable(object): def __init__(self, leaf): self.leaf = leaf self.alphabet = leaf.alphabet (uniq, alphabet_size) = leaf.input_likelihoods.shape full = len(leaf.index) self.plh = numpy.zeros([uniq+2, alphabet_size], float) self.plh[1:-1] = leaf.input_likelihoods self.index = numpy.zeros([full+2], int) self.index[1:-1] = numpy.asarray(leaf.index) + 1 self.index[0] = 0 self.index[full+1] = uniq+1 def _asCombinedArray(self): # POG in a format suitable for Pyrex code, two arrays # preds here means predecessor pred = [] offsets = [] for pre in self: offsets.append(len(pred)) pred.extend(pre) offsets.append(len(pred)) # provides the paths leading to a point (predecessors), and offsets # records index positions fdor each point (graph node) return (numpy.array(pred), numpy.array(offsets)) def asCombinedArray(self): if not hasattr(self, '_combined'): self._combined = self._asCombinedArray() return self._combined def getRowAssignmentPlan(self): d = self.getOuterLoopDiscardPoints() free = set() top = 0 assignments = [] for i in range(len(d)): if free: assignments.append(free.pop()) else: assignments.append(top) top = top + 1 for j in d[i]: free.add(assignments[j]) return assignments class AlignablePOG(_Alignable): """Alignable wrapper of a Partial Object Graph, ie: subalignment""" def __init__(self, leaf, pog, children=None): assert len(leaf) == len(pog), (len(leaf), len(pog)) _Alignable.__init__(self, leaf) self.pred = pog.asListOfPredLists() self.max_preds = max(len(pre) for pre in self.pred) self.pog = pog if children is not None: self.aligneds = self._calcAligneds(children) self.leaf = leaf def __repr__(self): return 'AlPOG(%s,%s)' % (self.pog.all_jumps, repr(self.leaf)) def getAlignment(self): return LoadSeqs(data=self.aligneds) def _calcAligneds(self, children): word_length = self.alphabet.getMotifLen() (starts, ends, maps) = map_traceback(self.pog.getFullAlignedPositions()) aligneds = [] for (dim, child) in enumerate(children): for (seq_name, aligned) in child.aligneds: #aligned = aligned[(starts[dim]-1)*word_length:(ends[dim]-1)*word_length] aligned = aligned.remappedTo((maps[dim]*word_length).inverse()) aligneds.append((seq_name, aligned)) return aligneds def backward(self): return self.__class__(self.leaf.backward(), self.pog.backward()) def getPOG(self): return self.pog def __len__(self): return len(self.pred) def __iter__(self): return iter(self.pred) def __getitem__(self, index): # XXX the int case should be a different method? if isinstance(index, int): return self.pred[index] else: pog = self.pog[index] leaf = self.leaf[index] return AlignablePOG(leaf, pog) def midlinks(self): return self.pog.midlinks() def getOuterLoopDiscardPoints(self): # for score row caching last_successor = {} discard_list = {} for (successor, ps) in enumerate(self): for i in ps: last_successor[i] = successor discard_list[successor] = [] for (i, successor) in last_successor.items(): discard_list[successor].append(i) return discard_list class AlignableSeq(_Alignable): """Wrapper for a Sequence which gives it the same interface as an AlignablePOG""" def __init__(self, leaf): _Alignable.__init__(self, leaf) if hasattr(leaf, 'sequence'): self.seq = leaf.sequence aligned = Aligned([(0, len(self.seq))], self.seq, len(self.seq)) self.aligneds = [(self.leaf.edge_name, aligned)] self.max_preds = 1 self._pog = None def __repr__(self): return 'AlSeq(%s)' % (getattr(self, 'seq', '?')) def getPOG(self): if self._pog is None: self._pog = leaf2pog(self.leaf) return self._pog def __len__(self): return len(self.index) def backward(self): return self.__class__(self.leaf.backward()) def __iter__(self): # empty list 1st since 0th position has no predecessor yield [] for i in range(1, len(self.index)): yield [i-1] def __getitem__(self, index): # XXX the int case should be a different method? if isinstance(index, int): if index == 0: return [] elif 0 < index < len(self.index): return [index-1] else: raise IndexError(index) #elif index == slice(None, None, None): # return self else: return AlignableSeq(self.leaf[index]) def midlinks(self): half = len(self.leaf) // 2 return [(half, half)] def getOuterLoopDiscardPoints(self): return [[]] + [[i] for i in range(len(self)-1)] def adaptPairTM(pairTM, finite=False): # constructs state_directions if finite: # BEGIN and END already specified assert list(pairTM.Tags[0]) == list(pairTM.Tags[-1]) == [] T = pairTM.Matrix assert not T[-1, ...] and not T[..., 0] for tag in pairTM.Tags[1:-1]: assert tag, 'silent state' state_directions_list = list(enumerate(pairTM.Tags[1:-1])) else: pairTM = pairTM.withoutSilentStates() stationary_probs = numpy.array(pairTM.StationaryProbs) T = pairTM.Matrix full_matrix = numpy.zeros([len(T)+2, len(T)+2], float) full_matrix[1:-1,1:-1] = T full_matrix[0,1:-1] = stationary_probs # from BEGIN full_matrix[:,-1] = 1.0 # to END T = full_matrix state_directions_list = list(enumerate(pairTM.Tags)) this_row_last = lambda (state, (dx,dy)):(not (dx or dy), not dx) state_directions_list.sort(key=this_row_last) # sorting into desirable order (sort may not be necessary) state_directions = numpy.zeros([len(state_directions_list), 4], int) for (i, (state, emit)) in enumerate(state_directions_list): (dx, dy) = emit assert dx==0 or dy==0 or dx==dy bin = max(dx, dy)-1 state_directions[i] = (state+1, bin, dx>0, dy>0) return (state_directions, T) class PairEmissionProbs(object): """A pair of sequences and the psubs that relate them, but no gap TM""" def __init__(self, pair, bins): self.pair = pair self.bins = bins self.scores = {} def makePartialLikelihoods(self, use_cost_function): # use_cost_function specifies whether eqn 2 of Loytynoja & Goldman # is applied. Without it insertions may be favored over deletions # because the emission probs of the insert aren't counted. plhs = [[], []] gap_plhs = [[], []] for bin in self.bins: for (dim, pred) in enumerate(self.pair.children): # first and last should be special START and END nodes plh = numpy.inner(pred.plh, bin.ppsubs[dim]) gap_plh = numpy.inner(pred.plh, bin.mprobs) if use_cost_function: plh /= gap_plh[..., numpy.newaxis] gap_plh[:] = 1.0 else: gap_plh[0] = gap_plh[-1] = 1.0 gap_plhs[dim].append(gap_plh) plhs[dim].append(plh) for dim in [0,1]: plhs[dim] = numpy.array(plhs[dim]) gap_plhs[dim] = numpy.array(gap_plhs[dim]) return (plhs, gap_plhs) def _makeEmissionProbs(self, use_cost_function): (plhs, gap_scores) = self.makePartialLikelihoods(use_cost_function) match_scores = numpy.zeros([len(self.bins)] + self.pair.uniq_size, float) for (b, (x, y, bin)) in enumerate(zip(plhs[0], plhs[1], self.bins)): match_scores[b] = numpy.inner(x*bin.mprobs, y) match_scores[:, 0, 0] = match_scores[:, -1, -1] = 1.0 return (match_scores, gap_scores) def _getEmissionProbs(self, use_logs, use_cost_function): key = (use_logs, use_cost_function) if key not in self.scores: if use_logs: (M, (X, Y)) = self._getEmissionProbs(False, use_cost_function) (M, X, Y) = [numpy.log(a) for a in [M, X, Y]] self.scores[key] = (M, (X, Y)) else: self.scores[key] = self._makeEmissionProbs(use_cost_function) return self.scores[key] def _calc_global_probs(self, pair, scores, kw, state_directions, T, rows, cells, backward=False): if kw['use_logs']: (impossible, inevitable) = (-numpy.inf, 0.0) else: (impossible, inevitable) = (0.0, 1.0) (M, N) = pair.size (mantissas, exponents) = rows mantissas[0,0,0] = inevitable if exponents is not None: exponents[0,0,0] = 0 probs = [] last_i = -1 to_end = numpy.array([(len(T)-1, 0, 0, 0)]) for (state, (i,j)) in cells: if i > last_i: rr = pair.calcRows(last_i+1, i+1, 0, N-1, state_directions, T, scores, rows, None, None, **kw) else: assert i == last_i, (i, last_i) last_i = i T2 = T.copy() if backward: T2[:, -1] = T[:, state] else: T2[:, -1] = impossible T2[state, -1] = inevitable global DEBUG _d = DEBUG DEBUG = False (maxpos, state, score) = pair.calcRows( i, i+1, j, j+1, to_end, T2, scores, rows, None, None, **kw) DEBUG = _d probs.append(score) return numpy.array(probs) def __getitem__(self, index): assert len(index) == 2, index return PairEmissionProbs(self.pair[index], self.bins) def hirschberg(self, TM, dp_options): """linear-space alignment algorithm A linear space algorithm for computing maximal common subsequences. Comm. ACM 18,6 (1975) 341-343. Dan Hirschberg """ (states, T) = TM # This implementation is slightly complicated by the need to handle # alignments of alignments, because a subalignment may have an indel # spanning the midpoint where we want to divide the problem in half. # That must be the sense in which the fatter and slower method used # in "Prank" (Loytynoja A, Goldman N. 2005) is "computationally more # attractive": for them there is only one link in the list: links = self.pair.children[0].midlinks() def _half_row_scores(backward): T2 = T.copy() if backward: T2[0, 1:-1] = 1.0 # don't count the begin state transition twice else: T2[1:-1:,-1] = 1.0 # don't count the end state transition twice return self.scores_at_rows( (states, T2), dp_options, last_row=[link[backward] for link in links], backward = not not backward) (last_row1, last_row2) = parallel.map(_half_row_scores, [0,1]) middle_row = (last_row1 + last_row2) (link, anchor, anchor_state) = numpy.unravel_index( numpy.argmax(middle_row.flat), middle_row.shape) score = middle_row[link, anchor, anchor_state] (join1, join2) = links[link] def _half_solution(part): T2 = T.copy() if part == 0: T2[-1] = 0.0 T2[anchor_state, -1] = 1.0 # Must end with the anchor's state part = self[:join1, :anchor] else: T2[0, :] = T[anchor_state, :] # Starting from the anchor's state part = self[join2:, anchor:] return part.dp((states, T2), dp_options) [(s1, tb_a), (s2, tb_b)] = parallel.map(_half_solution, [0,1]) tb = tb_a + tb_b.offset(join2, anchor) # Same return as for self.dp(..., tb=...) return score, tb def scores_at_rows(self, TM, dp_options, last_row, backward=False): """A score array shaped [rows, columns, states] but only for those row numbers requested. Used by Hirschberg algorithm""" (M, N) = self.pair.size (state_directions, T) = TM reverse = bool(dp_options.backward) ^ bool(backward) cells = [] p_rows = sorted(set(last_row)) if reverse: p_rows.reverse() for i in p_rows: for j in range(0, N-1): for state in range(len(T)-1): if reverse: cells.append((state, (M-2-i, N-2-j))) else: cells.append((state, (i, j))) probs = self.dp(TM, dp_options, cells=cells, backward=backward) probs = numpy.array(probs) probs.shape = (len(p_rows), N-1, len(T)-1) result = numpy.array([ probs[p_rows.index(i)] for i in last_row]) return result def dp(self, TM, dp_options, cells=None, backward=False): """Score etc. from a Dynamic Programming function applied to this pair. TM - (state_directions, array) describing the Transition Matrix. dp_options - instance of DPFlags indicating algorithm etc. cells - List of (state, posn) for which posterior probs are requested. backward - run algorithm in reverse order. """ (state_directions, T) = TM if dp_options.viterbi and cells is None: encoder = self.pair.getPointerEncoding(len(T)) problem_dimensions = self.pair.size + [len(T)] problem_size = numpy.product(problem_dimensions) memory = problem_size * encoder.bytes / 10**6 if dp_options.local: msg = 'Local alignment' elif cells is not None: msg = 'Posterior probs' elif self.pair.size[0]-2 >= 3 and not backward and ( problem_size > HIRSCHBERG_LIMIT or parallel.getCommunicator().Get_size() > 1): return self.hirschberg(TM, dp_options) else: msg = 'dp' if memory > 500: warnings.warn('%s will use > %sMb.' % (msg, memory)) track = encoder.getEmptyArray(problem_dimensions) else: track = encoder = None kw = dict( use_scaling=dp_options.use_scaling, use_logs=dp_options.use_logs, viterbi=dp_options.viterbi, local=dp_options.local) if dp_options.backward: backward = not backward if backward: pair = self.pair.backward() origT = T T = numpy.zeros(T.shape, float) T[1:-1,1:-1] = numpy.transpose(origT[1:-1,1:-1]) T[0,:] = origT[:, -1] T[:,-1] = origT[0,:] else: pair = self.pair if dp_options.use_logs: T = numpy.log(T) scores = self._getEmissionProbs( dp_options.use_logs, dp_options.use_cost_function) rows = pair.getEmptyScoreArrays(len(T), dp_options) if cells is not None: assert not dp_options.local result = self._calc_global_probs( pair, scores, kw, state_directions, T, rows, cells, backward) else: (M, N) = pair.size if dp_options.local: (maxpos, state, score) = pair.calcRows(1, M-1, 1, N-1, state_directions, T, scores, rows, track, encoder, **kw) else: pair.calcRows(0, M-1, 0, N-1, state_directions, T, scores, rows, track, encoder, **kw) end_state_only = numpy.array([(len(T)-1, 0, 1, 1)]) (maxpos, state, score) = pair.calcRows(M-1, M, N-1, N, end_state_only, T, scores, rows, track, encoder, **kw) if track is None: result = score else: tb = self.pair.traceback(track, encoder, maxpos, state, skip_last = not dp_options.local) result = (score, tb) return result def getAlignable(self, aligned_positions, ratio=None): assert ratio is None, "already 2-branched" children = self.pair.children # alignables leaves = [c.leaf for c in children] aligned_positions = [posn for (bin, posn) in aligned_positions] pog = self.pair.getPOG(aligned_positions) edge = LikelihoodTreeEdge(leaves, 'parent', pog.getAlignedPositions()) (plhs, gapscores) = self.makePartialLikelihoods(use_cost_function=False) plh = self.pair.edge2plh(edge, plhs) assert len(plh) == 1, ('bins!', len(plh)) leaf = edge.asLeaf(plh[0]) # like profile return AlignablePOG(leaf, pog, children) def makePairHMM(self, transition_matrix, finite=False): # whether TM includes Begin and End states return PairHMM(self, transition_matrix, finite=finite) class BinData(object): def __init__(self, mprobs, Qd, rate=1.0): self.Qd = Qd self.mprobs = mprobs self.rate = rate def forLengths(self, length1, length2): psub1 = self.Qd(length1 * self.rate) psub2 = self.Qd(length2 * self.rate) return PairBinData(self.mprobs, psub1, psub2) class PairBinData(object): def __init__(self, mprobs, psub1, psub2): self.mprobs = mprobs self.ppsubs = [psub1, psub2] class ReversiblePairEmissionProbs(object): """A pair of sequences and the psubs that relate them, but no gap TM 'Reversible' in the sense that how `length` is divided between the 2 edges shouldn't change the forward and viterbi results""" def __init__(self, pair, bins, length): self.pair = pair self.bins = bins self.length = length self.midpoint = self._makePairEmissionProbs(0.5) def dp(self, *args, **kw): return self.midpoint.dp(*args, **kw) def _makePairEmissionProbs(self, ratio): assert 0.0 <= ratio <= 1.0 lengths = [self.length * ratio, self.length * (1.0-ratio)] pbins = [bin.forLengths(*lengths) for bin in self.bins] return PairEmissionProbs(self.pair, pbins) def getAlignable(self, a_p, ratio=None): # a_p alignment positions if ratio in [None, 0.5]: ep = self.midpoint else: ep = self._makePairEmissionProbs(ratio=ratio) return ep.getAlignable(a_p) def makePairHMM(self, transition_matrix): return PairHMM(self, transition_matrix) class DPFlags(object): def __init__(self, viterbi, local=False, use_logs=None, use_cost_function=True, use_scaling=None, backward=False): if use_logs is None: use_logs = viterbi and not use_scaling if use_scaling is None: use_scaling = not use_logs if use_logs: assert viterbi, "logs only usable for viterbi" assert not use_scaling, "use logs or scaling but not both" self.use_cost_function = bool(use_cost_function) self.local = bool(local) self.use_logs = bool(use_logs) self.use_scaling = bool(use_scaling) self.viterbi = bool(viterbi) self.backward = bool(backward) self.as_tuple = tuple(n for n in ['viterbi', 'local', 'use_logs', 'use_cost_function', 'use_scaling', 'backward'] if getattr(self, n)) def __repr__(self): return '%s(%s)' % (type(self).__name__, ', '.join(self.as_tuple)) def __hash__(self): return hash(self.as_tuple) def __eq__(self, other): return self.as_tuple == other.as_tuple class PairHMM(object): def __init__(self, emission_probs, transition_matrix, finite=False): self.emission_probs = emission_probs self.transition_matrix = transition_matrix self._transition_matrix = adaptPairTM(transition_matrix, finite=finite) self.results = {} def _getDPResult(self, **kw): dp_options = DPFlags(**kw) if dp_options not in self.results: self.results[dp_options] = \ self.emission_probs.dp(self._transition_matrix, dp_options) return self.results[dp_options] def getForwardScore(self, **kw): return self._getDPResult(viterbi=False, **kw) def _getPosteriorProbs(self, tb, **kw): cells = tb.asStatePosTuples() score = self.getForwardScore(**kw) dp_options = DPFlags(viterbi=False, **kw) fwd = self.emission_probs.dp(self._transition_matrix, dp_options, cells) (N, M) = self.emission_probs.pair.size cells = [(state, (N-x-2, M-y-2)) for (state, (x,y)) in cells] tb.reverse() bck = self.emission_probs.dp(self._transition_matrix, dp_options, cells, backward=True)[::-1] return fwd + bck - score def getViterbiPath(self, local=False, **kw): result = self._getDPResult(viterbi=True, local=local, **kw) VP = LocalViterbiPath if local else GlobalViterbiPath return VP(self, result) def getViterbiScoreAndAlignment(self, ratio=None, posterior_probs=False, **kw): assert ratio in [None, 0.5], ratio vpath = self.getViterbiPath(**kw) result_tuple = (vpath.getScore(), vpath.getAlignment()) if posterior_probs: result_tuple = result_tuple + (vpath.getPosteriorProbs(),) return result_tuple def getLocalViterbiScoreAndAlignment(self, posterior_probs=False, **kw): kw['posterior_probs'] = posterior_probs return self.getViterbiScoreAndAlignment(local=True, **kw) class _ViterbiPath(object): """Heavyweight object representing the Viterbi path (ie: best alignment) and all of the inputs used to generate it.""" def __init__(self, pair_hmm, result): (self.vscore, self.tb) = result (state_directions, T) = pair_hmm._transition_matrix self.aligned_positions = self.tb.asBinPosTuples(state_directions) self.pair_hmm = pair_hmm def getScore(self): """The Viterbi score""" return self.vscore class GlobalViterbiPath(_ViterbiPath): def getAlignable(self, ratio=None): # Used during progressive sequence alignment. # Because the alignment depends on the total length (so long as the # model is reversable!) the same cached viterbi result can be re-used # to calculate the partial likelihoods even if the root of the 2-seq # tree is moved around. alignable = self.pair_hmm.emission_probs.getAlignable( self.aligned_positions, ratio=ratio) return alignable def getAlignment(self): """The alignment as a standard PyCogent Alignment object""" return self.getAlignable().getAlignment() def getPosteriorProbs(self): pp = self.pair_hmm._getPosteriorProbs(self.tb, use_cost_function=True) return numpy.exp(pp) class LocalViterbiPath(_ViterbiPath): # Only for pairwise alignments. Local and POGs don't mix well. def getAlignment(self): """The alignment as a standard PyCogent Alignment object""" seqs = self.pair_hmm.emission_probs.pair.getSeqNamePairs() word_length = self.pair_hmm.emission_probs.pair.alphabet.getMotifLen() aligned_positions = [posn for (bin, posn) in self.aligned_positions] return alignment_traceback(seqs, aligned_positions, word_length) def getPosteriorProbs(self): pp = self.pair_hmm._getPosteriorProbs(self.tb, use_cost_function=False) return numpy.exp(pp) pycogent-1.9/cogent/align/progressive.py000066400000000000000000000074061273014367000205200ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import with_statement from cogent import LoadTree from cogent.phylo import nj as NJ from cogent.phylo.distance import EstimateDistances from cogent.core.info import Info from cogent.util import progress_display as UI __author__ = "Peter Maxwell" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Peter Maxwell", "Gavin Huttley"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Peter Maxwell" __email__ = "pm67nz@gmail.com" __status__ = "Production" @UI.display_wrap def TreeAlign(model, seqs, tree=None, indel_rate=0.01, indel_length=0.01, ui = None, ests_from_pairwise=True, param_vals=None): """Returns a multiple alignment and tree. Uses the provided substitution model and a tree for determining the progressive order. If a tree is not provided a Neighbour Joining tree is constructed from pairwise distances estimated from pairwise aligning the sequences. If running in parallel, only the distance estimation is parallelised and only the master CPU returns the alignment and tree, other CPU's return None, None. Arguments: - model: a substitution model - seqs: a sequence collection - indel_rate, indel_length: parameters for the progressive pair-HMM - ests_from_pairwise: if no tree provided and True, the median value of the substitution model parameters are used - param_vals: named key, value pairs for model parameters. These override ests_from_pairwise. """ _exclude_params = ['mprobs', 'rate', 'bin_switch'] if param_vals: param_vals = dict(param_vals) else: param_vals = {} if isinstance(seqs, dict): seq_names = seqs.keys() else: seq_names = seqs.getSeqNames() two_seqs = len(seq_names) == 2 if tree: tip_names = tree.getTipNames() tip_names.sort() seq_names.sort() assert tip_names == seq_names, \ "names don't match between seqs and tree: tree=%s; seqs=%s" % \ (tip_names, seq_names) ests_from_pairwise = False elif two_seqs: tree = LoadTree(tip_names=seqs.getSeqNames()) ests_from_pairwise = False else: if ests_from_pairwise: est_params = [param for param in model.getParamList() \ if param not in _exclude_params] else: est_params = None dcalc = EstimateDistances(seqs, model, do_pair_align=True, est_params=est_params) dcalc.run() dists = dcalc.getPairwiseDistances() tree = NJ.nj(dists) LF = model.makeLikelihoodFunction(tree.bifurcating(name_unnamed=True), aligned=False) if ests_from_pairwise and not param_vals: # we use the Median to avoid the influence of outlier pairs param_vals = {} for param in est_params: numbers = dcalc.getParamValues(param) print "Param Estimate Summary Stats: %s" % param print numbers.summarize() param_vals[param] = numbers.Median ui.display("Doing %s alignment" % ["progressive", "pairwise"][two_seqs]) with LF.updatesPostponed(): for param, val in param_vals.items(): LF.setParamRule(param, value=val, is_constant=True) LF.setParamRule('indel_rate', value=indel_rate, is_constant=True) LF.setParamRule('indel_length', value=indel_length, is_constant=True) LF.setSequences(seqs) edge = LF.getLogLikelihood().edge align = edge.getViterbiPath().getAlignment() info = Info() info["AlignParams"] = param_vals info["AlignParams"].update(dict(indel_length=indel_length, indel_rate=indel_rate)) align.Info = info return align, tree pycogent-1.9/cogent/align/pycompare.py000066400000000000000000000046501273014367000201450ustar00rootroot00000000000000#!/usr/bin/env python # Very slow. See compare.pyx from __future__ import division import cogent.util.progress_display as UI from cogent.util.modules import importVersionedModule, ExpectedImportError __author__ = "Peter Maxwell" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Peter Maxwell", "Gavin Huttley"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Gavin Huttley" __email__ = "gavin.huttley@anu.edu.au" __status__ = "Production" def py_segments_from_diagonal(seq1, seq2, window, threshold, min_gap_length, diagonal): d_segments = [] was_high = False scores = [0] * window score = 0 (i_lo, i_hi) = max(0, -diagonal), min(len(seq1), len(seq2)-diagonal) for i in range(i_lo, i_hi): j = i + diagonal k = i % window score -= scores[k] scores[k] = seq1[i] == seq2[j] score += scores[k] if score >= threshold: if not was_high: start = max(i_lo, i - window) if d_segments and start-d_segments[-1][1] < min_gap_length: (start, jumped_end) = d_segments.pop() was_high = True else: if was_high: d_segments.append((start, i)) was_high = False if was_high: d_segments.append((start, i_hi)) return d_segments try: _compare = importVersionedModule('_compare', globals(), (1, 3), "slow Python dotplot") segments_from_diagonal = _compare.segments_from_diagonal except ExpectedImportError: segments_from_diagonal = py_segments_from_diagonal @UI.display_wrap def dotplot(seq1, seq2, window, threshold, min_gap_length=0, band=None, ui=None): """A list of line segments covering the window-mers with identical matches > threshold Gaps of size less than min_gap will be hidden, which saves on line segments. if 'band' is not None then it limits the searched area """ def one_diagonal(dia): segs = segments_from_diagonal(seq1, seq2, window, threshold, min_gap_length, dia) return [((start, start+dia), (end, end+dia)) for (start, end) in segs] if band is None: band = max(len(seq1), len(seq2)) diagonals = range(-min(len(seq1), band), min(len(seq2), band)+1) result = [] for diag_segments in ui.imap(one_diagonal, diagonals, noun='offset'): result.extend(diag_segments) return result pycogent-1.9/cogent/align/traceback.py000066400000000000000000000055771273014367000200760ustar00rootroot00000000000000#!/usr/bin/env python """Conversion of dynamic program results ("arrays of arrows") into gap vectors, gapped sequences or Cogent Alignment objects""" from cogent.core.alignment import Alignment, Aligned from cogent.core.annotation import Map __author__ = "Peter Maxwell" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Peter Maxwell", "Rob Knight", "Gavin Huttley"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Peter Maxwell" __email__ = "pm67nz@gmail.com" __status__ = "Production" def seq_traceback(s1, s2, aligned_positions, gap_value): """Gapped sequences from state matrix and ending point Gaps are signified by 'gap_value' inserted in the sequences. """ seqs = [s1, s2] alignments = [[], []] for posn in aligned_positions: for (dimension, pos) in enumerate(posn): if pos is not None: c = seqs[dimension][pos] else: c = gap_value alignments[dimension].append(c) for dimension in [0,1]: alignments[dimension].reverse() if isinstance(s1, basestring): alignments = [''.join(a) for a in alignments] return alignments def gap_traceback(aligned_positions): """Gap Vectors from state matrix and ending point""" consuming = [False, False] starts = [None, None] ends = [None, None] gap_vectors = [[], []] for (a, posn) in enumerate(aligned_positions): for dimension in [0, 1]: delta = posn[dimension] is not None if delta: if starts[dimension] is None: starts[dimension] = posn[dimension] ends[dimension] = posn[dimension] + 1 if consuming[dimension] != delta: gap_vectors[dimension].append(a) consuming[dimension] = delta a += 1 for dimension in [0,1]: gv = gap_vectors[dimension] if consuming[dimension]: gv.append(a) gap_vectors[dimension] = [ (gv[i], gv[i+1]) for i in range(0, len(gv), 2)] return (starts, ends, gap_vectors, a) def map_traceback(aligned_positions): # using Map's to keep track of gaps for indel alignment (starts, ends, gap_vectors, alignment_len) = gap_traceback( aligned_positions) #print 'gv', gap_vectors maps = [Map(gv, parent_length=alignment_len).inverse() for gv in gap_vectors] return (starts, ends, maps) def alignment_traceback(seqs, aligned_positions, word_length): """Alignment object from state matrix and ending point. """ (starts, ends, maps) = map_traceback( aligned_positions) aligneds = [] for (start, end, amap, (name, seq)) in zip(starts, ends, maps, seqs): gs = Aligned(amap*word_length, seq[start*word_length:end*word_length]) aligneds.append((name, gs)) return Alignment(MolType=None, data=aligneds) pycogent-1.9/cogent/align/weights/000077500000000000000000000000001273014367000172415ustar00rootroot00000000000000pycogent-1.9/cogent/align/weights/__init__.py000066400000000000000000000006271273014367000213570ustar00rootroot00000000000000#!/usr/bin/env python """ Implements sequence weighting using several standard algorithms. """ __all__ = ['util','methods'] __author__ = "Sandra Smit" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Sandra Smit", "Gavin Huttley", "Rob Knight"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Sandra Smit" __email__ = "sandra.smit@colorado.edu" __status__ = "Production" pycogent-1.9/cogent/align/weights/methods.py000066400000000000000000000434311273014367000212630ustar00rootroot00000000000000#!/usr/bin/env python """Provides an implementation of several sequence weighting algorithm""" from __future__ import division from random import choice from numpy.random.mtrand import exponential from numpy import array, float64 as Float64, dot as matrixmultiply, transpose,\ ones, zeros from numpy.linalg import inv as inverse from cogent.core.profile import Profile from cogent.core.alignment import Alignment, DenseAlignment from cogent.parse.tree import DndParser from cogent.util.array import hamming_distance from cogent.align.weights.util import Weights, number_of_pseudo_seqs,\ pseudo_seqs_exact, pseudo_seqs_monte_carlo, row_to_vote, distance_matrix,\ eigenvector_for_largest_eigenvalue, DNA_ORDER,RNA_ORDER,PROTEIN_ORDER,\ SeqToProfile from cogent.core.moltype import BYTES __author__ = "Sandra Smit" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Sandra Smit", "Rob Knight", "Gavin Huttley"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Sandra Smit" __email__ = "sandra.smit@colorado.edu" __status__ = "Development" def VA(alignment, distance_method=hamming_distance): """Returns Weight object with seq weights according to the VA method. alignment: Alignment object The VA method (Vingron & Argos 1989) calculates the Hamming distance between all sequences in the alignment. The weight assigned to a sequence is the sum of the distances of all other sequences in the alignment to that sequence, divided by the sum of all pairwise distances. Example: ABBA ABCA CBCB ABBA 0 1 3 ABCA 1 0 2 CBCB 3 2 1 ---------------------------- total 4 3 5 (=12) normal. 0.333 0.25 0.417 so: weight(ABBA) = 0.333, weight(ABCA)=0.25, etc. """ distances = distance_matrix(alignment, distance_method) sum_dist = sum(distances) #total weights are the normalized sum of distances (sum over each column, # divided by the total distance in the matrix weights = sum_dist/sum(sum_dist) #create a dictionary of {seq_id: weight} weight_dict = Weights(dict(zip(alignment.Names,weights))) return weight_dict def VOR(alignment,n=1000,force_monte_carlo=False,mc_threshold=1000): """Returns sequence weights according to the Voronoi weighting method. alignment: Alignment object n: sampling size (in case monte carlo is used) force_monte_carlo: generate pseudo seqs with monte carlo always (even if there's only a small number of possible unique pseudo seqs mc_threshold: threshold of when to use the monte carlo sampling method if the number of possible pseudo seqs exceeds this threshold monte carlo is used. VOR differs from VA in the set of sequences against which it's comparing all the sequences in the alignment. In addition to the sequences in the alignment itself, it uses a set of pseudo sequences. Generating discrete random sequences: A discrete random sequence is generated by choosing with equal likelihood at each position one of the residues observed at that position in the alighment. An occurrence of once in the alignment column is sufficient to make the residue type an option. Note: you're choosing with equal likelihood from each of the observed residues (independent of their frequency at that position). In earlier versions of the algorithm the characters were chosen either at the frequency with which they occur at a position or at the frequency with which they occur in the database. Both trials were unsuccesful, because they deviate from random sampling (see Sibbald & Argos 1990). Depending on the number of possible pseudo sequences, all of them are used or a random sample is taken (monte carlo). Example: Alignment: AA, AA, BB AA AA BB AA 0 (.5) 0 (.5) 2 AB 1 (1/3) 1 (1/3) 1 (1/3) BA 1 (1/3) 1 (1/3) 1 (1/3) BB 2 2 0 (1) ----------------------------- total 7/6 7/6 10/6 norm .291 .291 .418 For a bigger example with more pseudo sequences, see Henikoff 1994 I tried the described optimization (pre-calculate the distance to the closest sequence). I doesn't have an advantage over the original method. """ MC_THRESHOLD = mc_threshold #decide on sampling method if force_monte_carlo or number_of_pseudo_seqs(alignment) > MC_THRESHOLD: sampling_method = pseudo_seqs_monte_carlo else: sampling_method = pseudo_seqs_exact #change sequences into arrays aln_array = DenseAlignment(alignment, MolType=BYTES) weights = zeros(len(aln_array.Names),Float64) #calc distances for each pseudo seq rows = [array(seq, 'c') for seq in map(str, aln_array.Seqs)] for seq in sampling_method(aln_array,n=n): seq = array(seq, 'c') temp = [hamming_distance(row, seq) for row in rows] votes = row_to_vote(array(temp)) #change distances to votes weights += votes #add to previous weights weight_dict = Weights(dict(zip(aln_array.Names,weights))) weight_dict.normalize() #normalize return weight_dict def mVOR(alignment,n=1000,order=DNA_ORDER): """Returns sequence weights according to the modified Voronoi method. alignment: Alignment object n: sample size (=number of random profiles to be generated) order: specifies the order of the characters found in the alignment, used to build the sequence and random profiles. mVOR is a modification of the VOR method. Instead of generating discrete random sequences, it generates random profiles, to sample more equally from the sequence space and to prevent random sequences to be equidistant to multiple sequences in the alignment. See the Implementation notes to see how the random profiles are generated and compared to the 'sequence profiles' from the alignment. Random generalized sequences (or a profile filled with random numbers): Sequences that are equidistant to multiple sequences in the alignment can form a problem in small datasets. For longer sequences the likelihood of this event is negligable. Generating 'random generalized sequences' is a solution, because we're then sampling from continuous sequence space. Each column of a random profile is generated by normalizing a set of independent, exponentially distributed random numbers. In other words, a random profile is a two-dimensional array (rows are chars in the alphabet, columns are positions in the alignment) filled with a random numbers, sampled from the standard exponential distribution (lambda=1, and thus the mean=1), where each column is normalized to one. These random profiles are compared to the special profiles of just one sequence (ones for the single character observed at that position). The distance between the two profiles is simply the Euclidean distance. """ weights = zeros(len(alignment.Names),Float64) #get seq profiles seq_profiles = {} for k,v in alignment.items(): #seq_profiles[k] = ProfileFromSeq(v,order=order) seq_profiles[k] = SeqToProfile(v,alphabet=order) for count in range(n): #generate a random profile exp = exponential(1,[alignment.SeqLen,len(order)]) r = Profile(Data=exp,Alphabet=order) r.normalizePositions() #append the distance between the random profile and the sequence #profile to temp temp = [seq_profiles[key].distance(r) for key in alignment.Names] votes = row_to_vote(array(temp)) weights += votes weight_dict = Weights(dict(zip(alignment.Names,weights))) weight_dict.normalize() return weight_dict def pos_char_weights(alignment, order=DNA_ORDER): """Returns the contribution of each character at each position. alignment: Alignemnt object order: the order of characters in the profile (all observed chars in the alignment This function is used by the function position_based For example: GYVGS GFDGF GYDGF GYQGG 0 1 2 3 4 5 G 1/1*4 1/1*4 1/3*1 Y 1/2*3 F 1/2*1 1/3*2 V 1/3*1 D 1/3*2 Q 1/3*1 S 1/3*1 """ counts = alignment.columnFreqs() a = zeros([len(order), alignment.SeqLen],Float64) for col, c in enumerate(counts): for char in c: a[order.index(char),col] = 1/(len(c)*c[char]) return Profile(a,Alphabet=order) def PB(alignment, order=DNA_ORDER): """Returns sequence weights based on the diversity at each position. The position-based (PB) sequence weighting method is described in Henikoff 1994. The idea is that sequences are weighted by the diversity observed at each position in the alignment rather than on the diversity measured for whole sequences. A simple method to represent the diversity at a position is to award each different residue an equal share of the weight, and then to divide up that weight equally among the sequences sharing the same residue. So if in a position of a MSA, r different residues are represented, a residue represented in only one sequence contributes a score of 1/r to that sequence, whereas a residue represented in s sequences contributes a score of 1/rs to each of the s sequences. For each sequence, the contributions from each position are summed to give a sequences weight. See Henikoff 1994 for a good example. """ #calculate the contribution of each character at each position pos_weights = pos_char_weights(alignment, order) d = pos_weights.Data result = Weights() for key,seq in alignment.items(): weight = 0 for idx, char in enumerate(seq): weight += d[order.index(char),idx] result[key] = weight result.normalize() return result def SS(alignment): """Returns dict of {seq_id: weight} for sequences in the alignment alignment: Alignment object The SS sequence weighting method is named after Sander and Schneider, who published their method in 1991. Their method starts with the same distance matrix as in the VA method, where distances are the pairwise Hamming distances between the sequences in the alignment. Where the VA method uses the normalized total weights for each sequence, the SS method continues with calculating a self-consistent set of weights. They do this by finding the eigenvector of the distance matrix belonging to the largest eigenvalue for the matrix. This special eigenvector can be found by a numerical method. """ distances = distance_matrix(alignment) v = eigenvector_for_largest_eigenvalue(distances) return Weights(dict(zip(alignment.Names,v))) def ACL(tree): """Returns a normalized dictionary of sequence weights {seq_id: weight} tree: a PhyloNode object The ACL method is named after Altschul, Carroll and Lipman, who published a paper on sequence weighting in 1989. The ACL method is based on an idea of Felsenstein (1973). Imagine electrical current flows from the root of the tree down the edges and out the leaves. If the edge lengths are proportional to their electrical resistances, current flowing out each leaf equals the leaf weight. The first step in the calculation of the weight vector is calculating a variance-covariance matrix. The variance of a leaf is proportional to the distance from the root to that leaf. The covariance of two leaves is proportional to the distance from the root to the last common ancestor of the two leaves. The second step in the calculation results in a vector of weights. Suppose there are n leaves on the tree. Let i be the vector of size n, all of whose elements are 1.0. The weight vector is calculated as: w = (inverse(M)*i)/(transpose(i)*inverse(M)*i) See Altschul 1989 """ #clip branch lengths to avoid error due to negative or zero branch lengths _clip_branch_lengths(tree) #get a list of sequence IDs (in the order that the tree will be traversed) seqs = [] for n in tree.tips(): seqs.append(n.Name) #initialize the variance-covariance matrix m = zeros([len(seqs),len(seqs)],Float64) #calculate (co)variances #variance of a node is defined as the distance from the root to the leaf #covariance of two nodes is defined as the distance from the root to the #last common ancestor of the two leaves. for x in tree.tips(): for y in tree.tips(): idx_x = seqs.index(x.Name) idx_y = seqs.index(y.Name) if idx_x == idx_y: m[idx_x,idx_y] = x.distance(tree) else: lca = x.lastCommonAncestor(y) dist_lca_root = lca.distance(tree) m[idx_x,idx_y] = dist_lca_root m[idx_y,idx_x] = dist_lca_root #get the inverse of the variance-covariance matrix inv = inverse(m) #build vector i (vector or ones, length = # of leaves in the tree) i = ones(len(seqs),Float64) numerator = matrixmultiply(inv, i) denominator = matrixmultiply(matrixmultiply(transpose(i),inv),i) weight_vector = numerator/denominator #return a Weights object (is dict {seq_id: weight}) return Weights(dict(zip(seqs,weight_vector))) def _clip_branch_lengths(tree, min_val=1e-9, max_val=1e9): """Clips branch lengths in tree to a minimum or maximum value tree: TreeNode object min: minimum value that a branch length should have max: maximum value that a branch length should have Note: tree is changed in place!!! """ for i in tree.traverse(): bl = i.Length if bl > max_val: i.Length = max_val elif bl < min_val: i.Length = min_val def _set_branch_sum(tree): """Sets the branch sum to each node tree: TreeNode object The branch sum of a node is the total branch length of all the nodes under that node. WARNING: changes the tree in place!!! """ total = 0 for child in tree: _set_branch_sum(child) total += child.BranchSum total += child.Length tree.BranchSum = total def _set_node_weight(tree): """Sets the node weight to nodes according to the GSC method. tree: TreeNode object See documentation in GSC on how node weights are calculated. WARNING: changes the tree in place!!! """ parent = tree.Parent if parent is None: #root of tree always has weight of 1.0 tree.NodeWeight = 1.0 else: tree.NodeWeight = parent.NodeWeight * \ (tree.Length + tree.BranchSum)/parent.BranchSum for child in tree: _set_node_weight(child) def GSC(tree): """Returns dict of {seq_id: weight} for each leaf in the tree tree: PhyloNode object The GSC method is named after Gerstein, Sonnhammer, and Chothia, who published their method in 1994. The idea is that the sequences are weighted by their total branch length in the tree. In the original algorithm weights are calculated from leaves to root, we calculate them from the root to the leaves. First, the branch lengths have to be clipped to a minimum and maximum value to avoid errors due to negative or zero branch lengts, and to make sure the method behaves for two identical sequences. Next the branch sum for each node is pre-calulated (the branch sum is the total branch length in the tree below that node). From the (clipped) branch lengths and branch sums, we can now calulate how the weight has to be divided. Example: tree = (((A:20,B:10)x:30,C:40)r:0); weight of the root (r) is always 1 to the left node (x) goes ((30+30)/100)*1 = 0.6 to the right node (C) goed (40/100)*1 = 0.4 to node A goes (20/30)*0.6 = 0.4 to node B goes (10/30)*0.6 = 0.2 """ _clip_branch_lengths(tree) _set_branch_sum(tree) _set_node_weight(tree) weights = Weights() for n in tree.tips(): weights[n.Name] = n.NodeWeight return weights #====================================================== if __name__ == "__main__": from old_cogent.base.align import Alignment #This main block shows the results for four different alignments a = Alignment({'seq1':'GYVGS','seq2':'GFDGF','seq3':'GYDGF',\ 'seq4':'GYQGG'},Names=['seq1','seq2','seq3','seq4']) b = Alignment({'seq1':'AA', 'seq2':'AA', 'seq3':'BB'},\ Names=['seq1','seq2','seq3']) c = Alignment({'seq1':'AA', 'seq2':'AA', 'seq3':'BB', 'seq4':'BB',\ 'seq5':'CC'},Names=['seq1','seq2','seq3','seq4','seq5']) d = Alignment({'seq1':'AGCTA', 'seq2':'AGGTA', 'seq3':'ACCTG', 'seq4':'TGCAA'},Names=['seq1','seq2','seq3','seq4']) print "This is a quick test run of the alignment-based methods" for al in [a,b,c,d]: #determine the needed character order for each alignment if al is b or al is c: char_order = "ABC" elif al is a: #need protein_order char_order=PROTEIN_ORDER else: #need DNA_order char_order=DNA_ORDER print "===========ALIGNMENT==============" for k in al.Names: print '\t'.join([k,al[k]]) print 'RESULT OF THE VA METHOD:' print VA(al) print 'RESULT OF THE VOR METHOD:' print VOR(al) print 'RESULT OF THE mVOR METHOD:' print mVOR(al, n=10000, order=char_order) print 'RESULTS OF THE SS METHODS:' print SS(al) print 'RESULTS OF THE PB METHODS:' print PB(al, order=char_order) pycogent-1.9/cogent/align/weights/util.py000066400000000000000000000301511273014367000205700ustar00rootroot00000000000000#!/usr/bin/env python """Provides utility methods for sequence weighting """ from __future__ import division from numpy import array, zeros, dot as matrixmultiply, ones, identity, take,\ asarray, uint8 as UInt8, add, sqrt from random import choice from cogent.util.array import hamming_distance from cogent.core.profile import Profile, CharMeaningProfile from cogent.core.moltype import DNA, RNA, PROTEIN from cogent.core.alignment import Alignment __author__ = "Sandra Smit" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Sandra Smit", "Rob Knight", "Gavin Huttley", "Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Sandra Smit" __email__ = "sandra.smit@colorado.edu" __status__ = "Development" PROTEIN_ORDER = ''.join(PROTEIN.Alphabet) + '-' DNA_ORDER = ''.join(DNA.Alphabet) + '-' RNA_ORDER = ''.join(RNA.Alphabet) + '-' class Weights(dict): """Dictionary seq_ids: seq weight """ def normalize(self): """Normalizes to one. Works in place!""" total = sum(self.values(), 0) for k, v in self.items(): self[k] = v/total def number_of_pseudo_seqs(alignment): """Returns the # of unique randomized sequences that can be generated from the alignment. alignment: Alignment object A random sequence is created by randomly choosing at each position one of the residues observed at that position (column) in the alighment. A single occurrence of that residue type is sufficient to make it an option and the choice is with equal likelihood from any of the observed characters. (See Implementation Notes for more details). """ return reduce(lambda x, y: x*y, map(len,alignment.columnProbs())) def pseudo_seqs_exact(alignment,n=None): """Returns all possible pseudo sequences (generated from the alignment) alignment: Alignment object n: has NO FUNCTION, except to make the API for all functions that generate pseudo sequences the same. This function is used by the VOR method (only when the number of unique pseudo sequences is lower than 1000). The original sequences will be generated in this list of pseudo sequences. Duplications of sequences in the alignment don't cause duplications in the list of pseudo sequences. Example: AA, AA, BB in the alignment generates pseudo sequences: AA,BB,AB,BA ABC, BCC, BAC in the alignment generates pseudo sequences: AAC, ABC, ACC, BAC, BBC, and BCC """ counts = alignment.columnFreqs() results = [[]] for col in counts: new_results = [] for item in results: for option in col: new_results.append(item + [option]) results = new_results return [''.join(i) for i in results] def pseudo_seqs_monte_carlo(alignment,n=1000): """Yields sample of possible pseudo sequences (generated from alignment) alignment: Alignment object n = number of pseudo sequences generated (=sample size) This function is used by the VOR method, usually when the number of possible pseudo sequences exceeds 1000. To see how the pseudo sequences are generated read the Implementation Notes at the top of this file. """ freqs = alignment.columnFreqs() for x in range(n): seq = [] for i in freqs: seq.append(choice(i.keys())) yield ''.join(seq) def row_to_vote(row): """Changes distances to votes. There's one vote in total. The sequence with the lowest distance gets the vote. If there are multiple sequences equidistant at the minimum distance, the vote is split over all the sequences at the minimum distance. Example: [4,2,3,7] -> [0,1,0,0] [1,3,2,1] -> [.5,0,0,.5] [1,1,1,1] -> [.25,.25,.25,.25] """ result = array(row) - min(row) == 0 return result/sum(result, 0) def distance_matrix(alignment, distance_method=hamming_distance): """Returns distance matrix for seqs in the alignment. Order is either the Names in the alignment or the order in which is iterated over the rows. Distance is the Hamming distance between two sequences """ #change sequences into arrays alignment = [array(str(alignment.NamedSeqs[k]), 'c') for k in\ alignment.Names] nr_of_seqs = len(alignment) distances = zeros([nr_of_seqs,nr_of_seqs]) for i, seq_a in enumerate(alignment): for j, seq_b in enumerate(alignment): if i < j: dist = distance_method(seq_a,seq_b) distances[i,j] = dist distances[j,i] = dist else: # i==j (diagonal) or i>j (lower left half) continue return distances def eigenvector_for_largest_eigenvalue(matrix): """Returns eigenvector corresponding to largest eigenvalue of matrix. Implements a numerical method for finding an eigenvector by repeated application of the matrix to a starting vector. For a matrix A the process w(k) <-- A*w(k-1) converges to eigenvector w with the largest eigenvalue. Because distance matrix D has all entries >= 0, a theorem due to Perron and Frobenius on nonnegative matrices guarantees good behavior of this method, excepting degenerate cases where the iteration oscillates. For distance matrices a remedy is to add the identity matrix to A, permitting the iteration to converge to the eigenvector. (From Sander and Schneider (1991), and Vingron and Sibbald (1993)) Note: Only works on square matrices. """ #always add the identity matrix to avoid oscillating behavior matrix = matrix + identity(len(matrix)) #v is a random vector (chosen as the normalized vector of ones) v = ones(len(matrix))/len(matrix) #iterate until convergence for i in range(1000): new_v = matrixmultiply(matrix,v) new_v = new_v/sum(new_v, 0) #normalize if sum(map(abs,new_v-v), 0) > 1e-9: v = new_v #not converged yet continue else: #converged break return new_v def distance_to_closest(alignment, distance_method=hamming_distance): """Returns vector of distances to closest neighbor for each s in alignment alignment: Alignment object distance_method: function used to calculate the distance between two seqs Function returns the closest distances according to the Names in the alignment example: Alignment({1:'ABCD',2:'ABCC',3:'CBDD',4:'ACAA'},Names=[3,2,1,4]) [2,1,1,3] """ names = alignment.Names seqs = [array(str(alignment.NamedSeqs[n]), 'c') for n in names] closest = [] for i, key in enumerate(names): seq = seqs[i] dist = None for j, other_key in enumerate(names): if key == other_key: continue d = distance_method(seq,seqs[j]) if dist: if d < dist: dist = d else: dist = d closest.append(dist) return array(closest) def SeqToProfile(seq, alphabet=None, char_order=None,\ split_degenerates=False): """Generates a Profile object from a Sequence object. seq: Sequence object alphabet (optional): Alphabet object (if you want to split degenerate symbols, the alphabet object should have a Degenerates property. Default is the Alphabet associated with the Sequence object. char_order (optional): The order the characters occur in the Profile. Default is the list(alphabet) split_degenerates (optional): Whether you want the counts for the degenerate symbols to be divided over the non-degenerate symbols they code for. A Profile is a position x character matrix describing which characters occur at each position. In a sequence (as opposed to an alignment) only one character occurs at each position. In general a sequence profile will only contain ones and zeros. However, you have the possibility of splitting degenerate characters. For example, if a position is R, it means that you have 50/50% chance of A and G. It's also possible to ignore characters, which in a sequence profile will lead to positions (rows) containing only zeros. Example: Sequence = ACGU Profile(seq, CharOrder=UCAG): U C A G 0 0 1 0 first pos 0 1 0 0 second pos 0 0 0 1 third pos 1 0 0 0 fourth pos Sequence= GURY Profile(seq,CharOrder=UCAG, split_degenerates=True) U C A G 0 0 0 1 first pos 1 0 0 0 second pos 0 0 .5 .5 third pos .5 .5 0 0 fourth pos Characters can also be ignored Sequence = ACN- Profile(seq, CharOrder=UCAGN, split_degenerates=True) U C A G 0 0 1 0 first pos 0 1 0 0 second pos .25 .25 .25 .25 third pos 0 0 0 0 fourth pos <--contains only zeros """ if alphabet is None: alphabet = seq.MolType if char_order is None: char_order = list(alphabet) #Determine the meaning of each character based on the alphabet, the #character order, and the option to split degenerates char_meaning = CharMeaningProfile(alphabet, char_order,\ split_degenerates) #construct profile data idxs = array(str(seq).upper(), 'c').view(UInt8) result_data = char_meaning.Data[idxs] #result_data = take(char_meaning.Data, asarray(str(seq).upper(), UInt8), axis=0) return Profile(result_data, alphabet, char_order) def AlnToProfile(aln, alphabet=None, char_order=None, split_degenerates=False,\ weights=None): """Generates a Profile object from an Alignment. aln: Alignment object alphabet (optional): an Alphabet object (or list of chars, but if you want to split degenerate symbols, the alphabet must have a Degenerates property. Default is the alphabet of the first seq in the alignment. char_order (optional): order of the characters in the profile. Default is list(alphabet) split_degenerates (optional): Whether you want the counts for the degenerate symbols to be divided over the non-degenerate symbols they code for. weights (optional): dictionary of seq_id: weight. If not entered all seqs are weighted equally A Profile is a position x character matrix describing which characters occur at each position of an alignment. The Profile is always normalized, so it gives the probabilities of each character at each position. Ignoring chars: you can ignore characters in the alignment by not putting the char in the CharOrder. If you ignore all characters at a particular position, an error will be raised, because the profile can't be normalized. Splitting degenerates: you can split degenerate characters over the non-degenerate characters they code for. For example: R = A or G. So, an R at a position counts for 0.5 A and 0.5 G. Example: seq1 TCAG weight: 0.5 seq2 TAR- weight: 0.25 seq3 YAG- weight: 0.25 Profile(aln,alphabet=DNA,char_order="TACG",weights=w, split_degenerates=True) Profile: T A C G [[ 0.875 0. 0.125 0. ] [ 0. 0.5 0.5 0. ] [ 0. 0.625 0. 0.375] [ 0. 0. 0. 1. ]] """ if alphabet is None: alphabet = aln.values()[0].MolType if char_order is None: char_order = list(alphabet) if weights is None: weights = dict.fromkeys(aln.keys(),1/len(aln)) char_meaning = CharMeaningProfile(alphabet, char_order,\ split_degenerates) profiles = [] for k,v in aln.items(): idxs = array(str(v).upper(), 'c').view(UInt8) profiles.append(char_meaning.Data[idxs] * weights[k]) s = reduce(add,profiles) result = Profile(s,alphabet, char_order) try: result.normalizePositions() except Exception, e: raise ValueError,e #"Probably one of the rows in your profile adds up to zero,\n "+\ #"because you are ignoring all of the characters in the "+\ #"corresponding\n column in the alignment" return result pycogent-1.9/cogent/app/000077500000000000000000000000001273014367000152555ustar00rootroot00000000000000pycogent-1.9/cogent/app/__init__.py000066400000000000000000000027531273014367000173750ustar00rootroot00000000000000#!/usr/bin/env python """apps: provides support libraries for controlling applications (local or web). """ __all__ = ['blast', 'carnac', 'cd_hit', 'clustalw', 'cmfinder', 'comrna', 'consan', 'contrafold', 'cove', 'dialign', 'dynalign', 'fasttree', 'fasttree_v1' 'foldalign', 'gctmpca', 'ilm', 'knetfold', 'mfold', 'muscle', 'msms', 'nupack', 'parameters', 'pfold', 'pknotsrg', 'raxml', 'rdp_classifier', 'rnaalifold', 'rnaforester', 'rnashapes', 'rnaview', 'sfold', 'unafold', 'util', 'vienna_package'] __author__ = "" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Jeremy Widmann", "Catherine Lozuopone", "Gavin Huttley", "Rob Knight", "Zongzhi Liu", "Sandra Smit", "Micah Hamady", "Greg Caporaso", "Mike Robeson", "Daniel McDonald", "Marcin Cieslik"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Rob Knight" __email__ = "rob@spot.colorado.edu" __status__ = "Production" """Need to add: tcoffee alignment meme motif finding phylip phylogeny mrbayes phylogeny paml phylogeny other packages? web tools? """ pycogent-1.9/cogent/app/blast.py000066400000000000000000001326211273014367000167410ustar00rootroot00000000000000#!/usr/bin/env python """Application controllers for blast family """ from string import strip from os import remove, access, F_OK, environ, path from cogent.app.parameters import FlagParameter, ValuedParameter, MixedParameter from cogent.app.util import CommandLineApplication, ResultPath, \ get_tmp_filename, guess_input_handler, ApplicationNotFoundError from cogent.parse.fasta import FastaFinder, LabeledRecordFinder, is_fasta_label from cogent.parse.blast import LastProteinIds9, QMEBlast9, QMEPsiBlast9, BlastResult from cogent.util.misc import app_path from random import choice from copy import copy __author__ = "Micah Hamady" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Zongzhi Liu", "Micah Hamady", "Jeremy Widmann", "Catherine Lozupone", "Rob Knight","Greg Caporaso"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Micah Hamady" __email__ = "hamady@colorado.edu" __status__ = "Prototype" class Blast(CommandLineApplication): """BLAST generic application controller""" _common_options ={ # defaults to non-redundant database #WARNING: This will only work if BLASTDB environment variable is set '-d':ValuedParameter('-',Name='d',Delimiter=' ', Value="nr"), # query file '-i':ValuedParameter('-',Name='i',Delimiter=' '), # Multiple Hits window size [Integer] '-A':ValuedParameter('-',Name='A',Delimiter=' '), # Threshold for extending hits [Integer] '-f':ValuedParameter('-',Name='f',Delimiter=' '), # Expectation value (E) [Real] '-e':ValuedParameter('-',Name='e',Delimiter=' ', Value="10.0"), # alignment view options: # 0 = pairwise, # 1 = query-anchored showing identities, # 2 = query-anchored no identities, # 3 = flat query-anchored, show identities, # 4 = flat query-anchored, no identities, # 5 = query-anchored no identities and blunt ends, # 6 = flat query-anchored, no identities and blunt ends, # 7 = XML Blast output, # 8 = Tabular output, # 9 = Tabular output with comments # 10 = ASN, text # 11 = ASN, binary [Integer] '-m':ValuedParameter('-',Name='m',Delimiter=' ', Value="9"), # Output File for Alignment [File Out] Optional '-o':ValuedParameter('-',Name='o',Delimiter=' '), # Filter query sequence with SEG [String] '-F':ValuedParameter('-',Name='F',Delimiter=' '), # Cost to open a gap [Integer] '-G':ValuedParameter('-',Name='G',Delimiter=' '), # Cost to extend a gap [Integer] '-E':ValuedParameter('-',Name='E',Delimiter=' '), # X dropoff value for gapped alignment (in bits) [Integer] # blastn 30, megablast 20, tblastx 0, all others 15 [Integer] '-X':ValuedParameter('-',Name='X',Delimiter=' '), # Show GI's in deflines [T/F] '-I':ValuedParameter('-',Name='I',Delimiter=' '), # Number of database seqs to show one-line descriptionss for [Integer] '-v':ValuedParameter('-',Name='v',Delimiter=' '), # Number of database sequence to show alignments for (B) [Integer] '-b':ValuedParameter('-',Name='b',Delimiter=' '), # Perform gapped alignment (not available with tblastx) [T/F] '-g':ValuedParameter('-',Name='g',Delimiter=' '), # Number of processors to use [Integer] '-a':ValuedParameter('-',Name='a',Delimiter=' ', Value="1"), # Believe the query defline [T/F] '-J':ValuedParameter('-',Name='J',Delimiter=' '), # SeqAlign file ('Believe the query defline' must be TRUE) [File Out] # Optional '-O':ValuedParameter('-',Name='O',Delimiter=' '), # Matrix [String] '-M':ValuedParameter('-',Name='M',Delimiter=' ', Value="BLOSUM62"), # Word size [Integer] (blastn 11, megablast 28, all others 3) '-W':ValuedParameter('-',Name='W',Delimiter=' '), # Effective length of the database (use zero for the real size) [Real] '-z':ValuedParameter('-',Name='z',Delimiter=' '), # Number of best hits from a region to keep [Integer] '-K':ValuedParameter('-',Name='K',Delimiter=' '), # 0 for multiple hit, 1 for single hit [Integer] '-P':ValuedParameter('-',Name='P',Delimiter=' '), # Effective length of the search space (use zero for real size) [Real] '-Y':ValuedParameter('-',Name='Y',Delimiter=' '), # Produce HTML output [T/F] '-T':ValuedParameter('-',Name='T',Delimiter=' ', Value="F"), # Restrict search of database to list of GI's [String] Optional '-l':ValuedParameter('-',Name='l',Delimiter=' '), # Use lower case filtering of FASTA sequence [T/F] Optional '-U':ValuedParameter('-',Name='U',Delimiter=' '), # Dropoff (X) for blast extensions in bits (default if zero) [Real] # blastn 20, megablast 10, all others 7 '-y':ValuedParameter('-',Name='y',Delimiter=' '), # X dropoff value for final gapped alignment (in bits) [Integer] # blastn/megablast 50, tblastx 0, all others 25 '-Z':ValuedParameter('-',Name='Z',Delimiter=' '), # Input File for PSI-BLAST Restart [File In] Optional '-R':ValuedParameter('-',Name='R',Delimiter=' '), } _executable = 'blastall' _parameters = {} _parameters.update(_common_options) def __init__(self, cur_options, command, blast_mat_root=None, extra_env="", params=None,InputHandler=None, SuppressStderr=None, SuppressStdout=None,WorkingDir=None,\ HALT_EXEC=False): """ Initialize blast """ # update options self._parameters.update(cur_options) # check if need to set env variable (for cgi calls) if blast_mat_root: self._command = "export BLASTMAT=%s;%s%s" % (blast_mat_root, extra_env, command) else: # Determine if blast is installed and raise an ApplicationError # if not -- this is done here so the user will get the most # informative error message available. self._error_on_missing_application(params) # Otherwise raise error about $BLASTMAT not being set if not ('BLASTMAT' in environ or \ access(path.expanduser("~/.ncbirc"), F_OK) or \ access(".ncbirc", F_OK)): ## SHOULD THIS BE CHANGED TO RAISE AN ApplicationError? raise RuntimeError, blastmat_error_message self._command = command super(Blast, self).__init__(params=params, InputHandler=InputHandler,SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout,WorkingDir=WorkingDir,\ HALT_EXEC=HALT_EXEC) def _error_on_missing_application(self,params): """ Raise an ApplicationNotFoundError if the app is not accessible """ if not app_path('blastall'): raise ApplicationNotFoundError,\ "Cannot find blastall. Is it installed? Is it in your path?" def _input_as_seqs(self,data): lines = [] for i,s in enumerate(data): #will number the sequences 1,2,3,etc. lines.append(''.join(['>',str(i+1)])) lines.append(s) return self._input_as_lines(lines) def _input_as_seq_id_seq_pairs(self,data): lines = [] for seq_id,seq in data: lines.append(''.join(['>',str(seq_id)])) lines.append(seq) return self._input_as_lines(lines) def _input_as_lines(self,data): if data: self.Parameters['-i']\ .on(super(Blast,self)._input_as_lines(data)) return '' def _input_as_string(self,data): """Makes data the value of a specific parameter This method returns the empty string. The parameter will be printed automatically once set. """ if data: self.Parameters['-i'].on(str(data)) return '' def _input_as_multiline_string(self, data): if data: self.Parameters['-i']\ .on(super(Blast,self)._input_as_multiline_string(data)) return '' def _align_out_filename(self): if self.Parameters['-o'].isOn(): aln_filename = self._absolute(str(self.Parameters['-o'].Value)) else: raise ValueError, "No output file specified." return aln_filename def _get_result_paths(self,data): result = {} if self.Parameters['-o'].isOn(): out_name = self._align_out_filename() result['BlastOut'] = ResultPath(Path=out_name,IsWritten=True) return result blastmat_error_message =\ """BLAST cannot run if the BLASTMAT environment variable is not set. Usually, the BLASTMAT environment variable points to the NCBI data directory, which contains matrices like PAM30 and PAM70, etc. Alternatively, you may create a .ncbirc file to define these variables. From help file: 2) Create a .ncbirc file. In order for Standalone BLAST to operate, you have will need to have a .ncbirc file that contains the following lines: [NCBI] Data="path/data/" Where "path/data/" is the path to the location of the Standalone BLAST "data" subdirectory. For Example: Data=/root/blast/data The data subdirectory should automatically appear in the directory where the downloaded file was extracted. Please note that in many cases it may be necessary to delimit the entire path including the machine name and or the net work you are located on. Your systems administrator can help you if you do not know the entire path to the data subdirectory. Make sure that your .ncbirc file is either in the directory that you call the Standalone BLAST program from or in your root directory. """ class PsiBlast(Blast): """PSI-BLAST application controller - Prototype""" _options ={ # ASN.1 Scoremat input of checkpoint data: # 0: no scoremat input # 1: Restart is from ASCII scoremat checkpoint file, # 2: Restart is from binary scoremat checkpoint file [Integer] Optional '-q':ValuedParameter('-',Name='q',Delimiter=' '), # Output File for PSI-BLAST Matrix in ASCII [File Out] Optional '-Q':ValuedParameter('-',Name='Q',Delimiter=' '), # Start of required region in query [Integer] '-S':ValuedParameter('-',Name='S',Delimiter=' ', Value="1"), # ASN.1 Scoremat output of checkpoint data: # 0: no scoremat output # 1: Output is ASCII scoremat checkpoint file (requires -J), # 2: Output is binary scoremat checkpoint file (requires -J) Optional '-u':ValuedParameter('-',Name='u',Delimiter=' '), # Cost to decline alignment (disabled when 0) [Integer] '-L':ValuedParameter('-',Name='L',Delimiter=' ', Value="0"), # program option for PHI-BLAST [String] '-p':ValuedParameter('-',Name='p',Delimiter=' ', Value="blastpgp"), # Use composition based statistics [T/F] '-t':ValuedParameter('-',Name='t',Delimiter=' ', Value="T"), # Input Alignment File for PSI-BLAST Restart [File In] Optional '-B':ValuedParameter('-',Name='B',Delimiter=' '), # Number of bits to trigger gapping [Real] '-N':ValuedParameter('-',Name='N',Delimiter=' ', Value="22.0"), # End of required region in query (-1 indicates end of query) [Integer] '-H':ValuedParameter('-',Name='H',Delimiter=' ', Value="-1"), # e-value threshold for inclusion in multipass model [Real] '-h':ValuedParameter('-',Name='h',Delimiter=' ', Value="0.001"), # Constant in pseudocounts for multipass version [Integer] '-c':ValuedParameter('-',Name='c',Delimiter=' ', Value="9"), # Maximum number of passes to use in multipass version [Integer] '-j':ValuedParameter('-',Name='j',Delimiter=' ', Value="1"), # Output File for PSI-BLAST Checkpointing [File Out] Optional '-C':ValuedParameter('-',Name='C',Delimiter=' '), # Compute locally optimal Smith-Waterman alignments [T/F] '-s':ValuedParameter('-',Name='s',Delimiter=' ', Value="F"), # Hit File for PHI-BLAST [File In] '-k':ValuedParameter('-',Name='k',Delimiter=' '), } def __init__(self, blast_mat_root=None, params=None, extra_env="", InputHandler=None,SuppressStderr=None, SuppressStdout=None,WorkingDir=None, HALT_EXEC=False): """ Initialize the Psi-Blast""" super(PsiBlast, self).__init__(self._options, "blastpgp", extra_env=extra_env, blast_mat_root=blast_mat_root, params=params, InputHandler=InputHandler,SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout,WorkingDir=WorkingDir, HALT_EXEC=HALT_EXEC) # should probably go into blastall superclass. it's late, works for now BLASTALL_OPTIONS ={ # Use lower case filtering of FASTA sequence [T/F] Optional '-U':ValuedParameter('-',Name='U',Delimiter=' '), # Penalty for a nucleotide mismatch (blastn only) [Integer] # default = -3 '-q':ValuedParameter('-',Name='q',Delimiter=' '), # Reward for a nucleotide match (blastn only) [Integer] '-r':ValuedParameter('-',Name='r',Delimiter=' '), # Query Genetic code to use [Integer] default = 1 '-Q':ValuedParameter('-',Name='Q',Delimiter=' '), # DB Genetic code (for tblast[nx] only) [Integer] '-D':ValuedParameter('-',Name='D',Delimiter=' '), # Query strands to search against database (for blast[nx], and tblastx) # 3 is both, 1 is top, 2 is bottom [Integer] '-S':ValuedParameter('-',Name='S',Delimiter=' '), # Program Name '-p':ValuedParameter('-',Name='p',Delimiter=' '), # MegaBlast search [T/F] '-n':ValuedParameter('-',Name='n',Delimiter=' '), # Location on query sequence [String] Option '-L':ValuedParameter('-',Name='L',Delimiter=' '), # Frame shift penalty (OOF algorithm for blastx) [Integer] '-w':ValuedParameter('-',Name='w',Delimiter=' '), # Length of the largest intron allowed in tblastn for linking HSPs #(0 disables linking) [Integer] '-t':ValuedParameter('-',Name='t',Delimiter=' '), # Number of concatenated queries, for blastn and tblastn [Integer] '-B':ValuedParameter('-',Name='B',Delimiter=' '), } class Blastall(Blast): """blastall application controller - Prototype """ def __init__(self, blast_mat_root=None, params=None, extra_env="", InputHandler=None,SuppressStderr=None, SuppressStdout=None,WorkingDir=None, HALT_EXEC=False): """ Initialize the blastall""" super(Blastall, self).__init__(BLASTALL_OPTIONS, "blastall", blast_mat_root=blast_mat_root, extra_env=extra_env, params=params, InputHandler=InputHandler,SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout,WorkingDir=WorkingDir, HALT_EXEC=HALT_EXEC) class MpiBlast(Blast): """mpblast application controller - Prototype """ _mpi_options ={ # Produces verbose debugging output for each node, optionally logs the # output to a file '--debug':ValuedParameter('-',Name='--debug',Delimiter='='), # Set the scheduler process' MPI Rank (default is 1). Because the # scheduler uses very little CPU it can be useful to force the # scheduler to run on the same physical machine as the writer (rank 0). '--scheduler-rank':ValuedParameter('-',Name='--scheduler-rank', Delimiter='='), # Print the Altschul. et. al. 1997 paper reference instead of the # mpiBLAST paper reference. With this option mpiblast output is nearly # identical to NCBI-BLAST output. '--altschul-reference':FlagParameter(Prefix='--', Name='altschul-reference'), #Removes the local copy of the database from each node before # terminating execution '--removedb':FlagParameter(Prefix='--', Name='removedb'), # Sets the method of copying files that each worker will use. # Default = "cp" # * cp : use standard file system "cp" command. # Additional option is --concurrent. # * rcp : use rsh "rcp" command. Additonal option is --concurrent. # * scp : use ssh "scp" command. Additional option is --concurrent. # * mpi : use MPI_Send/MPI_Recv to copy files. # Additional option is --mpi-size. # * none : do not copy files,instead use shared storage as local storage '--copy-via':ValuedParameter('-',Name='--copy-via', Delimiter='='), # set the number of concurrent accesses to shared storage. Default = 1 '--concurrent':ValuedParameter('-',Name='--concurrent', Delimiter='='), # in bytes, set the maximum buffer size that MPI will use to send data # when transferring files. Default = 65536 '--mpi-size':ValuedParameter('-',Name='--mpi-size', Delimiter='='), # set whether file locking should be used to manage local fragment # lists. Defaults to off. When --concurrency > 1 defaults to on # [on|off] '--lock':ValuedParameter('-',Name='--lock', Delimiter='='), # When set, the writer will use the database on shared storage for # sequence lookup. Can drastically reduce overhead for some blastn # searches. '--disable-mpi-db':FlagParameter(Prefix='--', Name='disable-mpi-db'), # Under unix, sets the nice value for each mpiblast process. '--nice':ValuedParameter('-',Name='--nice', Delimiter='='), # Under unix, sets the nice value for each mpiblast process. '--config-file':ValuedParameter('--',Name='config-file', Delimiter='='), # Experimental. When set, mpiblast will read the output file and # attempt to continue a previously aborted run where it left off '--resume-run':FlagParameter(Prefix='--', Name='resume-run'), # print the mpiBLAST version '--version':FlagParameter(Prefix='--', Name='version'), } _mpi_options.update(BLASTALL_OPTIONS) def __init__(self, blast_mat_root=None, params=None, mpiblast_root="/usr/local/bin/", local_root="/var/scratch/mpiblastdata/", shared_root="/quicksand/hamady/data/blast/mpidb/", config_file="/quicksand2/downloads2/mpiblast/mpiblast.conf", num_db_frags=40, InputHandler=None,SuppressStderr=None, SuppressStdout=None,WorkingDir=None, HALT_EXEC=False): """ Initialize mpiblast""" if config_file: params["--config-file"] = config_file super(MpiBlast, self).__init__(self._mpi_options, "mpirun -np %d %smpiblast" % ((num_db_frags + 2), mpiblast_root), blast_mat_root=blast_mat_root, extra_env="export Local=%s; export Shared=%s;" %(local_root, shared_root), params=params, InputHandler=InputHandler,SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout,WorkingDir=WorkingDir, HALT_EXEC=HALT_EXEC) class FastaCmd(CommandLineApplication): """FastaCmd application controller - Prototype""" _options ={ # Database [String] Optional '-d':ValuedParameter('-',Name='d',Delimiter=' '), # Type of file # G - guess mode (look for protein, then nucleotide) # T - protein # F - nucleotide [String] Optional '-p':ValuedParameter('-',Name='p',Delimiter=' ', Value="G"), # Search str: GIs, accessions and loci may be used delimited by comma '-s':ValuedParameter('-',Name='s',Delimiter=' '), # Input file wilth GIs/accessions/loci for batch retrieval Optional '-i':ValuedParameter('-',Name='i',Delimiter=' '), # Retrieve duplicate accessions [T/F] Optional '-a':ValuedParameter('-',Name='a',Delimiter=' ', Value='F'), # Line length for sequence [Integer] Optional '-l':ValuedParameter('-',Name='l',Delimiter=' '), # Definition line should contain target gi only [T/F] Optional '-t':ValuedParameter('-',Name='t',Delimiter=' '), # Output file [File Out] Optional '-o':ValuedParameter('-',Name='o',Delimiter=' '), # Use Ctrl-A's as non-redundant defline separator [T/F] Optional '-c':ValuedParameter('-',Name='c',Delimiter=' '), # Dump the entire database in fasta format [T/F] Optional '-D':ValuedParameter('-',Name='D',Delimiter=' '), # Range of sequence to extract (Format: start,stop) # 0 in 'start' refers to the beginning of the sequence # 0 in 'stop' refers to the end of the sequence [String] Optional '-L':ValuedParameter('-',Name='L',Delimiter=' '), # Strand on subsequence (nucleotide only): 1 is top, 2 is bottom [Int] '-S':ValuedParameter('-',Name='S',Delimiter=' '), # Print taxonomic information for requested sequence(s) [T/F] '-T':ValuedParameter('-',Name='T',Delimiter=' '), # Print database information only (overrides all other options) [T/F] '-I':ValuedParameter('-',Name='I',Delimiter=' '), # Retrieve sequences with this PIG [Integer] Optional '-P':ValuedParameter('-',Name='P',Delimiter=' '), } _parameters = {} _parameters.update(_options) _command = 'fastacmd' def _input_as_lines(self,data): if data: self.Parameters['-i']\ .on(super(FastaCmd,self)._input_as_lines(data)) return '' def _input_as_seqs(self,data): lines = [] for i,s in enumerate(data): #will number the sequences 1,2,3,etc. lines.append(''.join(['>',str(i+1)])) lines.append(s) return self._input_as_lines(lines) def _input_as_string(self,data): """Makes data the value of a specific parameter This method returns the empty string. The parameter will be printed automatically once set. """ if data: self.Parameters['-s'].on(data) return '' def _out_filename(self): if self.Parameters['-o'].isOn(): aln_filename = self._absolute(str(self.Parameters['-o'].Value)) else: raise ValueError, "No output file specified." return aln_filename def _get_result_paths(self,data): result = {} if self.Parameters['-o'].isOn(): out_name = self._out_filename() result['FastaOut'] = ResultPath(Path=out_name,IsWritten=True) return result def seqs_to_stream(seqs, ih): """Converts seqs into stream of FASTA records, depending on input handler. Each FASTA record will be a list of lines. """ if ih == '_input_as_multiline_string': recs = FastaFinder(seqs.split('\n')) elif ih == '_input_as_string': recs = FastaFinder(open(seqs)) elif ih == '_input_as_seqs': recs = [['>'+str(i), s] for i, s in enumerate(seqs)] elif ih == '_input_as_lines': recs = FastaFinder(seqs) else: raise TypeError, "Unknown input handler %s" % ih return recs #SOME FUNCTIONS TO EXECUTE THE MOST COMMON TASKS def blast_seqs(seqs, blast_constructor, blast_db=None, blast_mat_root=None, params={}, add_seq_names=True, out_filename=None, WorkingDir=None, SuppressStderr=None, SuppressStdout=None, input_handler=None, HALT_EXEC=False ): """Blast list of sequences. seqs: either file name or list of sequence objects or list of strings or single multiline string containing sequences. WARNING: DECISION RULES FOR INPUT HANDLING HAVE CHANGED. Decision rules for data are as follows. If it's s list, treat as lines, unless add_seq_names is true (in which case treat as list of seqs). If it's a string, test whether it has newlines. If it doesn't have newlines, assume it's a filename. If it does have newlines, it can't be a filename, so assume it's a multiline string containing sequences. If you want to skip the detection and force a specific type of input handler, use input_handler='your_favorite_handler'. add_seq_names: boolean. if True, sequence names are inserted in the list of sequences. if False, it assumes seqs is a list of lines of some proper format that the program can handle """ # set num keep if blast_db: params["-d"] = blast_db if out_filename: params["-o"] = out_filename ih = input_handler or guess_input_handler(seqs, add_seq_names) blast_app = blast_constructor( params=params, blast_mat_root=blast_mat_root, InputHandler=ih, WorkingDir=WorkingDir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout, HALT_EXEC=HALT_EXEC) return blast_app(seqs) def fasta_cmd_get_seqs(acc_list, blast_db=None, is_protein=None, out_filename=None, params={}, WorkingDir="/tmp", SuppressStderr=None, SuppressStdout=None): """Retrieve sequences for list of accessions """ if is_protein is None: params["-p"] = 'G' elif is_protein: params["-p"] = 'T' else: params["-p"] = 'F' if blast_db: params["-d"] = blast_db if out_filename: params["-o"] = out_filename # turn off duplicate accessions params["-a"] = "F" # create Psi-BLAST fasta_cmd = FastaCmd(params=params, InputHandler='_input_as_string', WorkingDir=WorkingDir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout) # return results return fasta_cmd("\"%s\"" % ','.join(acc_list)) def fastacmd_is_crap(line): """Handles missing ids...""" return (not line) or line.isspace() or line.startswith('[') FastaCmdFinder = LabeledRecordFinder(is_fasta_label, ignore=fastacmd_is_crap) def seqs_from_fastacmd(acc_list, blast_db,is_protein=True): """Get dict of description:seq from fastacmd.""" fasta_cmd_res = fasta_cmd_get_seqs(acc_list, blast_db=blast_db, \ is_protein=is_protein) recs = FastaCmdFinder(fasta_cmd_res['StdOut']) result = {} for rec in recs: try: result[rec[0][1:].strip()] = ''.join(map(strip, rec[1:])) except IndexError: #maybe we didn't get a sequence? pass fasta_cmd_res.cleanUp() return result def psiblast_n_neighbors(seqs, n=100, blast_db=None, core_threshold=1e-50, extra_threshold=1e-10, lower_threshold=1e-6, step=100, method="two-step", blast_mat_root=None, params={}, add_seq_names=False, WorkingDir=None, SuppressStderr=None, SuppressStdout=None, input_handler=None, scorer=3, #shotgun with 3 hits needed to keep second_db=None ): """PsiBlasts sequences, stopping when n neighbors are reached. core_threshold: threshold for the core profile (default: 1e-50) extra_threshold: threshold for pulling in additional seqs (default:1e-10) lower_threshold: threshold for seqs in final round (default:1e-6) seqs: either file name or list of sequence objects or list of strings or single multiline string containing sequences. If you want to skip the detection and force a specific type of input handler, use input_handler='your_favorite_handler'. add_seq_names: boolean. if True, sequence names are inserted in the list of sequences. if False, it assumes seqs is a list of lines of some proper format that the program can handle """ if blast_db: params["-d"] = blast_db ih = input_handler or guess_input_handler(seqs, add_seq_names) recs = seqs_to_stream(seqs, ih) #checkpointing can only handle one seq... #set up the parameters for the core and additional runs max_iterations = params['-j'] params['-j'] = 2 #won't checkpoint with single iteration app = PsiBlast(params=params, blast_mat_root=blast_mat_root, InputHandler='_input_as_lines', WorkingDir=WorkingDir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout, ) result = {} for seq in recs: query_id = seq[0][1:].split(None,1)[0] if method == "two-step": result[query_id] = ids_from_seq_two_step(seq, n, max_iterations, \ app, core_threshold, extra_threshold, lower_threshold, second_db) elif method == "lower_threshold": result[query_id] = ids_from_seq_lower_threshold(seq, n, \ max_iterations, app, core_threshold, lower_threshold, step) elif method == "iterative": result[query_id] = ids_from_seqs_iterative(seq, app, \ QMEPsiBlast9, scorer, params['-j'], n) else: raise TypeError, "Got unknown method %s" % method params['-j'] = max_iterations return result def ids_from_seq_two_step(seq, n, max_iterations, app, core_threshold, \ extra_threshold, lower_threshold, second_db=None): """Returns ids that match a seq, using a 2-tiered strategy. Optionally uses a second database for the second search. """ #first time through: reset 'h' and 'e' to core #-h is the e-value threshold for including seqs in the score matrix model app.Parameters['-h'].on(core_threshold) #-e is the e-value threshold for the final blast app.Parameters['-e'].on(core_threshold) checkpoints = [] ids = [] last_num_ids = None for i in range(max_iterations): if checkpoints: app.Parameters['-R'].on(checkpoints[-1]) curr_check = 'checkpoint_%s.chk' % i app.Parameters['-C'].on(curr_check) output = app(seq) #if we didn't write a checkpoint, bail out if not access(curr_check, F_OK): break #if we got here, we wrote a checkpoint file checkpoints.append(curr_check) result = list(output.get('BlastOut', output['StdOut'])) output.cleanUp() if result: ids = LastProteinIds9(result,keep_values=True,filter_identity=False) num_ids = len(ids) if num_ids >= n: break if num_ids == last_num_ids: break last_num_ids = num_ids #if we didn't write any checkpoints, second run won't work, so return ids if not checkpoints: return ids #if we got too many ids and don't have a second database, return the ids we got if (not second_db) and num_ids >= n: return ids #second time through: reset 'h' and 'e' to get extra hits, and switch the #database if appropriate app.Parameters['-h'].on(extra_threshold) app.Parameters['-e'].on(lower_threshold) if second_db: app.Parameters['-d'].on(second_db) for i in range(max_iterations): #will always have last_check if we get here app.Parameters['-R'].on(checkpoints[-1]) curr_check = 'checkpoint_b_%s.chk' % i app.Parameters['-C'].on(curr_check) output = app(seq) #bail out if we couldn't write a checkpoint if not access(curr_check, F_OK): break #if we got here, the checkpoint worked checkpoints.append(curr_check) result = list(output.get('BlastOut', output['StdOut'])) if result: ids = LastProteinIds9(result,keep_values=True,filter_identity=False) num_ids = len(ids) if num_ids >= n: break if num_ids == last_num_ids: break last_num_ids = num_ids #return the ids we got. may not be as many as we wanted. for c in checkpoints: remove(c) return ids class ThresholdFound(Exception): pass def ids_from_seq_lower_threshold(seq, n, max_iterations, app, core_threshold, \ lower_threshold, step=100): """Returns ids that match a seq, decreasing the sensitivity.""" last_num_ids = None checkpoints = [] cp_name_base = make_unique_str() # cache ides for each iteration # store { iteration_num:(core_threshold, [list of matching ids]) } all_ids = {} try: i=0 while 1: #-h is the e-value threshold for inclusion in the score matrix model app.Parameters['-h'].on(core_threshold) app.Parameters['-e'].on(core_threshold) if core_threshold > lower_threshold: raise ThresholdFound if checkpoints: #-R restarts from a previously stored file app.Parameters['-R'].on(checkpoints[-1]) #store the score model from this iteration curr_check = 'checkpoint_' + cp_name_base + '_' + str(i) + \ '.chk' app.Parameters['-C'].on(curr_check) output = app(seq) result = list(output.get('BlastOut', output['StdOut'])) #sometimes fails on first try -- don't know why, but this seems #to fix problem while not result: output = app(seq) result = list(output.get('BlastOut', output['StdOut'])) ids = LastProteinIds9(result,keep_values=True,filter_identity=False) output.cleanUp() all_ids[i + 1] = (core_threshold, copy(ids)) if not access(curr_check, F_OK): raise ThresholdFound checkpoints.append(curr_check) num_ids = len(ids) if num_ids >= n: raise ThresholdFound last_num_ids = num_ids core_threshold *= step if i >= max_iterations - 1: #because max_iterations is 1-based raise ThresholdFound i += 1 except ThresholdFound: for c in checkpoints: remove(c) #turn app.Parameters['-R'] off so that for the next file it does not #try and read in a checkpoint file that is not there app.Parameters['-R'].off() return ids, i + 1, all_ids def make_unique_str(num_chars=20): """make a random string of characters for a temp filename""" chars = 'abcdefghigklmnopqrstuvwxyz' all_chars = chars + chars.upper() + '01234567890' picks = list(all_chars) return ''.join([choice(picks) for i in range(num_chars)]) def make_subject_match_scorer(count): def subject_match_scorer(checked_ids): """From {subject:{query:score}} returns subject ids w/ >= count hits. Useful for elminating subjects with few homologs. """ return [key for key, val in checked_ids.items() if len(val) >= count] return subject_match_scorer def make_shotgun_scorer(count): def shotgun_scorer(checked_ids): """From {subject:{query:score}} returns any ids w/ >= count hits. A hit counts towards a sequence's score if it was either the subject or the query, but we don't double-count (subject, query) pairs, i.e. if A hits B and B hits A, only one (A,B) hit will be counted, although it will be counted as both (A,B) and (B,A) (i.e. it will help preserve both A and B). """ result = {} for subject, val in checked_ids.items(): for query in val.keys(): if subject not in result: result[subject] = {} result[subject][query] = True if query not in result: result[query] = {} result[query][subject] = True return [key for key, val in result.items() if len(val) >= count] return shotgun_scorer def keep_everything_scorer(checked_ids): """Returns every query and every match in checked_ids, with best score.""" result = checked_ids.keys() for i in checked_ids.values(): result.extend(i.keys()) return dict.fromkeys(result).keys() def ids_from_seqs_iterative(seqs, app, query_parser, \ scorer=keep_everything_scorer, max_iterations=None, blast_db=None,\ max_seqs=None, ): """Gets the ids from each seq, then does each additional id until all done. If scorer is passed in as an int, uses shotgun scorer with that # hits. """ if isinstance(scorer, int): scorer = make_shotgun_scorer(scorer) seqs_to_check = list(seqs) checked_ids = {} curr_iteration = 0 while seqs_to_check: unchecked_ids = {} #pass seqs to command all_output = app(seqs_to_check) output = all_output.get('BlastOut', all_output['StdOut']) for query_id, match_id, match_score in query_parser(output): if query_id not in checked_ids: checked_ids[query_id] = {} checked_ids[query_id][match_id] = match_score if match_id not in checked_ids: unchecked_ids[match_id] = True all_output.cleanUp() if unchecked_ids: seq_file = fasta_cmd_get_seqs(unchecked_ids.keys(), app.Parameters['-d'].Value)['StdOut'] seqs_to_check = [] for s in FastaCmdFinder(fasta_cmd_get_seqs(\ unchecked_ids.keys(), app.Parameters['-d'].Value)['StdOut']): seqs_to_check.extend(s) else: seqs_to_check = [] #bail out if max iterations or max seqs was defined and we've reached it curr_iteration += 1 if max_iterations and (curr_iteration >= max_iterations): break if max_seqs: curr = scorer(checked_ids) if len(curr) >= max_seqs: return curr return scorer(checked_ids) #scorer should return list of good ids def blastp(seqs, blast_db="nr", e_value="1e-20", max_hits=200, working_dir="/tmp", blast_mat_root=None, extra_params={}): """ Returns BlastResult from input seqs, using blastp. Need to add doc string """ # set up params to use with blastp params = { # matrix "-M":"BLOSUM62", # max procs "-a":"1", # expectation "-e":e_value, # max seqs to show "-b":max_hits, # max one line descriptions "-v":max_hits, # program "-p":"blastp" } params.update(extra_params) # blast blast_res = blast_seqs(seqs, Blastall, blast_mat_root=blast_mat_root, blast_db=blast_db, params=params, add_seq_names=False, WorkingDir=working_dir ) # get prot id map if blast_res['StdOut']: lines = [x for x in blast_res['StdOut']] return BlastResult(lines) return None def blastn(seqs, blast_db="nt", e_value="1e-20", max_hits=200, working_dir="/tmp", blast_mat_root=None, extra_params={}): """ Returns BlastResult from input seqs, using blastn. Need to add doc string """ # set up params to use with blastp params = { # matrix "-M":"BLOSUM62", # max procs "-a":"1", # expectation "-e":e_value, # max seqs to show "-b":max_hits, # max one line descriptions "-v":max_hits, # program "-p":"blastn" } params.update(extra_params) # blast blast_res = blast_seqs(seqs, Blastall, blast_mat_root=blast_mat_root, blast_db=blast_db, params=params, add_seq_names=False, WorkingDir=working_dir ) # get prot id map if blast_res['StdOut']: lines = [x for x in blast_res['StdOut']] return BlastResult(lines) return None def blastx(seqs, params=None): """Returns BlastResults from input seqs, using blastx.""" raise NotImplementedError def tblastx(seqs, params=None): """Returns BlastResults from input seqs, using tblastx.""" raise NotImplementedError def psiblast(seqs, params=None): """Returns BlastResults from input seqs, using psiblast.""" raise NotImplementedError def reciprocal_best_blast_hit(query_id, db_1, db_2, exclude_self_hits=True,\ params=None): """Returns best hit in db_2 that maps back to query_id in db_1, or None. exclude_self_hits: if True (the default), returns the best hit that doesn't have the same id. Otherwise, will return the same id if it is in both databases (assuming it's the same sequence in both). """ raise NotImplementedError #make with factory functions for the blast hits if __name__ == "__main__": print "Debug. examples of how i've been using." print "Example of straightforward BLAST" # WARNING: I changed a bunch of stuff to make testing easier, since nr doesn't # fit in memory on my laptop. I created a database 'eco' using formatdb on the # E. coli K12 fasta file from this URL: # ftp://ftp.ncbi.nlm.nih.gov/genomes/Bacteria/Escherichia_coli_K12/NC_000913.faa # Because we're blasting an archaeal sequence against one bacterial genome, I # relaxed the inclusion thresholds substantially. DO NOT USE THESE AGAINST NR! in_filename = "test_seq.fasta" out_filename = "test.out" # if blast env variable set, can just say 'nr' #BLAST_DB = "/home/hamady/quicksand/data/blast/db/nr" BLAST_DB = 'nr' #'nr' BLAST_MAT_ROOT="/home/hamady/apps/blast-2.2.9/data" #BLAST_MAT_ROOT='/Users/rob/ncbi/data' # set up params to use with iterative #print seqs_from_fastacmd(['16766313'], 'nr', True) #raise ValueError, "dbug" params = { # matrix "-M":"PAM70", # max procs "-a":2, # expect "-e":1e-15, # blastall # # program # "-p":"blastp", # psi-blast # max iterations "-j":2, # max seqs to show "-b":50, # inclusion "-h":1e-2, } in_seqs = """>stm:STMabcdef thrA; aspartokinase I MRVLKFGGTSVANAERFLRVADILESNARQGQVATVLSAPAKITNHLVAMIEKTIGGQDA LPNISDAERIFSDLLAGLASAQPGFPLARLKMVVEQEFAQIKHVLHGISLLGQCPDSINA ALICRGEKMSIAIMAGLLEARGHRVTVIDPVEKLLAVGHYLESTVDIAESTRRIAASQIP ADHMILMAGFTAGNEKGELVVLGRNGSDYSAAVLAACLRADCCEIWTDVDGVYTCDPRQV PDARLLKSMSYQEAMELSYFGAKVLHPRTITPIAQFQIPCLIKNTGNPQAPGTLIGASDS DDNLPVKGISNLNNMAMFSVSGPGMKGMIGMAARVFAAMSRAGISVVLITQSSSEYSISF CVPQSDCARARRAMQDEFYLELKEGLLEPLAVTERLAIISVVGDGMRTLRGISAKFFAAL ARANINIVAIAQGSSERSISVVVNNDDATTGVRVTHQMLFNTDQVIEVFVIGVGGVGGAL""" # The following should now give the same output: # # in_seqs = 'tiny.faa' #tiny.faa in cwd contains the sequence above # # in_seqs = """>gi|2501594|sp|Q57997|Y577_METJA PROTEIN MJ0577 #MSVMYKKILYPTDFSETAEIALKHVKAFKTLKAEEVILLHVIDEREIKKRDIFSLLLGVAGLNKSVEEFE #NELKNKLTEEAKNKMENIKKELEDVGFKVKDIIVVGIPHEEIVKIAEDEGVDIIIMGSHGKTNLKEILLG #SVTENVIKKSNKPVLVVKRKNS""".split() #lines instead of multiline string # blast_res = blast_seqs(in_seqs, Blastall, blast_mat_root=BLAST_MAT_ROOT, add_seq_names=False, blast_db=BLAST_DB, params={'-p': 'blastp','-e': '1','-m': 9}, out_filename=out_filename) print [x for x in blast_res['StdOut']] print [x for x in blast_res['StdErr']] print blast_res #for x in blast_res['BlastOut']: # print x.rstrip() blast_res.cleanUp() #print '\n\n' #print "Example of psiblast_n_neighbors" #print "Method 1: two-step with high- and low-confidence matches" #print psiblast_n_neighbors(in_seqs, n=10, blast_db=BLAST_DB, \ # method="two-step", blast_mat_root=BLAST_MAT_ROOT,params=params,\ # core_threshold=1e-5, extra_threshold=1e-2, lower_threshold=1e-1) #print #print "Method 2: keep lowering threshold" #print psiblast_n_neighbors(in_seqs, n=10, blast_db=BLAST_DB, \ # method="lower_threshold", blast_mat_root=BLAST_MAT_ROOT,params=params, # core_threshold=1e-6, lower_threshold=1e-2) #print #print "Method 3: psi-blast shotgun" #print psiblast_n_neighbors(in_seqs, n=10, blast_db=BLAST_DB, \ # method="iterative", blast_mat_root=BLAST_MAT_ROOT,params=params, # core_threshold=1e-5, lower_threshold=1e-2) #print #print "Method 4: two-step with high- and low-confidence matches, diff dbs" #print psiblast_n_neighbors(in_seqs, n=10, blast_db=BLAST_DB, \ # method="two-step", blast_mat_root=BLAST_MAT_ROOT,params=params,\ # core_threshold=1e-5, extra_threshold=1e-2, lower_threshold=1e-1, second_db='stm') #print pycogent-1.9/cogent/app/blat.py000066400000000000000000000402641273014367000165570ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for BLAT v34""" from cogent.app.parameters import FlagParameter, ValuedParameter, \ MixedParameter, FilePath from cogent.app.util import CommandLineApplication, ResultPath, \ ApplicationError, get_tmp_filename from cogent import DNA, PROTEIN from cogent.core.genetic_code import DEFAULT as standard_code from cogent.parse.fasta import MinimalFastaParser from os import remove from os.path import isabs __author__ = "Adam Robbins-Pianka" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Adam Robbins-Pianka", "Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Adam Robbins-Pianka" __email__ = "adam.robbinspianka@colorado.edu" __status__ = "Production" class Blat(CommandLineApplication): """BLAT generic application controller""" _command = 'blat' _input_handler = "_input_as_list" _database_types = ['dna', 'prot', 'dnax'] _query_types = ['dna', 'rna', 'prot', 'dnax', 'rnax'] _mask_types = ['lower', 'upper', 'out', 'file.out'] _out_types = ['psl', 'pslx', 'axt', 'maf', 'sim4', 'wublast', 'blast', 'blast8', 'blast9'] _valid_combinations = [('dna', 'dna'), ('dna', 'rna'), ('prot', 'prot'), ('dnax', 'prot'), ('dnax', 'dnax'), ('dnax', 'rnax')] _database = None _query = None _output = None _parameters = { # database type (dna, prot, or dnax, where dnax is DNA sequence # translated in six frames to protein '-t':ValuedParameter('-',Delimiter='=',Name='t'), # query type (dna, rna, prot, dnax, rnax, where rnax is DNA sequence # translated in three frames to protein '-q':ValuedParameter('-',Delimiter='=',Name='q'), # Use overused tile file N.ooc, and N should correspond to the tileSize '-ooc':ValuedParameter('-',Delimiter='=',Name='ooc', IsPath=True), # Sets the size of at match that that triggers an alignment '-tileSize':ValuedParameter('-',Delimiter='=',Name='tileSize'), # Spacing between tiles. '-stepSize':ValuedParameter('-',Delimiter='=',Name='stepSize'), # If set to 1, allows one mismatch in the tile and still triggers # an alignment. '-oneOff':ValuedParameter('-',Delimiter='=',Name='oneOff'), # sets the number of tile matches '-minMatch':ValuedParameter('-',Delimiter='=',Name='minMatch'), #sets the minimum score '-minScore':ValuedParameter('-',Delimiter='=',Name='minScore'), # sets the minimum sequence identity in percent '-minIdentity':ValuedParameter('-',Delimiter='=',Name='minIdentity'), # sets the size o the maximum gap between tiles in a clump '-maxGap':ValuedParameter('-',Delimiter='=',Name='maxGap'), # make an overused tile file. Target needs to be complete genome. '-makeOoc':ValuedParameter('-',Delimiter='=',Name='makeOoc', IsPath=True), # sets the number of repetitions of a tile allowed before it is marked # as overused '-repMatch':ValuedParameter('-',Delimiter='=',Name='repMatch'), # mask out repeats. Alignments won't be started in masked region but # may extend through it in nucleotide searches. Masked areas are # ignored entirely in protein or translated searches. Types are: # lower, upper, out, file.out (file.out - mask database according to # RepeatMasker file.out '-mask':ValuedParameter('-',Delimiter='=',Name='mask'), # Mask out repeats in query sequence. similar to -mask but for query # rather than target sequence '-qMask':ValuedParameter('-',Delimiter='=',Name='qMask'), # repeat bases will not be masked in any way, but matches in # repeat areas will be reported separately from matches in other # areas in the pls output '-repeats':ValuedParameter('-',Delimiter='=',Name='repeats'), # minimum percent divergence of repeats to allow them to be unmasked '-minRepDivergence':ValuedParameter('-',Delimiter='=', Name='minRepDivergence'), # output dot every N sequences to show program's progress '-dots':ValuedParameter('-',Delimiter='=',Name='dots'), # controls output file format. One of: # psl - Default. Tab separated format, no sequence # pslx - Tab separated format with sequence # axt - blastz-associated axt format # maf - multiz-associated maf format # sim4 - similar to sim4 format # wublast - similar to wublast format # blast - similar to NCBI blast format # blast8- NCBI blast tabular format # blast9 - NCBI blast tabular format with comments '-out':ValuedParameter('-',Delimiter='=',Name='out'), # sets maximum intron size '-maxIntron':ValuedParameter('-',Delimiter='=',Name='maxIntron'), # suppress column headers in psl output '-noHead':FlagParameter('-',Name='noHead'), # trim leading poly-T '-trimT':FlagParameter('-',Name='trimT'), # do not trim trailing poly-A '-noTrimA':FlagParameter('-',Name='noTrimA'), # Remove poly-A tail from qSize as well as alignments in psl output '-trimHardA':FlagParameter('-',Name='trimHardA'), # run for fast DNA/DNA remapping - not allowing introns, # requiring high %ID '-fastMap':FlagParameter('-',Name='fastMap'), # for high quality mRNAs, look harder for small initial and terminal # exons '-fine':FlagParameter('-',Name='fine'), # Allows extension of alignment through large blocks of N's '-extendThroughN':FlagParameter('-',Name='extendThroughN') } def _get_result_paths(self, data): """Returns the file location for result output """ return {'output':ResultPath(data[2], IsWritten=True)} def _get_base_command(self): """Gets the command that will be run when the app controller is called. """ command_parts = [] cd_command = ''.join(['cd ',str(self.WorkingDir),';']) if self._command is None: raise ApplicationError, '_command has not been set.' command = self._command parameters = sorted([str(x) for x in self.Parameters.values() if str(x)]) synonyms = self._synonyms command_parts.append(cd_command) command_parts.append(command) command_parts.append(self._database) # Positional argument command_parts.append(self._query) # Positional argument command_parts += parameters if self._output: command_parts.append(self._output.Path) # Positional return self._command_delimiter.join(filter(None,command_parts)).strip() BaseCommand = property(_get_base_command) def _input_as_list(self, data): '''Takes the positional arguments as input in a list. The list input here should be [query_file_path, database_file_path, output_file_path]''' query, database, output = data if (not isabs(database)) \ or (not isabs(query)) \ or (not isabs(output)): raise ApplicationError, "Only absolute paths allowed.\n%s" %\ ', '.join(data) self._database = FilePath(database) self._query = FilePath(query) self._output = ResultPath(output, IsWritten=True) ## check parameters that can only take a particular set of values # check combination of databse and query type if self.Parameters['-t'].isOn() and self.Parameters['-q'].isOn() and \ (self.Parameters['-t'].Value, self.Parameters['-q'].Value) not in \ self._valid_combinations: error_message = "Invalid combination of database and query " + \ "types ('%s', '%s').\n" % \ (self.Paramters['-t'].Value, self.Parameters['-q'].Value) error_message += "Must be one of: %s\n" % \ repr(self._valid_combinations) raise ApplicationError(error_message) # check database type if self.Parameters['-t'].isOn() and \ self.Parameters['-t'].Value not in self._database_types: error_message = "Invalid database type %s\n" % \ self.Parameters['-t'].Value error_message += "Allowed values: %s\n" % \ ', '.join(self._database_types) raise ApplicationError(error_message) # check query type if self.Parameters['-q'].isOn() and \ self.Parameters['-q'].Value not in self._query_types: error_message = "Invalid query type %s\n" % \ self.Parameters['-q'].Value error_message += "Allowed values: %s\n" % \ ', '.join(self._query_types) raise ApplicationError(error_message) # check mask type if self.Parameters['-mask'].isOn() and \ self.Parameters['-mask'].Value not in self._mask_types: error_message = "Invalid mask type %s\n" % \ self.Parameters['-mask'] error_message += "Allowed Values: %s\n" % \ ', '.join(self._mask_types) raise ApplicationError(error_message) # check qmask type if self.Parameters['-qMask'].isOn() and \ self.Parameters['-qMask'].Value not in self._mask_types: error_message = "Invalid qMask type %s\n" % \ self.Parameters['-qMask'].Value error_message += "Allowed values: %s\n" % \ ', '.join(self._mask_types) raise ApplicationError(error_message) # check repeat type if self.Parameters['-repeats'].isOn() and \ self.Parameters['-repeats'].Value not in self._mask_types: error_message = "Invalid repeat type %s\n" % \ self.Parameters['-repeat'].Value error_message += "Allowed values: %s\n" % \ ', '.join(self._mask_types) raise ApplicationError(error_message) # check output format if self.Parameters['-out'].isOn() and \ self.Parameters['-out'].Value not in self._out_types: error_message = "Invalid output type %s\n" % \ self.Parameters['-out'] error_message += "Allowed values: %s\n" % \ ', '.join(self._out_types) raise ApplicationError(error_message) return '' def assign_reads_to_database(query_fasta_fp, database_fasta_fp, output_fp, params=None): """Assign a set of query sequences to a reference database query_fasta_fp : absolute file path to query sequences database_fasta_fp : absolute file path to the reference database output_fp : absolute file path of the output file to write params : dict of BLAT specific parameters. This method returns an open file object. The output format defaults to blast9 and should be parsable by the PyCogent BLAST parsers. """ if params is None: params = {} if '-out' not in params: params['-out'] = 'blast9' blat = Blat(params = params) result = blat([query_fasta_fp, database_fasta_fp, output_fp]) return result['output'] def assign_dna_reads_to_dna_database(query_fasta_fp, database_fasta_fp, output_fp, params = None): """Assign DNA reads to a database fasta of DNA sequences. Wraps assign_reads_to_database, setting database and query types. All parameters are set to default unless params is passed. query_fasta_fp: absolute path to the query fasta file containing DNA sequences. database_fasta_fp: absolute path to the database fasta file containing DNA sequences. output_fp: absolute path where the output file will be generated. params: optional. dict containing parameter settings to be used instead of default values. Cannot change database or query file types from dna and dna, respectively. This method returns an open file object. The output format defaults to blast9 and should be parsable by the PyCogent BLAST parsers. """ if params is None: params = {} my_params = {'-t': 'dna', '-q': 'dna' } # if the user specified parameters other than default, then use them. # However, if they try to change the database or query types, raise an # applciation error. if '-t' in params or '-q' in params: raise ApplicationError("Cannot change database or query types when " +\ "using assign_dna_reads_to_dna_database. " +\ "Use assign_reads_to_database instead.\n") my_params.update(params) result = assign_reads_to_database(query_fasta_fp, database_fasta_fp, output_fp, my_params) return result def assign_dna_reads_to_protein_database(query_fasta_fp, database_fasta_fp, output_fp, temp_dir = "/tmp", params = None): """Assign DNA reads to a database fasta of protein sequences. Wraps assign_reads_to_database, setting database and query types. All parameters are set to default unless params is passed. A temporary file must be written containing the translated sequences from the input query fasta file because BLAT cannot do this automatically. query_fasta_fp: absolute path to the query fasta file containing DNA sequences. database_fasta_fp: absolute path to the database fasta file containing protein sequences. output_fp: absolute path where the output file will be generated. temp_dir: optional. Change the location where the translated sequences will be written before being used as the query. Defaults to /tmp. params: optional. dict containing parameter settings to be used instead of default values. Cannot change database or query file types from protein and dna, respectively. This method returns an open file object. The output format defaults to blast9 and should be parsable by the PyCogent BLAST parsers. """ if params is None: params = {} my_params = {'-t': 'prot', '-q': 'prot' } # make sure temp_dir specifies an absolute path if not isabs(temp_dir): raise ApplicationError, "temp_dir must be an absolute path." # if the user specified parameters other than default, then use them. # However, if they try to change the database or query types, raise an # applciation error. if '-t' in params or '-q' in params: raise ApplicationError, "Cannot change database or query types " + \ "when using " + \ "assign_dna_reads_to_dna_database. " + \ "Use assign_reads_to_database instead." my_params.update(params) # get six-frame translation of the input DNA sequences and write them to # temporary file. tmp = get_tmp_filename(tmp_dir=temp_dir, result_constructor=str) tmp_out = open(tmp, 'w') for label, sequence in MinimalFastaParser(open(query_fasta_fp)): seq_id = label.split()[0] s = DNA.makeSequence(sequence) translations = standard_code.sixframes(s) frames = [1,2,3,-1,-2,-3] translations = dict(zip(frames, translations)) for frame, translation in sorted(translations.iteritems()): entry = '>{seq_id}_frame_{frame}\n{trans}\n' entry = entry.format(seq_id=seq_id, frame=frame, trans=translation) tmp_out.write(entry) tmp_out.close() result = assign_reads_to_database(tmp, database_fasta_fp, output_fp, \ params = my_params) remove(tmp) return result pycogent-1.9/cogent/app/bwa.py000066400000000000000000000627121273014367000164100ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for BWA 0.6.2 (release 19 June 2012)""" from cogent.app.parameters import FlagParameter, ValuedParameter, \ MixedParameter, FilePath from cogent.app.util import CommandLineApplication, ResultPath, \ ApplicationError, get_tmp_filename from os.path import isabs __author__ = "Adam Robbins-Pianka" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Adam Robbins-Pianka", "Jai Ram Rideout"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Adam Robbins-Pianka" __email__ = "adam.robbinspianka@colorado.edu" __status__ = "Production" # helper functions for argument checking def is_int(x): # return true if it's an int return ((type(x) == int) or \ # or it's a string that is all digits (type(x) == str and x.isdigit()) or \ # otherwise return False False) def is_float(x): return (is_int(x) or \ # or if it's a float (type(x) == float) or \ # or it's a string with exactly one decimal and all digits on both sides of # the decimal (type(x) == str and '.' in x and all(map(str.isdigit, x.split('.', 1)))) \ # otherwise return False or False) #Base class class BWA(CommandLineApplication): """BWA generic application controller. Do not instantiate directly. Instead of instantiating this class, instantiate a subclass for each subcommand. Available subclasses are: BWA_index BWA_aln BWA_samse BWA_sampe BWA_bwasw """ # all subclasses will accept dictionaries as input that specify input # and output files. The required (and optional) types of input and output # files differ by subcommand. _input_handler = "_input_as_dict" # the main command. The program bwa should be in the PATH _command = "bwa" # holds the values of the dict handled by the input handler _input = {} # Each subclass can have a dictionary (keys = option names, e.g., -a # and values = boolean fucntions) called _valid_arguments # that specifies checks to be made on the parameters. def check_arguments(self): """Sanity check the arguments passed in. Uses the boolean functions specified in the subclasses in the _valid_arguments dictionary to determine if an argument is valid or invalid. """ for k, v in self.Parameters.iteritems(): if self.Parameters[k].isOn(): if k in self._valid_arguments: if not self._valid_arguments[k](v.Value): error_message = 'Invalid argument (%s) ' % v.Value error_message += 'for parameter %s\n' % k raise ApplicationError(error_message) def _get_base_command(self): """ Returns the full command string Overridden here because there are positional arguments (specifically the input and output files). """ command_parts = [] # Append a change directory to the beginning of the command to change # to self.WorkingDir before running the command # WorkingDir should be in quotes -- filenames might contain spaces cd_command = ''.join(['cd ',str(self.WorkingDir),';']) if self._command is None: raise ApplicationError, '_command has not been set.' command = self._command # also make sure there's a subcommand! if self._subcommand is None: raise ApplicationError, '_subcommand has not been set.' subcommand = self._subcommand # sorting makes testing easier, since the options will be written out # in alphabetical order. Could of course use option parsing scripts # in cogent for this, but this works as well. parameters = sorted([str(x) for x in self.Parameters.values() if str(x)]) synonyms = self._synonyms command_parts.append(cd_command) command_parts.append(command) # add in subcommand command_parts.append(subcommand) command_parts += parameters # add in the positional arguments in the correct order for k in self._input_order: # this check is necessary to account for optional positional # arguments, such as the mate file for bwa bwasw # Note that the input handler will ensure that all required # parameters have valid values if k in self._input: command_parts.append(self._input[k]) return self._command_delimiter.join(command_parts).strip() BaseCommand = property(_get_base_command) def _input_as_dict(self, data): """Takes dictionary that sets input and output files. Valid keys for the dictionary are specified in the subclasses. File paths must be absolute. """ # clear self._input; ready to receive new input and output files self._input = {} # Check that the arguments to the # subcommand-specific parameters are valid self.check_arguments() # Ensure that we have all required input (file I/O) for k in self._input_order: # N.B.: optional positional arguments begin with underscore (_)! # (e.g., see _mate_in for bwa bwasw) if k[0] != '_' and k not in data: raise ApplicationError, "Missing required input %s" % k # Set values for input and output files for k in data: # check for unexpected keys in the dict if k not in self._input_order: error_message = "Invalid input arguments (%s)\n" % k error_message += "Valid keys are: %s" % repr(self._input_order) raise ApplicationError(error_message + '\n') # check for absolute paths if not isabs(data[k][0]): raise ApplicationError, "Only absolute paths allowed.\n%s" %\ repr(data) self._input[k] = data[k] # if there is a -f option to specify an output file, force the user to # use it (otherwise things to to stdout) if '-f' in self.Parameters and not self.Parameters['-f'].isOn(): raise ApplicationError, "Please specify an output file with -f" return '' class BWA_index(BWA): """Controls the "index" subcommand of the bwa application. Valid input keys are: fasta_in """ # the subcommand for bwa index _subcommand = "index" _parameters = { # which algorithm to use. # is # IS linear-time algorithm for constructing suffix array. It requires # 5.37N memory where N is the size of the database. IS is moderately # fast, but does not work with database larger than 2GB. IS is the # default algorithm due to its simplicity. The current codes for IS # algorithm are reimplemented by Yuta Mori. # # bwtsw # Algorithm implemented in BWT-SW. This method works with the whole # human genome, but it does not work with database smaller than 10MB # and it is usually slower than IS. # # DEFAULTs to auto-select (based on input fasta file size) '-a':ValuedParameter('-', Delimiter=' ', Name='a'), # prefix for the output index. # DEFAULTs to the base name of the input fasta file '-p':ValuedParameter('-', Delimiter=' ', Name='p'), # index files named as .64.* instead of .* '-6':FlagParameter('-', Name='6') } # The -a command can take on of only two possible values # the -p command allows the user to specify a prefix; for our purposes, # this prefix should be an abolute path _valid_arguments = { '-a': lambda x: x in ['is', 'bwtsw'], '-p': isabs } # For the position specific arguments, this is the order that they will # be written in the base command # input file keys beginning with _ are optional inputs _input_order = ['fasta_in'] def _get_result_paths(self, data): """Gets the results for a run of bwa index. bwa index outputs 5 files when the index is created. The filename prefix will be the same as the input fasta, unless overridden with the -p option, and the 5 extensions are listed below: .amb .ann .bwt .pac .sa and these extentions (including the period) are the keys to the dictionary that is returned. """ # determine the names of the files. The name will be the same as the # input fasta file unless overridden with the -p option if self.Parameters['-p'].isOn(): prefix = self.Parameters['-p'].Value else: prefix = data['fasta_in'] # the 5 output file suffixes suffixes = ['.amb', '.ann', '.bwt', '.pac', '.sa'] out_files = {} for suffix in suffixes: out_files[suffix] = ResultPath(prefix+suffix, IsWritten=True) return out_files class BWA_aln(BWA): """Controls the "aln" subcommand of the bwa application. Valid input keys are: prefix, fastq_in """ _parameters = { # max #diff (int) or missing prob under 0.02 err rate (float) [0.04] '-n': ValuedParameter('-', Delimiter=' ', Name='n'), #maximum number or fraction of gap opens [1] '-o': ValuedParameter('-', Delimiter=' ', Name='o'), #maximum number of gap extensions, -1 for disabling long gaps [-1] '-e': ValuedParameter('-', Delimiter=' ', Name='e'), #do not put an indel within bp towards the ends [5] '-i': ValuedParameter('-', Delimiter=' ', Name='i'), #maximum occurrences for extending a long deletion [10] '-d': ValuedParameter('-', Delimiter=' ', Name='d'), #seed length [32] '-l': ValuedParameter('-', Delimiter=' ', Name='l'), #maximum differences in the seed [2] '-k': ValuedParameter('-', Delimiter=' ', Name='k'), #maximum entries in the queue [2000000] '-m': ValuedParameter('-', Delimiter=' ', Name='m'), #number of threads [1] '-t': ValuedParameter('-', Delimiter=' ', Name='t'), #mismatch penalty [3] '-M': ValuedParameter('-', Delimiter=' ', Name='M'), #gap open penalty [11] '-O': ValuedParameter('-', Delimiter=' ', Name='O'), #gap extension penalty [4] '-E': ValuedParameter('-', Delimiter=' ', Name='E'), #stop searching when there are > equally best hits [30] '-R': ValuedParameter('-', Delimiter=' ', Name='R'), #quality threshold for read trimming down to 35bp [0] '-q': ValuedParameter('-', Delimiter=' ', Name='q'), #file to write output to instead of stdout '-f': ValuedParameter('-', Delimiter=' ', Name='f'), #length of barcode '-B': ValuedParameter('-', Delimiter=' ', Name='B'), #log-scaled gap penalty for long deletions '-L': FlagParameter('-', Name='L'), #non-iterative mode: search for all n-difference hits (slooow) '-N': FlagParameter('-', Name='N'), #the input is in the Illumina 1.3+ FASTQ-like format '-I': FlagParameter('-', Name='I'), #the input read file is in the BAM format '-b': FlagParameter('-', Name='b'), #use single-end reads only (effective with -b) '-0': FlagParameter('-', Name='0'), #use the 1st read in a pair (effective with -b) '-1': FlagParameter('-', Name='1'), #use the 2nd read in a pair (effective with -b) '-2': FlagParameter('-', Name='2'), #filter Casava-filtered sequences '-Y': FlagParameter('-', Name='Y') } # the subcommand for bwa aln _subcommand = 'aln' _valid_arguments = { # check to see if this is decimal numbers '-n': is_float, # check to see if these are integers '-o': is_int, '-e': is_int, '-i': is_int, '-d': is_int, '-l': is_int, '-k': is_int, '-m': is_int, '-t': is_int, '-M': is_int, '-O': is_int, '-E': is_int, '-R': is_int, '-q': is_int, '-B': is_int, # check to see if this is an absolute file path '-f': isabs } # input file keys beginning with _ are optional inputs _input_order = ['prefix', 'fastq_in'] def _get_result_paths(self, data): """Gets the result file for a bwa aln run. There is only one output file of a bwa aln run, a .sai file and it can be retrieved with the key 'output'. """ return {'output': ResultPath(self.Parameters['-f'].Value, IsWritten=True)} class BWA_samse(BWA): """Controls the "samse" subcommand of the bwa application. Valid input keys are: prefix, sai_in, fastq_in """ _parameters = { # Maximum number of alignments to output in the XA tag for reads # paired properly. If a read has more than this number of hits, the # XA tag will not be written '-n': ValuedParameter('-', Delimiter=' ', Name='n'), #file to write output to instead of stdout '-f': ValuedParameter('-', Delimiter=' ', Name='f'), # Specify the read group in a format like '@RG\tID:foo\tSM:bar' '-r': ValuedParameter('-', Delimiter=' ', Name='r') } # the subcommand for samse _subcommand = 'samse' _valid_arguments = { # make sure that this is an int '-n': is_int, # check to see if this is an absolute file path '-f': isabs } # input file keys beginning with _ are optional inputs _input_order = ['prefix', 'sai_in', 'fastq_in'] def _get_result_paths(self, data): """Gets the result file for a bwa samse run. There is only one output file of a bwa samse run, a .sam file and it can be retrieved with the key 'output'. """ return {'output': ResultPath(self.Parameters['-f'].Value, IsWritten=True)} class BWA_sampe(BWA): """Controls the "sampe" subcommand of the bwa application. Valid input keys are: prefix, sai1_in, sai2_in, fastq1_in, fastq2_in """ _parameters = { # Maximum insert size for a read pair to be considered being mapped # properly '-a': ValuedParameter('-', Delimiter=' ', Name='a'), # Maximum occurrences of a read for pairing '-o': ValuedParameter('-', Delimiter=' ', Name='o'), # Load the entire FM-index into memory to reduce disk operations '-P': FlagParameter('-', Name='P'), # maximum hits to output for paired reads [3] '-n': ValuedParameter('-', Delimiter=' ', Name='n'), # maximum hits to output for discordant pairs [10] '-N': ValuedParameter('-', Delimiter=' ', Name='N'), #file to write output to instead of stdout '-f': ValuedParameter('-', Delimiter=' ', Name='f'), # Specify the read group in a format like '@RG\tID:foo\tSM:bar' '-r': ValuedParameter('-', Delimiter=' ', Name='r'), # disable Smith-Waterman for the unmapped mate '-s': FlagParameter('-', Name='s'), # prior of chimeric rate (lower bound) [1.0e-05] '-c': ValuedParameter('-', Delimiter= ' ', Name='c'), # disable insert size estimate (force -s) '-A': FlagParameter('-', Name='A') } # the subcommand for sampe _subcommand = 'sampe' _valid_arguments = { # make sure this is a float '-c': is_float, # make sure these are all ints '-a': is_int, '-o': is_int, '-n': is_int, '-N': is_int, # check to see if this is an absolute file path '-f': isabs } # input file keys beginning with _ are optional inputs _input_order = ['prefix', 'sai1_in', 'sai2_in', 'fastq1_in', 'fastq2_in'] def _get_result_paths(self, data): """Gets the result file for a bwa sampe run. There is only one output file of a bwa sampe run, a .sam file, and it can be retrieved with the key 'output'. """ return {'output': ResultPath(self.Parameters['-f'].Value, IsWritten=True)} class BWA_bwasw(BWA): """Controls the "bwasw" subcommand of the bwa application. Valid input keys are: prefix, query_fasta, _query_fasta2 input keys beginning with an underscore are optional. """ _parameters = { #Score of a match [1] '-a': ValuedParameter('-', Delimiter=' ', Name='a'), #Mismatch penalty [3] '-b': ValuedParameter('-', Delimiter=' ', Name='b'), #Gap open penalty [5] '-q': ValuedParameter('-', Delimiter=' ', Name='q'), #Gap extension penalty. '-r': ValuedParameter('-', Delimiter=' ', Name='r'), # mask level [0.50] '-m': ValuedParameter('-', Delimiter=' ', Name='m'), #Number of threads in the multi-threading mode [1] '-t': ValuedParameter('-', Delimiter=' ', Name='t'), # file to output results to instead of stdout '-f': ValuedParameter('-', Delimiter=' ', Name='f'), #Band width in the banded alignment [33] '-w': ValuedParameter('-', Delimiter=' ', Name='w'), #Minimum score threshold divided by a [30] '-T': ValuedParameter('-', Delimiter=' ', Name='T'), #Coefficient for threshold adjustment according to query length. #Given an l-long query, the threshold for a hit to be retained is #a*max{T,c*log(l)}. [5.5] '-c': ValuedParameter('-', Delimiter=' ', Name='c'), #Z-best heuristics. Higher -z increases accuracy at the cost #of speed. [1] '-z': ValuedParameter('-', Delimiter=' ', Name='z'), #Maximum SA interval size for initiating a seed. Higher -s increases #accuracy at the cost of speed. [3] '-s': ValuedParameter('-', Delimiter=' ', Name='s'), #Minimum number of seeds supporting the resultant alignment to #trigger reverse alignment. [5] '-N': ValuedParameter('-', Delimiter=' ', Name='N'), # in SAM output, use hard clipping instead of soft clipping '-H': FlagParameter('-', Name='H'), # mark multi-part alignments as secondary '-M': FlagParameter('-', Name='M'), # skip Smith-Waterman read pariing '-S': FlagParameter('-', Name='S'), # ignore pairs with insert >= INT for inferring the size of distr # [20000] '-I': ValuedParameter('-', Delimiter=' ', Name='I') } # the subcommand fo bwasw _subcommand = 'bwasw' # input file keys beginning with _ are optional inputs _input_order = ['prefix', 'query_fasta', '_query_fasta_2'] _valid_arguments = { # Make sure this is a float '-c': is_float, '-m': is_float, # Make sure these are ints '-a': is_int, '-b': is_int, '-q': is_int, '-r': is_int, '-t': is_int, '-w': is_int, '-T': is_int, '-z': is_int, '-s': is_int, '-N': is_int, '-I': is_int, # make sure this is an absolute path '-f': isabs } def _get_result_paths(self, data): """Gets the result file for a bwa bwasw run. There is only one output file of a bwa bwasw run, a .sam file, and it can be retrieved with the key 'output'. """ return {'output': ResultPath(self.Parameters['-f'].Value, IsWritten=True)} def create_bwa_index_from_fasta_file(fasta_in, params=None): """Create a BWA index from an input fasta file. fasta_in: the input fasta file from which to create the index params: dict of bwa index specific paramters This method returns a dictionary where the keys are the various output suffixes (.amb, .ann, .bwt, .pac, .sa) and the values are open file objects. The index prefix will be the same as fasta_in, unless the -p parameter is passed in params. """ if params is None: params = {} # Instantiate the app controller index = BWA_index(params) # call the application, passing the fasta file in results = index({'fasta_in':fasta_in}) return results def assign_reads_to_database(query, database_fasta, out_path, params=None): """Assign a set of query sequences to a reference database database_fasta_fp: absolute file path to the reference database query_fasta_fp: absolute file path to query sequences output_fp: absolute file path of the file to be output params: dict of BWA specific parameters. * Specify which algorithm to use (bwa-short or bwasw) using the dict key "algorithm" * if algorithm is bwasw, specify params for the bwa bwasw subcommand * if algorithm is bwa-short, specify params for the bwa samse subcommand * if algorithm is bwa-short, must also specify params to use with bwa aln, which is used to get the sai file necessary to run samse. bwa aln params should be passed in using dict key "aln_params" and the associated value should be a dict of params for the bwa aln subcommand * if a temporary directory is not specified in params using dict key "temp_dir", it will be assumed to be /tmp This method returns an open file object (SAM format). """ if params is None: params = {} # set the output path params['-f'] = out_path # if the algorithm is not specified in the params dict, or the algorithm # is not recognized, raise an exception if 'algorithm' not in params: raise ApplicationError("Must specify which algorithm to use " + \ "('bwa-short' or 'bwasw')") elif params['algorithm'] not in ('bwa-short', 'bwasw'): raise ApplicationError('Unknown algorithm "%s". ' % \ params['algorithm'] + \ "Please enter either 'bwa-short' or 'bwasw'.") # if the temp directory is not specified, assume /tmp if 'temp_dir' not in params: params['temp_dir'] = '/tmp' # if the algorithm is bwa-short, we must build use bwa aln to get an sai # file before calling bwa samse on that sai file, so we need to know how # to run bwa aln. Therefore, we must ensure there's an entry containing # those parameters if params['algorithm'] == 'bwa-short': if 'aln_params' not in params: raise ApplicationError("With bwa-short, need to specify a key " + \ "'aln_params' and its value, a " + \ "dictionary to pass to bwa aln, since " + \ "bwa aln is an intermediate step when " + \ "doing bwa-short.") # we have this params dict, with "algorithm" and "temp_dir", etc which are # not for any of the subcommands, so make a new params dict that is the # same as the original minus these addendums subcommand_params = {} for k, v in params.iteritems(): if k not in ('algorithm', 'temp_dir', 'aln_params'): subcommand_params[k] = v # build index from database_fasta # get a temporary file name that is not in use index_prefix = get_tmp_filename(tmp_dir=params['temp_dir'], suffix='', \ result_constructor=str) create_bwa_index_from_fasta_file(database_fasta, {'-p': index_prefix}) # if the algorithm is bwasw, things are pretty simple. Just instantiate # the proper controller and set the files if params['algorithm'] == 'bwasw': bwa = BWA_bwasw(params = subcommand_params) files = {'prefix': index_prefix, 'query_fasta': query} # if the algorithm is bwa-short, it's not so simple elif params['algorithm'] == 'bwa-short': # we have to call bwa_aln to get the sai file needed for samse # use the aln_params we ensured we had above bwa_aln = BWA_aln(params = params['aln_params']) aln_files = {'prefix': index_prefix, 'fastq_in': query} # get the path to the sai file sai_file_path = bwa_aln(aln_files)['output'].name # we will use that sai file to run samse bwa = BWA_samse(params = subcommand_params) files = {'prefix': index_prefix, 'sai_in': sai_file_path, 'fastq_in': query} # run which ever app controller we decided was correct on the files # we set up result = bwa(files) # they both return a SAM file, so return that return result['output'] def assign_dna_reads_to_dna_database(query_fasta_fp, database_fasta_fp, out_fp, params = {}): """Wraps assign_reads_to_database, setting various parameters. The default settings are below, but may be overwritten and/or added to using the params dict: algorithm: bwasw """ my_params = {'algorithm': 'bwasw'} my_params.update(params) result = assign_reads_to_database(query_fasta_fp, database_fasta_fp, out_fp, my_params) return result def assign_dna_reads_to_protein_database(query_fasta_fp, database_fasta_fp, out_fp, temp_dir='/tmp', params = {}): """Wraps assign_reads_to_database, setting various parameters. Not yet implemented, as BWA can only align DNA reads to DNA databases. """ raise NotImplementedError, "BWA cannot at this point align DNA to protein" pycogent-1.9/cogent/app/carnac.py000066400000000000000000000064671273014367000170730ustar00rootroot00000000000000#!/usr/bin/env python from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter,FlagParameter,Parameters __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class Carnac(CommandLineApplication): """Application controller for Carnac RNAfolding application Info at: http://bioinfo.lifl.fr/carnac/index.html Options: -a Inhibit the energy correction that is automatically performed to create the initial set of potential stems. By default, the energy correction depends of the GC percentage of each sequence. -c Eliminate sequences that are too similar. The similarity treshold is 98%. -h Add hairpins that are present only in one sequence to the initial set of potential stems (may be time and space demanding). """ #Limitation #if -c is turned on and file is deleted error in file handling in _get_result_paths _parameters = { '-c':FlagParameter(Prefix='-',Name='c',Value=False), '-a':FlagParameter(Prefix='-',Name='a'), '-h':FlagParameter(Prefix='-',Name='h')} _command = 'carnac' _input_handler='_input_as_string' def _get_result_paths(self,data): """Specifies the paths of output files generated by the application data: the data the instance of the application is called on Carnac produces it's output to a .ct, .eq, to the location of input file and .out files located in the same folder as the program is run from. graph and align file is also created. You always get back: StdOut,StdErr, and ExitStatus """ result={} name_counter = 0 ones='00' tens='0' count='' if not isinstance(data,list): #means data is file path=str(data) data=open(data).readlines() else: #data input as lines #path=''.join([self.WorkingDir,self._input_filename.split('/')[-1]]) path = ''.join(['/tmp/', self._input_filename.split('/')[-1]]) for item in data: if item.startswith('>'): name_counter += 1 if name_counter < 10: count=ones if name_counter > 9: count=tens if name_counter > 99: count='' name = item.strip('>\n') else: nr=name_counter result['ct%d' % nr] =\ ResultPath(Path=('%s%s%d.ct' % (path,count,nr))) result['eq%d' % nr] =\ ResultPath(Path=('%s%s%d.eq' % (path,count,nr))) result['out_seq%d' % nr] = \ ResultPath(Path=(''.join([self.WorkingDir,'Z_%s%d.%s.out'% \ (count,nr,name)]))) result['graph'] =\ ResultPath(Path=(self.WorkingDir+'graph.out')) result['align'] =\ ResultPath(Path=(self.WorkingDir+'alignment.out')) return result pycogent-1.9/cogent/app/cd_hit.py000066400000000000000000000272221273014367000170660ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for CD-HIT v3.1.1""" import shutil from os import remove from cogent.app.parameters import ValuedParameter from cogent.app.util import CommandLineApplication, ResultPath,\ get_tmp_filename from cogent.core.moltype import RNA, DNA, PROTEIN from cogent.core.alignment import SequenceCollection from cogent.parse.fasta import MinimalFastaParser __author__ = "Daniel McDonald" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Daniel McDonald" __email__ = "mcdonadt@colorado.edu" __status__ = "Development" class CD_HIT(CommandLineApplication): """cd-hit Application Controller Use this version of CD-HIT if your MolType is PROTEIN """ _command = 'cd-hit' _input_handler = '_input_as_multiline_string' _parameters = { # input input filename in fasta format, required '-i':ValuedParameter('-',Name='i',Delimiter=' ',IsPath=True), # output filename, required '-o':ValuedParameter('-',Name='o',Delimiter=' ',IsPath=True), # sequence identity threshold, default 0.9 # this is the default cd-hit's "global sequence identity" calc'd as : # number of identical amino acids in alignment # divided by the full length of the shorter sequence '-c':ValuedParameter('-',Name='c',Delimiter=' '), # use global sequence identity, default 1 # if set to 0, then use local sequence identity, calculated as : # number of identical amino acids in alignment # divided by the length of the alignment # NOTE!!! don't use -G 0 unless you use alignment coverage controls # see options -aL, -AL, -aS, -AS '-g':ValuedParameter('-',Name='g',Delimiter=' '), # band_width of alignment, default 20 '-b':ValuedParameter('-',Name='b',Delimiter=' '), # max available memory (Mbyte), default 400 '-M':ValuedParameter('-',Name='M',Delimiter=' '), # word_length, default 8, see user's guide for choosing it '-n':ValuedParameter('-',Name='n',Delimiter=' '), # length of throw_away_sequences, default 10 '-l':ValuedParameter('-',Name='l',Delimiter=' '), # tolerance for redundance, default 2 '-t':ValuedParameter('-',Name='t',Delimiter=' '), # length of description in .clstr file, default 20 # if set to 0, it takes the fasta defline and stops at first space '-d':ValuedParameter('-',Name='d',Delimiter=' '), # length difference cutoff, default 0.0 # if set to 0.9, the shorter sequences need to be # at least 90% length of the representative of the cluster '-s':ValuedParameter('-',Name='s',Delimiter=' '), # length difference cutoff in amino acid, default 999999 # f set to 60, the length difference between the shorter sequences # and the representative of the cluster can not be bigger than 60 '-S':ValuedParameter('-',Name='S',Delimiter=' '), # alignment coverage for the longer sequence, default 0.0 # if set to 0.9, the alignment must covers 90% of the sequence '-aL':ValuedParameter('-',Name='aL',Delimiter=' '), # alignment coverage control for the longer sequence, default 99999999 # if set to 60, and the length of the sequence is 400, # then the alignment must be >= 340 (400-60) residues '-AL':ValuedParameter('-',Name='AL',Delimiter=' '), # alignment coverage for the shorter sequence, default 0.0 # if set to 0.9, the alignment must covers 90% of the sequence '-aS':ValuedParameter('-',Name='aS',Delimiter=' '), # alignment coverage control for the shorter sequence, default 99999999 # if set to 60, and the length of the sequence is 400, # then the alignment must be >= 340 (400-60) residues '-AS':ValuedParameter('-',Name='AS',Delimiter=' '), # 1 or 0, default 0, by default, sequences are stored in RAM # if set to 1, sequence are stored on hard drive # it is recommended to use -B 1 for huge databases '-B':ValuedParameter('-',Name='B',Delimiter=' '), # 1 or 0, default 0 # if set to 1, print alignment overlap in .clstr file '-p':ValuedParameter('-',Name='p',Delimiter=' '), # 1 or 0, default 0 # by cd-hit's default algorithm, a sequence is clustered to the first # cluster that meet the threshold (fast cluster). If set to 1, the program # will cluster it into the most similar cluster that meet the threshold # (accurate but slow mode) # but either 1 or 0 won't change the representatives of final clusters '-g':ValuedParameter('-',Name='g',Delimiter=' '), # print this help '-h':ValuedParameter('-',Name='h',Delimiter=' ') } _synonyms = {'Similarity':'-c'} def getHelp(self): """Method that points to documentation""" help_str =\ """ CD-HIT is hosted as an open source project at: http://www.bioinformatics.org/cd-hit/ The following papers should be cited if this resource is used: Clustering of highly homologous sequences to reduce thesize of large protein database", Weizhong Li, Lukasz Jaroszewski & Adam Godzik Bioinformatics, (2001) 17:282-283 Tolerating some redundancy significantly speeds up clustering of large protein databases", Weizhong Li, Lukasz Jaroszewski & Adam Godzik Bioinformatics, (2002) 18:77-82 """ return help_str def _input_as_multiline_string(self, data): """Writes data to tempfile and sets -i parameter data -- list of lines """ if data: self.Parameters['-i']\ .on(super(CD_HIT,self)._input_as_multiline_string(data)) return '' def _input_as_lines(self, data): """Writes data to tempfile and sets -i parameter data -- list of lines, ready to be written to file """ if data: self.Parameters['-i']\ .on(super(CD_HIT,self)._input_as_lines(data)) return '' def _input_as_seqs(self, data): """Creates a list of seqs to pass to _input_as_lines data -- list like object of sequences """ lines = [] for i,s in enumerate(data): # will number the sequences 1,2,3, etc... lines.append(''.join(['>',str(i+1)])) lines.append(s) return self._input_as_lines(lines) def _input_as_string(self, data): """Makes data the value of a specific parameter""" if data: self.Parameters['-i'].on(str(data)) return '' def _get_seqs_outfile(self): """Returns the absolute path to the seqs outfile""" if self.Parameters['-o'].isOn(): return self.Parameters['-o'].Value else: raise ValueError, "No output file specified" def _get_clstr_outfile(self): """Returns the absolute path to the clstr outfile""" if self.Parameters['-o'].isOn(): return ''.join([self.Parameters['-o'].Value, '.clstr']) else: raise ValueError, "No output file specified" def _get_result_paths(self, data): """Return dict of {key: ResultPath}""" result = {} result['FASTA'] = ResultPath(Path=self._get_seqs_outfile()) result['CLSTR'] = ResultPath(Path=self._get_clstr_outfile()) return result class CD_HIT_EST(CD_HIT): """cd-hit Application Controller Use this version of CD-HIT if your MolType is PROTEIN """ _command = 'cd-hit-est' _input_handler = '_input_as_multiline_string' _parameters = CD_HIT._parameters _parameters.update({\ # 1 or 0, default 0, by default only +/+ strand alignment # if set to 1, do both +/+ & +/- alignments '-r':ValuedParameter('-',Name='r',Delimiter=' ') }) def cdhit_clusters_from_seqs(seqs, moltype, params=None): """Returns the CD-HIT clusters given seqs seqs : dict like collection of sequences moltype : cogent.core.moltype object params : cd-hit parameters NOTE: This method will call CD_HIT if moltype is PROTIEN, CD_HIT_EST if moltype is RNA/DNA, and raise if any other moltype is passed. """ # keys are not remapped. Tested against seq_ids of 100char length seqs = SequenceCollection(seqs, MolType=moltype) #Create mapping between abbreviated IDs and full IDs int_map, int_keys = seqs.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) # setup params and make sure the output argument is set if params is None: params = {} if '-o' not in params: params['-o'] = get_tmp_filename() # call the correct version of cd-hit base on moltype working_dir = get_tmp_filename() if moltype is PROTEIN: app = CD_HIT(WorkingDir=working_dir, params=params) elif moltype is RNA: app = CD_HIT_EST(WorkingDir=working_dir, params=params) elif moltype is DNA: app = CD_HIT_EST(WorkingDir=working_dir, params=params) else: raise ValueError, "Moltype must be either PROTEIN, RNA, or DNA" # grab result res = app(int_map.toFasta()) clusters = parse_cdhit_clstr_file(res['CLSTR'].readlines()) remapped_clusters = [] for c in clusters: curr = [int_keys[i] for i in c] remapped_clusters.append(curr) # perform cleanup res.cleanUp() shutil.rmtree(working_dir) remove(params['-o'] + '.bak.clstr') return remapped_clusters def cdhit_from_seqs(seqs, moltype, params=None): """Returns the CD-HIT results given seqs seqs : dict like collection of sequences moltype : cogent.core.moltype object params : cd-hit parameters NOTE: This method will call CD_HIT if moltype is PROTIEN, CD_HIT_EST if moltype is RNA/DNA, and raise if any other moltype is passed. """ # keys are not remapped. Tested against seq_ids of 100char length seqs = SequenceCollection(seqs, MolType=moltype) # setup params and make sure the output argument is set if params is None: params = {} if '-o' not in params: params['-o'] = get_tmp_filename() # call the correct version of cd-hit base on moltype working_dir = get_tmp_filename() if moltype is PROTEIN: app = CD_HIT(WorkingDir=working_dir, params=params) elif moltype is RNA: app = CD_HIT_EST(WorkingDir=working_dir, params=params) elif moltype is DNA: app = CD_HIT_EST(WorkingDir=working_dir, params=params) else: raise ValueError, "Moltype must be either PROTEIN, RNA, or DNA" # grab result res = app(seqs.toFasta()) new_seqs = dict(MinimalFastaParser(res['FASTA'].readlines())) # perform cleanup res.cleanUp() shutil.rmtree(working_dir) remove(params['-o'] + '.bak.clstr') return SequenceCollection(new_seqs, MolType=moltype) def clean_cluster_seq_id(id): """Returns a cleaned cd-hit sequence id The cluster file has sequence ids in the form of: >some_id... """ return id[1:-3] def parse_cdhit_clstr_file(lines): """Returns a list of list of sequence ids representing clusters""" clusters = [] curr_cluster = [] for l in lines: if l.startswith('>Cluster'): if not curr_cluster: continue clusters.append(curr_cluster) curr_cluster = [] else: curr_cluster.append(clean_cluster_seq_id(l.split()[2])) if curr_cluster: clusters.append(curr_cluster) return clusters pycogent-1.9/cogent/app/cdbfasta.py000066400000000000000000000245051273014367000174040ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for cdbfasta Code obtained from http://sourceforge.net/projects/cdbfasta/ cdbfasta Version 0.99, dated 07-22-10 on download cdbyank Version 0.981, dated 07-22-10 on download """ from os import remove, path from cogent.app.parameters import FlagParameter, ValuedParameter from cogent.app.util import CommandLineApplication, ResultPath, \ get_tmp_filename, guess_input_handler __author__ = "Daniel McDonald" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Daniel McDonald" __email__ = "mcdonadt@colorado.edu" __status__ = "Prototype" class cdbfasta(CommandLineApplication): """cdbfasta application controller""" _options ={ # -o the index file will be named ; if not given, # the index filename is database name plus the suffix '.cidx' '-o':ValuedParameter('-',Name='anchorspacing',Delimiter=' '), # -r a string of characters at the beginning of line # marking the start of a record (default: '>') '-clw':FlagParameter(Prefix='-',Name='clw'), # -Q treat input as fastq format, i.e. with '@' as record delimiter # and with records expected to have at least 4 lines '-Q':FlagParameter(Prefix='-',Name='Q'), # -z database is compressed into the file # before indexing ( can be "-" or "stdin" # in order to get the input records from stdin) '-z':ValuedParameter('-',Name='z',Delimiter=' '), # -s strip extraneous characters from *around* the space delimited # tokens, for the multikey options below (-m,-n,-f); # Default set is: '",`.(){}/[]!:;~|><+- '-s':ValuedParameter('-',Name='s',Delimiter=' '), # -m ("multi-key" option) create hash entries pointing to # the same record for all tokens found in # the defline '-m':FlagParameter('-',Name='m'), # -n same as -m, but only takes the first # tokens from the defline '-n':ValuedParameter('-',Name='n',Delimiter=' '), # -f indexes *space* delimited tokens (fields) in the defline as given # by LIST of fields or fields ranges (the same syntax as UNIX 'cut') '-f':ValuedParameter('-',Name='f',Delimiter=''), # -w exclude from indexing all the words found # in the file (for options -m, -n and -k) '-w':ValuedParameter('-',Name='w',Delimiter=' '), # -i do case insensitive indexing (i.e. create additional keys for # all-lowercase tokens used for indexing from the defline '-i':FlagParameter('-',Name='i'), # -c for deflines in the format: db1|accession1|db2|accession2|..., # only the first db-accession pair ('db1|accession1') is taken as key '-c':FlagParameter('-',Name='c'), # -C like -c, but also subsequent db|accession constructs are indexed, # along with the full (default) token; additionally, # all nrdb concatenated accessions found in the defline # are parsed and stored (assuming 0x01 or '^|^' as separators) '-C':FlagParameter('-', Name='C'), # -a accession mode: like -C option, but indexes the 'accession' # part for all 'db|accession' constructs found '-a':FlagParameter('-', Name='a'), # -A like -a and -C together (both accessions and 'db|accession' # constructs are used as keys '-A':FlagParameter('-', Name='A'), # -v show program version and exit '-v':FlagParameter('-', Name='v') } _parameters = {} _parameters.update(_options) _command = "cdbfasta" _input_file = "" def _input_as_string(self, data): """Index a single file""" if not data: raise ValueError, "Expected a file!" if not path.exists(data): raise ValueError, "File to index doesn't exist: %s" % data self._input_file = data return "" def _get_result_paths(self,data): if self.Parameters['-v'].isOn(): return {} output = {} if self.Parameters['-o'].isOn(): output['cidx'] = ResultPath(self.Parameters['-o'].Value) else: output['cidx'] = ResultPath(self._input_file + '.cidx') return output def _get_base_command(self): """Yay for positional arguments...""" command_parts = [] cd_command = ''.join(['cd ',str(self.WorkingDir),';']) if self._command is None: raise ApplicationError, '_command has not been set.' command = self._command parameters = sorted([str(x) for x in self.Parameters.values() if str(x)]) synonyms = self._synonyms command_parts.append(cd_command) command_parts.append(command) command_parts.append(self._input_file) # Positional argument command_parts += parameters return self._command_delimiter.join(filter(None,command_parts)).strip() BaseCommand = property(_get_base_command) class cdbyank(CommandLineApplication): """cdbyank application controller""" _options ={ # -a the sequence name (accession) for a fasta record to be # retrieved; if not given, a list of accessions is expected # at stdin '-a':ValuedParameter('-',Name='a', Delimiter=' '), # -d is the fasta file to pull records from; # if not specified, cdbyank will look in the same directory # where resides, for a file with the same name # but without the ".cidx" suffix '-d':ValuedParameter('-', Name='d', Delimiter=' '), # -o the records found are written to file instead of stdout '-o':ValuedParameter('-', Name='o', Delimiter=' '), # -x allows retrieval of multiple records per key, if the indexed # database had records with the same key (non-unique keys); # (without -x only one record for a given key is retrieved) '-x':FlagParameter('-', Name='x'), # -i case insensitive query (expects the to have been # created with cdbfasta -i option) '-i':FlagParameter('-', Name='i'), # -Q output the query key surrounded by character '%' before the # corresponding record '-Q':FlagParameter('-', Name='Q'), # -q same as -Q but use character instead of '%' '-q':ValuedParameter('-', Name='q', Delimiter=' '), # -w enable warnings (sent to stderr) when a key is not found '-w':FlagParameter('-', Name='w'), # -F pulls only the defline for each record (discard the sequence) '-F':FlagParameter('-', Name='F'), # -P only displays the position(s) (file offset) within the # database file, for the requested record(s) '-P':FlagParameter('-', Name='P'), # -R sequence range extraction: expects the input to have # the format: ' ' # and pulls only the specified sequence range '-R':ValuedParameter('-', Name='R', Delimiter=' '), # -z decompress the entire file # (assumes it was built using cdbfasta with '-z' option) '-z':ValuedParameter('-', Name='z', Delimiter=' '), # -v show version number and exit '-v':FlagParameter('-', Name='v'), ### # Index file statistics (no database file needed): # -n display the number of records indexed '-n':FlagParameter('-', Name='n'), # -l list all keys stored in '-l':FlagParameter('-', Name='l'), # -s display indexing summary info '-s':FlagParameter('-', Name='s') } _parameters = {} _parameters.update(_options) _command = "cdbyank" _input_file = "" _queries = [] def _input_as_string(self, data): """File path for an index""" if not data: raise ValueError, "Expected a file!" if not path.exists(data): raise ValueError, "Index doesn't exist: %s" % data self._input_file = data return "" def _get_result_paths(self, data): if self.Parameters['-v'].isOn(): return {} output = {} if self.Parameters['-o'].isOn(): output['seqs'] = ResultPath(self.Parameters['-o'].Value) return output def _get_base_command(self): """Yay for positional arguments...""" command_parts = [] cd_command = ''.join(['cd ',str(self.WorkingDir),';']) if self._command is None: raise ApplicationError, '_command has not been set.' command = self._command parameters = sorted([str(x) for x in self.Parameters.values() if str(x)]) synonyms = self._synonyms if self._queries: bulk_query = 'echo "%s" | ' % " ".join(self._queries) else: bulk_query = "" command_parts.append(cd_command) command_parts.append(bulk_query) command_parts.append(command) command_parts.append(self._input_file) # Positional argument command_parts += parameters return self._command_delimiter.join(filter(None,command_parts)).strip() BaseCommand = property(_get_base_command) def setQueries(self, queries): """Sets queries""" self._queries = queries def index_fasta(filename, params=None): """Index a fasta file, returns the absolute path for the index""" if params is None: params = {} app = cdbfasta(params) return app(filename)['cidx'].name def index_fastq(filename, params=None): """Index a fastq file, returns the absolute path for the index""" if params is None: params = {'-Q':True} app = cdbfasta(params) return app(filename)['cidx'].name def query_indexed_seqs(queries, path_to_index, params=None): """Returns sequences from the indexed file works with both fasta and fastq, returns in the file type of the indexed """ if params is None: params = {} app = cdbyank(params) app.setQueries(queries) res = app(path_to_index) if 'seqs' not in res: res['seqs'] = res['StdOut'] return res['seqs'].read() pycogent-1.9/cogent/app/clearcut.py000066400000000000000000000327131273014367000174370ustar00rootroot00000000000000#!/usr/bin/env python """Provides an application controller for the commandline version of: Clearcut v1.0.8 """ from cogent.app.parameters import FlagParameter, ValuedParameter, \ MixedParameter from cogent.app.util import CommandLineApplication, ResultPath, get_tmp_filename from cogent.core.alignment import SequenceCollection, Alignment from cogent.core.moltype import DNA, RNA, PROTEIN from cogent.parse.tree import DndParser from cogent.core.tree import PhyloNode from cogent.util.dict2d import Dict2D from cogent.format.table import phylipMatrix __author__ = "Jeremy Widmann" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Jeremy Widmann"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Jeremy Widmann" __email__ = "jeremy.widmann@colorado.edu" __status__ = "Development" MOLTYPE_MAP = {'DNA':'-D', 'RNA':'-D', 'PROTEIN':'-P', } class Clearcut(CommandLineApplication): """ clearcut application controller The parameters are organized by function to give some idea of how the program works. However, no restrictions are put on any combinations of parameters. Misuse of parameters can lead to errors or otherwise strange results. """ #General options. _general = {\ # --verbose. More Output. (Default:OFF) '-v':FlagParameter('-',Name='v'), # --quiet. Silent operation. (Default: ON) '-q':FlagParameter('-',Name='q',Value=True), # --seed=. Explicitly set the PRNG seed to a specific value. '-s':ValuedParameter('-',Name='s',Delimiter='='), # --norandom. Attempt joins deterministically. (Default: OFF) '-r':FlagParameter('-',Name='r'), # --shuffle. Randomly shuffle the distance matrix. (Default: OFF) '-S':FlagParameter('-',Name='S'), #--neighbor. Use traditional Neighbor-Joining algorithm. (Default: OFF) '-N':FlagParameter('-',Name='N'), } # Input file is distance matrix or alignment. Default expects distance # matrix. Output file is tree created by clearcut. _input = {\ # --in=. Input file '--in':ValuedParameter('--',Name='in',Delimiter='=',IsPath=True), # --stdin. Read input from STDIN. '-I':FlagParameter('-',Name='I'), # --distance. Input file is a distance matrix. (Default: ON) '-d':FlagParameter('-',Name='d',Value=True), # --alignment. Input file is a set of aligned sequences. # (Default: OFF) '-a':FlagParameter('-',Name='a'), # --DNA. Input alignment are DNA sequences. '-D':FlagParameter('-',Name='D'), # --protein. Input alignment are protein sequences. '-P':FlagParameter('-',Name='P'), } #Correction model for computing distance matrix (Default: NO Correction): _correction={\ # --jukes. Use Jukes-Cantor correction for computing distance matrix. '-j':FlagParameter('-',Name='j'), # --kimura. Use Kimura correction for distance matrix. '-k':FlagParameter('-',Name='k'), } _output={\ # --out=. Output file '--out':ValuedParameter('--',Name='out',Delimiter='=',IsPath=True), # --stdout. Output tree to STDOUT. '-O':FlagParameter('-',Name='O'), # --matrixout= Output distance matrix to specified file. '-m':ValuedParameter('-',Name='m',Delimiter='='), # --ntrees=. Output n trees. (Default: 1) '-n':ValuedParameter('-',Name='n',Delimiter='='), # --expblen. Exponential notation for branch lengths. (Default: OFF) '-e':FlagParameter('-',Name='e'), # --expdist. Exponential notation in distance output. (Default: OFF) '-E':FlagParameter('-',Name='E'), } #NOT SUPPORTED #'-h':FlagParameter('-','h'), #Help #'-V':FlagParameter('-','V'), #Version _parameters = {} _parameters.update(_general) _parameters.update(_input) _parameters.update(_correction) _parameters.update(_output) _command = 'clearcut' def getHelp(self): """Method that points to the Clearcut documentation.""" help_str =\ """ See Clearcut homepage at: http://bioinformatics.hungry.com/clearcut/ """ return help_str def _input_as_multiline_string(self, data): """Writes data to tempfile and sets -infile parameter data -- list of lines """ if data: self.Parameters['--in']\ .on(super(Clearcut,self)._input_as_multiline_string(data)) return '' def _input_as_lines(self,data): """Writes data to tempfile and sets -infile parameter data -- list of lines, ready to be written to file """ if data: self.Parameters['--in']\ .on(super(Clearcut,self)._input_as_lines(data)) return '' def _input_as_seqs(self,data): """writes sequences to tempfile and sets -infile parameter data -- list of sequences Adds numbering to the sequences: >1, >2, etc. """ lines = [] for i,s in enumerate(data): #will number the sequences 1,2,3,etc. lines.append(''.join(['>',str(i+1)])) lines.append(s) return self._input_as_lines(lines) def _input_as_string(self,data): """Makes data the value of a specific parameter This method returns the empty string. The parameter will be printed automatically once set. """ if data: self.Parameters['--in'].on(data) return '' def _tree_filename(self): """Return name of file containing the alignment prefix -- str, prefix of alignment file. """ if self.Parameters['--out']: aln_filename = self._absolute(self.Parameters['--out'].Value) else: raise ValueError, "No tree output file specified." return aln_filename def _get_result_paths(self,data): """Return dict of {key: ResultPath} """ result = {} if self.Parameters['--out'].isOn(): out_name = self._tree_filename() result['Tree'] = ResultPath(Path=out_name,IsWritten=True) return result #SOME FUNCTIONS TO EXECUTE THE MOST COMMON TASKS def align_unaligned_seqs(seqs, moltype, params=None): """Returns an Alignment object from seqs. seqs: SequenceCollection object, or data that can be used to build one. moltype: a MolType object. DNA, RNA, or PROTEIN. params: dict of parameters to pass in to the Clearcut app controller. Result will be an Alignment object. """ #Clearcut does not support alignment raise NotImplementedError, """Clearcut does not support alignment.""" def align_and_build_tree(seqs, moltype, best_tree=False, params={}): """Returns an alignment and a tree from Sequences object seqs. seqs: SequenceCollection object, or data that can be used to build one. best_tree: if True (default:False), uses a slower but more accurate algorithm to build the tree. params: dict of parameters to pass in to the Clearcut app controller. The result will be a tuple containing an Alignment object and a cogent.core.tree.PhyloNode object (or None for the alignment and/or tree if either fails). """ #Clearcut does not support alignment raise NotImplementedError, """Clearcut does not support alignment.""" def build_tree_from_alignment(aln, moltype, best_tree=False, params={},\ working_dir='/tmp'): """Returns a tree from Alignment object aln. aln: an cogent.core.alignment.Alignment object, or data that can be used to build one. - Clearcut only accepts aligned sequences. Alignment object used to handle unaligned sequences. moltype: a cogent.core.moltype object. - NOTE: If moltype = RNA, we must convert to DNA since Clearcut v1.0.8 gives incorrect results if RNA is passed in. 'U' is treated as an incorrect character and is excluded from distance calculations. best_tree: if True (default:False), uses a slower but more accurate algorithm to build the tree. params: dict of parameters to pass in to the Clearcut app controller. The result will be an cogent.core.tree.PhyloNode object, or None if tree fails. """ params['--out'] = get_tmp_filename(working_dir) # Create instance of app controller, enable tree, disable alignment app = Clearcut(InputHandler='_input_as_multiline_string', params=params, \ WorkingDir=working_dir, SuppressStdout=True,\ SuppressStderr=True) #Input is an alignment app.Parameters['-a'].on() #Turn off input as distance matrix app.Parameters['-d'].off() #If moltype = RNA, we must convert to DNA. if moltype == RNA: moltype = DNA if best_tree: app.Parameters['-N'].on() #Turn on correct moltype moltype_string = moltype.label.upper() app.Parameters[MOLTYPE_MAP[moltype_string]].on() # Setup mapping. Clearcut clips identifiers. We will need to remap them. # Clearcut only accepts aligned sequences. Let Alignment object handle # unaligned sequences. seq_aln = Alignment(aln,MolType=moltype) #get int mapping int_map, int_keys = seq_aln.getIntMap() #create new Alignment object with int_map int_map = Alignment(int_map) # Collect result result = app(int_map.toFasta()) # Build tree tree = DndParser(result['Tree'].read(), constructor=PhyloNode) for node in tree.tips(): node.Name = int_keys[node.Name] # Clean up result.cleanUp() del(seq_aln, app, result, int_map, int_keys, params) return tree def add_seqs_to_alignment(seqs, aln, params=None): """Returns an Alignment object from seqs and existing Alignment. seqs: an cogent.core.sequence.Sequence object, or data that can be used to build one. aln: an cogent.core.alignment.Alignment object, or data that can be used to build one params: dict of parameters to pass in to the Clearcut app controller. """ #Clearcut does not support alignment raise NotImplementedError, """Clearcut does not support alignment.""" def align_two_alignments(aln1, aln2, params=None): """Returns an Alignment object from two existing Alignments. aln1, aln2: cogent.core.alignment.Alignment objects, or data that can be used to build them. params: dict of parameters to pass in to the Clearcut app controller. """ #Clearcut does not support alignment raise NotImplementedError, """Clearcut does not support alignment.""" def build_tree_from_distance_matrix(matrix, best_tree=False, params={},\ working_dir='/tmp'): """Returns a tree from a distance matrix. matrix: a square Dict2D object (cogent.util.dict2d) best_tree: if True (default:False), uses a slower but more accurate algorithm to build the tree. params: dict of parameters to pass in to the Clearcut app controller. The result will be an cogent.core.tree.PhyloNode object, or None if tree fails. """ params['--out'] = get_tmp_filename(working_dir) # Create instance of app controller, enable tree, disable alignment app = Clearcut(InputHandler='_input_as_multiline_string', params=params, \ WorkingDir=working_dir, SuppressStdout=True,\ SuppressStderr=True) #Turn off input as alignment app.Parameters['-a'].off() #Input is a distance matrix app.Parameters['-d'].on() if best_tree: app.Parameters['-N'].on() # Turn the dict2d object into the expected input format matrix_input, int_keys = _matrix_input_from_dict2d(matrix) # Collect result result = app(matrix_input) # Build tree tree = DndParser(result['Tree'].read(), constructor=PhyloNode) # reassign to original names for node in tree.tips(): node.Name = int_keys[node.Name] # Clean up result.cleanUp() del(app, result, params) return tree def _matrix_input_from_dict2d(matrix): """makes input for running clearcut on a matrix from a dict2D object""" #clearcut truncates names to 10 char- need to rename before and #reassign after #make a dict of env_index:full name int_keys = dict([('env_' + str(i), k) for i,k in \ enumerate(sorted(matrix.keys()))]) #invert the dict int_map = {} for i in int_keys: int_map[int_keys[i]] = i #make a new dict2D object with the integer keys mapped to values instead of #the original names new_dists = [] for env1 in matrix: for env2 in matrix[env1]: new_dists.append((int_map[env1], int_map[env2], matrix[env1][env2])) int_map_dists = Dict2D(new_dists) #names will be fed into the phylipTable function - it is the int map names names = sorted(int_map_dists.keys()) rows = [] #populated rows with values based on the order of names #the following code will work for a square matrix only for index, key1 in enumerate(names): row = [] for key2 in names: row.append(str(int_map_dists[key1][key2])) rows.append(row) input_matrix = phylipMatrix(rows, names) #input needs a trailing whitespace or it will fail! input_matrix += '\n' return input_matrix, int_keys pycogent-1.9/cogent/app/clustalw.py000066400000000000000000000701141273014367000174700ustar00rootroot00000000000000#!/usr/bin/env python """Provides an application controller for the commandline version of: CLUSTALW v1.83 """ from cogent.app.parameters import FlagParameter, ValuedParameter, \ MixedParameter, FilePath from cogent.app.util import CommandLineApplication, ResultPath, remove from cogent.core.alignment import SequenceCollection, Alignment from cogent.parse.tree import DndParser from cogent.parse.clustal import ClustalParser from cogent.core.tree import PhyloNode from cogent.core.moltype import RNA, DNA, PROTEIN from numpy.random import randint __author__ = "Sandra Smit" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Sandra Smit", "Micah Hamady", "Rob Knight", "Jeremy Widmann", "Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Sandra Smit" __email__ = "sandra.smit@colorado.edu" __status__ = "Development" class Clustalw(CommandLineApplication): """ clustalw application controller The parameters are organized by function to give some idea of how the program works. However, no restrictions are put on any combinations of parameters. Misuse of parameters can lead to errors or otherwise strange results. You are supposed to choose one action for the program to perform. (align, profile, sequences, tree, or bootstrap). If you choose multiple, only the dominant action (see order above) will be executed. By DEFAULT, the -align parameter is turned on. If you decide to turn another one on, you should turn '-align' off IN ADDITION! Some references to help pages are available in the 'getHelp' method. Some might be useful to you. """ _actions = {\ '-align':FlagParameter('-','align',Value=True), '-profile':FlagParameter('-','profile'), '-sequences':FlagParameter('-','sequences'), '-tree':FlagParameter('-','tree'), '-bootstrap':MixedParameter('-','bootstrap',Delimiter='=')} #sequence file for alignment, or alignment file for bootstrap and tree #actions _input = {'-infile':ValuedParameter('-','infile',Delimiter='=',IsPath=True)} # matrix and dnamatrix can be filenames as well, but not always. # They won't be treated as filenames and thus not quoted. # Therefore filepaths containing spaces might result in errors. _multiple_alignment={\ '-quicktree':FlagParameter('-','quicktree'), '-type':ValuedParameter('-','type',Delimiter='='), '-matrix':ValuedParameter('-','matrix',Delimiter='='), '-dnamatrix':ValuedParameter('-','dnamatrix',Delimiter='='), '-gapopen':ValuedParameter('-','gapopen',Delimiter='='), '-gapext':ValuedParameter('-','gapext',Delimiter='='), '-endgaps':FlagParameter('-','endgaps'), '-gapdist':ValuedParameter('-',Name='gapdist',Delimiter='='), '-nopgap':FlagParameter('-','nopgap'), '-nohgap':FlagParameter('-','nohgap'), '-hgapresidues':ValuedParameter('-','hgapresidues',Delimiter='='), '-maxdiv':ValuedParameter('-',Name='maxdiv',Delimiter='='), '-negative':FlagParameter('-','negative'), '-transweight':ValuedParameter('-',Name='transweight',Delimiter='='), '-newtree':ValuedParameter('-','newtree',Delimiter='=',IsPath=True), '-usetree':ValuedParameter('-','usetree',Delimiter='=',IsPath=True)} _fast_pairwise={\ '-ktuple':ValuedParameter('-',Name='ktuple',Delimiter='='), '-topdiags':ValuedParameter('-',Name='topdiags',Delimiter='='), '-window':ValuedParameter('-',Name='window',Delimiter='='), '-pairgap':ValuedParameter('-',Name='pairgap',Delimiter='='), '-score':ValuedParameter('-',Name='score',Delimiter='=')} # pwmatrix and pwdnamatrix can be filenames as well, but not always. # They won't be treated as filenames and thus not quoted. # Therefore filepaths containing spaces might result in errors. _slow_pairwise={\ '-pwmatrix':ValuedParameter('-',Name='pwmatrix',Delimiter='='), '-pwdnamatrix':ValuedParameter('-',Name='pwdnamatrix',Delimiter='='), '-pwgapopen':ValuedParameter('-',Name='pwgapopen',Delimiter='='), '-pwgapext':ValuedParameter('-',Name='pwgapext',Delimiter='=')} #plus -bootstrap _tree={\ '-kimura':FlagParameter('-',Name='kimura'), '-tossgaps':FlagParameter('-',Name='tossgaps'), '-bootlabels':ValuedParameter('-',Name='bootlabels',Delimiter='='), '-seed':ValuedParameter('-',Name='seed',Delimiter='='), '-outputtree':ValuedParameter('-',Name='outputtree',Delimiter='=')} _output={\ '-outfile':ValuedParameter('-',Name='outfile',Delimiter='=',\ IsPath=True), '-output':ValuedParameter('-',Name='output',Delimiter='='), '-case':ValuedParameter('-',Name='case',Delimiter='='), '-outorder':ValuedParameter('-',Name='outorder',Delimiter='='), '-seqnos':ValuedParameter('-',Name='seqnos',Delimiter='=')} _profile_alignment={\ '-profile1':ValuedParameter('-','profile1',Delimiter='=',IsPath=True), '-profile2':ValuedParameter('-','profile2',Delimiter='=',IsPath=True), '-usetree1':ValuedParameter('-','usetree1',Delimiter='=',IsPath=True), '-usetree2':ValuedParameter('-','usetree2',Delimiter='=',IsPath=True), '-newtree1':ValuedParameter('-','newtree1',Delimiter='=',IsPath=True), '-newtree2':ValuedParameter('-','newtree2',Delimiter='=',IsPath=True)} _structure_alignment={\ '-nosecstr1':FlagParameter('-',Name='nosecstr1'), '-nosecstr2':FlagParameter('-',Name='nosecstr2'), '-helixgap':ValuedParameter('-',Name='helixgap',Delimiter='='), '-strandgap':ValuedParameter('-',Name='strandgap',Delimiter='='), '-loopgap':ValuedParameter('-',Name='loopgap',Delimiter='='), '-terminalgap':ValuedParameter('-',Name='terminalgap',Delimiter='='), '-helixendin':ValuedParameter('-',Name='helixendin',Delimiter='='), '-helixendout':ValuedParameter('-',Name='helixendout',Delimiter='='), '-strandendin':ValuedParameter('-',Name='strandendin',Delimiter='='), '-strandendout':ValuedParameter('-',Name='strandendout',Delimiter='='), '-secstrout':ValuedParameter('-',Name='secstrout',Delimiter='=')} #NOT SUPPORTED #'-help':FlagParameter('-','help'), #'-check':FlagParameter('-','check'), #'-options':FlagParameter('-','options'), #'-convert':FlagParameter('-','convert'), #'-batch':FlagParameter('-','batch'), #'-noweights':FlagParameter('-','noweights'), #'-novgap':FlagParameter('-','novgap'), #'-debug':ValuedParameter('-',Name='debug',Delimiter='='), _parameters = {} _parameters.update(_actions) _parameters.update(_input) _parameters.update(_multiple_alignment) _parameters.update(_fast_pairwise) _parameters.update(_slow_pairwise) _parameters.update(_tree) _parameters.update(_output) _parameters.update(_profile_alignment) _parameters.update(_structure_alignment) _command = 'clustalw' def getHelp(self): """Methods that points to the documentation""" help_str =\ """ There are several help pages available online. For example: http://searchlauncher.bcm.tmc.edu/multi-align/Help/ clustalw_help_1.8.html http://hypernig.nig.ac.jp/homology/clustalw-e_help.html http://www.genebee.msu.su/clustal/help.html A page that give reasonable insight in use of the parameters: http://bioweb.pasteur.fr/seqanal/interfaces/clustalw.html """ return help_str def _input_as_multiline_string(self, data): """Writes data to tempfile and sets -infile parameter data -- list of lines """ if data: self.Parameters['-infile']\ .on(super(Clustalw,self)._input_as_multiline_string(data)) return '' def _input_as_lines(self,data): """Writes data to tempfile and sets -infile parameter data -- list of lines, ready to be written to file """ if data: self.Parameters['-infile']\ .on(super(Clustalw,self)._input_as_lines(data)) return '' def _input_as_seqs(self,data): """writes sequences to tempfile and sets -infile parameter data -- list of sequences Adds numbering to the sequences: >1, >2, etc. """ lines = [] for i,s in enumerate(data): #will number the sequences 1,2,3,etc. lines.append(''.join(['>',str(i+1)])) lines.append(s) return self._input_as_lines(lines) def _input_as_string(self,data): """Makes data the value of a specific parameter This method returns the empty string. The parameter will be printed automatically once set. """ if data: self.Parameters['-infile'].on(data) return '' def _suffix(self): """Return appropriate suffix for alignment file""" _output_formats={'GCG':'.msf', 'GDE':'.gde', 'PHYLIP':'.phy', 'PIR':'.pir', 'NEXUS':'.nxs'} if self.Parameters['-output'].isOn(): return _output_formats[self.Parameters['-output'].Value] else: return '.aln' def _aln_filename(self,prefix): """Return name of file containing the alignment prefix -- str, prefix of alignment file. """ if self.Parameters['-outfile'].isOn(): aln_filename = self._absolute(self.Parameters['-outfile'].Value) else: aln_filename = prefix + self._suffix() return aln_filename def _tempfile_as_multiline_string(self, data): """Write a multiline string to a temp file and return the filename. data: a multiline string to be written to a file. * Note: the result will be the filename as a FilePath object (which is a string subclass). """ filename = FilePath(self.getTmpFilename(self.TmpDir)) data_file = open(filename,'w') data_file.write(data) data_file.close() return filename def _get_result_paths(self,data): """Return dict of {key: ResultPath} """ #clustalw .aln is used when no or unkown output type specified _treeinfo_formats = {'nj':'.nj', 'dist':'.dst', 'nexus':'.tre'} result = {} par = self.Parameters abs = self._absolute if par['-align'].isOn(): prefix = par['-infile'].Value.rsplit('.', 1)[0] #prefix = par['-infile'].Value.split('.')[0] aln_filename = self._aln_filename(prefix) if par['-newtree'].isOn(): dnd_filename = abs(par['-newtree'].Value) elif par['-usetree'].isOn(): dnd_filename = abs(par['-usetree'].Value) else: dnd_filename = abs(prefix + '.dnd') result['Align'] = ResultPath(Path=aln_filename,IsWritten=True) result['Dendro'] = ResultPath(Path=dnd_filename,IsWritten=True) elif par['-profile'].isOn(): prefix1 = par['-profile1'].Value.rsplit('.', 1)[0] prefix2 = par['-profile2'].Value.rsplit('.', 1)[0] #prefix1 = par['-profile1'].Value.split('.')[0] #prefix2 = par['-profile2'].Value.split('.')[0] aln_filename = ''; aln_written = True dnd1_filename = ''; tree1_written = True dnd2_filename = ''; tree2_written = True aln_filename = self._aln_filename(prefix1) #usetree1 if par['-usetree1'].isOn(): tree1_written = False #usetree2 if par['-usetree2'].isOn(): tree2_written = False if par['-newtree1'].isOn(): dnd1_filename = abs(par['-newtree1'].Value) aln_written=False else: dnd1_filename = abs(prefix1 + '.dnd') if par['-newtree2'].isOn(): dnd2_filename = abs(par['-newtree2'].Value) aln_written=False else: dnd2_filename = abs(prefix2 + '.dnd') result['Align'] = ResultPath(Path=aln_filename, IsWritten=aln_written) result['Dendro1'] = ResultPath(Path=dnd1_filename, IsWritten=tree1_written) result['Dendro2'] = ResultPath(Path=dnd2_filename, IsWritten=tree2_written) elif par['-sequences'].isOn(): prefix1 = par['-profile1'].Value.rsplit('.', 1)[0] prefix2 = par['-profile2'].Value.rsplit('.', 1)[0] #prefix1 = par['-profile1'].Value.split('.')[0] #alignment #prefix2 = par['-profile2'].Value.split('.')[0] #sequences aln_filename = ''; aln_written = True dnd_filename = ''; dnd_written = True aln_filename = self._aln_filename(prefix2) if par['-usetree'].isOn(): dnd_written = False elif par['-newtree'].isOn(): aln_written = False dnd_filename = abs(par['-newtree'].Value) else: dnd_filename = prefix2 + '.dnd' result['Align'] = ResultPath(Path=aln_filename,\ IsWritten=aln_written) result['Dendro'] = ResultPath(Path=dnd_filename,\ IsWritten=dnd_written) elif par['-tree'].isOn(): prefix = par['-infile'].Value.rsplit('.', 1)[0] #prefix = par['-infile'].Value.split('.')[0] tree_filename = ''; tree_written = True treeinfo_filename = ''; treeinfo_written = False tree_filename = prefix + '.ph' if par['-outputtree'].isOn() and\ par['-outputtree'].Value != 'phylip': treeinfo_filename = prefix +\ _treeinfo_formats[par['-outputtree'].Value] treeinfo_written = True result['Tree'] = ResultPath(Path=tree_filename,\ IsWritten=tree_written) result['TreeInfo'] = ResultPath(Path=treeinfo_filename,\ IsWritten=treeinfo_written) elif par['-bootstrap'].isOn(): prefix = par['-infile'].Value.rsplit('.', 1)[0] #prefix = par['-infile'].Value.split('.')[0] boottree_filename = prefix + '.phb' result['Tree'] = ResultPath(Path=boottree_filename,IsWritten=True) return result #SOME FUNCTIONS TO EXECUTE THE MOST COMMON TASKS def alignUnalignedSeqs(seqs,add_seq_names=True,WorkingDir=None,\ SuppressStderr=None,SuppressStdout=None): """Aligns unaligned sequences seqs: either list of sequence objects or list of strings add_seq_names: boolean. if True, sequence names are inserted in the list of sequences. if False, it assumes seqs is a list of lines of some proper format that the program can handle """ if add_seq_names: app = Clustalw(InputHandler='_input_as_seqs',\ WorkingDir=WorkingDir,SuppressStderr=SuppressStderr,\ SuppressStdout=SuppressStdout) else: app = Clustalw(InputHandler='_input_as_lines',\ WorkingDir=WorkingDir,SuppressStderr=SuppressStderr,\ SuppressStdout=SuppressStdout) return app(seqs) def alignUnalignedSeqsFromFile(filename,WorkingDir=None,SuppressStderr=None,\ SuppressStdout=None): """Aligns unaligned sequences from some file (file should be right format) filename: string, the filename of the file containing the sequences to be aligned in a valid format. """ app = Clustalw(WorkingDir=WorkingDir,SuppressStderr=SuppressStderr,\ SuppressStdout=SuppressStdout) return app(filename) def alignTwoAlignments(aln1,aln2,outfile,WorkingDir=None,SuppressStderr=None,\ SuppressStdout=None): """Aligns two alignments. Individual sequences are not realigned aln1: string, name of file containing the first alignment aln2: string, name of file containing the second alignment outfile: you're forced to specify an outfile name, because if you don't aln1 will be overwritten. So, if you want aln1 to be overwritten, you should specify the same filename. WARNING: a .dnd file is created with the same prefix as aln1. So an existing dendrogram might get overwritten. """ app = Clustalw({'-profile':None,'-profile1':aln1,\ '-profile2':aln2,'-outfile':outfile},SuppressStderr=\ SuppressStderr,WorkingDir=WorkingDir,SuppressStdout=SuppressStdout) app.Parameters['-align'].off() return app() def addSeqsToAlignment(aln1,seqs,outfile,WorkingDir=None,SuppressStderr=None,\ SuppressStdout=None): """Aligns sequences from second profile against first profile aln1: string, name of file containing the alignment seqs: string, name of file containing the sequences that should be added to the alignment. opoutfile: string, name of the output file (the new alignment) """ app = Clustalw({'-sequences':None,'-profile1':aln1,\ '-profile2':seqs,'-outfile':outfile},SuppressStderr=\ SuppressStderr,WorkingDir=WorkingDir, SuppressStdout=SuppressStdout) app.Parameters['-align'].off() return app() def buildTreeFromAlignment(filename,WorkingDir=None,SuppressStderr=None): """Builds a new tree from an existing alignment filename: string, name of file containing the seqs or alignment """ app = Clustalw({'-tree':None,'-infile':filename},SuppressStderr=\ SuppressStderr,WorkingDir=WorkingDir) app.Parameters['-align'].off() return app() def align_and_build_tree(seqs, moltype, best_tree=False, params=None): """Returns an alignment and a tree from Sequences object seqs. seqs: an cogent.core.alignment.SequenceCollection object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object best_tree: if True (default:False), uses a slower but more accurate algorithm to build the tree. params: dict of parameters to pass in to the Clustal app controller. The result will be a tuple containing a cogent.core.alignment.Alignment and a cogent.core.tree.PhyloNode object (or None for the alignment and/or tree if either fails). """ aln = align_unaligned_seqs(seqs, moltype=moltype, params=params) tree = build_tree_from_alignment(aln, moltype, best_tree, params) return {'Align':aln,'Tree':tree} def build_tree_from_alignment(aln, moltype, best_tree=False, params=None): """Returns a tree from Alignment object aln. aln: an cogent.core.alignment.Alignment object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object best_tree: if True (default:False), uses a slower but more accurate algorithm to build the tree. params: dict of parameters to pass in to the Clustal app controller. The result will be an cogent.core.tree.PhyloNode object, or None if tree fails. """ # Create instance of app controller, enable tree, disable alignment app = Clustalw(InputHandler='_input_as_multiline_string', params=params, \ WorkingDir='/tmp') app.Parameters['-align'].off() #Set params to empty dict if None. if params is None: params={} if moltype == DNA or moltype == RNA: params['-type'] = 'd' elif moltype == PROTEIN: params['-type'] = 'p' else: raise ValueError, "moltype must be DNA, RNA, or PROTEIN" # best_tree -> bootstrap if best_tree: if '-bootstrap' not in params: app.Parameters['-bootstrap'].on(1000) if '-seed' not in params: app.Parameters['-seed'].on(randint(0,1000)) if '-bootlabels' not in params: app.Parameters['-bootlabels'].on('nodes') else: app.Parameters['-tree'].on() # Setup mapping. Clustalw clips identifiers. We will need to remap them. seq_collection = SequenceCollection(aln) int_map, int_keys = seq_collection.getIntMap() int_map = SequenceCollection(int_map) # Collect result result = app(int_map.toFasta()) # Build tree tree = DndParser(result['Tree'].read(), constructor=PhyloNode) for node in tree.tips(): node.Name = int_keys[node.Name] # Clean up result.cleanUp() del(seq_collection, app, result, int_map, int_keys) return tree def bootstrap_tree_from_alignment(aln, seed=None, num_trees=None, params=None): """Returns a tree from Alignment object aln with bootstrap support values. aln: an cogent.core.alignment.Alignment object, or data that can be used to build one. seed: an interger, seed value to use num_trees: an integer, number of trees to bootstrap against params: dict of parameters to pass in to the Clustal app controller. The result will be an cogent.core.tree.PhyloNode object, or None if tree fails. If seed is not specifed in params, a random integer between 0-1000 is used. """ # Create instance of controllor, enable bootstrap, disable alignment,tree app = Clustalw(InputHandler='_input_as_multiline_string', params=params, \ WorkingDir='/tmp') app.Parameters['-align'].off() app.Parameters['-tree'].off() if app.Parameters['-bootstrap'].isOff(): if num_trees is None: num_trees = 1000 app.Parameters['-bootstrap'].on(num_trees) if app.Parameters['-seed'].isOff(): if seed is None: seed = randint(0,1000) app.Parameters['-seed'].on(seed) if app.Parameters['-bootlabels'].isOff(): app.Parameters['-bootlabels'].on("node") # Setup mapping. Clustalw clips identifiers. We will need to remap them. seq_collection = SequenceCollection(aln) int_map, int_keys = seq_collection.getIntMap() int_map = SequenceCollection(int_map) # Collect result result = app(int_map.toFasta()) # Build tree tree = DndParser(result['Tree'].read(), constructor=PhyloNode) for node in tree.tips(): node.Name = int_keys[node.Name] # Clean up result.cleanUp() del(seq_collection, app, result, int_map, int_keys) return tree def align_unaligned_seqs(seqs, moltype, params=None): """Returns an Alignment object from seqs. seqs: cogent.core.alignment.SequenceCollection object, or data that can be used to build one. moltype: a MolType object. DNA, RNA, or PROTEIN. params: dict of parameters to pass in to the Clustal app controller. Result will be a cogent.core.alignment.Alignment object. """ #create SequenceCollection object from seqs seq_collection = SequenceCollection(seqs,MolType=moltype) #Create mapping between abbreviated IDs and full IDs int_map, int_keys = seq_collection.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) #Create Clustalw app. app = Clustalw(InputHandler='_input_as_multiline_string',params=params) #Get results using int_map as input to app res = app(int_map.toFasta()) #Get alignment as dict out of results alignment = dict(ClustalParser(res['Align'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): new_alignment[int_keys[k]]=v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment,MolType=moltype) #Clean up res.cleanUp() del(seq_collection,int_map,int_keys,app,res,alignment) return new_alignment def add_seqs_to_alignment(seqs, aln, moltype, params=None): """Returns an Alignment object from seqs and existing Alignment. seqs: a cogent.core.alignment.SequenceCollection object, or data that can be used to build one. aln: a cogent.core.alignment.Alignment object, or data that can be used to build one params: dict of parameters to pass in to the Clustal app controller. """ #create SequenceCollection object from seqs seq_collection = SequenceCollection(seqs,MolType=moltype) #Create mapping between abbreviated IDs and full IDs seq_int_map, seq_int_keys = seq_collection.getIntMap() #Create SequenceCollection from int_map. seq_int_map = SequenceCollection(seq_int_map,MolType=moltype) #create Alignment object from aln aln = Alignment(aln,MolType=moltype) #Create mapping between abbreviated IDs and full IDs aln_int_map, aln_int_keys = aln.getIntMap(prefix='seqn_') #Create SequenceCollection from int_map. aln_int_map = Alignment(aln_int_map,MolType=moltype) #Update seq_int_keys with aln_int_keys seq_int_keys.update(aln_int_keys) #Create Mafft app. app = Clustalw(InputHandler='_input_as_multiline_string',\ params=params, SuppressStderr=True) app.Parameters['-align'].off() app.Parameters['-infile'].off() app.Parameters['-sequences'].on() #Add aln_int_map as profile1 app.Parameters['-profile1'].on(\ app._tempfile_as_multiline_string(aln_int_map.toFasta())) #Add seq_int_map as profile2 app.Parameters['-profile2'].on(\ app._tempfile_as_multiline_string(seq_int_map.toFasta())) #Get results using int_map as input to app res = app() #Get alignment as dict out of results alignment = dict(ClustalParser(res['Align'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): new_alignment[seq_int_keys[k]]=v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment,MolType=moltype) #Clean up res.cleanUp() remove(app.Parameters['-profile1'].Value) remove(app.Parameters['-profile2'].Value) del(seq_collection,seq_int_map,seq_int_keys,\ aln,aln_int_map,aln_int_keys,app,res,alignment) return new_alignment def align_two_alignments(aln1, aln2, moltype, params=None): """Returns an Alignment object from two existing Alignments. aln1, aln2: cogent.core.alignment.Alignment objects, or data that can be used to build them. params: dict of parameters to pass in to the Clustal app controller. """ #create SequenceCollection object from seqs aln1 = Alignment(aln1,MolType=moltype) #Create mapping between abbreviated IDs and full IDs aln1_int_map, aln1_int_keys = aln1.getIntMap() #Create SequenceCollection from int_map. aln1_int_map = Alignment(aln1_int_map,MolType=moltype) #create Alignment object from aln aln2 = Alignment(aln2,MolType=moltype) #Create mapping between abbreviated IDs and full IDs aln2_int_map, aln2_int_keys = aln2.getIntMap(prefix='seqn_') #Create SequenceCollection from int_map. aln2_int_map = Alignment(aln2_int_map,MolType=moltype) #Update aln1_int_keys with aln2_int_keys aln1_int_keys.update(aln2_int_keys) #Create Mafft app. app = Clustalw(InputHandler='_input_as_multiline_string',\ params=params, SuppressStderr=True) app.Parameters['-align'].off() app.Parameters['-infile'].off() app.Parameters['-profile'].on() #Add aln_int_map as profile1 app.Parameters['-profile1'].on(\ app._tempfile_as_multiline_string(aln1_int_map.toFasta())) #Add seq_int_map as profile2 app.Parameters['-profile2'].on(\ app._tempfile_as_multiline_string(aln2_int_map.toFasta())) #Get results using int_map as input to app res = app() #Get alignment as dict out of results alignment = dict(ClustalParser(res['Align'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): new_alignment[aln1_int_keys[k]]=v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment,MolType=moltype) #Clean up res.cleanUp() remove(app.Parameters['-profile1'].Value) remove(app.Parameters['-profile2'].Value) del(aln1,aln1_int_map,aln1_int_keys,\ aln2,aln2_int_map,aln2_int_keys,app,res,alignment) return new_alignment pycogent-1.9/cogent/app/cmfinder.py000066400000000000000000000203701273014367000174200ustar00rootroot00000000000000#!/usr/bin/env python """Provides application controller for CMfinder v0.2""" import os from cogent.app.util import CommandLineApplication, \ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters from sys import exit from os.path import isfile __author__ = "Daniel McDonald and Greg Caporaso" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Shandy Wikman"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" if 'CMfinder' not in os.environ: raise RuntimeError, \ 'cmfinder cannot run if the CMfinder environment variable is not set.' class CMfinder(CommandLineApplication): """The application controller for CMfinder 0.2 application Options: -b Do not use BLAST search to locate anchors -v Verbose. Print running information, and save intermediate results -c The maximum number of candidates in each sequence. Default 40. No bigger than 100. -m The minimum length of candidates. Default 30 -M The maximum length of candidates. Default 100 -n The maximum number of output motifs. Default 3 -f The fraction of the sequences expected to contain the motif. Default 0.80 -s The number of stem-loops in the motif -h Show help """ #-n default is 3, set to 3 because of resultpath concerns _parameters = { '-b':FlagParameter(Prefix='-',Name='b',Value=True), '-v':FlagParameter(Prefix='-',Name='v'), '-c':ValuedParameter(Prefix='-',Name='c',Value=None,Delimiter=' '), '-m':ValuedParameter(Prefix='-',Name='m',Value=None,Delimiter=' '), '-M':ValuedParameter(Prefix='-',Name='M',Value=None,Delimiter=' '), '-n':ValuedParameter(Prefix='-',Name='n',Value=3,Delimiter=' '), '-f':ValuedParameter(Prefix='-',Name='f',Value=None,Delimiter=' '), '-s':ValuedParameter(Prefix='-',Name='s',Value=None,Delimiter=' ')} _command = 'cmfinder.pl' _input_handler = '_input_as_string' def _get_result_paths(self,data): """Specifies the paths of output files generated by the application data: the data the instance the application is called on CMfinder produces it's output in two files .align and .motif it also prints an output to sdtout. """ result={} if not isinstance(data,list): inputPath = str(data) else: inputPath=self._input_filename itr=self.Parameters['-n'].Value for i in range(itr): nr=str(i+1) try: #unknown nr of output files f = open((inputPath+'.motif.h1.'+nr)) #if exists add to path f.close() result[('cm_'+nr)] =\ ResultPath(Path=(inputPath+'.cm.h1.'+nr)) result[('motif_'+nr)] =\ ResultPath(Path=(inputPath+'.motif.h1.'+nr)) except IOError: # else no more outputs break if self._input_filename is not None: result['_input_filename'] = ResultPath(self._input_filename) if isfile(self.WorkingDir+'latest.cm'): result['latest'] =\ ResultPath(Path=(self.WorkingDir+'latest.cm')) else: pass return result class CombMotif(CommandLineApplication): """ Application controller for the combmotif.pl program Only works for input as string since filnames are needed to located input """ _command = 'CombMotif.pl' _input_handler = '_input_as_string' def _input_as_string(self,data): """ Return data as a string """ input = str(data) +' '+str(data)+'.motif' return input def _input_as_lines(self,data): """ """ print 'Use input as string with cmfinder input_filename as input' exit(1) def _get_result_paths(self,data): """Specifies the paths of output files generated by the application data: the data the instance of the application is called on CombMotif will generate an output, the combination that was possible, the modified _get_result_path will detect that output and return the path to that output file. Since the output is not possible to predict one has to try all possible outputs. Assumes that one stem loop is used may correct this later """ result={} filename = str(data) motifList = [] mnr = 0 #motif number if not isinstance(data,list): inputPath = str(data) else: inputPath=self._input_filename for h in range(2): #numbers of stem loops in each motif, recommended 1-2 if h == 0: s = '.motif.h1.' else: s = '.motif.h2.' for i in range(1,6): for x in range(1,6): #two combined motifs if x == i: continue try: z = str(i) w = str(x) file = filename+s+z+'.'+w f = open((file)) #print 'found',file f.close() mnr += 1 n = str(mnr) result['comb'+n] = ResultPath(Path=file) except IOError: pass for y in range(1,6): # three combined motifs if y == x: continue try: z = str(i) w = str(x) q = str(y) file = filename+s+z+'.'+w+'.'+q f = open((file)) #print 'found', file f.close() mnr += 1 n = str(mnr) result['comb'+n] = ResultPath(Path=file) except IOError: pass for k in range(1,6): # four combined motifs if k == y: continue try: z = str(i) w = str(x) q = str(y) v = str(k) file = filename+s+z+'.'+w+'.'+q+'.'+v f = open(file) #print 'found',file f.close() mnr += 1 n = str(mnr) result['comb'+n] = ResultPath(Path=file) except IOError: pass for j in range(1,6): #five combined motifs if j == k: continue try: z = str(i) w = str(x) q = str(y) v = str(k) u = str(j) file = filename+s+z+'.'+w+'.'+q+'.'+v+'.'+u f = open(file) #print 'found',file f.close() mnr += 1 n = str(mnr) result['comb'+n] = ResultPath(Path=file) except IOError: pass if isfile(self.WorkingDir+'latest.cm'): result['latest'] =\ ResultPath(Path=(self.WorkingDir+'latest.cm')) else: pass return result pycogent-1.9/cogent/app/comrna.py000066400000000000000000000057041273014367000171140ustar00rootroot00000000000000#!/usr/bin/env python from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters, _find_synonym, is_not_None __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class comRNA(CommandLineApplication): """Application controller comRNA v1.80 for comRNA options type comRNA at the promt """ _parameters = { '-L':ValuedParameter(Prefix='',Name='L',Value=None,Delimiter=' '), '-E':ValuedParameter(Prefix='',Name='E',Value=None,Delimiter=' '), '-S':ValuedParameter(Prefix='',Name='S',Value=None,Delimiter=' '), '-Sh':ValuedParameter(Prefix='',Name='Sh',Value=None,Delimiter=' '), '-Sl':ValuedParameter(Prefix='',Name='Sl',Value=None,Delimiter=' '), '-P':ValuedParameter(Prefix='',Name='P',Value=None,Delimiter=' '), '-n':ValuedParameter(Prefix='',Name='n',Value=None,Delimiter=' '), '-x':ValuedParameter(Prefix='',Name='x',Value=None,Delimiter=' '), '-m':ValuedParameter(Prefix='',Name='m',Value=None,Delimiter=' '), '-tp':ValuedParameter(Prefix='',Name='tp',Value=None,Delimiter=' '), '-ts':ValuedParameter(Prefix='',Name='ts',Value=None,Delimiter=' '), '-a':ValuedParameter(Prefix='',Name='a',Value=None,Delimiter=' '), '-o':ValuedParameter(Prefix='',Name='o',Value=None,Delimiter=' '), '-c':ValuedParameter(Prefix='',Name='c',Value=None,Delimiter=' '), '-j':ValuedParameter(Prefix='',Name='j',Value=None,Delimiter=' '), '-r':ValuedParameter(Prefix='',Name='r',Value=None,Delimiter=' '), '-f':ValuedParameter(Prefix='',Name='f',Value=None,Delimiter=' '), '-v':ValuedParameter(Prefix='',Name='v',Value=None,Delimiter=' '), '-g':ValuedParameter(Prefix='',Name='g',Value=None,Delimiter=' '), '-d':ValuedParameter(Prefix='',Name='d',Value=None,Delimiter=' '), '-wa':ValuedParameter(Prefix='',Name='wa',Value=None,Delimiter=' '), '-wb':ValuedParameter(Prefix='',Name='wb',Value=None,Delimiter=' '), '-wc':ValuedParameter(Prefix='',Name='wc',Value=None,Delimiter=' '), '-wd':ValuedParameter(Prefix='',Name='wd',Value=None,Delimiter=' '), '-we':ValuedParameter(Prefix='',Name='we',Value=None,Delimiter=' '), '-pk':ValuedParameter(Prefix='',Name='pk',Value=None,Delimiter=' '), '-pg':ValuedParameter(Prefix='',Name='pg',Value=None,Delimiter=' '), '-pd':ValuedParameter(Prefix='',Name='pd',Value=None,Delimiter=' '), '-ps':ValuedParameter(Prefix='',Name='ps',Value=None,Delimiter=' '), '-pc':ValuedParameter(Prefix='',Name='pc',Value=None,Delimiter=' ')} _command = 'comRNA' _input_handler = '_input_as_string' pycogent-1.9/cogent/app/consan.py000066400000000000000000000126031273014367000171120ustar00rootroot00000000000000#!/usr/bin/env python from os import remove, system, rmdir, mkdir from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath, FilePath, ApplicationError from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters, _find_synonym, is_not_None __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman", "Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class Consan(CommandLineApplication): """Application controller for CONSAN v1.1""" _parameters = { '-m':ValuedParameter(Prefix='-',Name='m'), '-M':ValuedParameter(Prefix='-',Name='M'), '-C':ValuedParameter(Prefix='-',Name='C'), '-P':ValuedParameter(Prefix='-',Name='P'), '-V':FlagParameter(Prefix='-',Name='V'), '-f':FlagParameter(Prefix='-',Name='f'), '-x':FlagParameter(Prefix='-',Name='x'), '-t':FlagParameter(Prefix='-',Name='t')} _command = 'sfold' _input_handler='_input_as_string' def _input_as_string(self,data): """ Takes two files in a list as input eg. data = [path1,path2] """ inputFiles = ' '.join(data) self._input_filename = data return inputFiles def _input_as_lines(self,data): """ Writes to first sequences(fasta) in a list to two temp files data: a sequence to be written to a file, each element of the sequence will compose a line in the file Data should be in the following format: data = ['>tag1','sequence1','>tag2','sequence2'] Note: '\n' will be stripped off the end of each sequence element before writing to a file in order to avoid multiple new lines accidentally be written to a file """ inputFiles = '' self._input_filename = [] for i in range(2): filename = self.getTmpFilename(self.WorkingDir) self._input_filename.append(filename) data_file = open(filename,'w') if i == 0: data_to_file = '\n'.join(data[:2]) tmp1 = filename else: data_to_file = '\n'.join(data[2:]) tmp2 = filename data_file.write(data_to_file) data_file.close() inputFiles = ' '.join([tmp1,tmp2]) return inputFiles # need to override __call__ to remove files properly def __call__(self,data=None, remove_tmp=True): """Run the application with the specified kwargs on data data: anything that can be cast into a string or written out to a file. Usually either a list of things or a single string or number. input_handler will be called on this data before it is passed as part of the command-line argument, so by creating your own input handlers you can customize what kind of data you want your application to accept remove_tmp: if True, removes tmp files """ input_handler = self.InputHandler suppress_stdout = self.SuppressStdout suppress_stderr = self.SuppressStderr if suppress_stdout: outfile = FilePath('/dev/null') else: outfile = self.getTmpFilename(self.TmpDir) if suppress_stderr: errfile = FilePath('/dev/null') else: errfile = FilePath(self.getTmpFilename(self.TmpDir)) if data is None: input_arg = '' else: input_arg = getattr(self,input_handler)(data) # Build up the command, consisting of a BaseCommand followed by # input and output (file) specifications command = self._command_delimiter.join(filter(None,\ [self.BaseCommand,str(input_arg),'>',str(outfile),'2>',\ str(errfile)])) if self.HaltExec: raise AssertionError, "Halted exec with command:\n" + command # The return value of system is a 16-bit number containing the signal # number that killed the process, and then the exit status. # We only want to keep the exit status so do a right bitwise shift to # get rid of the signal number byte tmp_dir = ''.join([self.WorkingDir, 'tmp']) mkdir(tmp_dir) exit_status = system(command) >> 8 rmdir(tmp_dir) # Determine if error should be raised due to exit status of # appliciation if not self._accept_exit_status(exit_status): raise ApplicationError, \ 'Unacceptable application exit status: %s, command: %s'\ % (str(exit_status),command) # open the stdout and stderr if not being suppressed out = None if not suppress_stdout: out = open(outfile,"r") err = None if not suppress_stderr: err = open(errfile,"r") result = CommandLineAppResult(out,err,exit_status,\ result_paths=self._get_result_paths(data)) # Clean up the input file if one was created if remove_tmp: if self._input_filename: for f in self._input_filename: remove(f) self._input_filename = None return result pycogent-1.9/cogent/app/contrafold.py000066400000000000000000000014621273014367000177650ustar00rootroot00000000000000#!/usr/bin/env python from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters, _find_synonym, is_not_None __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class Contrafold(CommandLineApplication): """Application controler for CONTRAfold v1.0""" _parameters = {'predict':FlagParameter(Prefix='',Name='predict',Value=True), 'train':FlagParameter(Prefix='',Name='train')} _command = 'contrafold' _input_handler='_input_as_string' pycogent-1.9/cogent/app/cove.py000066400000000000000000000156601273014367000165730ustar00rootroot00000000000000#!/usr/bin/env python from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters, _find_synonym, is_not_None __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class Covet(CommandLineApplication): """Application controller for Covet Generate new models, by training them on example sequences. where options are: -a : make starting model from alignment -A : save alignments to filename.1, etc., for animation -b : each iteration, back up curr model to -f : use flat text save formats, portable but clumsy -G : gap-open prob 0 < gop < 1 for random alignment generation -h : print short help and version info -i : take start model from -m : do maximum likelihood model construction (slow!) -p : use prior in ; default is Laplace plus-one -s : set random() seed -X : gap-extend prob 0 < gex < 1 for random alignment generation """ _parameters = { '-a':ValuedParameter(Prefix='-',Name='a',Delimiter=' '), '-A':ValuedParameter(Prefix='-',Name='A',Delimiter=' '), '-b':ValuedParameter(Prefix='-',Name='b',Delimiter=' '), '-f':FlagParameter(Prefix='-',Name='f'), '-G':ValuedParameter(Prefix='-',Name='G',Delimiter=' '), '-i':ValuedParameter(Prefix='-',Name='i',Delimiter=' '), '-m':FlagParameter(Prefix='-',Name='m'), '-p':ValuedParameter(Prefix='-',Name='p',Delimiter=' '), '-s':ValuedParameter(Prefix='-',Name='s',Delimiter=' '), '-X':ValuedParameter(Prefix='-',Name='X',Delimiter=' ')} _command = 'covet' _input_handlar = '_input_as_string' def _input_as_string(self,filename): """Returns 'modelname' and 'filename' to redirect input to stdin""" return ' '.join([filename+'.cm',super(Covet,self)._input_as_string(filename)]) def _input_as_lines(self,data): """Returns 'temp_filename to redirect input to stdin""" filename = self._input_filename = self.getTmpFilename(self.WorkingDir) data_file = open(filename,'w') data_to_file = '\n'.join([str(d).strip('\n') for d in data]) data_file.write(data_to_file) data_file.write('\n') #must end with new line data_file.close() return ' '.join([filename+'.cm',filename]) def _get_result_paths(self,data): """Specifies the paths of output files generated by the application data: the data the instance of the application is called on CMfinder produces it's output in two files .align and .motif it also prints an output to sdtout. """ result={} if not isinstance(data,list): inputPath=data else: inputPath=''.join([self._input_filename]) result['cm'] =\ ResultPath(Path=(inputPath+'.cm')) if self._input_filename is not None: result['_input_filename'] = ResultPath(self._input_filename) return result class Coves(CommandLineApplication): """Application controller for Coves Computes the score of each whole sequence individually, and prints the scores. You might use it to detect sequences which, according to the model, don't belong to the same structural consensus; sequences which don't fit the model get negative scores. where options are: -a : show all pairs, not just Watson-Crick -g : set expected background GC composition (default 0.5) -m : mountain representation of structural alignment -s : secondary structure string representation of structural alignment """ _parameters = { '-a':FlagParameter(Prefix='-',Name='a'), '-g':ValuedParameter(Prefix='-',Name='g',Delimiter=' '), '-m':FlagParameter(Prefix='-',Name='m'), '-s':FlagParameter(Prefix='-',Name='s',Value=True)} _command = 'coves' _input_handler = '_input_as_string' def _input_as_string(self,filename): """Returns 'modelname' and 'filename' to redirect input to stdin""" return ' '.join([filename+'.cm',super(Coves,self)._input_as_string(filename)]) class Covee(CommandLineApplication): """Application controller for Covee emits a consensus structure prediction for the family. where options are: -a : annotate all pairs, not just canonical ones -b : emit single most probable sequence -l : print as mountain landscape -s : set seed for random() EXPERIMENTAL OPTIONS: -L : calculate expected length distributions for states """ _parameters = { '-a':FlagParameter(Prefix='-',Name='a'), '-b':FlagParameter(Prefix='-',Name='b',Value=True), '-l':FlagParameter(Prefix='-',Name='l'), '-s':ValuedParameter(Prefix='-',Name='s',Delimiter=' '), '-L':FlagParameter(Prefix='-',Name='L')} _command = 'covee' _input_handler = '_input_as_string' def _input_as_string(self,filename): """Returns 'modelname' and 'filename' to redirect input to stdin""" return ' '.join([filename+'.cm',super(Covee,self)._input_as_string(filename)]) def _input_as_lines(self,data): """Returns 'temp_filename to redirect input to stdin""" return ''.join([data+'.cm',super(Covee,self)._input_as_lines(data)]) class Covea(CommandLineApplication): """Application controller for Covea here supported options are: -a : annotate all base pairs, not just canonical ones -h : print short help and version info -o : write alignment to in SELEX format -s : save individual alignment scores to Experimental options: -S : use small-memory variant of alignment algorithm """ _parameters = { '-a':FlagParameter(Prefix='-',Name='a'), '-o':ValuedParameter(Prefix='-',Name='o',Delimiter=' '), '-s':ValuedParameter(Prefix='-',Name='s',Delimiter=' '), '-S':FlagParameter(Prefix='-',Name='S')} _command = 'covea' _input_handler = '_input_as_string' def _input_as_string(self,filename): """Returns 'modelname' and 'filename' to redirect input to stdin""" return ' '.join([filename+'.cm',super(Covea,self)._input_as_string(filename)]) def _input_as_lines(self,data): """Returns 'temp_filename to redirect input to stdin""" return ''.join([data+'.cm',super(Covea,self)._input_as_lines(data)]) pycogent-1.9/cogent/app/dialign.py000066400000000000000000000237751273014367000172540ustar00rootroot00000000000000#!/usr/bin/env python """ Application controller for dialign2-2 """ __author__ = "Gavin Huttley" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Gavin Huttley"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Gavin Huttley" __email__ = "gavin.huttley@anu.edu.au" __status__ = "Production" from cogent.app.parameters import FlagParameter, ValuedParameter from cogent.app.util import CommandLineApplication, ResultPath, \ get_tmp_filename, guess_input_handler from random import choice from cogent.parse.tree import DndParser from cogent.core.tree import PhyloNode from cogent.parse.fasta import MinimalFastaParser class Dialign(CommandLineApplication): """Dialign application controller""" _options ={ # -afc Creates additional output file "*.afc" containing data of # all fragments considered for alignment # WARNING: this file can be HUGE ! '-afc':FlagParameter(Prefix='-',Name='afc'), # -afc_v like "-afc" but verbose: fragments are explicitly printed # WARNING: this file can be EVEN BIGGER ! '-afc_v':FlagParameter(Prefix='-',Name='afc_v'), # -anc Anchored alignment. Requires a file .anc # containing anchor points. '-anc':FlagParameter(Prefix='-',Name='anc'), # -cs if segments are translated, not only the `Watson strand' # but also the `Crick strand' is looked at. '-cs':FlagParameter(Prefix='-',Name='cs'), # -cw additional output file in CLUSTAL W format. '-cw':FlagParameter(Prefix='-',Name='cw'), # -ds `dna alignment speed up' - non-translated nucleic acid # fragments are taken into account only if they start with # at least two matches. Speeds up DNA alignment at the expense # of sensitivity. '-ds':FlagParameter(Prefix='-',Name='ds'), # -fa additional output file in FASTA format. '-fa':FlagParameter(Prefix='-',Name='fa'), # -ff Creates file *.frg containing information about all # fragments that are part of the respective optimal pairwise # alignmnets plus information about consistency in the multiple # alignment '-ff':FlagParameter(Prefix='-',Name='ff'), # -fn output files are named . . '-fn':ValuedParameter('-',Name='fn',Delimiter=' ', IsPath=True), # # # -fop Creates file *.fop containing coordinates of all fragments # that are part of the respective pairwise alignments. '-fop':FlagParameter(Prefix='-',Name='fop'), # -fsm Creates file *.fsm containing coordinates of all fragments # that are part of the final alignment '-fsm':FlagParameter(Prefix='-',Name='fsm'), # -iw overlap weights switched off (by default, overlap weights are # used if up to 35 sequences are aligned). This option # speeds up the alignment but may lead to reduced alignment # quality. '-iw':FlagParameter(Prefix='-',Name='iw'), # -lgs `long genomic sequences' - combines the following options: # -ma, -thr 2, -lmax 30, -smin 8, -nta, -ff, # -fop, -ff, -cs, -ds, -pst '-lgs':FlagParameter(Prefix='-',Name='lgs'), # -lgs_t Like "-lgs" but with all segment pairs assessed at the # peptide level (rather than 'mixed alignments' as with the # "-lgs" option). Therefore faster than -lgs but not very # sensitive for non-coding regions. '-lgs_t':FlagParameter(Prefix='-',Name='lgs_t'), # -lmax maximum fragment length = x (default: x = 40 or x = 120 # for `translated' fragments). Shorter x speeds up the program # but may affect alignment quality. '-lmax':ValuedParameter('-',Name='lmax',Delimiter=' '), # -lo (Long Output) Additional file *.log with information abut # fragments selected for pairwise alignment and about # consistency in multi-alignment proceedure '-lo':FlagParameter(Prefix='-',Name='lo'), # -ma `mixed alignments' consisting of P-fragments and N-fragments # if nucleic acid sequences are aligned. '-ma':FlagParameter(Prefix='-',Name='ma'), # -mask residues not belonging to selected fragments are replaced # by `*' characters in output alignment (rather than being # printed in lower-case characters) '-mask':FlagParameter(Prefix='-',Name='mask'), # -mat Creates file *mat with substitution counts derived from the # fragments that have been selected for alignment '-mat':FlagParameter(Prefix='-',Name='mat'), # -mat_thr Like "-mat" but only fragments with weight score > t # are considered '-mat_thr':ValuedParameter('-',Name='mat_thr',Delimiter=' '), # -max_link "maximum linkage" clustering used to construct sequence tree # (instead of UPGMA). '-max_link':FlagParameter(Prefix='-',Name='max_link'), # -min_link "minimum linkage" clustering used. '-min_link':FlagParameter(Prefix='-',Name='min_link'), # # -mot "motif" option. '-mot':FlagParameter(Prefix='-',Name='mot'), # -msf separate output file in MSF format. '-msf':FlagParameter(Prefix='-',Name='msf'), # -n input sequences are nucleic acid sequences. No translation # of fragments. '-n':FlagParameter(Prefix='-',Name='n'), # -nt input sequences are nucleic acid sequences and `nucleic acid # segments' are translated to `peptide segments'. '-nt':FlagParameter(Prefix='-',Name='nt'), # -nta `no textual alignment' - textual alignment suppressed. This # option makes sense if other output files are of intrest -- # e.g. the fragment files created with -ff, -fop, -fsm or -lo '-nta':FlagParameter(Prefix='-',Name='nta'), # -o fast version, resulting alignments may be slightly different. '-o':FlagParameter(Prefix='-',Name='o'), # # -ow overlap weights enforced (By default, overlap weights are # used only if up to 35 sequences are aligned since calculating # overlap weights is time consuming). Warning: overlap weights # generally improve alignment quality but the running time # increases in the order O(n^4) with the number of sequences. # This is why, by default, overlap weights are used only for # sequence sets with < 35 sequences. '-ow':FlagParameter(Prefix='-',Name='ow'), # -pst "print status". Creates and updates a file *.sta with # information about the current status of the program run. # This option is recommended if large data sets are aligned # since it allows the user to estimate the remaining running # time. '-pst':FlagParameter(Prefix='-',Name='pst'), # -smin minimum similarity value for first residue pair (or codon # pair) in fragments. Speeds up protein alignment or alignment # of translated DNA fragments at the expense of sensitivity. '-smin':ValuedParameter('-',Name='smin',Delimiter=' '), # -stars maximum number of `*' characters indicating degree of # local similarity among sequences. By default, no stars # are used but numbers between 0 and 9, instead. '-stars':ValuedParameter('-',Name='stars',Delimiter=' '), # -stdo Results written to standard output. '-stdo':FlagParameter(Prefix='-',Name='stdo'), # -ta standard textual alignment printed (overrides suppression # of textual alignments in special options, e.g. -lgs) '-ta':FlagParameter(Prefix='-',Name='ta'), # -thr Threshold T = x. '-thr':ValuedParameter('-',Name='thr',Delimiter=' '), # -xfr "exclude fragments" - list of fragments can be specified # that are NOT considered for pairwise alignment '-xfr':FlagParameter(Prefix='-',Name='xfr'), } _parameters = {} _parameters.update(_options) _command = "dialign2-2" def _input_as_seqs(self,data): lines = [] for i,s in enumerate(data): #will number the sequences 1,2,3,etc. lines.append(''.join(['>',str(i+1)])) lines.append(s) return self._input_as_lines(lines) def _align_out_filename(self): if self.Parameters['-fn'].isOn(): aln_filename = self._absolute(str(self.Parameters['-fn'].Value)) else: raise ValueError, "No output file specified." return aln_filename def _get_result_paths(self,data): result = {} if self.Parameters['-fn'].isOn(): out_name = self._align_out_filename() result['Align'] = ResultPath(Path=out_name,IsWritten=True) return result def getHelp(self): """Dialign help""" help_str = """ """ return help_str pycogent-1.9/cogent/app/dotur.py000066400000000000000000000201251273014367000167640ustar00rootroot00000000000000#!/usr/bin/env python """Provides an application controller for the commandline version of: DOTUR v1.53 """ import shutil from cogent.app.parameters import FlagParameter, ValuedParameter, \ MixedParameter from cogent.app.util import CommandLineApplication, ResultPath, \ get_tmp_filename, FilePath from cogent.core.alignment import SequenceCollection, Alignment from cogent.core.moltype import DNA, RNA, PROTEIN from cogent.format.table import phylipMatrix from cogent.parse.dotur import OtuListParser __author__ = "Jeremy Widmann" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Jeremy Widmann"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Jeremy Widmann" __email__ = "jeremy.widmann@colorado.edu" __status__ = "Development" class Dotur(CommandLineApplication): """Dotur application controller. """ # Options: _options = {\ # -i: Number of iterations (default = 1000) '-i':ValuedParameter('-',Name='i',Delimiter=' '),\ # -c: Clustering method - (f) furthest neighbor, (n) nearest # neighbor, (a) average neighbor (default = f) '-c':ValuedParameter('-',Name='c',Delimiter=' '),\ # -p: Precision of distances for output, increasing can # dramatically lengthen execution times - 10, 100, 1000, 10000 # (default = 100) '-p':ValuedParameter('-',Name='p',Delimiter=' '),\ # -l: Input file is lower triangular (default = square matrix) '-l':FlagParameter('-',Name='l'),\ # -r: Calculates rarefaction curves for each parameter, can # dramatically lengthen execution times. Simple rarefaction # curve always calculated. '-r':FlagParameter('-',Name='r'),\ # -stop: Stops clustering when cutoff has been reached. '-stop':FlagParameter('-',Name='stop'),\ # -wrep: Samples with replacement. '-wrep':FlagParameter('-',Name='wrep'),\ # -jumble: Jumble the order of the distance matrix. '-jumble':FlagParameter('-',Name='jumble'),\ # -sim: Converts similarity score to distance (D=1-S). '-sim':FlagParameter('-',Name='sim'),\ } _parameters = {} _parameters.update(_options) _input_handler = '_input_as_multiline_string' _command = 'dotur' def getHelp(self): """Method that points to the DOTUR documentation.""" help_str =\ """ See DOTUR Documentation page at: http://schloss.micro.umass.edu/software/dotur/documentation.html """ return help_str def _input_as_multiline_string(self, data): """Write a multiline string to a temp file and return the filename. data: a multiline string to be written to a file. * Note: the result will be the filename as a FilePath object (which is a string subclass). """ filename = self._input_filename = \ FilePath(self.getTmpFilename(self.WorkingDir)) data_file = open(filename,'w') data_file.write(data) data_file.close() return filename def _get_cluster_method(self): """Returns cluster method as string. """ if self.Parameters['-c'].isOn(): cluster_method = self._absolute(str(\ self.Parameters['-c'].Value))+'n' else: # f (furthest neighbor) is default cluster_method = 'fn' return cluster_method def _get_result_paths(self,data): """Return dict of {key: ResultPath} - NOTE: Only putting a few files on the results path. Add more here if needed. """ result = {} out_name = self._input_filename.split('.txt')[0] cluster_method = self._get_cluster_method() #only care about Otu, List and Rank, can add others later. result['Otu'] = ResultPath(Path=out_name+'.%s.otu'%(cluster_method)) result['List'] = ResultPath(Path=out_name+'.%s.list'%(cluster_method)) result['Rank'] = ResultPath(Path=out_name+'.%s.rank'%(cluster_method)) result['Rarefaction'] = \ ResultPath(Path=out_name+'.%s.rarefaction'%(cluster_method)) return result def remap_seq_names(otu_list, int_map): """Returns list with seq names remapped. - otu_list: list of lists containing sequence names in an OTU. - int_map: mapping between names in otu_list and original names. """ res = [] for otu in otu_list: curr_otu = [] for seq in otu: curr_otu.append(int_map[seq]) res.append(curr_otu) return res def dotur_from_alignment(aln,moltype,distance_function,params=None): """Returns dotur results given an alignment and distance function. - aln: An Alignment object or something that behaves like one. Sequences must be aligned. - moltype: cogent.core.moltype object. - distance_function: function that can be passed to distanceMatrix() method of SequenceCollection. Must be able to find distance between two sequences. - NOTE: This function will only return the parsed *.list file, as it contains the OTU identities. Dotur generates 23 output files, so if this is not the one you are looking for, check out the documentation and add the others to the result path. """ #construct Alignment object. This will handle unaligned sequences. aln = Alignment(aln, MolType=moltype) #need to make int map. int_map, int_keys = aln.getIntMap() #construct Alignment object from int map to use object functionality int_map = Alignment(int_map, MolType=moltype) order = sorted(int_map.Names) #Build distance matrix. d_matrix_dict = int_map.distanceMatrix(f=distance_function) d_matrix_dict.RowOrder=order d_matrix_dict.ColOrder=order #Get distance matrix in list form. d_matrix_list = d_matrix_dict.toLists() #must be strings to use phylipMatrix for i,line in enumerate(d_matrix_list): d_matrix_list[i]=map(str,line) #Get phylip formatted string. phylip_matrix_string = phylipMatrix(rows=d_matrix_list,names=order) working_dir = get_tmp_filename(suffix='') app = Dotur(InputHandler='_input_as_multiline_string',\ WorkingDir=working_dir,params=params) res = app(phylip_matrix_string) otu_list = OtuListParser(res['List'].readlines()) #remap sequence names for i,otu in enumerate(otu_list): otu_list[i][2]=remap_seq_names(otu[2], int_keys) shutil.rmtree(app.WorkingDir) return otu_list def dotur_from_file(distance_matrix_file_path,params=None): """Returns dotur results given a distance matrix file. - distance_matrix_file_path: Path to distance matrix file. This file must a PHYLIP formatted square distance matrix. This format is available in cogent.format.table. - IMPORANT NOTE: This distance matrix format allows only 10 characters for the row labels in the distance matrix. Also, the IDs must be unique and ungapped to be useful when using dotur. - NOTE: This function will only return the parsed *.list file, as it contains the OTU identities. Dotur generates 23 output files, so if this is not the one you are looking for, check out the documentation and add the others to the result path. """ # Read out the data from the distance_matrix_file_path. # This is important so we can run dotur in a temp directory and avoid # having to handle all 23 output files. d_matrix_string = open(distance_matrix_file_path,'U').read() working_dir = get_tmp_filename(suffix='') app = Dotur(InputHandler='_input_as_multiline_string',\ WorkingDir=working_dir,params=params) res = app(d_matrix_string) otu_list = OtuListParser(res['List'].readlines()) shutil.rmtree(app.WorkingDir) return otu_list pycogent-1.9/cogent/app/dynalign.py000066400000000000000000000221261273014367000174370ustar00rootroot00000000000000#!/usr/bin/env python from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath, ApplicationError from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters from sys import platform from os import remove,system,mkdir,getcwd,close __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman", "Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class Dynalign(CommandLineApplication): """Application controller for Dynalign Input: Sequences for input in Dynalign are assumed to be in the following format: ;(first line of file) Comments must start with a ;semicolon ;There can be any number of comments A single line title must immediately follow: AAA GCGG UUTGTT UTCUTaaTCTXXXXUCAGG1 where the terminal 1 is required at the end. pknotsRG is a tool for thermodynamic folding of RNA secondary structures, including the class of canonical simple recursive pseudoknots. -alignment The alignment file that will be created -M Maximum seperation parameter (larger then diff in length of seq) -gap_cost 0.4 good value -max_precent_diff maximum % diff in free energy in suboptimal struct. 20 good starting point -bp_window specifies how different the suboptimal structures must be from each other. 2 good starting point -align_window specifies how different alignments must be, 1 good starting point. -single_bp_inserts specifies whether single base pair inserts are allowed; 0 = no; 1 = yes. -[savefile] optional """ _parameters = { '-alignment':ValuedParameter(Prefix='',Name='',Value='align',Delimiter=' '), '-M':ValuedParameter(Prefix='',Name='',Value=10,Delimiter=' '), '-gap_cost':ValuedParameter(Prefix='',Name='',Value=0.4,Delimiter=' '), '-max_structures':ValuedParameter(Prefix='',Name='',Value=8,Delimiter=' '), '-max_percent_diff':ValuedParameter(Prefix='',Name='',Value=20,\ Delimiter=' '), '-bp_window':ValuedParameter(Prefix='',Name='',Value=2,Delimiter=' '), '-align_window':ValuedParameter(Prefix='',Name='',Value=1,Delimiter=' '), '-single_bp_inserts':ValuedParameter(Prefix='',Name='',Value=1,\ Delimiter=' '),} _command = 'dynalign' _input_handler = '_input_as_string' def _input_as_string(self,data): """Return data as a string Data = list with two file paths ex: data = ['path1,'path2'']""" inputFiles = '' self._input_filename = [] for i in data: self._input_filename.append(i) inputFiles = ' '.join([inputFiles,i]) outputFile = ' '.join(['ct1', 'ct2']) inputFiles = ' '.join([inputFiles,outputFile]) return inputFiles def _input_as_lines(self,data): """ Write a seq of lines to a temp file and return the filename string data: a sequence to be written to a file, each element of the sequence will compose a line in the file. ex. data = [file1,file2], file1 and 2 is lists of lines -> [[List],[List]] Note: '\n' will be stripped off the end of each sequence element before writing to a file in order to avoid multiple new lines accidentally be written to a file """ inputFiles = '' self._input_filename = [] for el in data: filename = self.getTmpFilename(self.WorkingDir) self._input_filename.append(filename) data_file = open(filename,'w') data_to_file = '\n'.join([str(d).strip('\n') for d in el]) data_file.write(data_to_file) data_file.close() inputFiles = ' '.join([inputFiles,filename]) outputFiles = ' '.join(['ct1', 'ct2']) inputFiles = ' '.join([inputFiles,outputFiles]) return inputFiles def _get_result_paths(self,data): """ data: the data the instance of the application is called on """ result = {} result['seq_1_ct'] =\ ResultPath(Path=(self.WorkingDir+'ct1')) result['seq_2_ct'] =\ ResultPath(Path=(self.WorkingDir+'ct2')) result['alignment'] =\ ResultPath(Path=(self.WorkingDir+'align')) return result #Below from Cogent/app/util.py modified to accommodate dynalign def __call__(self,data=None): """Run the application with the specified kwargs on data Overides the __call__ function in util.py becasue of the special circumstance surrounding the command line input. data: anything that can be cast into a string or written out to a file. Usually either a list of things or a single string or number. input_handler will be called on this data before it is passed as part of the command-line argument, so by creating your own input handlers you can customize what kind of data you want you application to accept """ input_handler = self.InputHandler suppress_stdout = self.SuppressStdout suppress_stderr = self.SuppressStderr if suppress_stdout: outfile = '/dev/null' else: outfile = self.getTmpFilename(self.WorkingDir) if suppress_stderr: errfile = '/dev/null' else: errfile = self.getTmpFilename(self.WorkingDir) if data is None: input_arg = '' else: input_arg = getattr(self,input_handler)(data) # Build up the command, consisting of a BaseCommand followed by # input and output (file) specifications first,second=self.BaseCommand command = self._command_delimiter.join(filter(None,\ [first,input_arg,second,'>',outfile,'2>',errfile])) if self.HaltExec: raise AssertionError, "Halted exec with command:\n" + command # The return value of system is a 16-bit number containing the signal # number that killed the process, and then the exit status. # We only want to keep the exit status so do a right bitwise shift to # get rid of the signal number byte exit_status = system(command) >> 8 # Determine if error should be raised due to exit status of # appliciation if not self._accept_exit_status(exit_status): raise ApplicationError, \ 'Unacceptable application exit status: %s, command: %s'\ % (str(exit_status),command) # open the stdout and stderr if not being suppressed out = None if not suppress_stdout: out = open(outfile,"r") err = None if not suppress_stderr: err = open(errfile,"r") result = CommandLineAppResult(out,err,exit_status,\ result_paths=self._get_result_paths(data)) # Clean up the input file if one was created if self._input_filename: for f in self._input_filename: remove(f) self._input_filename = None return result def _get_base_command(self): """ Returns the full command string Overides the __call__ function in util.py becasue of the special circumstance surrounding the command line input. input_arg: the argument to the command which represents the input to the program, this will be a string, either representing input or a filename to get input from """ command_part1 = [] command_part2 = [] # Append a change directory to the beginning of the command to change # to self.WorkingDir before running the command cd_command = ''.join(['cd ',self.WorkingDir,';']) if self._command is None: raise ApplicationError, '_command has not been set.' command = self._command command_part1.append(cd_command) command_part1.append(command) lista = [self.Parameters['-alignment'],\ self.Parameters['-M'],\ self.Parameters['-gap_cost'],\ self.Parameters['-max_structures'],\ self.Parameters['-max_percent_diff'],\ self.Parameters['-bp_window'],\ self.Parameters['-align_window'],\ self.Parameters['-single_bp_inserts']] command_part2.append(self._command_delimiter.join(filter(\ None,(map(str,lista))))) return self._command_delimiter.join(command_part1).strip(),\ self._command_delimiter.join(command_part2).strip() BaseCommand = property(_get_base_command) pycogent-1.9/cogent/app/fastq_join.py000066400000000000000000000211061273014367000177640ustar00rootroot00000000000000#!/usr/bin/env python # file: fastq_join.py # Application controller for ea-utils v1.1.2-537 # fastq processing utilities # http://code.google.com/p/ea-utils/ # from cogent.app.parameters import ValuedParameter, FlagParameter from cogent.app.util import CommandLineApplication, ResultPath, \ ApplicationError import os import tempfile import shutil __author__ = "Michael Robeson" __copyright__ = "Copyright 2007-2013, The Cogent Project" __credits__ = ["Michael Robeson"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Michael Robeson" __email__ = "robesonms@ornl.gov" __status__ = "Development" class FastqJoin(CommandLineApplication): """fastq-join (v1.1.2) application controller for joining paired-end reads.""" _command = 'fastq-join' _parameters = { # Description copied from 'fastq-join' # Usage: fastq-join [options] [mate.fq] -o # Output: # You can supply 3 -o arguments, for un1, un2, join files, or one # argument as a file name template. The suffix 'un1, un2, or join' is # appended to the file, or they replace a %-character if present. # If a 'mate' input file is present (barcode read), then the files # 'un3' and 'join2' are also created. # we'll only handle one output base path / file name # -o FIL: See 'Output' above '-o':ValuedParameter(Prefix='-', Delimiter=' ', Name='o'), # -v C: Verifies that the 2 files probe id's match up to char C # use ' ' (space) for Illumina reads '-v':ValuedParameter(Prefix='-', Delimiter=' ', Name='v'), # -p N: N-percent maximum difference (8) '-p':ValuedParameter(Prefix='-', Delimiter=' ', Name='p'), # -m N: N-minimum overlap (6) '-m':ValuedParameter(Prefix='-', Delimiter=' ', Name='m'), # -r FIL: Verbose stitch length report '-r':ValuedParameter(Prefix='-', Delimiter=' ', Name='r')} _input_handler = '_input_as_paths' def _get_output_path(self): """Checks if a base file label / path is set. Returns absolute path.""" if self.Parameters['-o'].isOn(): output_path = self._absolute(str(self.Parameters['-o'].Value)) else: raise ValueError, "No output path specified." return output_path def _get_stitch_report_path(self): """Checks if stitch report label / path is set. Returns absolute path.""" if self.Parameters['-r'].isOn(): stitch_path = self._absolute(str(self.Parameters['-r'].Value)) return stitch_path elif self.Parameters['-r'].isOff(): return None def _get_result_paths(self, data): """Capture fastq-join output. Three output files are produced, in the form of outputjoin : assembled paired reads outputun1 : unassembled reads_1 outputun2 : unassembled reads_2 If a barcode / mate-pairs file is also provided then the following additional files are output: outputjoin2 outputun3 If a verbose stitch length report (-r) is chosen to be written by the user then use a user specified filename. """ output_path = self._get_output_path() result = {} # always output: result['Assembled'] = ResultPath(Path = output_path + 'join', IsWritten=True) result['UnassembledReads1'] = ResultPath(Path = output_path + 'un1', IsWritten=True) result['UnassembledReads2'] = ResultPath(Path = output_path + 'un2', IsWritten=True) # check if stitch report is requested: stitch_path = self._get_stitch_report_path() if stitch_path: result['Report'] = ResultPath(Path = stitch_path, IsWritten=True) # Check if mate file / barcode file is present. # If not, return result # We need to check this way becuase there are no infile parameters. mate_path_string = output_path + 'join2' mate_unassembled_path_string = output_path + 'un3' if os.path.exists(mate_path_string) and \ os.path.exists(mate_unassembled_path_string): result['Mate'] = ResultPath(Path = mate_path_string, IsWritten=True) result['MateUnassembled'] = ResultPath(Path = mate_unassembled_path_string, IsWritten=True) else: pass return result def getHelp(self): """fastq-join (v1.1.2) help""" help_str = """ For issues with the actual program 'fastq-join', see the following: For basic help, type the following at the command line: 'fastq-join' Website: http://code.google.com/p/ea-utils/ For questions / comments subit an issue to: http://code.google.com/p/ea-utils/issues/list """ return help_str def join_paired_end_reads_fastqjoin( reads1_infile_path, reads2_infile_path, perc_max_diff=None, # typical default is 8 min_overlap=None, # typical default is 6 outfile_label = 'fastqjoin', params={}, working_dir=tempfile.gettempdir(), SuppressStderr=True, SuppressStdout=True, HALT_EXEC=False): """ Runs fastq-join, with default parameters to assemble paired-end reads. Returns file path string. -reads1_infile_path : reads1.fastq infile path -reads2_infile_path : reads2.fastq infile path -perc_max_diff : maximum % diff of overlap differences allowed -min_overlap : minimum allowed overlap required to assemble reads -outfile_label : base name for output files. -params : dictionary of application controller parameters """ abs_r1_path = os.path.abspath(reads1_infile_path) abs_r2_path = os.path.abspath(reads2_infile_path) infile_paths = [abs_r1_path, abs_r2_path] # check / make absolute infile paths for p in infile_paths: if not os.path.exists(p): raise IOError, 'File not found at: %s' % p fastq_join_app = FastqJoin(params=params, WorkingDir=working_dir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout, HALT_EXEC=HALT_EXEC) # set param. Helps with QIIME integration to have these values # set to None by default. This way we do not have to worry # about changes in default behaviour of the wrapped # application if perc_max_diff is not None: if isinstance(perc_max_diff, int) and 0 <= perc_max_diff <= 100: fastq_join_app.Parameters['-p'].on(perc_max_diff) else: raise ValueError, "perc_max_diff must be int between 0-100!" if min_overlap is not None: if isinstance(min_overlap, int) and 0 < min_overlap: fastq_join_app.Parameters['-m'].on(min_overlap) else: raise ValueError, "min_overlap must be an int >= 0!" if outfile_label is not None: if isinstance(outfile_label, str): fastq_join_app.Parameters['-o'].on(outfile_label +'.') else: raise ValueError, "outfile_label must be a string!" else: pass # run assembler result = fastq_join_app(infile_paths) # Store output file path data to dict path_dict = {} path_dict['Assembled'] = result['Assembled'].name path_dict['UnassembledReads1'] = result['UnassembledReads1'].name path_dict['UnassembledReads2'] = result['UnassembledReads2'].name # sanity check that files actually exist in path lcoations for path in path_dict.values(): if not os.path.exists(path): raise IOError, 'Output file not found at: %s' % path # fastq-join automatically appends: 'join', 'un1', or 'un2' # to the end of the file names. But we want to rename them so # they end in '.fastq'. So, we iterate through path_dict to # rename the files and overwrite the dict values. for key,file_path in path_dict.items(): new_file_path = file_path + '.fastq' shutil.move(file_path, new_file_path) path_dict[key] = new_file_path # sanity check that files actually exist in path lcoations for path in path_dict.values(): if not os.path.exists(path): raise IOError, 'Output file not found at: %s' % path return path_dict pycogent-1.9/cogent/app/fasttree.py000066400000000000000000000143041273014367000174460ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for FastTree designed for FastTree v1.1.0 . Also functions with v2.0.1, v2.1.0, and v2.1.3 though only with basic functionality""" from cogent.app.parameters import ValuedParameter, FlagParameter, \ MixedParameter from cogent.app.util import CommandLineApplication, FilePath, system, \ CommandLineAppResult, ResultPath, remove, ApplicationError from cogent.core.tree import PhyloNode from cogent.parse.tree import DndParser from cogent.core.moltype import DNA, RNA, PROTEIN from cogent.core.alignment import SequenceCollection __author__ = "Daniel McDonald" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Daniel McDonald", "Justin Kuczynski"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Daniel McDonald" __email__ = "mcdonadt@colorado.edu" __status__ = "Development" class FastTree(CommandLineApplication): """FastTree application Controller""" _command = 'FastTree' _input_handler = '_input_as_multiline_string' _parameters = { '-quiet':FlagParameter('-',Name='quiet'), '-boot':ValuedParameter('-',Delimiter=' ',Name='boot'), '-seed':ValuedParameter('-',Delimiter=' ',Name='seed'), '-nni':ValuedParameter('-',Delimiter=' ',Name='nni'), '-slow':FlagParameter('-',Name='slow'), '-fastest':FlagParameter('-',Name='fastest'), '-top':FlagParameter('-',Name='top'), '-notop':FlagParameter('-',Name='notop'), '-topm':ValuedParameter('-',Delimiter=' ',Name='topm'), '-close':ValuedParameter('-',Delimiter=' ',Name='close'), '-refresh':ValuedParameter('-',Delimiter=' ',Name='refresh'), '-matrix':ValuedParameter('-',Delimiter=' ',Name='matrix'), '-nomatrix':FlagParameter('-',Name='nomatrix'), '-nj':FlagParameter('-',Name='nj'), '-bionj':FlagParameter('-',Name='bionj'), '-nt':FlagParameter('-',Name='nt'), '-n':ValuedParameter('-',Delimiter=' ',Name='n'), '-pseudo':MixedParameter('-',Delimiter=' ', Name='pseudo'), '-intree':ValuedParameter('-',Delimiter=' ',Name='intree'), '-spr':ValuedParameter('-',Delimiter=' ',Name='spr'), '-constraints':ValuedParameter('-',Delimiter=' ',\ Name='constraints'), '-constraintWeight':ValuedParameter('-',Delimiter=' ',\ Name='constraintWeight'),\ '-makematrix':ValuedParameter('-',Delimiter=' ',Name='makematrix')} def __call__(self,data=None, remove_tmp=True): """Run the application with the specified kwargs on data data: anything that can be cast into a string or written out to a file. Usually either a list of things or a single string or number. input_handler will be called on this data before it is passed as part of the command-line argument, so by creating your own input handlers you can customize what kind of data you want your application to accept remove_tmp: if True, removes tmp files NOTE: Override of the base class to handle redirected output """ input_handler = self.InputHandler suppress_stderr = self.SuppressStderr outfile = self.getTmpFilename(self.TmpDir) self._outfile = outfile if suppress_stderr: errfile = FilePath('/dev/null') else: errfile = FilePath(self.getTmpFilename(self.TmpDir)) if data is None: input_arg = '' else: input_arg = getattr(self,input_handler)(data) # Build up the command, consisting of a BaseCommand followed by # input and output (file) specifications command = self._command_delimiter.join(filter(None,\ [self.BaseCommand,str(input_arg),'>',str(outfile),'2>',\ str(errfile)])) if self.HaltExec: raise AssertionError, "Halted exec with command:\n" + command # The return value of system is a 16-bit number containing the signal # number that killed the process, and then the exit status. # We only want to keep the exit status so do a right bitwise shift to # get rid of the signal number byte exit_status = system(command) >> 8 # Determine if error should be raised due to exit status of # appliciation if not self._accept_exit_status(exit_status): raise ApplicationError, \ 'Unacceptable application exit status: %s, command: %s'\ % (str(exit_status),command) out = open(outfile,"r") err = None if not suppress_stderr: err = open(errfile,"r") result = CommandLineAppResult(out,err,exit_status,\ result_paths=self._get_result_paths(data)) # Clean up the input file if one was created if remove_tmp: if self._input_filename: remove(self._input_filename) self._input_filename = None return result def _get_result_paths(self, data): result = {} result['Tree'] = ResultPath(Path=self._outfile) return result def build_tree_from_alignment(aln, moltype, best_tree=False, params=None): """Returns a tree from alignment Will check MolType of aln object """ if params is None: params = {} if moltype == DNA or moltype == RNA: params['-nt'] = True elif moltype == PROTEIN: params['-nt'] = False else: raise ValueError, \ "FastTree does not support moltype: %s" % moltype.label if best_tree: params['-slow'] = True #Create mapping between abbreviated IDs and full IDs int_map, int_keys = aln.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) app = FastTree(params=params) result = app(int_map.toFasta()) tree = DndParser(result['Tree'].read(), constructor=PhyloNode) #remap tip names for tip in tree.tips(): tip.Name = int_keys[tip.Name] return tree pycogent-1.9/cogent/app/fasttree_v1.py000066400000000000000000000126761273014367000200660ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for FastTree v1.0""" from cogent.app.parameters import ValuedParameter, FlagParameter from cogent.app.util import CommandLineApplication, FilePath, system, \ CommandLineAppResult, ResultPath, remove, ApplicationError from cogent.core.tree import PhyloNode from cogent.parse.tree import DndParser from cogent.core.moltype import DNA, RNA, PROTEIN __author__ = "Daniel McDonald" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Daniel McDonald" __email__ = "mcdonadt@colorado.edu" __status__ = "Development" class FastTree(CommandLineApplication): """FastTree application Controller""" _command = 'FastTree' _input_handler = '_input_as_multiline_string' _parameters = { '-quiet':FlagParameter('-',Name='quiet'), '-boot':ValuedParameter('-',Delimiter=' ',Name='boot'), '-seed':ValuedParameter('-',Delimiter=' ',Name='seed'), '-nni':ValuedParameter('-',Delimiter=' ',Name='nni'), '-slow':FlagParameter('-',Name='slow'), '-fastest':FlagParameter('-',Name='fastest'), '-top':FlagParameter('-',Name='top'), '-notop':FlagParameter('-',Name='notop'), '-topm':ValuedParameter('-',Delimiter=' ',Name='topm'), '-close':ValuedParameter('-',Delimiter=' ',Name='close'), '-refresh':ValuedParameter('-',Delimiter=' ',Name='refresh'), '-matrix':ValuedParameter('-',Delimiter=' ',Name='matrix'), '-nomatrix':FlagParameter('-',Name='nomatrix'), '-nj':FlagParameter('-',Name='nj'), '-bionj':FlagParameter('-',Name='bionj'), '-nt':FlagParameter('-',Name='nt'), '-n':ValuedParameter('-',Delimiter=' ',Name='n')} #FastTree [-quiet] [-boot 1000] [-seed 1253] [-nni 10] [-slow | -fastest] # [-top | -notop] [-topm 1.0 [-close 0.75] [-refresh 0.8]] # [-matrix Matrix | -nomatrix] [-nj | -bionj] # [-nt] [-n 100] [alignment] > newick_tree def __call__(self,data=None, remove_tmp=True): """Run the application with the specified kwargs on data data: anything that can be cast into a string or written out to a file. Usually either a list of things or a single string or number. input_handler will be called on this data before it is passed as part of the command-line argument, so by creating your own input handlers you can customize what kind of data you want your application to accept remove_tmp: if True, removes tmp files NOTE: Override of the base class to handle redirected output """ input_handler = self.InputHandler suppress_stderr = self.SuppressStderr outfile = self.getTmpFilename(self.TmpDir) self._outfile = outfile if suppress_stderr: errfile = FilePath('/dev/null') else: errfile = FilePath(self.getTmpFilename(self.TmpDir)) if data is None: input_arg = '' else: input_arg = getattr(self,input_handler)(data) # Build up the command, consisting of a BaseCommand followed by # input and output (file) specifications command = self._command_delimiter.join(filter(None,\ [self.BaseCommand,str(input_arg),'>',str(outfile),'2>',\ str(errfile)])) if self.HaltExec: raise AssertionError, "Halted exec with command:\n" + command # The return value of system is a 16-bit number containing the signal # number that killed the process, and then the exit status. # We only want to keep the exit status so do a right bitwise shift to # get rid of the signal number byte exit_status = system(command) >> 8 # Determine if error should be raised due to exit status of # appliciation if not self._accept_exit_status(exit_status): raise ApplicationError, \ 'Unacceptable application exit status: %s, command: %s'\ % (str(exit_status),command) out = open(outfile,"r") err = None if not suppress_stderr: err = open(errfile,"r") result = CommandLineAppResult(out,err,exit_status,\ result_paths=self._get_result_paths(data)) # Clean up the input file if one was created if remove_tmp: if self._input_filename: remove(self._input_filename) self._input_filename = None return result def _get_result_paths(self, data): result = {} result['Tree'] = ResultPath(Path=self._outfile) return result def build_tree_from_alignment(aln, moltype, best_tree=False, params=None): """Returns a tree from alignment Will check MolType of aln object """ if params is None: params = {} if moltype == DNA or moltype == RNA: params['-nt'] = True elif moltype == PROTEIN: params['-nt'] = False else: raise ValueError, \ "FastTree does not support moltype: %s" % moltype.label app = FastTree(params=params) if best_tree: raise NotImplementedError, "best_tree not implemented yet" result = app(aln.toFasta()) tree = DndParser(result['Tree'].read(), constructor=PhyloNode) return tree pycogent-1.9/cogent/app/flash.py000066400000000000000000000356411273014367000167350ustar00rootroot00000000000000#!/usr/bin/env python # file: flash.py # Application controller for FLASh v1.2.7 # Fast Length Adjustment of Short reads: # http://ccb.jhu.edu/software/FLASH/ from cogent.app.parameters import ValuedParameter, FlagParameter from cogent.app.util import CommandLineApplication, ResultPath, \ ApplicationError import os import tempfile __author__ = "Michael Robeson" __copyright__ = "Copyright 2007-2013, The Cogent Project" __credits__ = ["Michael Robeson"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Michael Robeson" __email__ = "robesonms@ornl.gov" __status__ = "Development" class Flash(CommandLineApplication): """FLASh (v1.2.7) application controller for paired-end illumina data""" _command = 'flash' _parameters = { # Descriptions of parameters copied directly from 'flash -h' # and pasted below. # NOTE: FLASh does not have flags for infiles. # These will be handled in separate convenience functions below # via the input handlers '_input_as_path' and _input_as_paths. # -m, --min-overlap # The minimum required overlap length between two # reads to provide a confident overlap. Default: # 10bp. '-m':ValuedParameter(Prefix='-', Delimiter=' ', Name='m'), # -M, --max-overlap # Maximum overlap length expected in approximately # 90% of read pairs. It is by default set to 70bp, # which works well for 100bp reads generated from a # 180bp library, assuming a normal distribution of # fragment lengths. Overlaps longer than the maximum # overlap parameter are still considered as good # overlaps, but the mismatch density (explained below) # is calculated over the first max_overlap bases in # the overlapped region rather than the entire # overlap. Default: 70bp, or calculated from the # specified read length, fragment length, and fragment # length standard deviation. '-M':ValuedParameter(Prefix='-', Delimiter=' ', Name='M'), # -x, --max-mismatch-density # Maximum allowed ratio between the number of # mismatched base pairs and the overlap length. # Two reads will not be combined with a given overlap # if that overlap results in a mismatched base density # higher than this value. Note: Any occurence of an # 'N' in either read is ignored and not counted # towards the mismatches or overlap length. Our # experimental results suggest that higher values of # the maximum mismatch density yield larger # numbers of correctly merged read pairs but at # the expense of higher numbers of incorrectly # merged read pairs. Default: 0.25. '-x':ValuedParameter(Prefix='-', Delimiter=' ', Name='x'), # -p, --phred-offset=OFFSET # The smallest ASCII value of the characters used to # represent quality values of bases in FASTQ files. # It should be set to either 33, which corresponds # to the later Illumina platforms and Sanger # platforms, or 64, which corresponds to the # earlier Illumina platforms. Default: 33. '-p':ValuedParameter(Prefix='-', Delimiter=' ', Name='p'), # -r, --read-len=LEN # -f, --fragment-len=LEN # -s, --fragment-len-stddev=LEN # Average read length, fragment length, and fragment # standard deviation. These are convenience parameters # only, as they are only used for calculating the # maximum overlap (--max-overlap) parameter. # The maximum overlap is calculated as the overlap of # average-length reads from an average-size fragment # plus 2.5 times the fragment length standard # deviation. The default values are -r 100, -f 180, # and -s 18, so this works out to a maximum overlap of # 70 bp. If --max-overlap is specified, then the # specified value overrides the calculated value. # If you do not know the standard deviation of the # fragment library, you can probably assume that the # standard deviation is 10% of the average fragment # length. '-r':ValuedParameter(Prefix='-', Delimiter=' ', Name='r'), '-f':ValuedParameter(Prefix='-', Delimiter=' ', Name='f'), '-s':ValuedParameter(Prefix='-', Delimiter=' ', Name='s'), # --interleaved-input # Instead of requiring files MATES_1.FASTQ and # MATES_2.FASTQ, allow a single file MATES.FASTQ that # has the paired-end reads interleaved. Specify "-" # to read from standard input. '--interleaved-input':FlagParameter(Prefix='--', Name='interleaved-input'), # --interleaved-output # Write the uncombined pairs in interleaved format. '--interleaved-output':FlagParameter(Prefix='--', Name='interleaved-output'), # -I, --interleaved # Equivalent to specifying both --interleaved-input # and --interleaved-output. '-I':FlagParameter(Prefix='-', Name='I'), # -o, --output-prefix=PREFIX # Prefix of output files. Default: "out". '-o':ValuedParameter(Prefix='-', Delimiter=' ', Name='o'), # -d, --output-directory=DIR # Path to directory for output files. Default: # current working directory. '-d':ValuedParameter(Prefix='-', Delimiter=' ', Name='d'), # -c, --to-stdout # Write the combined reads to standard output; do not # write uncombined reads to anywhere. '-c':FlagParameter(Prefix='-', Name='c'), # -z, --compress # Compress the FASTQ output files directly with zlib. # Similar to specifying --compress-prog=gzip and # --suffix=gz, but may be slightly faster. '-z':FlagParameter(Prefix='-', Name='z'), # --compress-prog=PROG # Pipe the output through the compression program # PROG, which will be called as `PROG -c -', # plus any arguments specified by --compress-prog-args. # PROG must read uncompressed data from standard input # and write compressed data to standard output. # Examples: gzip, bzip2, xz, pigz. '--compress-prog':FlagParameter(Prefix='--', Name='compress-prog'), # --compress-prog-args=ARGS # A string of arguments that will be passed to the # compression program if one is specified with # --compress-prog. Note: the argument -c is already # assumed. '--compress-prog-args':ValuedParameter(Prefix='--', Delimiter=' ', Name='compress-prog-args'), # --suffix=SUFFIX, --output-suffix=SUFFIX # Use SUFFIX as the suffix of the output files # after ".fastq". A dot before the suffix is assumed, # unless an empty suffix is provided. Default: # nothing; or 'gz' if -z is specified; or PROG if # --compress-prog is specified. '--suffix':ValuedParameter(Prefix='--', Delimiter=' ', Name='suffix'), '--output-suffix':ValuedParameter(Prefix='--', Delimiter=' ', Name='output-suffix'), # -t, --threads=NTHREADS # Set the number of worker threads. This is in # addition to the I/O threads. Default: number of # processors. Note: if you need FLASH's output to # appear deterministically or in the same order as # the original reads, you must specify -t 1 # (--threads=1). '-t':ValuedParameter(Prefix='-', Delimiter=' ', Name='t'), # -q, --quiet # Do not print informational messages. (Implied with # --to-stdout.) '-q':FlagParameter(Prefix='-', Name='q'), # -h, --help # Display this help and exit. '-h':FlagParameter(Prefix='-', Name='h'), # -v, --version # Display version. '-v':FlagParameter(Prefix='-', Name='v')} _synonyms = { '--min-overlap':'-m', '--max-overlap':'-M', '--max-mismatch-density':'-x', '--phred-offset':'-p', '--read-len':'-r', '--fragment-len':'-f', '--fragment-len-stddev':'-s', '--interleaved':'-I', '--output-prefix':'-o', '--output-directory':'-d', '--to-stdout':'-c', '--compress':'-z', '--threads':'-t', '--quiet':'q', '--help':'-h', '--version':'-v'} _input_handler = '_input_as_paths' def _output_dir_path(self): if self.Parameters['-d'].isOn(): output_dir_path = self._absolute(str(self.Parameters['-d'].Value) +'/') else: raise ValueError, "No output diretory specified." return output_dir_path def _output_label(self): if self.Parameters['-o'].isOn(): base_outfile_name = str(self.Parameters['-o'].Value) else: raise ValueError, "No base outfile label specified." return base_outfile_name def _get_result_paths(self, data): """Captures FLASh output paths. FLASh defaults writing output to 5 files: - the assembled reads stored as *.extendedFrags.fastq - reads1 that failed to assemble as *.notCombined_1.fastq' - reads2 that failed to assemble as *.notCombined_2.fastq' - hist frag size x sequence count *.hist - histogram frag size distribution *.histogram Where '*' is set by the '-d' (directory output path) and '-o' (output file label) flags. e.g. -d = '/home/usr/data_out/' and -o = 'my_assembly' are converted to these paths: /home/usr/data_out/myassembly.extendedFrags.fastq' /home/usr/data_out/myassembly.notCombined_1.fastq' /home/usr/data_out/myassembly.notCombined_2.fastq' /home/usr/data_out/myassembly.hist' /home/usr/data_out/myassembly.histogram' """ output_dir_path = self._output_dir_path() base_outfile_name = self._output_label() result = {} result['Assembled'] = ResultPath(Path = output_dir_path + base_outfile_name + '.extendedFrags.fastq', IsWritten=True) result['UnassembledReads1'] = ResultPath(Path = output_dir_path + base_outfile_name + '.notCombined_1.fastq', IsWritten=True) result['UnassembledReads2'] = ResultPath(Path = output_dir_path + base_outfile_name + '.notCombined_2.fastq', IsWritten=True) result['NumHist'] = ResultPath(Path = output_dir_path + base_outfile_name + '.hist', IsWritten=True) result['Histogram'] = ResultPath(Path = output_dir_path + base_outfile_name + '.histogram', IsWritten=True) return result def getHelp(self): """FLASh (v1.2.7) description and help.""" help_str =\ """ For basic help, type the following at the command line: 'flash -h' Website: http://ccb.jhu.edu/software/FLASH/ For questions / comments send e-mail to: flash.comment@gmail.com """ return help_str ################################################### # SOME FUNCTIONS TO EXECUTE THE MOST COMMON TASKS # ################################################### def join_paired_end_reads_flash( reads1_infile_path, reads2_infile_path, outfile_label='FLASH', read_length='100', frag_length='180', frag_std_dev='18', mis_match_density='0.25', min_overlap='10', num_threads='1', max_overlap=None, working_dir=tempfile.gettempdir(), params={}, SuppressStderr=True, SuppressStdout=True, HALT_EXEC=False): """Runs FLASh, to assemble paired-end reads. Default settings are for HISEQ. -reads1_infile_path : reads1.fastq infile path -reads2_infile_path : reads2.fastq infile path -outfile_label : base name for output files -read_length : average length of individual reads -frag_length : average length of assembled reads -frag_std_dev : fragment length standard deviation, ~ 10% of frag_length -mis_match_identity : max allowable ratio of mismatched bases and overlap length. Reads above this value will not be assembled. -min_overlap : minimum allowable overlab to assemble reads -max_overlap : if set this will override the settings specified by '-r','-s', and '-f'. These three parameters are used to dynamically calculate max_overlap when max_overlap is not provided. -num_threads : number of CPUs [default 1] For HISEQ a good default 'max_overlap' would be between '70' to '100'. For MISEQ try these parameters if you assume ~380 bp assembled frags with highly overlaping reads (reads get the full 250 bp): read_length=\'250\' frag_length=\'380\' frag_std_dev=\'38\', or alternatively: max_overlap = \'120\' """ # There are no input options for fastq infiles. So, we check if they exist # and store them as a list for later input via '_input_as_paths' # for the default '_input_handler'. abs_r1_path = os.path.abspath(reads1_infile_path) abs_r2_path = os.path.abspath(reads2_infile_path) infile_paths = [abs_r1_path, abs_r2_path] # check / make absolute infile paths for p in infile_paths: if not os.path.exists(p): raise IOError, 'Infile not found at: %s' % p # required params params['-d'] = working_dir #output_dir params['-o'] = outfile_label params['-x'] = mis_match_density params['-m'] = min_overlap params['-t'] = num_threads if max_overlap: params['-M'] = max_overlap else: params['-f'] = frag_length params['-s'] = frag_std_dev params['-r'] = read_length # set up assembler flash_app = Flash(params=params, WorkingDir=working_dir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout, HALT_EXEC=HALT_EXEC) # run assembler result = flash_app(infile_paths) # use default '_input_as_paths' # Store output file path data to dict path_dict = {} path_dict['Assembled'] = result['Assembled'].name path_dict['UnassembledReads1'] = result['UnassembledReads1'].name path_dict['UnassembledReads2'] = result['UnassembledReads2'].name path_dict['NumHist'] = result['NumHist'].name path_dict['Histogram'] = result['Histogram'].name # sanity check that files actually exist in path lcoations for path in path_dict.values(): if not os.path.exists(path): raise IOError, 'Output file not found at: %s' % path return path_dict pycogent-1.9/cogent/app/foldalign.py000066400000000000000000000027051273014367000175720ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for Foldalign v2.0.3 application Foldalign takes two sequences as input, these sequences can be in the same file(2) or separate files. ex1 Foldalign file(2) ex2 Foldalign seq1 seq2 """ from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters, _find_synonym, is_not_None __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class foldalign(CommandLineApplication): """Applictation controller for foldalign RNA secondary structure prediction application """ _parameters = { '-max_length':ValuedParameter(Prefix='-',Name='max_length',Delimiter=' '), '-max_diff':ValuedParameter(Prefix='-',Name='max_diff',Delimiter=' '), '-score_matrix':ValuedParameter(Prefix='-',Name='score_matrix',Delimiter=' '), '-format':ValuedParameter(Prefix='-',Name='format',Delimiter=' '), '-plot_score':FlagParameter(Prefix='-',Name='plot_score'), '-global':FlagParameter(Prefix='-',Name='global'), '-summary':FlagParameter(Prefix='-',Name='summary'),} _command = 'foldalign' _input_handler = '_input_as_string' pycogent-1.9/cogent/app/formatdb.py000077500000000000000000000207731273014367000174410ustar00rootroot00000000000000#!/usr/bin/env python # Author: Greg Caporaso (gregcaporaso@gmail.com) # formatdb.py """ Description File created on 16 Sep 2009. """ from __future__ import division from optparse import OptionParser from os.path import split, splitext from os import remove from glob import glob from cogent.app.util import CommandLineApplication, ResultPath, get_tmp_filename from cogent.app.parameters import ValuedParameter, FilePath __author__ = "Greg Caporaso" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Greg Caporaso"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Greg Caporaso" __email__ = "gregcaporaso@gmail.com" __status__ = "Production" class FormatDb(CommandLineApplication): """ ApplicationController for formatting blast databases Currently contains a minimal parameter set. """ _command = 'formatdb' _parameters = {\ '-i':ValuedParameter(Prefix='-',Name='i',Delimiter=' ',IsPath=True),\ '-l':ValuedParameter(Prefix='-',Name='l',Delimiter=' ',IsPath=True),\ '-o':ValuedParameter(Prefix='-',Name='o',Delimiter=' ',Value='T'),\ '-p':ValuedParameter(Prefix='-',Name='p',Delimiter=' ',Value='F'),\ '-n':ValuedParameter(Prefix='-',Name='n',Delimiter=' ') } _input_handler = '_input_as_parameter' _suppress_stdout = True _suppress_stderr = True def _input_as_parameter(self,data): """ Set the input path and log path based on data (a fasta filepath) """ self.Parameters['-i'].on(data) # access data through self.Parameters so we know it's been cast # to a FilePath input_filepath = self.Parameters['-i'].Value input_file_dir, input_filename = split(input_filepath) input_file_base, input_file_ext = splitext(input_filename) # FIXME: the following all other options # formatdb ignores the working directory if not name is passed. self.Parameters['-l'].on(FilePath('%s.log') % input_filename) self.Parameters['-n'].on(FilePath(input_filename)) return '' def _get_result_paths(self,data): """ Build the dict of result filepaths """ # access data through self.Parameters so we know it's been cast # to a FilePath wd = self.WorkingDir db_name = self.Parameters['-n'].Value log_name = self.Parameters['-l'].Value result = {} result['log'] = ResultPath(Path=wd + log_name, IsWritten=True) if self.Parameters['-p'].Value == 'F': extensions = ['nhr','nin','nsq','nsd','nsi'] else: extensions = ['phr','pin','psq','psd','psi'] for extension in extensions: for file_path in glob(wd + (db_name + '*' + extension)): # this will match e.g. nr.01.psd and nr.psd key = file_path.split(db_name + '.')[1] result_path = ResultPath(Path=file_path, IsWritten=True) result[key] = result_path return result def _accept_exit_status(self,exit_status): """ Return True when the exit status was 0 """ return exit_status == 0 def build_blast_db_from_fasta_path(fasta_path,is_protein=False,\ output_dir=None,HALT_EXEC=False): """Build blast db from fasta_path; return db name and list of files created **If using to create temporary blast databases, you can call cogent.util.misc.remove_files(db_filepaths) to clean up all the files created by formatdb when you're done with the database. fasta_path: path to fasta file of sequences to build database from is_protein: True if working on protein seqs (default: False) output_dir: directory where output should be written (default: directory containing fasta_path) HALT_EXEC: halt just before running the formatdb command and print the command -- useful for debugging """ fasta_dir, fasta_filename = split(fasta_path) if not output_dir: output_dir = fasta_dir or '.' # Will cd to this directory, so just pass the filename # so the app is not confused by relative paths fasta_path = fasta_filename if not output_dir.endswith('/'): db_name = output_dir + '/' + fasta_filename else: db_name = output_dir + fasta_filename # instantiate the object fdb = FormatDb(WorkingDir=output_dir,HALT_EXEC=HALT_EXEC) if is_protein: fdb.Parameters['-p'].on('T') else: fdb.Parameters['-p'].on('F') app_result = fdb(fasta_path) db_filepaths = [] for v in app_result.values(): try: db_filepaths.append(v.name) except AttributeError: # not a file object, so no path to return pass return db_name, db_filepaths def build_blast_db_from_fasta_file(fasta_file,is_protein=False,\ output_dir=None,HALT_EXEC=False): """Build blast db from fasta_path; return db name and list of files created **If using to create temporary blast databases, you can call cogent.util.misc.remove_files(db_filepaths) to clean up all the files created by formatdb when you're done with the database. fasta_path: path to fasta file of sequences to build database from is_protein: True if working on protein seqs (default: False) output_dir: directory where output should be written (default: directory containing fasta_path) HALT_EXEC: halt just before running the formatdb command and print the command -- useful for debugging """ output_dir = output_dir or '.' fasta_path = get_tmp_filename(\ tmp_dir=output_dir, prefix="BLAST_temp_db_", suffix=".fasta") fasta_f = open(fasta_path,'w') for line in fasta_file: fasta_f.write('%s\n' % line.strip()) fasta_f.close() blast_db, db_filepaths = build_blast_db_from_fasta_path(\ fasta_path, is_protein=is_protein, output_dir=None, HALT_EXEC=HALT_EXEC) db_filepaths.append(fasta_path) return blast_db, db_filepaths def build_blast_db_from_seqs(seqs,is_protein=False,\ output_dir='./',HALT_EXEC=False): """Build blast db from seqs; return db name and list of files created **If using to create temporary blast databases, you can call cogent.util.misc.remove_files(db_filepaths) to clean up all the files created by formatdb when you're done with the database. seqs: sequence collection or alignment object is_protein: True if working on protein seqs (default: False) output_dir: directory where output should be written (default: current directory) HALT_EXEC: halt just before running the formatdb command and print the command -- useful for debugging """ # Build a temp filepath tmp_fasta_filepath = get_tmp_filename(\ prefix='Blast_tmp_db',suffix='.fasta') # open the temp file tmp_fasta_file = open(tmp_fasta_filepath,'w') # write the sequence collection to file tmp_fasta_file.write(seqs.toFasta()) tmp_fasta_file.close() # build the bast database db_name, db_filepaths = build_blast_db_from_fasta_path(\ tmp_fasta_filepath,is_protein=is_protein,\ output_dir=output_dir,HALT_EXEC=HALT_EXEC) # clean-up the temporary file remove(tmp_fasta_filepath) # return the results return db_name, db_filepaths def parse_command_line_parameters(): """ Parses command line arguments """ usage = 'usage: %prog [options] fasta_filepath' version = 'Version: %prog 0.1' parser = OptionParser(usage=usage, version=version) # A binary 'verbose' flag parser.add_option('-p','--is_protein',action='store_true',\ dest='is_protein',default=False,\ help='Pass if building db of protein sequences '+\ '[default: False, nucleotide db]') parser.add_option('-o','--output_dir',action='store',\ type='string',dest='output_dir',default=None, help='the output directory '+\ '[default: directory containing input fasta_filepath]') opts,args = parser.parse_args() num_args = 1 if len(args) != num_args: parser.error('Must provide single filepath to build database from.') return opts,args if __name__ == "__main__": opts,args = parse_command_line_parameters() fasta_filepath = args[0] is_protein = opts.is_protein output_dir = opts.output_dir db_name, db_filepaths = build_blast_db_from_fasta_path(\ fasta_filepath,is_protein=is_protein,output_dir=output_dir) pycogent-1.9/cogent/app/gctmpca.py000077500000000000000000000272361273014367000172620ustar00rootroot00000000000000#!/usr/bin/env python # Author: Greg Caporaso (gregcaporaso@gmail.com) # gctmpca.py """Application controller for the Generalized Continuous-Time Markov Process Coevolutionary Algorithm (GCTMPCA). GCTMPCA is presented in: Detecting coevolution in and among protein domains. Yeang CH, Haussler D., PLoS Comput Biol. 2007 Nov;3(11):e211. Detecting the coevolution of biosequences--an example of RNA interaction prediction. Yeang CH, Darot JF, Noller HF, Haussler D. Mol Biol Evol. 2007 Sep;24(9):2119-31. This code requires the GCTMPCA package to be installed. As of Nov. 2008, that software is available at: http://www.sns.ias.edu/~chyeang/coevolution_download.zip Note that the authors did not name their algorithm or software when they published it. GCTMPCA was suggested as a name by the first author via e-mail. """ from __future__ import division from cogent.app.util import CommandLineApplication, ResultPath,\ ApplicationError from cogent.app.parameters import FilePath from cogent.evolve.models import DSO78_freqs, DSO78_matrix __author__ = "Greg Caporaso" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Greg Caporaso"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Greg Caporaso" __email__ = "gregcaporaso@gmail.com" __status__ = "Beta" # Are these values in PyCogent somewhere? gctmpca_base_order = 'ACGU' default_gctmpca_rna_priors = {'A':0.2528,'C':0.2372,'G':0.3099,'U':0.2001} default_gctmpca_rna_sub_matrix = """-1.4150\t0.2372\t0.9777\t0.2001 0.2528\t-1.1940\t0.3099\t0.6313 0.7976\t0.2372\t-1.2349\t0.2001 0.2528\t0.7484\t0.3099\t-1.3111""" gctmpca_aa_order = 'ARNDCQEGHILKMFPSTWYV' # By default, the Gctmpca method used the Dayhoff 78 frequencies and rate matrix default_gctmpca_aa_priors = DSO78_freqs default_gctmpca_aa_sub_matrix = """-133.941451\t1.104408\t3.962336\t5.624640\t1.205064\t3.404695\t9.806940\t21.266880\t0.773214\t2.397590\t3.499637\t2.092532\t1.062216\t0.715896\t12.670000\t28.456993\t21.719082\t0.000000\t0.717984\t13.461344 2.352429\t-86.970372\t1.293824\t0.000000\t0.769902\t9.410730\t0.049530\t0.797508\t8.068320\t2.360704\t1.280355\t37.343648\t1.327770\t0.556808\t5.220040\t10.714858\t1.522092\t2.109294\t0.239328\t1.553232 8.538446\t1.308928\t-179.776579\t42.419160\t0.000000\t3.940265\t7.330440\t12.317068\t17.985630\t2.840222\t2.902138\t25.593276\t0.014753\t0.556808\t2.128560\t34.440615\t13.406118\t0.241362\t2.842020\t0.970770 10.455240\t0.000000\t36.590960\t-142.144945\t0.000000\t5.126170\t57.108090\t11.076500\t2.891148\t0.885264\t0.000000\t5.714222\t0.000000\t0.000000\t0.658840\t6.609815\t3.863772\t0.000000\t0.000000\t1.164924 3.136572\t0.940792\t0.000000\t0.000000\t-26.760991\t0.000000\t0.000000\t0.974732\t0.941304\t1.622984\t0.000000\t0.000000\t0.000000\t0.000000\t0.962920\t11.201897\t0.936672\t0.000000\t2.871936\t3.171182 7.754303\t10.062384\t4.164496\t6.280848\t0.000000\t-124.487960\t35.463480\t2.481136\t20.372508\t0.663948\t6.231061\t12.313746\t1.681842\t0.000000\t7.754040\t3.896312\t3.102726\t0.000000\t0.000000\t2.265130 17.251146\t0.040904\t5.983936\t54.043416\t0.000000\t27.390580\t-136.769106\t7.177572\t1.445574\t2.250046\t0.938927\t6.680006\t0.442590\t0.000000\t2.584680\t5.496583\t1.990428\t0.000000\t0.658152\t2.394566 20.910480\t0.368136\t5.620048\t5.859000\t0.368214\t1.071140\t4.011930\t-65.418192\t0.336180\t0.000000\t0.597499\t2.173014\t0.250801\t0.596580\t1.723120\t16.281018\t1.756260\t0.000000\t0.000000\t3.494772 2.003921\t9.816960\t21.631120\t4.030992\t0.937272\t23.182530\t2.129790\t0.886120\t-88.051504\t0.258202\t3.755708\t2.092532\t0.000000\t1.909056\t4.763920\t2.435195\t1.287924\t0.283338\t3.799332\t2.847592 5.663255\t2.617856\t3.113264\t1.124928\t1.472856\t0.688590\t3.021330\t0.000000\t0.235326\t-128.487912\t21.936749\t3.702172\t4.957008\t7.795312\t0.608160\t1.669848\t11.240064\t0.000000\t1.106892\t57.534302 3.572207\t0.613560\t1.374688\t0.000000\t0.000000\t2.792615\t0.544830\t0.620284\t1.479192\t9.479702\t-53.327266\t1.448676\t7.774831\t6.244204\t1.621760\t1.182809\t1.931886\t0.482724\t0.837648\t11.325650 2.265302\t18.979456\t12.857376\t3.327912\t0.000000\t5.853015\t4.110990\t2.392524\t0.874068\t1.696756\t1.536426\t-74.828436\t3.584979\t0.000000\t1.672440\t6.679392\t7.961712\t0.000000\t0.388908\t0.647180 6.273144\t3.681360\t0.040432\t0.000000\t0.000000\t4.361070\t1.485900\t1.506404\t0.000000\t12.393696\t44.983139\t19.557126\t-125.902241\t3.659024\t0.861560\t4.313774\t6.088368\t0.000000\t0.000000\t16.697244 1.568286\t0.572656\t0.566048\t0.000000\t0.000000\t0.000000\t0.000000\t1.329180\t1.613664\t7.229656\t13.401049\t0.000000\t1.357276\t-54.612411\t0.557480\t3.200542\t0.761046\t0.797544\t20.881368\t0.776616 21.781750\t4.213112\t1.698144\t0.609336\t0.636006\t5.853015\t2.526030\t3.012808\t3.160092\t0.442632\t2.731424\t2.655906\t0.250801\t0.437492\t-74.727653\t17.046365\t4.566276\t0.000000\t0.000000\t3.106464 35.634943\t6.299216\t20.013840\t4.452840\t5.389314\t2.142280\t3.912870\t20.735208\t1.176630\t0.885264\t1.451069\t7.726272\t0.914686\t1.829512\t12.416600\t-160.924378\t32.198100\t0.787050\t1.017144\t1.941540 32.324117\t1.063504\t9.258928\t3.093552\t0.535584\t2.027515\t1.684020\t2.658360\t0.739596\t7.082112\t2.816781\t10.945552\t1.534312\t0.517036\t3.953040\t38.267350\t-129.918557\t0.000000\t1.256472\t10.160726 0.000000\t8.221704\t0.929936\t0.000000\t0.000000\t0.000000\t0.000000\t0.000000\t0.907686\t0.000000\t3.926422\t0.000000\t0.000000\t3.022672\t0.000000\t5.218275\t0.000000\t-24.051571\t1.824876\t0.000000 2.091048\t0.327232\t3.841040\t0.000000\t3.213504\t0.000000\t1.089660\t0.000000\t4.269486\t1.364782\t2.389996\t1.046266\t0.000000\t27.760856\t0.000000\t2.365618\t2.458764\t0.640134\t-54.670490\t1.812104 18.122416\t0.981696\t0.606480\t0.843696\t1.640226\t1.338925\t1.832610\t4.785048\t1.479192\t32.791654\t14.937475\t0.804820\t3.806274\t0.477264\t2.432640\t2.087310\t9.191094\t0.000000\t0.837648\t-98.996468""" class Gctmpca(CommandLineApplication): """ App controller for the GCTMPCA algorithm for detecting sequence coevolution The Generalized Continuous-Time Markov Process Coevolutionary Algorithm (GCTMPCA) is presented in: Detecting coevolution in and among protein domains. Yeang CH, Haussler D., PLoS Comput Biol. 2007 Nov;3(11):e211. Detecting the coevolution of biosequences--an example of RNA interaction prediction. Yeang CH, Darot JF, Noller HF, Haussler D. Mol Biol Evol. 2007 Sep;24(9):2119-31. This code requires the GCTMPCA package to be installed. As of 11/08, that software is available at: http://www.sns.ias.edu/~chyeang/coevolution_download.zip """ _command = 'calculate_likelihood' _input_handler = '_gctmpca_cl_input' _data = {'mol_type':None,'comparison_type':0,'seqs1':None,\ 'seqs2':'-','tree1':None,'tree2':'-',\ 'seq_names':None,'species_tree':None,\ 'seq_to_species1':None,'seq_to_species2':'-',\ 'char_priors':None,'sub_matrix':None,'epsilon':0.7,\ 'max_gap_threshold':1.0,'max_seq_distance':1.0,\ 'covariation_threshold':0.0,'likelihood_threshold':0.0,\ 'output_path':None,'single_pair_only':0,'family_reps':'-',\ 'pos1':'','pos2':''} _parameter_order = ['mol_type','comparison_type','seqs1','seqs2',\ 'tree1','tree2','seq_names','species_tree',\ 'seq_to_species1','seq_to_species2','char_priors',\ 'sub_matrix','epsilon','max_gap_threshold','max_seq_distance',\ 'covariation_threshold','likelihood_threshold','output_path',\ 'single_pair_only','family_reps','pos1','pos2'] _potential_paths = ['seqs1','tree1','seq_names',\ 'species_tree','seq_to_species1'] _mol_type_lookup = {'rna':0,'0':0,'protein':1,'1':1} _default_priors = {0:default_gctmpca_rna_priors, 1:default_gctmpca_aa_priors} _default_sub_matrix = {0:default_gctmpca_rna_sub_matrix, 1:default_gctmpca_aa_sub_matrix} _char_order = {0:gctmpca_base_order,1:gctmpca_aa_order} _required_parameters = {}.fromkeys(['mol_type','seqs1','tree1',\ 'seq_names','species_tree','seq_to_species1']) def _set_command_line_parameters(self,data): """ Get the right setting for each command line parameter """ # This function could be cleaned up. # for each command line parameter, set it to the value passed in or # the default value. for p in self._parameter_order: if p not in data: if p in self._required_parameters: raise ApplicationError,\ "Required parameter %s missing." % p else: data[p] = self._data[p] # Write necessary files to disk -- need to modify this so paths # to existing files can be passed in. if p in self._potential_paths: try: data[p] = self._input_as_lines(data[p]) except TypeError: pass if data['single_pair_only'] == 1 and \ not (data['pos1'] and data['pos2']): raise ApplicationError,\ "Must specify pos1 and pos2 if single_pair_only == 1." # Make sure the MolType is in the correct format (i.e., 1 or 0) data['mol_type'] = mol_type = \ self._mol_type_lookup[str(data['mol_type']).lower()] char_order = self._char_order[mol_type] # If we didn't get several values as parameters, set the defaults. # These are done outside of the above loop b/c they require special # handling. if not data['char_priors']: data['char_priors'] = self._default_priors[mol_type] data['char_priors'] = \ self._input_as_lines(\ self._input_as_gctmpca_char_priors(\ data['char_priors'],char_order)) if not data['sub_matrix']: data['sub_matrix'] = \ self._input_as_multiline_string(\ self._default_sub_matrix[mol_type]) else: data['sub_matrix'] = \ self._input_as_lines(\ self._input_as_gctmpca_rate_matrix(\ data['sub_matrix'],char_order)) if not data['output_path']: data['output_path'] = \ self._input_as_path(self.getTmpFilename()) return data def _gctmpca_cl_input(self,data): """ Write the list of 22 command line parameters to a string """ # Get the right setting for each parameter data = self._set_command_line_parameters(data) # Explicitly disallow intermolecular experiments (I do this here to # make sure I'm looking at the final version of data) if data['comparison_type'] == 1: raise NotImplementedError,\ "Intermolecular experiments currently supported only via coevolve_alignments." # Create the command line parameter string and return it return ' '.join([str(data[p]) for p in self._parameter_order]).strip() def _input_as_gctmpca_char_priors(self,priors,char_order): """convert dict of priors to string and write it to tmp file """ # priors t be followed by a newline return ['\t'.join([str(priors[c]) for c in char_order]),''] def _input_as_gctmpca_rate_matrix(self,matrix,char_order): """convert 2D dict rate matrix to string and write it to tmp file """ matrix_rows = [] for c in char_order: matrix_rows.append('\t'.join([str(matrix[c][col_c]) \ for col_c in char_order])) return matrix_rows def _get_result_paths(self,data): """A single file is written, w/ name specified in command line input """ return {'output':ResultPath(Path=data['output_path'],IsWritten=True)} pycogent-1.9/cogent/app/guppy.py000066400000000000000000000163001273014367000167730ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for guppy 1.1""" __author__ = "Jesse Stombaugh" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Jesse Stombaugh"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Jesse Stombaugh" __email__ = "jesse.stombaugh@colorado.edu" __status__ = "Production" from cogent.app.parameters import ValuedParameter, FlagParameter from cogent.app.util import CommandLineApplication, FilePath, system, \ CommandLineAppResult, ResultPath, remove, ApplicationError from cogent.core.alignment import Alignment from os.path import splitext,split,join from os import listdir from cogent.parse.tree import DndParser from cogent.core.tree import PhyloNode class Guppy(CommandLineApplication): """guppy Application Controller """ _command = 'guppy' _input_handler = '_input_as_multiline_string' _parameters = { #visualizations # makes trees with edges fattened in proportion to the number of reads 'fat': FlagParameter('', Name='fat'), # maps an an arbitrary vector of the correct length to the tree 'heat': FlagParameter('', Name='heat'), # writes a taxonomically annotated reference tree and an induced # taxonomic tree 'ref_tree': FlagParameter('', Name='ref_tree'), # makes one tree for each query sequence, showing uncertainty 'sing': FlagParameter('', Name='sing'), # makes a tree with each of the reads represented as a pendant edge 'tog': FlagParameter('', Name='tog'), #statistical comparison # draws the barycenter of a placement collection on the reference tree 'bary': FlagParameter('', Name='bary'), # makes a phyloXML tree showing the bootstrap values 'bootviz': FlagParameter('', Name='bootviz'), # calculates the EDPL uncertainty values for a collection of pqueries 'edpl': FlagParameter('', Name='edpl'), # calculates the Kantorovich-Rubinstein distance and corresponding # p-values 'kr': FlagParameter('', Name='kr'), # makes a heat tree 'kr_heat': FlagParameter('', Name='kr_heat'), # performs edge principal components 'pca': FlagParameter('', Name='pca'), # writes out differences of masses for the splits of the tree 'splitify': FlagParameter('', Name='splitify'), # performs squash clustering 'squash': FlagParameter('', Name='squash'), #classification # outputs classification information in a tabular or SQLite format 'classify': FlagParameter('', Name='classify'), #utilities # check a reference package 'check_refpkg': FlagParameter('', Name='check_refpkg'), # splits apart placements with multiplicity, undoing a round procedure 'demulti': FlagParameter('', Name='demulti'), # prints out a pairwise distance matrix between the edges 'distmat': FlagParameter('', Name='distmat'), # filters one or more placefiles by placement name 'filter': FlagParameter('', Name='filter'), # writes the number of leaves of the reference tree and the number of # pqueries 'info': FlagParameter('', Name='info'), # merges placefiles together 'merge': FlagParameter('', Name='merge'), # restores duplicates to deduped placefiles 'redup': FlagParameter('', Name='redup'), # clusters the placements by rounding branch lengths 'round': FlagParameter('', Name='round'), # makes SQL enabling taxonomic querying of placement results 'taxtable': FlagParameter('', Name='taxtable'), # converts old-style .place files to .json placement files 'to_json': FlagParameter('', Name='to_json'), # Run the provided batch file of guppy commands 'batch': FlagParameter('--', Name='batch'), # Print version and exit 'version': FlagParameter('--', Name='version'), # Print a list of the available commands. 'cmds': FlagParameter('--', Name='cmds'), # Display this list of options '--help': FlagParameter('--', Name='help'), # Display this list of options '-help': FlagParameter('-', Name='help'), } def getTmpFilename(self, tmp_dir='/tmp/',prefix='tmp',suffix='.json',\ include_class_id=False,result_constructor=FilePath): """ Define Tmp filename to contain .json suffix, since guppy requires the suffix to be .json """ return super(Guppy,self).getTmpFilename(tmp_dir=tmp_dir, prefix=prefix, suffix=suffix, include_class_id=include_class_id, result_constructor=result_constructor) def _handle_app_result_build_failure(self,out,err,exit_status,result_paths): """ Catch the error when files are not produced """ raise ApplicationError, \ 'Guppy failed to produce an output file due to the following error: \n\n%s ' \ % err.read() def _get_result_paths(self,data): basepath,basename=split(splitext(self._input_filename)[0]) outfile_list=listdir(split(self._input_filename)[0]) result = {} for i in outfile_list: if i.startswith(basename) and not i.endswith('.json') and \ not i.endswith('.txt'): result['result'] = ResultPath(Path=join(basepath,i)) return result def build_tree_from_json_using_params(fname,output_dir='/tmp/',params={}): """Returns a tree from a json. fname: filepath to input json output_dir: location of output files params: dict of parameters to pass in to the RAxML app controller. The result will be a Tree. """ # convert aln to fasta in case it is not already a fasta file ih = '_input_as_multiline_string' guppy_app = Guppy(params=params, InputHandler=ih, WorkingDir=output_dir, TmpDir=output_dir, SuppressStderr=True, SuppressStdout=True, HALT_EXEC=False) guppy_result = guppy_app(open(fname).read()) try: new_tree=guppy_result['result'].read() except: # catch the error of not producing any results and print the command # run so user can check error guppy_cmd=Guppy(params=params, InputHandler=ih, WorkingDir=output_dir, TmpDir=output_dir, SuppressStderr=True, SuppressStdout=True, HALT_EXEC=True) out_msg=guppy_cmd(open(fname).read()) tree = DndParser(new_tree, constructor=PhyloNode) guppy_result.cleanUp() return tree pycogent-1.9/cogent/app/ilm.py000066400000000000000000000067551273014367000164250ustar00rootroot00000000000000#!/usr/bin/env python from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter,ValuedParameter,Parameters __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class ILM(CommandLineApplication): """Application controller ILM application Predict a secondary structure given a score matrix Main options: -L l: minimum loop length (default=3) -V v: minimum virtual loop length (default=3) -H h: minimum helix length (default=3) -N n: number of helices selected per iteration (default=1) -I i: number of iterations before termination(default=unlimited) """ _parameters = { '-L':ValuedParameter(Prefix='-',Name='L',Delimiter=' '), '-V':ValuedParameter(Prefix='-',Name='V',Delimiter=' '), '-H':ValuedParameter(Prefix='-',Name='H',Delimiter=' '), '-N':ValuedParameter(Prefix='-',Name='N',Delimiter=' '), '-I':ValuedParameter(Prefix='-',Name='I',Delimiter=' ')} _command = 'ilm' _input_handler = '_input_as_string' class hlxplot(CommandLineApplication): """Application controller hlxplot application Compute a helix plot score matrix from a sequence alignment Options: -b B: Set bad pair penalty to B (Default = 2) -g G: Set good pair score to G (Default = 1) -h H: Set minimum helix length to H (Default = 2) -l L: Set minimum loop length to L (Default = 3) -s S: Set helix length score to S (Default = 2.0) -t : Write output in text format (Default = Binary format) -x X: Set paired gap penalty to X (Default = 3) """ _parameters = { '-b':ValuedParameter(Prefix='-',Name='b',Delimiter=' '), '-g':ValuedParameter(Prefix='-',Name='g',Delimiter=' '), '-h':ValuedParameter(Prefix='-',Name='h',Delimiter=' '), '-l':ValuedParameter(Prefix='-',Name='l',Delimiter=' '), '-s':ValuedParameter(Prefix='-',Name='s',Delimiter=' '), '-t':ValuedParameter(Prefix='-',Name='t',Delimiter=' '), '-x':ValuedParameter(Prefix='-',Name='x',Delimiter=' ')} _command = 'hlxplot' _input_handler = '_input_as_string' class xhlxplot(CommandLineApplication): """Application controller xhlxplot application Compute an extended helix plot score matrix from a single sequence Options: -b B: Set bad pair penalty to B (Default = 200) -h H: Set minimum helix length to H (Default = 2) -l L: Set minimum loop length to L (Default = 3) -x X: Set paired gap penalty to X (Default = 500) -t : Write output in text format (Default = Binary format) -c : No Closing GU (Default = allows closing GU) """ _parameters = { '-b':ValuedParameter(Prefix='-',Name='b',Delimiter=' '), '-h':ValuedParameter(Prefix='-',Name='h',Delimiter=' '), '-l':ValuedParameter(Prefix='-',Name='l',Delimiter=' '), '-x':ValuedParameter(Prefix='-',Name='x',Delimiter=' '), '-t':ValuedParameter(Prefix='-',Name='t',Delimiter=' '), '-c':ValuedParameter(Prefix='-',Name='c',Delimiter=' ')} _command = 'xhlxplot' _input_handler = '_input_as_string' pycogent-1.9/cogent/app/infernal.py000066400000000000000000002121231273014367000174260ustar00rootroot00000000000000#!/usr/bin/env python """ Provides an application controller for the commandline version of: Infernal 1.0 and 1.0.2 only. """ from cogent.app.parameters import FlagParameter, ValuedParameter, FilePath from cogent.app.util import CommandLineApplication, ResultPath, get_tmp_filename from cogent.parse.fasta import MinimalFastaParser from cogent.parse.rfam import MinimalRfamParser, ChangedSequence, \ ChangedRnaSequence, ChangedDnaSequence from cogent.parse.infernal import CmsearchParser from cogent.core.moltype import DNA, RNA from cogent.core.alignment import SequenceCollection, Alignment, DataError from cogent.format.stockholm import stockholm_from_alignment from cogent.struct.rna2d import ViennaStructure, wuss_to_vienna from os import remove __author__ = "Jeremy Widmann" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Jeremy Widmann"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Jeremy Widmann" __email__ = "jeremy.widmann@colorado.edu" __status__ = "Development" MOLTYPE_MAP = {'DNA':'--dna',\ DNA:'--dna',\ 'RNA':'--rna',\ RNA:'--rna',\ } SEQ_CONSTRUCTOR_MAP = {'DNA':ChangedDnaSequence,\ DNA:ChangedDnaSequence,\ 'RNA':ChangedRnaSequence,\ RNA:ChangedRnaSequence,\ } class Cmalign(CommandLineApplication): """cmalign application controller.""" _options = { # -o Save the alignment in Stockholm format to a file . The default # is to write it to standard output. '-o':ValuedParameter(Prefix='-',Name='o',Delimiter=' '),\ # -l Turn on the local alignment algorithm. Default is global. '-l':FlagParameter(Prefix='-',Name='l'),\ # -p Annotate the alignment with posterior probabilities calculated using # the Inside and Outside algorithms. '-p':FlagParameter(Prefix='-',Name='p'),\ # -q Quiet; suppress the verbose banner, and only print the resulting # alignment to stdout. '-q':FlagParameter(Prefix='-',Name='q'),\ # --informat Assert that the input seqfile is in format . Do not run # Babelfish format autodection. Acceptable formats are: FASTA, EMBL, # UNIPROT, GENBANK, and DDBJ. is case-insensitive. '--informat':ValuedParameter(Prefix='--',Name='informat',Delimiter=' '),\ # --mpi Run as an MPI parallel program. (see User's Guide for details). '--mpi':FlagParameter(Prefix='--',Name='mpi'),\ # Expert Options # --optacc Align sequences using the Durbin/Holmes optimal accuracy # algorithm. This is default behavior, so this option is probably useless. '--optacc':FlagParameter(Prefix='--',Name='optacc'),\ # --cyk Do not use the Durbin/Holmes optimal accuracy alignment to align the # sequences, instead use the CYK algorithm which determines the optimally # scoring alignment of the sequence to the model. '--cyk':FlagParameter(Prefix='--',Name='cyk'),\ # --sample Sample an alignment from the posterior distribution of # alignments. '--sample':FlagParameter(Prefix='--',Name='sample'),\ # -s Set the random number generator seed to , where is a # positive integer. This option can only be used in combination with # --sample. The default is to use time() to generate a different seed for # each run, which means that two different runs of cmalign --sample on the # same alignment will give slightly different results. You can use this # option to generate reproducible results. '-s':ValuedParameter(Prefix='-',Name='s',Delimiter=' '),\ # --viterbi Do not use the CM to align the sequences, instead use the HMM # Viterbi algorithm to align with a CM Plan 9 HMM. '--viterbi':FlagParameter(Prefix='--',Name='viterbi'),\ # --sub Turn on the sub model construction and alignment procedure. '--sub':FlagParameter(Prefix='--',Name='sub'),\ # --small Use the divide and conquer CYK alignment algorithm described in # SR Eddy, BMC Bioinformatics 3:18, 2002. '--small':FlagParameter(Prefix='--',Name='small'),\ # --hbanded This option is turned on by default. Accelerate alignment by # pruning away regions of the CM DP matrix that are deemed negligible by # an HMM. '--hbanded':FlagParameter(Prefix='--',Name='hbanded'),\ # --nonbanded Turns off HMM banding. '--nonbanded':FlagParameter(Prefix='--',Name='nonbanded'),\ # --tau Set the tail loss probability used during HMM band calculation # to . '--tau':ValuedParameter(Prefix='--',Name='tau',Delimiter=' '),\ # --mxsize Set the maximum allowable DP matrix size to megabytes. '--mxsize':ValuedParameter(Prefix='--',Name='mxsize',Delimiter=' '),\ # --rna Output the alignments as RNA sequence alignments. This is true by # default. '--rna':FlagParameter(Prefix='--',Name='rna'),\ # --dna Output the alignments as DNA sequence alignments. '--dna':FlagParameter(Prefix='--',Name='dna'),\ # --matchonly Only include match columns in the output alignment, do not # include any insertions relative to the consensus model. '--matchonly':FlagParameter(Prefix='--',Name='matchonly'),\ # --resonly Only include match columns in the output alignment that have at # least 1 residue (non-gap character) in them. '--resonly':FlagParameter(Prefix='--',Name='resonly'),\ # --fins Change the behavior of how insert emissions are placed in the # alignment. '--fins':FlagParameter(Prefix='--',Name='fins'),\ # --onepost Modifies behavior of the -p option. Use only one character # instead of two to annotate the posterior probability of each aligned # residue. '--onepost':FlagParameter(Prefix='--',Name='onepost'),\ # --withali Reads an alignment from file and aligns it as a single # object to the CM; e.g. the alignment in is held fixed. '--withali':ValuedParameter(Prefix='--',Name='withali',Delimiter=' '),\ # --withpknots Must be used in combination with --withali . Propogate # structural information for any pseudoknots that exist in to the # output alignment. '--withpknots':FlagParameter(Prefix='--',Name='withpknots'),\ # --rf Must be used in combination with --withali . Specify that the # alignment in has the same "#=GC RF" annotation as the alignment file # the CM was built from using cmbuild and further that the --rf option was # supplied to cmbuild when the CM was constructed. '--rf':FlagParameter(Prefix='--',Name='rf'),\ # --gapthresh Must be used in combination with --withali . Specify # that the --gapthresh option was supplied to cmbuild when the CM was # constructed from the alignment file . '--gapthresh':ValuedParameter(Prefix='--',Name='gapthresh',Delimiter=' '),\ # --tfile Dump tabular sequence tracebacks for each individual sequence # to a file . Primarily useful for debugging. '--tfile':ValuedParameter(Prefix='--',Name='tfile',Delimiter=' '),\ } _parameters = {} _parameters.update(_options) _command = "cmalign" _suppress_stderr=True def getHelp(self): """Method that points to the Infernal documentation.""" help_str = \ """ See Infernal documentation at: http://infernal.janelia.org/ """ return help_str def _tempfile_as_multiline_string(self, data): """Write a multiline string to a temp file and return the filename. data: a multiline string to be written to a file. * Note: the result will be the filename as a FilePath object (which is a string subclass). """ filename = FilePath(self.getTmpFilename(self.TmpDir)) data_file = open(filename,'w') data_file.write(data) data_file.close() return filename def _alignment_out_filename(self): if self.Parameters['-o'].isOn(): refined_filename = self._absolute(str(\ self.Parameters['-o'].Value)) else: raise ValueError, 'No alignment output file specified.' return refined_filename def _get_result_paths(self,data): result = {} if self.Parameters['-o'].isOn(): out_name = self._alignment_out_filename() result['Alignment'] = ResultPath(Path=out_name,IsWritten=True) return result class Cmbuild(CommandLineApplication): """cmbuild application controller.""" _options = { # -n Name the covariance model . (Does not work if alifile contains # more than one alignment). '-n':ValuedParameter(Prefix='-',Name='n',Delimiter=' '),\ # -A Append the CM to cmfile, if cmfile already exists. '-A':FlagParameter(Prefix='-',Name='A'),\ # -F Allow cmfile to be overwritten. Normally, if cmfile already exists, # cmbuild exits with an error unless the -A or -F option is set. '-F':FlagParameter(Prefix='-',Name='F'),\ # -v Run in verbose output mode instead of using the default single line # tabular format. This output format is similar to that used by older # versions of Infernal. '-v':FlagParameter(Prefix='-',Name='v'),\ # --iins Allow informative insert emissions for the CM. By default, all CM # insert emission scores are set to 0.0 bits. '--iins':FlagParameter(Prefix='--',Name='iins'),\ # --Wbeta Set the beta tail loss probability for query-dependent banding # (QDB) to The QDB algorithm is used to determine the maximium length # of a hit to the model. For more information on QDB see (Nawrocki and # Eddy, PLoS Computational Biology 3(3): e56). '--Wbeta':ValuedParameter(Prefix='--',Name='Wbeta',Delimiter=' '),\ # Expert Options # --rsearch Parameterize emission scores a la RSEARCH, using the # RIBOSUM matrix in file . For more information see the RSEARCH # publication (Klein and Eddy, BMC Bioinformatics 4:44, 2003). Actually, # the emission scores will not exactly With --rsearch enabled, all # alignments in alifile must contain exactly one sequence or the --call # option must also be enabled. '--rsearch':ValuedParameter(Prefix='--',Name='rsearch',Delimiter=' '),\ # --binary Save the model in a compact binary format. The default is a more # readable ASCII text format. '--binary':FlagParameter(Prefix='--',Name='binary'),\ # --rf Use reference coordinate annotation (#=GC RF line, in Stockholm) to # determine which columns are consensus, and which are inserts. '--rf':FlagParameter(Prefix='--',Name='rf'),\ # --gapthresh Set the gap threshold (used for determining which columns # are insertions versus consensus; see --rf above) to . The default is # 0.5. '--gapthresh':ValuedParameter(Prefix='--',Name='gapthresh',Delimiter=' '),\ # --ignorant Strip all base pair secondary structure information from all # input alignments in alifile before building the CM(s). '--ignorant':FlagParameter(Prefix='--',Name='ignorant'),\ # --wgsc Use the Gerstein/Sonnhammer/Chothia (GSC) weighting algorithm. # This is the default unless the number of sequences in the alignment # exceeds a cutoff (see --pbswitch), in which case the default becomes # the faster Henikoff position-based weighting scheme. '--wgsc':FlagParameter(Prefix='--',Name='wgsc'),\ # --wblosum Use the BLOSUM filtering algorithm to weight the sequences, # instead of the default GSC weighting. '--wblosum':FlagParameter(Prefix='--',Name='wblosum'),\ # --wpb Use the Henikoff position-based weighting scheme. This weighting # scheme is automatically used (overriding --wgsc and --wblosum) if the # number of sequences in the alignment exceeds a cutoff (see --pbswitch). '--wpb':FlagParameter(Prefix='--',Name='wpb'),\ # --wnone Turn sequence weighting off; e.g. explicitly set all sequence # weights to 1.0. '--wnone':FlagParameter(Prefix='--',Name='wnone'),\ # --wgiven Use sequence weights as given in annotation in the input # alignment file. If no weights were given, assume they are all 1.0. # The default is to determine new sequence weights by the Gerstein/ # Sonnhammer/Chothia algorithm, ignoring any annotated weights. '--wgiven':FlagParameter(Prefix='--',Name='wgiven'),\ # --pbswitch Set the cutoff for automatically switching the weighting # method to the Henikoff position-based weighting scheme to . If the # number of sequences in the alignment exceeds Henikoff weighting is # used. By default is 5000. '--pbswitch':ValuedParameter(Prefix='--',Name='pbswitch',Delimiter=' '),\ # --wid Controls the behavior of the --wblosum weighting option by # setting the percent identity for clustering the alignment to . '--wid':ValuedParameter(Prefix='--',Name='wid',Delimiter=' '),\ # --eent Use the entropy weighting strategy to determine the effective # sequence number that gives a target mean match state relative entropy. '--wgiven':FlagParameter(Prefix='--',Name='wgiven'),\ # --enone Turn off the entropy weighting strategy. The effective sequence # number is just the number of sequences in the alignment. '--wgiven':FlagParameter(Prefix='--',Name='wgiven'),\ # --ere Set the target mean match state entropy as . By default the # target entropy 1.46 bits. '--ere':ValuedParameter(Prefix='--',Name='ere',Delimiter=' '),\ # --null Read a null model from . The null model defines the # probability of each RNA nucleotide in background sequence, the default # is to use 0.25 for each nucleotide. '--null':ValuedParameter(Prefix='--',Name='null',Delimiter=' '),\ # --prior Read a Dirichlet prior from , replacing the default mixture # Dirichlet. '--prior':ValuedParameter(Prefix='--',Name='prior',Delimiter=' '),\ # --ctarget Cluster each alignment in alifile by percent identity. # find a cutoff percent id threshold that gives exactly clusters and # build a separate CM from each cluster. If is greater than the number # of sequences in the alignment the program will not complain, and each # sequence in the alignment will be its own cluster. Each CM will have a # positive integer appended to its name indicating the order in which it # was built. '--ctarget':ValuedParameter(Prefix='--',Name='ctarget',Delimiter=' '),\ # --cmaxid Cluster each sequence alignment in alifile by percent # identity. Define clusters at the cutoff fractional id similarity of # and build a separate CM from each cluster. '--cmaxid':ValuedParameter(Prefix='--',Name='cmaxid',Delimiter=' '),\ # --call Build a separate CM from each sequence in each alignment in # alifile. Naming of CMs takes place as described above for --ctarget. '--call':FlagParameter(Prefix='--',Name='call'),\ # --corig After building multiple CMs using --ctarget, --cmindiff or --call # as described above, build a final CM using the complete original # alignment from alifile. '--corig':FlagParameter(Prefix='--',Name='corig'),\ # --cdump Dump the multiple alignments of each cluster to in # Stockholm format. This option only works in combination with --ctarget, # --cmindiff or --call. '--cdump':ValuedParameter(Prefix='--',Name='cdump',Delimiter=' '),\ # --refine Attempt to refine the alignment before building the CM using # expectation-maximization (EM). The final alignment (the alignment used # to build the CM that gets written to cmfile) is written to . '--refine':ValuedParameter(Prefix='--',Name='refine',Delimiter=' '),\ # --gibbs Modifies the behavior of --refine so Gibbs sampling is used # instead of EM. '--gibbs':FlagParameter(Prefix='--',Name='gibbs'),\ # -s Set the random seed to , where is a positive integer. # This option can only be used in combination with --gibbs. The default is # to use time() to generate a different seed for each run, which means # that two different runs of cmbuild --refine --gibbs on the same # alignment will give slightly different results. You can use this option # to generate reproducible results. '-s':ValuedParameter(Prefix='-',Name='s',Delimiter=' '),\ # -l With --refine, turn on the local alignment algorithm, which allows the # alignment to span two or more subsequences if necessary (e.g. if the # structures of the query model and target sequence are only partially # shared), allowing certain large insertions and deletions in the # structure to be penalized differently than normal indels. The default is # to globally align the query model to the target sequences. '-l':ValuedParameter(Prefix='-',Name='l',Delimiter=' '),\ # -a With --refine, print the scores of each individual sequence alignment. '-a':ValuedParameter(Prefix='-',Name='a',Delimiter=' '),\ # --cyk With --refine, align with the CYK algorithm. '--cyk':FlagParameter(Prefix='--',Name='cyk'),\ # --sub With --refine, turn on the sub model construction and alignment # procedure. '--sub':FlagParameter(Prefix='--',Name='sub'),\ # --nonbanded With --refine, do not use HMM bands to accelerate alignment. # Use the full CYK algorithm which is guaranteed to give the optimal # alignment. This will slow down the run significantly, especially for # large models. '--nonbanded':FlagParameter(Prefix='--',Name='nonbanded'),\ # --tau With --refine, set the tail loss probability used during HMM # band calculation to . This is the amount of probability mass within # the HMM posterior probabilities that is considered negligible. The # default value is 1E-7. In general, higher values will result in greater # acceleration, but increase the chance of missing the optimal alignment # due to the HMM bands. '--tau':ValuedParameter(Prefix='--',Name='tau',Delimiter=' '),\ # --fins With --refine, change the behavior of how insert emissions are # placed in the alignment. '--fins':FlagParameter(Prefix='--',Name='fins'),\ # --mxsize With --refine, set the maximum allowable matrix size for # alignment to megabytes. '--mxsize':ValuedParameter(Prefix='--',Name='mxsize',Delimiter=' '),\ # --rdump With --refine, output the intermediate alignments at each # iteration of the refinement procedure (as described above for --refine ) # to file . '--rdump':ValuedParameter(Prefix='--',Name='rdump',Delimiter=' '),\ } _parameters = {} _parameters.update(_options) _command = "cmbuild" _suppress_stderr=True def getHelp(self): """Method that points to the Infernal documentation.""" help_str = \ """ See Infernal documentation at: http://infernal.janelia.org/ """ return help_str def _refine_out_filename(self): if self.Parameters['--refine'].isOn(): refined_filename = self._absolute(str(\ self.Parameters['--refine'].Value)) else: raise ValueError, 'No refine output file specified.' return refined_filename def _cm_out_filename(self): if self.Parameters['-n'].isOn(): refined_filename = self._absolute(str(\ self.Parameters['-n'].Value)) else: raise ValueError, 'No cm output file specified.' return refined_filename def _tempfile_as_multiline_string(self, data): """Write a multiline string to a temp file and return the filename. data: a multiline string to be written to a file. * Note: the result will be the filename as a FilePath object (which is a string subclass). """ filename = FilePath(self.getTmpFilename(self.TmpDir)) data_file = open(filename,'w') data_file.write(data) data_file.close() return filename def _get_result_paths(self,data): result = {} if self.Parameters['--refine'].isOn(): out_name = self._refine_out_filename() result['Refined'] = ResultPath(Path=out_name,IsWritten=True) if self.Parameters['-n'].isOn(): cm_name = self._cm_out_filename() result['CmFile'] = ResultPath(Path=cm_name,IsWritten=True) return result class Cmcalibrate(CommandLineApplication): """cmcalibrate application controller.""" _options = { # -s Set the random number generator seed to , where is a # positive integer. The default is to use time() to generate a different # seed for each run, which means that two different runs of cmcalibrate on # the same CM will give slightly different E-value and HMM filter # threshold parameters. You can use this option to generate reproducible # results. '-s':ValuedParameter(Prefix='-',Name='s',Delimiter=' '),\ # --forecast Predict the running time of the calibration for cmfile and # provided options and exit, DO NOT perform the calibration. '--forecast':ValuedParameter(Prefix='--',Name='forecast',Delimiter=' '),\ # --mpi Run as an MPI parallel program. '--mpi':FlagParameter(Prefix='--',Name='mpi'),\ # Expert Options # --exp-cmL-glc Set the length of random sequence to search for the CM # glocal exponential tail fits to megabases (Mb). '--exp-cmL-glc':ValuedParameter(Prefix='--',Name='exp-cmL-glc',\ Delimiter=' '),\ # --exp-cmL-loc Set the length of random sequence to search for the CM # local exponential tail fits to megabases (Mb). '--exp-cmL-loc':ValuedParameter(Prefix='--',Name='exp-cmL-loc',\ Delimiter=' '),\ # --exp-hmmLn-glc Set the minimum random sequence length to search for # the HMM glocal exponential tail fits to megabases (Mb). '--exp-hmmLn-glc':ValuedParameter(Prefix='--',Name='exp-hmmLn-glc',\ Delimiter=' '),\ # --exp-hmmLn-loc Set the minimum random sequence length to search for # the HMM local exponential tail fits to megabases (Mb). '--exp-hmmLn-loc':ValuedParameter(Prefix='--',Name='exp-hmmLn-loc',\ Delimiter=' '),\ # --exp-hmmLx Set the maximum random sequence length to search when # determining HMM E-values to megabases (Mb). '--exp-hmmLx':ValuedParameter(Prefix='--',Name='exp-hmmLx',Delimiter=' '),\ # --exp-fract Set the HMM/CM fraction of dynamic programming # calculations to . '--exp-fract':ValuedParameter(Prefix='--',Name='exp-fract',Delimiter=' '),\ # --exp-tailn-cglc During E-value calibration of glocal CM search modes # fit the exponential tail to the high scores in the histogram tail that # includes hits per Mb searched. '--exp-tailn-cglc':ValuedParameter(Prefix='--',Name='exp-tailn-cglc',\ Delimiter=' '),\ # --exp-tailn-cloc During E-value calibration of local CM search modes # fit the exponential tail to the high scores in the histogram tail that # includes hits per Mb searched. '--exp-tailn-cloc':ValuedParameter(Prefix='--',Name='exp-tailn-cloc',\ Delimiter=' '),\ # --exp-tailn-hglc During E-value calibration of glocal HMM search modes # fit the exponential tail to the high scores in the histogram tail that # includes hits per Mb searched. '--exp-tailn-hglc':ValuedParameter(Prefix='--',Name='exp-tailn-hglc',\ Delimiter=' '),\ # --exp-tailn-hloc During E-value calibration of local HMM search modes # fit the exponential tail to the high scores in the histogram tail that # includes hits per Mb searched. '--exp-tailn-hloc':ValuedParameter(Prefix='--',Name='exp-tailn-hloc',\ Delimiter=' '),\ # --exp-tailp Ignore the --exp-tailn prefixed options and fit the # fraction right tail of the histogram to exponential tails, for all # search modes. '--exp-tailp':ValuedParameter(Prefix='--',Name='exp-tailp',Delimiter=' '),\ # --exp-tailxn With --exp-tailp enforce that the maximum number of hits # in the tail that is fit is . '--exp-tailxn':ValuedParameter(Prefix='--',Name='exp-tailxn',\ Delimiter=' '),\ # --exp-beta During E-value calibration, by default query-dependent # banding (QDB) is used to accelerate the CM search algorithms with a beta # tail loss probability of 1E-15. '--exp-beta':ValuedParameter(Prefix='--',Name='exp-beta',Delimiter=' '),\ # --exp-no-qdb Turn of QDB during E-value calibration. This will slow down # calibration, and is not recommended unless you plan on using --no-qdb in # cmsearch. '--exp-no-qdb':FlagParameter(Prefix='--',Name='exp-no-qdb'),\ # --exp-hfile Save the histograms fit for the E-value calibration to # file . The format of this file is two tab delimited columns. '--exp-hfile':ValuedParameter(Prefix='--',Name='exp-hfile',Delimiter=' '),\ # --exp-sfile Save a survival plot for the E-value calibration to file # . The format of this file is two tab delimited columns. '--exp-sfile':ValuedParameter(Prefix='--',Name='exp-sfile',Delimiter=' '),\ # --exp-qqfile Save a quantile-quantile plot for the E-value calibration # to file . The format of this file is two tab delimited columns. '--exp-qqfile':ValuedParameter(Prefix='--',Name='exp-qqfile',\ Delimiter=' '),\ # --exp-ffile Save statistics on the exponential tail statistics to file # . The file will contain the lambda and mu values for exponential # tails fit to tails of different sizes. '--exp-ffile':ValuedParameter(Prefix='--',Name='exp-ffile',Delimiter=' '),\ # --fil-N Set the number of sequences sampled and searched for the HMM # filter threshold calibration to . By default, is 10,000. '--fil-N':ValuedParameter(Prefix='--',Name='fil-N',Delimiter=' '),\ # --fil-F Set the fraction of sample sequences the HMM filter must be # able to recognize, and allow to survive, to , where is a positive # real number less than or equal to 1.0. By default, is 0.995. '--fil-F':ValuedParameter(Prefix='--',Name='fil-F',Delimiter=' '),\ # --fil-xhmm Set the target number of dynamic programming calculations # for a HMM filtered CM QDB search with beta = 1E-7 to times the # number of calculations required to do an HMM search. By default, is # 2.0. '--fil-xhmm':ValuedParameter(Prefix='--',Name='fil-xhmm',Delimiter=' '),\ # --fil-tau Set the tail loss probability during HMM band calculation # for HMM filter threshold calibration to . '--fil-tau':ValuedParameter(Prefix='--',Name='fil-tau',Delimiter=' '),\ # --fil-gemit During HMM filter calibration, always sample sequences from a # globally configured CM, even when calibrating local modes. '--fil-gemit':FlagParameter(Prefix='--',Name='fil-gemit'),\ # --fil-dfile Save statistics on filter threshold calibration, including # HMM and CM scores for all sampled sequences, to file . '--fil-dfile':ValuedParameter(Prefix='--',Name='fil-dfile',Delimiter=' '),\ # --mxsize Set the maximum allowable DP matrix size to megabytes. '--mxsize':ValuedParameter(Prefix='--',Name='mxsize',Delimiter=' '),\ } _parameters = {} _parameters.update(_options) _command = "cmcalibrate" _suppress_stderr=True def getHelp(self): """Method that points to the Infernal documentation.""" help_str = \ """ See Infernal documentation at: http://infernal.janelia.org/ """ return help_str class Cmemit(CommandLineApplication): """cmemit application controller.""" _options = { # -o Save the synthetic sequences to file rather than writing them # to stdout. '-o':ValuedParameter(Prefix='-',Name='o',Delimiter=' '),\ # -n Generate sequences. Default is 10. '-n':ValuedParameter(Prefix='-',Name='n',Delimiter=' '),\ # -u Write the generated sequences in unaligned format (FASTA). This is the # default, so this option is probably useless. '-u':FlagParameter(Prefix='-',Name='u'),\ # -a Write the generated sequences in an aligned format (STOCKHOLM) with # consensus structure annotation rather than FASTA. '-a':FlagParameter(Prefix='-',Name='a'),\ # -c Predict a single majority-rule consensus sequence instead of sampling # sequences from the CM's probability distribution. '-c':FlagParameter(Prefix='-',Name='c'),\ # -l Configure the CMs into local mode before emitting sequences. See the # User's Guide for more information on locally configured CMs. '-l':FlagParameter(Prefix='-',Name='l'),\ # -s Set the random seed to , where is a positive integer. The # default is to use time() to generate a different seed for each run, # which means that two different runs of cmemit on the same CM will give # different results. You can use this option to generate reproducible # results. '-s':ValuedParameter(Prefix='-',Name='s',Delimiter=' '),\ # --rna Specify that the emitted sequences be output as RNA sequences. This # is true by default. '--rna':FlagParameter(Prefix='--',Name='rna'),\ # --dna Specify that the emitted sequences be output as DNA sequences. By # default, the output alphabet is RNA. '--dna':FlagParameter(Prefix='--',Name='dna'),\ # --tfile Dump tabular sequence parsetrees (tracebacks) for each emitted # sequence to file . Primarily useful for debugging. '--tfile':ValuedParameter(Prefix='--',Name='tfile',Delimiter=' '),\ # --exp Exponentiate the emission and transition probabilities of the CM # by and then renormalize those distributions before emitting # sequences. '--exp':ValuedParameter(Prefix='--',Name='exp',Delimiter=' '),\ # --begin Truncate the resulting alignment by removing all residues # before consensus column , where is a positive integer no greater # than the consensus length of the CM. Must be used in combination with # --end and either -a or --shmm (a developer option). '--begin':ValuedParameter(Prefix='--',Name='begin',Delimiter=' '),\ # --end Truncate the resulting alignment by removing all residues after # consensus column , where is a positive integer no greater than # the consensus length of the CM. Must be used in combination with --begin # and either -a or --shmm (a developer option). '--end':ValuedParameter(Prefix='--',Name='end',Delimiter=' '),\ } _parameters = {} _parameters.update(_options) _command = "cmemit" _suppress_stderr=True def getHelp(self): """Method that points to the Infernal documentation.""" help_str = \ """ See Infernal documentation at: http://infernal.janelia.org/ """ return help_str class Cmscore(CommandLineApplication): """cmscore application controller.""" _options = { # -n Set the number of sequences to generate and align to . This # option is incompatible with the --infile option. '-n':ValuedParameter(Prefix='-',Name='n',Delimiter=' '),\ # -l Turn on the local alignment algorithm, which allows the alignment to # span two or more subsequences if necessary (e.g. if the structures of # the query model and target sequence are only partially shared), allowing # certain large insertions and deletions in the structure to be penalized # differently than normal indels. The default is to globally align the # query model to the target sequences. '-l':FlagParameter(Prefix='-',Name='l'),\ # -s Set the random seed to , where is a positive integer. The # default is to use time() to generate a different seed for each run, # which means that two different runs of cmscore on the same CM will give # different results. You can use this option to generate reproducible # results. The random number generator is used to generate sequences to # score, so -s is incompatible with the --infile option which supplies # the sequences to score in an input file. '-s':ValuedParameter(Prefix='-',Name='s',Delimiter=' '),\ # -a Print individual timings and score comparisons for each sequence in # seqfile. By default only summary statistics are printed. '-a':FlagParameter(Prefix='-',Name='a'),\ # --sub Turn on the sub model construction and alignment procedure. '--sub':FlagParameter(Prefix='--',Name='sub'),\ # --mxsize Set the maximum allowable DP matrix size to megabytes. '--mxsize':ValuedParameter(Prefix='--',Name='mxsize',Delimiter=' '),\ # --mpi Run as an MPI parallel program. '--mpi':FlagParameter(Prefix='--',Name='mpi'),\ # Expert Options # --emit Generate sequences to score by sampling from the CM. '--emit':FlagParameter(Prefix='--',Name='emit'),\ # --random Generate sequences to score by sampling from the CMs null # distribution. This option turns the --emit option off. '--random':FlagParameter(Prefix='--',Name='random'),\ # --infile Sequences to score are read from the file . All the # sequences from are read and scored, the -n and -s options are # incompatible with --infile. '--infile':ValuedParameter(Prefix='--',Name='infile',Delimiter=' '),\ # --outfile Save generated sequences that are scored to the file in # FASTA format. This option is incompatible with the --infile option. '--outfile':ValuedParameter(Prefix='--',Name='outfile',Delimiter=' '),\ # --Lmin Must be used in combination with --random and --Lmax . '--Lmin':ValuedParameter(Prefix='--',Name='Lmin',Delimiter=' '),\ # --pad Must be used in combination with --emit and --search. Add cm->W # (max hit length) minus L (sequence length) residues to the 5' and 3' # end of each emitted sequence . '--pad':FlagParameter(Prefix='--',Name='pad'),\ # --hbanded Specify that the second stage alignment algorithm be HMM banded # CYK. This option is on by default. '--hbanded':FlagParameter(Prefix='--',Name='hbanded'),\ # --tau For stage 2 alignment, set the tail loss probability used during # HMM band calculation to . '--tau':ValuedParameter(Prefix='--',Name='tau',Delimiter=' '),\ # --aln2bands With --search, when calculating HMM bands, use an HMM # alignment algorithm instead of an HMM search algorithm. '--aln2bands':FlagParameter(Prefix='--',Name='aln2bands'),\ # --hsafe For stage 2 HMM banded alignment, realign any sequences with a # negative alignment score using non-banded CYK to guarantee finding the # optimal alignment. '--hsafe':FlagParameter(Prefix='--',Name='hsafe'),\ # --nonbanded Specify that the second stage alignment algorithm be standard, # non-banded, non-D&C CYK. When --nonbanded is enabled, the program fails # with a non-zero exit code and prints an error message if the parsetree # score for any sequence from stage 1 D&C alignment and stage 2 alignment # differs by more than 0.01 bits. In theory, this should never happen as # both algorithms are guaranteed to determine the optimal parsetree. For # larger RNAs (more than 300 residues) if memory is limiting, --nonbanded # should be used in combination with --scoreonly. '--nonbanded':FlagParameter(Prefix='--',Name='nonbanded'),\ # --scoreonly With --nonbanded during the second stage standard non-banded # CYK alignment, use the "score only" variant of the algorithm to save # memory, and don't recover a parse tree. '--scoreonly':FlagParameter(Prefix='--',Name='scoreonly'),\ # --viterbi Specify that the second stage alignment algorithm be Viterbi to # a CM Plan 9 HMM. '--viterbi':FlagParameter(Prefix='--',Name='viterbi'),\ # --search Run all algorithms in scanning mode, not alignment mode. '--search':FlagParameter(Prefix='--',Name='search'),\ # --inside With --search Compare the non-banded scanning Inside algorithm to # the HMM banded scanning Inside algorith, instead of using CYK versions. '--inside':FlagParameter(Prefix='--',Name='inside'),\ # --forward With --search Compare the scanning Forward scoring algorithm # against CYK. '--forward':FlagParameter(Prefix='--',Name='forward'),\ # --taus Specify the first alignment algorithm as non-banded D&C CYK, # and multiple stages of HMM banded CYK alignment. The first HMM banded # alignment will use tau=1E-, which will be the highest value of tau # used. Must be used in combination with --taue. '--taus':ValuedParameter(Prefix='--',Name='taus',Delimiter=' '),\ # --taue Specify the first alignment algorithm as non-banded D&C CYK, # and multiple stages of HMM banded CYK alignment. The final HMM banded # alignment will use tau=1E-, which will be the lowest value of tau # used. Must be used in combination with --taus. '--taue':ValuedParameter(Prefix='--',Name='taue',Delimiter=' '),\ # --tfile Print the parsetrees for each alignment of each sequence to # file . '--tfile':ValuedParameter(Prefix='--',Name='tfile',Delimiter=' '),\ } _parameters = {} _parameters.update(_options) _command = "cmscore" _suppress_stderr=True def getHelp(self): """Method that points to the Infernal documentation.""" help_str = \ """ See Infernal documentation at: http://infernal.janelia.org/ """ return help_str class Cmsearch(CommandLineApplication): """cmsearch application controller.""" _options = { # -o Save the high-scoring alignments of hits to a file . The default # is to write them to standard output. '-o':ValuedParameter(Prefix='-',Name='o',Delimiter=' '),\ # -g Turn on the 'glocal' alignment algorithm, local with respect to the # target database, and global with respect to the model. By default, the # local alignment algorithm is used which is local with respect to both # the target sequence and the model. '-g':ValuedParameter(Prefix='-',Name='g',Delimiter=' '),\ # -p Append posterior probabilities to alignments of hits. '-p':FlagParameter(Prefix='-',Name='p'),\ # -x Annotate non-compensatory basepairs and basepairs that include a gap in # the left and/or right half of the pair with x's in the alignments of # hits. '-x':FlagParameter(Prefix='-',Name='x'),\ # -Z Calculate E-values as if the target database size was megabases # (Mb). Ignore the actual size of the database. This option is only valid # if the CM file has been calibrated. Warning: the predictions for timings # and survival fractions will be calculated as if the database was of size # Mb, which means they will be inaccurate. '-Z':ValuedParameter(Prefix='-',Name='Z',Delimiter=' '),\ # --toponly Only search the top (Watson) strand of the sequences in seqfile. # By default, both strands are searched. '--toponly':FlagParameter(Prefix='--',Name='toponly'),\ # --bottomonly Only search the bottom (Crick) strand of the sequences in # seqfile. By default, both strands are searched. '--bottomonly':FlagParameter(Prefix='--',Name='bottomonly'),\ # --forecast Predict the running time of the search with provided files # and options and exit, DO NOT perform the search. This option is only # available with calibrated CM files. '--forecast':ValuedParameter(Prefix='--',Name='forecast',Delimiter=' '),\ # --informat Assert that the input seqfile is in format . Do not run # Babelfish format autodection. This increases the reliability of the # program somewhat, because the Babelfish can make mistakes; particularly # recommended for unattended, high-throughput runs of @PACKAGE@. is # case-insensitive. Acceptable formats are: FASTA, EMBL, UNIPROT, GENBANK, # and DDBJ. is case-insensitive. '--informat':ValuedParameter(Prefix='--',Name='informat',Delimiter=' '),\ # --mxsize Set the maximum allowable DP matrix size to megabytes. '--mxsize':ValuedParameter(Prefix='--',Name='mxsize',Delimiter=' '),\ # --mpi Run as an MPI parallel program. '--mpi':FlagParameter(Prefix='--',Name='mpi'),\ # Expert Options # --inside Use the Inside algorithm for the final round of searching. This # is true by default. '--inside':FlagParameter(Prefix='--',Name='inside'),\ # --cyk Use the CYK algorithm for the final round of searching. '--cyk':FlagParameter(Prefix='--',Name='cyk'),\ # --viterbi Search only with an HMM. This is much faster but less sensitive # than a CM search. Use the Viterbi algorithm for the HMM search. '--viterbi':FlagParameter(Prefix='--',Name='viterbi'),\ # --forward Search only with an HMM. This is much faster but less sensitive # than a CM search. Use the Forward algorithm for the HMM search. '--forward':FlagParameter(Prefix='--',Name='forward'),\ # -E Set the E-value cutoff for the per-sequence/strand ranked hit list # to , where is a positive real number. '-E':ValuedParameter(Prefix='-',Name='E',Delimiter=' '),\ # -T Set the bit score cutoff for the per-sequence ranked hit list to # , where is a positive real number. '-T':ValuedParameter(Prefix='-',Name='T',Delimiter=' '),\ # --nc Set the bit score cutoff as the NC cutoff value used by Rfam curators # as the noise cutoff score. '--nc':FlagParameter(Prefix='--',Name='nc'),\ # --ga Set the bit score cutoff as the GA cutoff value used by Rfam curators # as the gathering threshold. '--ga':FlagParameter(Prefix='--',Name='ga'),\ # --tc Set the bit score cutoff as the TC cutoff value used by Rfam curators # as the trusted cutoff. '--tc':FlagParameter(Prefix='--',Name='tc'),\ # --no-qdb Do not use query-dependent banding (QDB) for the final round of # search. '--no-qdb':FlagParameter(Prefix='--',Name='no-qdb'),\ # --beta " " For query-dependent banding (QDB) during the final round of # search, set the beta parameter to where is any positive real # number less than 1.0. '--beta':ValuedParameter(Prefix='--',Name='beta',Delimiter=' '),\ # --hbanded Use HMM bands to accelerate the final round of search. # Constraints for the CM search are derived from posterior probabilities # from an HMM. This is an experimental option and it is not recommended # for use unless you know exactly what you're doing. '--hbanded':FlagParameter(Prefix='--',Name='hbanded'),\ # --tau Set the tail loss probability during HMM band calculation to # . '--tau':ValuedParameter(Prefix='--',Name='tau',Delimiter=' '),\ # --fil-no-hmm Turn the HMM filter off. '--fil-no-hmm':FlagParameter(Prefix='--',Name='fil-no-hmm'),\ # --fil-no-qdb Turn the QDB filter off. '--fil-no-qdb':FlagParameter(Prefix='--',Name='fil-no-qdb'),\ # --fil-beta For the QDB filter, set the beta parameter to where is # any positive real number less than 1.0. '--fil-beta':FlagParameter(Prefix='--',Name='fil-beta'),\ # --fil-T-qdb Set the bit score cutoff for the QDB filter round to , # where is a positive real number. '--fil-T-qdb':ValuedParameter(Prefix='--',Name='fil-T-qdb',Delimiter=' '),\ # --fil-T-hmm Set the bit score cutoff for the HMM filter round to , # where is a positive real number. '--fil-T-hmm':ValuedParameter(Prefix='--',Name='fil-T-hmm',Delimiter=' '),\ # --fil-E-qdb Set the E-value cutoff for the QDB filter round. , # where is a positive real number. Hits with E-values better than # (less than) or equal to this threshold will survive and be passed to the # final round. This option is only available if the CM file has been # calibrated. '--fil-E-qdb':ValuedParameter(Prefix='--',Name='fil-E-qdb',Delimiter=' '),\ # --fil-E-hmm Set the E-value cutoff for the HMM filter round. , # where is a positive real number. Hits with E-values better than # (less than) or equal to this threshold will survive and be passed to the # next round, either a QDB filter round, or if the QDB filter is disable, # to the final round of search. This option is only available if the CM # file has been calibrated. '--fil-E-hmm':ValuedParameter(Prefix='--',Name='fil-E-hmm',Delimiter=' '),\ # --fil-Smax-hmm Set the maximum predicted survival fraction for an HMM # filter as , where is a positive real number less than 1.0. '--fil-Smax-hmm':ValuedParameter(Prefix='--',Name='fil-Smax-hmm',\ Delimiter=' '),\ # --noalign Do not calculate and print alignments of each hit, only print # locations and scores. '--noalign':FlagParameter(Prefix='--',Name='noalign'),\ # --aln-hbanded Use HMM bands to accelerate alignment during the hit # alignment stage. '--aln-hbanded':FlagParameter(Prefix='--',Name='aln-hbanded'),\ # --aln-optacc Calculate alignments of hits from final round of search using # the optimal accuracy algorithm which computes the alignment that # maximizes the summed posterior probability of all aligned residues given # the model, which can be different from the highest scoring one. '--aln-optacc':FlagParameter(Prefix='--',Name='aln-optacc'),\ # --tabfile Create a new output file and print tabular results to # it. '--tabfile':ValuedParameter(Prefix='--',Name='tabfile',Delimiter=' '),\ # --gcfile Create a new output file and print statistics of the GC # content of the sequences in seqfile to it. '--gcfile':ValuedParameter(Prefix='--',Name='gcfile',Delimiter=' '),\ # --rna Output the hit alignments as RNA sequences alignments. This is true # by default. '--rna':FlagParameter(Prefix='--',Name='rna'),\ # --dna Output the hit alignments as DNA sequence alignments. '--dna':FlagParameter(Prefix='--',Name='dna'),\ } _parameters = {} _parameters.update(_options) _command = "cmsearch" _suppress_stderr=True def getHelp(self): """Method that points to the Infernal documentation.""" help_str = \ """ See Infernal documentation at: http://infernal.janelia.org/ """ return help_str def _tabfile_out_filename(self): if self.Parameters['--tabfile'].isOn(): tabfile_filename = self._absolute(str(\ self.Parameters['--tabfile'].Value)) else: raise ValueError, 'No tabfile output file specified.' return tabfile_filename def _tempfile_as_multiline_string(self, data): """Write a multiline string to a temp file and return the filename. data: a multiline string to be written to a file. * Note: the result will be the filename as a FilePath object (which is a string subclass). """ filename = FilePath(self.getTmpFilename(self.TmpDir)) data_file = open(filename,'w') data_file.write(data) data_file.close() return filename def _get_result_paths(self,data): result = {} if self.Parameters['--tabfile'].isOn(): out_name = self._tabfile_out_filename() result['SearchResults'] = ResultPath(Path=out_name,IsWritten=True) return result class Cmstat(CommandLineApplication): """cmstat application controller.""" _options = { # -g Turn on the 'glocal' alignment algorithm, local with respect to the # target database, and global with respect to the model. By default, the # model is configured for local alignment which is local with respect to # both the target sequence and the model. '-g':FlagParameter(Prefix='-',Name='g'),\ # -m print general statistics on the models in cmfile and the alignment it # was built from. '-m':FlagParameter(Prefix='-',Name='m'),\ # -Z Calculate E-values as if the target database size was megabases # (Mb). Ignore the actual size of the database. This option is only valid # if the CM file has been calibrated. '-Z':ValuedParameter(Prefix='-',Name='Z',Delimiter=' '),\ # --all print all available statistics '--all':FlagParameter(Prefix='--',Name='all'),\ # --le print local E-value statistics. This option only works if cmfile has # been calibrated with cmcalibrate. '--le':FlagParameter(Prefix='--',Name='le'),\ # --ge print glocal E-value statistics. This option only works if cmfile has # been calibrated with cmcalibrate. '--ge':FlagParameter(Prefix='--',Name='ge'),\ # --beta With the --search option set the beta parameter for the query- # dependent banding algorithm stages to Beta is the probability mass # considered negligible during band calculation. The default is 1E-7. '--beta':ValuedParameter(Prefix='--',Name='beta',Delimiter=' '),\ # --qdbfile Save the query-dependent bands (QDBs) for each state to file # '--qdbfile':ValuedParameter(Prefix='--',Name='qdbfile',Delimiter=' '),\ # Expert Options # --lfi Print the HMM filter thresholds for the range of relevant CM bit # score cutoffs for searches with locally configured models using the # Inside algorithm. '--lfi':FlagParameter(Prefix='--',Name='lfi'),\ # --gfi Print the HMM filter thresholds for the range of relevant CM bit # score cutoffs for searches with globally configured models using the # Inside algorithm. '--gfi':FlagParameter(Prefix='--',Name='gfi'),\ # --lfc Print the HMM filter thresholds for the range of relevant CM bit # score cutoffs for searches with locally configured models using the CYK # algorithm. '--lfc':FlagParameter(Prefix='--',Name='lfc'),\ # --gfc Print the HMM filter thresholds for the range of relevant CM bit # score cutoffs for searches with globally configured models using the CYK # algorithm. '--gfc':FlagParameter(Prefix='--',Name='gfc'),\ # -E Print filter threshold statistics for an HMM filter if a final CM # E-value cutoff of were to be used for a run of cmsearch on 1 MB of # sequence. '-E':ValuedParameter(Prefix='-',Name='E',Delimiter=' '),\ # -T Print filter threshold statistics for an HMM filter if a final CM # bit score cutoff of were to be used for a run of cmsearch. '-T':ValuedParameter(Prefix='-',Name='T',Delimiter=' '),\ # --nc Print filter threshold statistics for an HMM filter if a CM bit score # cutoff equal to the Rfam NC cutoff were to be used for a run of # cmsearch. '--nc':FlagParameter(Prefix='--',Name='nc'),\ # --ga Print filter threshold statistics for an HMM filter if a CM bit score # cutoff of Rfam GA cutoff value were to be used for a run of cmsearch. '--ga':FlagParameter(Prefix='--',Name='ga'),\ # --tc Print filter threshold statistics for an HMM filter if a CM bit score # cutoff equal to the Rfam TC cutoff value were to be used for a run of # cmsearch. '--tc':FlagParameter(Prefix='--',Name='tc'),\ # --seqfile With the -E option, use the database size of the database in # instead of the default database size of 1 MB. '--seqfile':ValuedParameter(Prefix='--',Name='seqfile',Delimiter=' '),\ # --toponly In combination with --seqfile option, only consider the top # strand of the database in instead of both strands. --search perform # an experiment to determine how fast the CM(s) can search with different # search algorithms. '--toponly':FlagParameter(Prefix='--',Name='toponly'),\ # --cmL With the --search option set the length of sequence to search # with CM algorithms as residues. By default, is 1000. '--cmL':ValuedParameter(Prefix='--',Name='cmL',Delimiter=' '),\ # --hmmL With the --search option set the length of sequence to search # with HMM algorithms as residues. By default, is 100,000. '--hmmL':ValuedParameter(Prefix='--',Name='hmmL',Delimiter=' '),\ # --efile Save a plot of cmsearch HMM filter E value cutoffs versus CM # E-value cutoffs in xmgrace format to file . This option must be used # in combination with --lfi, --gfi, --lfc or --gfc. '--efile':ValuedParameter(Prefix='--',Name='efile',Delimiter=' '),\ # --bfile Save a plot of cmsearch HMM bit score cutoffs versus CM bit # score cutoffs in xmgrace format to file . This option must be used in # combination with --lfi, --gfi, --lfc or --gfc. '--bfile':ValuedParameter(Prefix='--',Name='bfile',Delimiter=' '),\ # --sfile Save a plot of cmsearch predicted survival fraction from the # HMM filter versus CM E value cutoff in xmgrace format to file . This # option must be used in combination with --lfi, --gfi, --lfc or --gfc. '--sfile':ValuedParameter(Prefix='--',Name='sfile',Delimiter=' '),\ # --xfile Save a plot of 'xhmm' versus CM E value cutoff in xmgrace # format to file 'xhmm' is the ratio of the number of dynamic # programming calculations predicted to be required for the HMM filter and # the CM search of the filter survivors versus the number of dynamic # programming calculations for the filter alone. This option must be # used in combination with --lfi, --gfi, --lfc or --gfc. '--xfile':ValuedParameter(Prefix='--',Name='xfile',Delimiter=' '),\ # --afile Save a plot of the predicted acceleration for an HMM filtered # search versus CM E value cutoff in xmgrace format to file . This # option must be used in combination with --lfi, --gfi, --lfc or --gfc. '--afile':ValuedParameter(Prefix='--',Name='afile',Delimiter=' '),\ # --bits With --efile, --sfile, --xfile, and --afile use CM bit score # cutoffs instead of CM E value cutoffs for the x-axis values of the plot. '--bits':FlagParameter(Prefix='--',Name='bits'),\ } _parameters = {} _parameters.update(_options) _command = "cmstat" _suppress_stderr=True def getHelp(self): """Method that points to the Infernal documentation.""" help_str = \ """ See Infernal documentation at: http://infernal.janelia.org/ """ return help_str def cmbuild_from_alignment(aln, structure_string, refine=False, \ return_alignment=False,params=None): """Uses cmbuild to build a CM file given an alignment and structure string. - aln: an Alignment object or something that can be used to construct one. All sequences must be the same length. - structure_string: vienna structure string representing the consensus stucture for the sequences in aln. Must be the same length as the alignment. - refine: refine the alignment and realign before building the cm. (Default=False) - return_alignment: Return (in Stockholm format) alignment file used to construct the CM file. This will either be the original alignment and structure string passed in, or the refined alignment if --refine was used. (Default=False) - Note. This will be a string that can either be written to a file or parsed. """ aln = Alignment(aln) if len(structure_string) != aln.SeqLen: raise ValueError, """Structure string is not same length as alignment. Structure string is %s long. Alignment is %s long."""%(len(structure_string),\ aln.SeqLen) else: struct_dict = {'SS_cons':structure_string} #Make new Cmbuild app instance. app = Cmbuild(InputHandler='_input_as_paths',WorkingDir='/tmp',\ params=params) #turn on refine flag if True. if refine: app.Parameters['--refine'].on(get_tmp_filename(app.WorkingDir)) #Get alignment in Stockholm format aln_file_string = stockholm_from_alignment(aln,GC_annotation=struct_dict) #get path to alignment filename aln_path = app._input_as_multiline_string(aln_file_string) cm_path = aln_path.split('.txt')[0]+'.cm' app.Parameters['-n'].on(cm_path) filepaths = [cm_path,aln_path] res = app(filepaths) cm_file = res['CmFile'].read() if return_alignment: #If alignment was refined, return refined alignment and structure, # otherwise return original alignment and structure. if refine: aln_file_string = res['Refined'].read() res.cleanUp() return cm_file, aln_file_string #Just return cm_file else: res.cleanUp() return cm_file def cmbuild_from_file(stockholm_file_path, refine=False,return_alignment=False,\ params=None): """Uses cmbuild to build a CM file given a stockholm file. - stockholm_file_path: a path to a stockholm file. This file should contain a multiple sequence alignment formated in Stockholm format. This must contain a sequence structure line: #=GC SS_cons - refine: refine the alignment and realign before building the cm. (Default=False) - return_alignment: Return alignment and structure string used to construct the CM file. This will either be the original alignment and structure string passed in, or the refined alignment if --refine was used. (Default=False) """ #get alignment and structure string from stockholm file. info, aln, structure_string = \ list(MinimalRfamParser(open(stockholm_file_path,'U'),\ seq_constructor=ChangedSequence))[0] #call cmbuild_from_alignment. res = cmbuild_from_alignment(aln, structure_string, refine=refine, \ return_alignment=return_alignment,params=params) return res def cmalign_from_alignment(aln, structure_string, seqs, moltype,\ include_aln=True,refine=False, return_stdout=False,params=None,\ cmbuild_params=None): """Uses cmbuild to build a CM file, then cmalign to build an alignment. - aln: an Alignment object or something that can be used to construct one. All sequences must be the same length. - structure_string: vienna structure string representing the consensus stucture for the sequences in aln. Must be the same length as the alignment. - seqs: SequenceCollection object or something that can be used to construct one, containing unaligned sequences that are to be aligned to the aligned sequences in aln. - moltype: Cogent moltype object. Must be RNA or DNA. - include_aln: Boolean to include sequences in aln in final alignment. (Default=True) - refine: refine the alignment and realign before building the cm. (Default=False) - return_stdout: Boolean to return standard output from infernal. This includes alignment and structure bit scores and average probabilities for each sequence. (Default=False) """ #NOTE: Must degap seqs or Infernal well seg fault! seqs = SequenceCollection(seqs,MolType=moltype).degap() #Create mapping between abbreviated IDs and full IDs int_map, int_keys = seqs.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) cm_file, aln_file_string = cmbuild_from_alignment(aln, structure_string,\ refine=refine,return_alignment=True,params=cmbuild_params) if params is None: params = {} params.update({MOLTYPE_MAP[moltype]:True}) app = Cmalign(InputHandler='_input_as_paths',WorkingDir='/tmp',\ params=params) app.Parameters['--informat'].on('FASTA') #files to remove that aren't cleaned up by ResultPath object to_remove = [] #turn on --withali flag if True. if include_aln: app.Parameters['--withali'].on(\ app._tempfile_as_multiline_string(aln_file_string)) #remove this file at end to_remove.append(app.Parameters['--withali'].Value) seqs_path = app._input_as_multiline_string(int_map.toFasta()) cm_path = app._tempfile_as_multiline_string(cm_file) #add cm_path to to_remove to_remove.append(cm_path) paths = [cm_path,seqs_path] app.Parameters['-o'].on(get_tmp_filename(app.WorkingDir)) res = app(paths) info, aligned, struct_string = \ list(MinimalRfamParser(res['Alignment'].readlines(),\ seq_constructor=SEQ_CONSTRUCTOR_MAP[moltype]))[0] #Make new dict mapping original IDs new_alignment={} for k,v in aligned.NamedSeqs.items(): new_alignment[int_keys.get(k,k)]=v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment,MolType=moltype) std_out = res['StdOut'].read() #clean up files res.cleanUp() for f in to_remove: remove(f) if return_stdout: return new_alignment, struct_string, std_out else: return new_alignment, struct_string def cmalign_from_file(cm_file_path, seqs, moltype, alignment_file_path=None,\ include_aln=False,return_stdout=False,params=None): """Uses cmalign to align seqs to alignment in cm_file_path. - cm_file_path: path to the file created by cmbuild, containing aligned sequences. This will be used to align sequences in seqs. - seqs: unaligned sequendes that are to be aligned to the sequences in cm_file. - moltype: cogent.core.moltype object. Must be DNA or RNA - alignment_file_path: path to stockholm alignment file used to create cm_file. __IMPORTANT__: This MUST be the same file used by cmbuild originally. Only need to pass in this file if include_aln=True. This helper function will NOT check if the alignment file is correct so you must use it correctly. - include_aln: Boolean to include sequences in aln_file in final alignment. (Default=False) - return_stdout: Boolean to return standard output from infernal. This includes alignment and structure bit scores and average probabilities for each sequence. (Default=False) """ #NOTE: Must degap seqs or Infernal well seg fault! seqs = SequenceCollection(seqs,MolType=moltype).degap() #Create mapping between abbreviated IDs and full IDs int_map, int_keys = seqs.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) if params is None: params = {} params.update({MOLTYPE_MAP[moltype]:True}) app = Cmalign(InputHandler='_input_as_paths',WorkingDir='/tmp',\ params=params) app.Parameters['--informat'].on('FASTA') #turn on --withali flag if True. if include_aln: if alignment_file_path is None: raise DataError, """Must have path to alignment file used to build CM if include_aln=True.""" else: app.Parameters['--withali'].on(alignment_file_path) seqs_path = app._input_as_multiline_string(int_map.toFasta()) paths = [cm_file_path,seqs_path] app.Parameters['-o'].on(get_tmp_filename(app.WorkingDir)) res = app(paths) info, aligned, struct_string = \ list(MinimalRfamParser(res['Alignment'].readlines(),\ seq_constructor=SEQ_CONSTRUCTOR_MAP[moltype]))[0] #Make new dict mapping original IDs new_alignment={} for k,v in aligned.items(): new_alignment[int_keys.get(k,k)]=v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment,MolType=moltype) std_out = res['StdOut'].read() res.cleanUp() if return_stdout: return new_alignment, struct_string, std_out else: return new_alignment, struct_string def cmsearch_from_alignment(aln, structure_string, seqs, moltype, cutoff=0.0,\ refine=False,params=None): """Uses cmbuild to build a CM file, then cmsearch to find homologs. - aln: an Alignment object or something that can be used to construct one. All sequences must be the same length. - structure_string: vienna structure string representing the consensus stucture for the sequences in aln. Must be the same length as the alignment. - seqs: SequenceCollection object or something that can be used to construct one, containing unaligned sequences that are to be searched. - moltype: cogent.core.moltype object. Must be DNA or RNA - cutoff: bitscore cutoff. No sequences < cutoff will be kept in search results. (Default=0.0). Infernal documentation suggests a cutoff of log2(number nucleotides searching) will give most likely true homologs. - refine: refine the alignment and realign before building the cm. (Default=False) """ #NOTE: Must degap seqs or Infernal well seg fault! seqs = SequenceCollection(seqs,MolType=moltype).degap() #Create mapping between abbreviated IDs and full IDs int_map, int_keys = seqs.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) cm_file, aln_file_string = cmbuild_from_alignment(aln, structure_string,\ refine=refine,return_alignment=True) app = Cmsearch(InputHandler='_input_as_paths',WorkingDir='/tmp',\ params=params) app.Parameters['--informat'].on('FASTA') app.Parameters['-T'].on(cutoff) to_remove = [] seqs_path = app._input_as_multiline_string(int_map.toFasta()) cm_path = app._tempfile_as_multiline_string(cm_file) paths = [cm_path,seqs_path] to_remove.append(cm_path) app.Parameters['--tabfile'].on(get_tmp_filename(app.WorkingDir)) res = app(paths) search_results = list(CmsearchParser(res['SearchResults'].readlines())) if search_results: for i,line in enumerate(search_results): label = line[1] search_results[i][1]=int_keys.get(label,label) res.cleanUp() for f in to_remove:remove(f) return search_results def cmsearch_from_file(cm_file_path, seqs, moltype, cutoff=0.0, params=None): """Uses cmbuild to build a CM file, then cmsearch to find homologs. - cm_file_path: path to the file created by cmbuild, containing aligned sequences. This will be used to search sequences in seqs. - seqs: SequenceCollection object or something that can be used to construct one, containing unaligned sequences that are to be searched. - moltype: cogent.core.moltype object. Must be DNA or RNA - cutoff: bitscore cutoff. No sequences < cutoff will be kept in search results. (Default=0.0). Infernal documentation suggests a cutoff of log2(number nucleotides searching) will give most likely true homologs. """ #NOTE: Must degap seqs or Infernal well seg fault! seqs = SequenceCollection(seqs,MolType=moltype).degap() #Create mapping between abbreviated IDs and full IDs int_map, int_keys = seqs.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) app = Cmsearch(InputHandler='_input_as_paths',WorkingDir='/tmp',\ params=params) app.Parameters['--informat'].on('FASTA') app.Parameters['-T'].on(cutoff) seqs_path = app._input_as_multiline_string(int_map.toFasta()) paths = [cm_file_path,seqs_path] app.Parameters['--tabfile'].on(get_tmp_filename(app.WorkingDir)) res = app(paths) search_results = list(CmsearchParser(res['SearchResults'].readlines())) if search_results: for i,line in enumerate(search_results): label = line[1] search_results[i][1]=int_keys.get(label,label) res.cleanUp() return search_results pycogent-1.9/cogent/app/knetfold.py000066400000000000000000000067771273014367000174560ustar00rootroot00000000000000#!/usr/bin/env python from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters, _find_synonym __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman", "Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class Knetfold(CommandLineApplication): """Application controller for Knetfold v1.4.4b application""" _parameters = {'-i':ValuedParameter(Prefix='-',Name='i',Delimiter=' '), '-n':ValuedParameter(Prefix='-',Name='n',Delimiter=' '), '-d':ValuedParameter(Prefix='-',Name='d',Delimiter=' '), '-m':ValuedParameter(Prefix='-',Name='m',Delimiter=' '), '-q':ValuedParameter(Prefix='-',Name='q',Delimiter=' '), '-o':ValuedParameter(Prefix='-',Name='o',Delimiter=' '), '-r':ValuedParameter(Prefix='-',Name='r',Delimiter=' '), '-f':ValuedParameter(Prefix='-',Name='f',Delimiter=' '), '-h':ValuedParameter(Prefix='-',Name='h',Delimiter=' '),} _command = 'knetfold.pl' _input_handler = '_input_as_string' def _input_as_lines(self,data): """ Infile needs to be set with parameter -i """ filename = self._input_filename = self.getTmpFilename(self.WorkingDir) data_file = open(filename,'w') data_to_file = '\n'.join([str(d).strip('\n') for d in data]) data_file.write(data_to_file) data_file.write('\n') data_file.close() #set input flag and give it the input filename self.Parameters['-i'].on(filename) return '' def _input_as_string(self,data): """Makes data the value of a specific parameter This method returns the empty string. The parameter will be printed automatically once set. """ if data: self.Parameters['-i'].on(data) return '' def _get_result_paths(self,data): """ Adds output files to the resultpath """ result = {} if isinstance(data,list): filename=self._input_filename.split('/')[-1] else: filename=(data.split('/')[-1]).split('.')[0] #output files created in extensions list extensions = ['ct','coll','sec','fasta','pdf'] #file = '%s%s%s' % (self.WorkingDir,filename,'_knet') file = ''.join([self.WorkingDir, filename, '_knet']) for ext in extensions: try: path = '%s.%s' % (file,ext) f = open(path) f.close() result[ext]=\ ResultPath(Path=(path)) except IOError: pass number = 0 #Unknown number of mx files, try/except to find all #file = '%s%s%s%d' % (self.WorkingDir,filename,'_knet.mx',number) file_base = ''.join([self.WorkingDir, filename, '_knet.mx']) while(True): try: file = file_base + str(number) f = open(file) result['%s%d' % ('mx',number)]= ResultPath(Path=(file)) f.close() number +=1 except IOError: #No more mx files break return result pycogent-1.9/cogent/app/mafft.py000066400000000000000000000444331273014367000167340ustar00rootroot00000000000000#!/usr/bin/env python """ Provides an application controller for the commandline version of: MAFFT v6.602 """ from cogent.app.parameters import FlagParameter, ValuedParameter, FilePath from cogent.app.util import CommandLineApplication, ResultPath, \ get_tmp_filename from random import choice from cogent.parse.fasta import MinimalFastaParser from cogent.core.moltype import DNA, RNA, PROTEIN from cogent.core.alignment import SequenceCollection, Alignment from cogent.core.tree import PhyloNode from cogent.parse.tree import DndParser from os import remove __author__ = "Jeremy Widmann" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Jeremy Widmann", "Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Jeremy Widmann" __email__ = "jeremy.widmann@colorado.edu" __status__ = "Development" MOLTYPE_MAP = {'DNA':'--nuc',\ 'RNA':'--nuc',\ 'PROTEIN':'--amino',\ } class Mafft(CommandLineApplication): """Mafft application controller""" _options ={ # Algorithm # Automatically selects an appropriate strategy from L-INS-i, FFT-NS-i # and FFT-NS-2, according to data size. Default: off (always FFT-NS-2) '--auto':FlagParameter(Prefix='--',Name='auto'),\ # Distance is calculated based on the number of shared 6mers. Default: on '--6merpair':FlagParameter(Prefix='--',Name='6merpair'),\ # All pairwise alignments are computed with the Needleman-Wunsch algorithm. # More accurate but slower than --6merpair. Suitable for a set of globally # alignable sequences. Applicable to up to ~200 sequences. A combination # with --maxiterate 1000 is recommended (G-INS-i). Default: off # (6mer distance is used) '--globalpair':FlagParameter(Prefix='--',Name='globalpair'),\ # All pairwise alignments are computed with the Smith-Waterman algorithm. # More accurate but slower than --6merpair. Suitable for a set of locally # alignable sequences. Applicable to up to ~200 sequences. A combination # with --maxiterate 1000 is recommended (L-INS-i). Default: off # (6mer distance is used) '--localpair':FlagParameter(Prefix='--',Name='localpair'),\ # All pairwise alignments are computed with a local algorithm with the # generalized affine gap cost (Altschul 1998). More accurate but slower than # --6merpair. Suitable when large internal gaps are expected. Applicable to # up to ~200 sequences. A combination with --maxiterate 1000 is recommended # (E-INS-i). Default: off (6mer distance is used) '--genafpair':FlagParameter(Prefix='--',Name='genafpair'),\ # All pairwise alignments are computed with FASTA (Pearson and Lipman 1988). # FASTA is required. Default: off (6mer distance is used) '--fastapair':FlagParameter(Prefix='--',Name='fastapair'),\ # Weighting factor for the consistency term calculated from pairwise # alignments. Valid when either of --blobalpair, --localpair, --genafpair, # --fastapair or --blastpair is selected. Default: 2.7 '--weighti':ValuedParameter(Prefix='--',Name='weighti',Delimiter=' '),\ # Guide tree is built number times in the progressive stage. Valid with 6mer # distance. Default: 2 '--retree':ValuedParameter(Prefix='--',Name='retree',Delimiter=' '),\ # number cycles of iterative refinement are performed. Default: 0 '--maxiterate':ValuedParameter(Prefix='--',Name='maxiterate',\ Delimiter=' '),\ # Use FFT approximation in group-to-group alignment. Default: on '--fft':FlagParameter(Prefix='--',Name='fft'),\ # Do not use FFT approximation in group-to-group alignment. Default: off '--nofft':FlagParameter(Prefix='--',Name='nofft'),\ #Alignment score is not checked in the iterative refinement stage. Default: # off (score is checked) '--noscore':FlagParameter(Prefix='--',Name='noscore'),\ # Use the Myers-Miller (1988) algorithm. Default: automatically turned on # when the alignment length exceeds 10,000 (aa/nt). '--memsave':FlagParameter(Prefix='--',Name='memsave'),\ # Use a fast tree-building method (PartTree, Katoh and Toh 2007) with the # 6mer distance. Recommended for a large number (> ~10,000) of sequences are # input. Default: off '--parttree':FlagParameter(Prefix='--',Name='parttree'),\ # The PartTree algorithm is used with distances based on DP. Slightly more # accurate and slower than --parttree. Recommended for a large number # (> ~10,000) of sequences are input. Default: off '--dpparttree':FlagParameter(Prefix='--',Name='dpparttree'),\ # The PartTree algorithm is used with distances based on FASTA. Slightly # more accurate and slower than --parttree. Recommended for a large number # (> ~10,000) of sequences are input. FASTA is required. Default: off '--fastaparttree':FlagParameter(Prefix='--',Name='fastaparttree'),\ # The number of partitions in the PartTree algorithm. Default: 50 '--partsize':ValuedParameter(Prefix='--',Name='partsize',Delimiter=' '),\ # Do not make alignment larger than number sequences. Valid only with the # --*parttree options. Default: the number of input sequences '--groupsize':ValuedParameter(Prefix='--',Name='groupsize',Delimiter=' '),\ # Parameter # Gap opening penalty at group-to-group alignment. Default: 1.53 '--op':ValuedParameter(Prefix='--',Name='op',Delimiter=' '),\ # Offset value, which works like gap extension penalty, for group-to-group # alignment. Deafult: 0.123 '--ep':ValuedParameter(Prefix='--',Name='ep',Delimiter=' '),\ # Gap opening penalty at local pairwise alignment. Valid when the # --localpair or --genafpair option is selected. Default: -2.00 '--lop':ValuedParameter(Prefix='--',Name='lop',Delimiter=' '),\ # Offset value at local pairwise alignment. Valid when the --localpair or # --genafpair option is selected. Default: 0.1 '--lep':ValuedParameter(Prefix='--',Name='lep',Delimiter=' '),\ # Gap extension penalty at local pairwise alignment. Valid when the # --localpair or --genafpair option is selected. Default: -0.1 '--lexp':ValuedParameter(Prefix='--',Name='lexp',Delimiter=' '),\ # Gap opening penalty to skip the alignment. Valid when the --genafpair # option is selected. Default: -6.00 '--LOP':ValuedParameter(Prefix='--',Name='LOP',Delimiter=' '),\ # Gap extension penalty to skip the alignment. Valid when the --genafpair # option is selected. Default: 0.00 '--LEXP':ValuedParameter(Prefix='--',Name='LEXP',Delimiter=' '),\ # BLOSUM number matrix (Henikoff and Henikoff 1992) is used. number=30, 45, # 62 or 80. Default: 62 '--bl':ValuedParameter(Prefix='--',Name='bl',Delimiter=' '),\ # JTT PAM number (Jones et al. 1992) matrix is used. number>0. # Default: BLOSUM62 '--jtt':ValuedParameter(Prefix='--',Name='jtt',Delimiter=' '),\ # Transmembrane PAM number (Jones et al. 1994) matrix is used. number>0. # Default: BLOSUM62 '--tm':ValuedParameter(Prefix='--',Name='tm',Delimiter=' '),\ # Use a user-defined AA scoring matrix. The format of matrixfile is the same # to that of BLAST. Ignored when nucleotide sequences are input. # Default: BLOSUM62 '--aamatrix':ValuedParameter(Prefix='--',Name='aamatrix',Delimiter=' '),\ # Incorporate the AA/nuc composition information into the scoring matrix. # Deafult: off '--fmodel':FlagParameter(Prefix='--',Name='fmodel'),\ # Output # Output format: clustal format. Default: off (fasta format) '--clustalout':FlagParameter(Prefix='--',Name='clustalout'),\ # Output order: same as input. Default: on '--inputorder':FlagParameter(Prefix='--',Name='inputorder'),\ # Output order: aligned. Default: off (inputorder) '--reorder':FlagParameter(Prefix='--',Name='reorder'),\ # Guide tree is output to the input.tree file. Default: off '--treeout':FlagParameter(Prefix='--',Name='treeout'),\ # Do not report progress. Default: off '--quiet':FlagParameter(Prefix='--',Name='quiet'),\ # Input # Assume the sequences are nucleotide. Deafult: auto '--nuc':FlagParameter(Prefix='--',Name='nuc'),\ # Assume the sequences are amino acid. Deafult: auto '--amino':FlagParameter(Prefix='--',Name='amino'),\ # Seed alignments given in alignment_n (fasta format) are aligned with # sequences in input. The alignment within every seed is preserved. '--seed':ValuedParameter(Prefix='--',Name='seed',Delimiter=' '),\ } _parameters = {} _parameters.update(_options) _command = "mafft" _suppress_stderr=True def _input_as_seqs(self,data): lines = [] for i,s in enumerate(data): #will number the sequences 1,2,3,etc. lines.append(''.join(['>',str(i+1)])) lines.append(s) return self._input_as_lines(lines) def _tree_out_filename(self): if self.Parameters['--treeout'].isOn(): tree_filename = self._absolute(str(self._input_filename))+'.tree' else: raise ValueError, "No tree output file specified." return tree_filename def _tempfile_as_multiline_string(self, data): """Write a multiline string to a temp file and return the filename. data: a multiline string to be written to a file. * Note: the result will be the filename as a FilePath object (which is a string subclass). """ filename = FilePath(self.getTmpFilename(self.TmpDir)) data_file = open(filename,'w') data_file.write(data) data_file.close() return filename def getHelp(self): """Method that points to the Mafft documentation.""" help_str = \ """ See Mafft documentation at: http://align.bmr.kyushu-u.ac.jp/mafft/software/manual/manual.html """ return help_str def _get_result_paths(self,data): result = {} if self.Parameters['--treeout'].isOn(): out_name = self._tree_out_filename() result['Tree'] = ResultPath(Path=out_name,IsWritten=True) return result def align_unaligned_seqs(seqs,moltype,params=None,accurate=False): """Aligns unaligned sequences seqs: either list of sequence objects or list of strings add_seq_names: boolean. if True, sequence names are inserted in the list of sequences. if False, it assumes seqs is a list of lines of some proper format that the program can handle """ #create SequenceCollection object from seqs seq_collection = SequenceCollection(seqs,MolType=moltype) #Create mapping between abbreviated IDs and full IDs int_map, int_keys = seq_collection.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) #Create Mafft app. app = Mafft(InputHandler='_input_as_multiline_string',params=params) #Turn on correct moltype moltype_string = moltype.label.upper() app.Parameters[MOLTYPE_MAP[moltype_string]].on() #Do not report progress app.Parameters['--quiet'].on() #More accurate alignment, sacrificing performance. if accurate: app.Parameters['--globalpair'].on() app.Parameters['--maxiterate'].Value=1000 #Get results using int_map as input to app res = app(int_map.toFasta()) #Get alignment as dict out of results alignment = dict(MinimalFastaParser(res['StdOut'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): new_alignment[int_keys[k]]=v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment,MolType=moltype) #Clean up res.cleanUp() del(seq_collection,int_map,int_keys,app,res,alignment) return new_alignment def align_and_build_tree(seqs, moltype, best_tree=False, params={}): """Returns an alignment and a tree from Sequences object seqs. seqs: SequenceCollection object, or data that can be used to build one. best_tree: if True (default:False), uses a slower but more accurate algorithm to build the tree. params: dict of parameters to pass in to the Mafft app controller. The result will be a tuple containing an Alignment object and a cogent.core.tree.PhyloNode object (or None for the alignment and/or tree if either fails). """ #Current version of Mafft does not support tree building. raise NotImplementedError, """Current version of Mafft does not support tree building.""" def build_tree_from_alignment(aln, moltype, best_tree=False, params={},\ working_dir='/tmp'): """Returns a tree from Alignment object aln. aln: a cogent.core.alignment.Alignment object, or data that can be used to build one. best_tree: if True (default:False), uses a slower but more accurate algorithm to build the tree. NOTE: Mafft does not necessarily support best_tree option. Will only return guide tree used to align sequences. Passing best_tree = True will construct the guide tree 100 times instead of default 2 times. ***Mafft does allow you to get the guide tree back, but the IDs in the output guide tree do not match the original IDs in the fasta file and are impossible to map. Sent bug report to Mafft authors; possibly expect this option in future version.*** params: dict of parameters to pass in to the Mafft app controller. The result will be an cogent.core.tree.PhyloNode object, or None if tree fails. """ #Current version of Mafft does not support tree building. raise NotImplementedError, """Current version of Mafft does not support tree building.""" def add_seqs_to_alignment(seqs, aln, moltype, params=None, accurate=False): """Returns an Alignment object from seqs and existing Alignment. seqs: a cogent.core.sequence.Sequence object, or data that can be used to build one. aln: an cogent.core.alignment.Alignment object, or data that can be used to build one params: dict of parameters to pass in to the Mafft app controller. """ #create SequenceCollection object from seqs seq_collection = SequenceCollection(seqs,MolType=moltype) #Create mapping between abbreviated IDs and full IDs seq_int_map, seq_int_keys = seq_collection.getIntMap() #Create SequenceCollection from int_map. seq_int_map = SequenceCollection(seq_int_map,MolType=moltype) #create Alignment object from aln aln = Alignment(aln,MolType=moltype) #Create mapping between abbreviated IDs and full IDs aln_int_map, aln_int_keys = aln.getIntMap(prefix='seqn_') #Create SequenceCollection from int_map. aln_int_map = Alignment(aln_int_map,MolType=moltype) #Update seq_int_keys with aln_int_keys seq_int_keys.update(aln_int_keys) #Create Mafft app. app = Mafft(InputHandler='_input_as_multiline_string',\ params=params, SuppressStderr=True) #Turn on correct moltype moltype_string = moltype.label.upper() app.Parameters[MOLTYPE_MAP[moltype_string]].on() #Do not report progress app.Parameters['--quiet'].on() #Add aln_int_map as seed alignment app.Parameters['--seed'].on(\ app._tempfile_as_multiline_string(aln_int_map.toFasta())) #More accurate alignment, sacrificing performance. if accurate: app.Parameters['--globalpair'].on() app.Parameters['--maxiterate'].Value=1000 #Get results using int_map as input to app res = app(seq_int_map.toFasta()) #Get alignment as dict out of results alignment = dict(MinimalFastaParser(res['StdOut'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): key = k.replace('_seed_','') new_alignment[seq_int_keys[key]]=v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment,MolType=moltype) #Clean up res.cleanUp() remove(app.Parameters['--seed'].Value) del(seq_collection,seq_int_map,seq_int_keys,\ aln,aln_int_map,aln_int_keys,app,res,alignment) return new_alignment def align_two_alignments(aln1, aln2, moltype, params=None): """Returns an Alignment object from two existing Alignments. aln1, aln2: cogent.core.alignment.Alignment objects, or data that can be used to build them. - Mafft profile alignment only works with aligned sequences. Alignment object used to handle unaligned sequences. params: dict of parameters to pass in to the Mafft app controller. """ #create SequenceCollection object from seqs aln1 = Alignment(aln1,MolType=moltype) #Create mapping between abbreviated IDs and full IDs aln1_int_map, aln1_int_keys = aln1.getIntMap() #Create SequenceCollection from int_map. aln1_int_map = Alignment(aln1_int_map,MolType=moltype) #create Alignment object from aln aln2 = Alignment(aln2,MolType=moltype) #Create mapping between abbreviated IDs and full IDs aln2_int_map, aln2_int_keys = aln2.getIntMap(prefix='seqn_') #Create SequenceCollection from int_map. aln2_int_map = Alignment(aln2_int_map,MolType=moltype) #Update aln1_int_keys with aln2_int_keys aln1_int_keys.update(aln2_int_keys) #Create Mafft app. app = Mafft(InputHandler='_input_as_paths',\ params=params, SuppressStderr=False) app._command = 'mafft-profile' aln1_path = app._tempfile_as_multiline_string(aln1_int_map.toFasta()) aln2_path = app._tempfile_as_multiline_string(aln2_int_map.toFasta()) filepaths = [aln1_path,aln2_path] #Get results using int_map as input to app res = app(filepaths) #Get alignment as dict out of results alignment = dict(MinimalFastaParser(res['StdOut'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): key = k.replace('_seed_','') new_alignment[aln1_int_keys[key]]=v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment,MolType=moltype) #Clean up res.cleanUp() remove(aln1_path) remove(aln2_path) remove('pre') remove('trace') del(aln1,aln1_int_map,aln1_int_keys,\ aln2,aln2_int_map,aln2_int_keys,app,res,alignment) return new_alignment pycogent-1.9/cogent/app/mfold.py000066400000000000000000000102411273014367000167260ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for mfold v3.2 application !!!To get mfold app.controller to work TmpNameLen should be max 10 (unknown reason). """ from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter, ValuedParameter,Parameters from random import choice __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman", "Daniel McDonald"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class Mfold(CommandLineApplication): """Application controller for mfold 3.2 application""" #Not all parameters included! #skipped: NA_CONC,MG_CONC,LB_FR,ROT_ANG,START,STOP,REUSE _parameters = { 'LC':ValuedParameter(Prefix='',Name='LC=',Value=None,Delimiter=''), 'T':ValuedParameter(Prefix='',Name='T=',Value=None,Delimiter=''), 'P':ValuedParameter(Prefix='',Name='P=',Value=None,Delimiter=''), 'MAXBP':ValuedParameter(Prefix='',Name='MAXBP=',Value=None,Delimiter=''), 'MAX':ValuedParameter(Prefix='',Name='MAX=',Value=30,Delimiter=''), 'MAX_LP':ValuedParameter(Prefix='',Name='MAX_LP=',Value=None,Delimiter=''), 'MAX_AS':ValuedParameter(Prefix='',Name='MAX_AS=',Value=None,Delimiter=''), 'MODE':ValuedParameter(Prefix='',Name='MODE=',Value=None,Delimiter=''), } _command = 'mfold' _input_handler = '_input_as_string' def _input_as_string(self,filename): """ mfold dosen't take full paths so a tmp-file is created in the working dir for mfold to read. """ nr = choice(range(150)) input_file = open(filename).readlines() filename = self._input_filename = 'mfold_in%d.txt' % nr data_file = open(filename,'w') data_to_file = '\n'.join([str(d).strip('\n') for d in input_file]) data_file.write(data_to_file) data_file.close() data = '='.join(['SEQ',filename]) return data def _input_as_lines(self,data): """ Uses a fixed tmp filename since weird truncation of the generated filename sometimes occured. """ nr = choice(range(150)) filename = self._input_filename = 'mfold_in%d.txt' % nr data_file = open(filename,'w') data_to_file = '\n'.join([str(d).strip('\n') for d in data]) data_file.write(data_to_file) data_file.close() return '='.join(['SEQ',filename]) def _get_result_paths(self,data): """Return a dict of ResultPath objects representing all possible output """ result = {} itr=self.Parameters['MAX'].Value if itr == None: itr = 30 filename=self._input_filename.split('/')[-1] for i in range(1,itr+1): try: ct = self.WorkingDir+filename+'_'+str(i)+'.ct' f = open(ct) f.close() result['ct'+str(i)] =\ ResultPath(Path=ct) pdf = self.WorkingDir+filename+'_'+str(i)+'.pdf' f = open(pdf) f.close() result['pdf'+str(i)] =\ ResultPath(Path=pdf) except IOError: pass result['ct_all'] =\ ResultPath(Path=(self.WorkingDir+filename+'.ct')) name = self.WorkingDir+filename #output files files = ['log', 'ann', 'h-num', 'det', 'pnt', 'sav', 'ss-count', '-local.seq', 'rnaml', 'out', 'plot', 'ps', '_1.ps', '_1.ss'] for f in files: if f == '-local.seq': file = ''.join([name, f]) elif f.startswith('_1'): file = ''.join([name, f]) else: file = '.'.join([name, f]) result['%s' % f] = ResultPath(Path=file) return result pycogent-1.9/cogent/app/mothur.py000066400000000000000000000466671273014367000171700ustar00rootroot00000000000000#!/usr/bin/env python """Provides an application controller for the commandline version of mothur Version 1.6.0 """ from __future__ import with_statement from operator import attrgetter from os import path, getcwd, mkdir, remove, listdir, rmdir import re from shutil import copyfile from subprocess import Popen from tempfile import mkdtemp, NamedTemporaryFile from cogent.app.parameters import ValuedParameter from cogent.app.util import CommandLineApplication, ResultPath, \ CommandLineAppResult, ApplicationError from cogent.parse.fasta import MinimalFastaParser from cogent.parse.mothur import parse_otu_list __author__ = "Kyle Bittinger" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Kyle Bittinger"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Kyle Bittinger" __email__ = "kylebittinger@gmail.com" __status__ = "Prototype" class Mothur(CommandLineApplication): """Mothur application controller """ _options = { # Clustering algorithm. Choices are furthest, nearest, and # average 'method': ValuedParameter( Name='method', Value='furthest', Delimiter='=', Prefix=''), # Cutoff distance for the distance matrix 'cutoff': ValuedParameter( Name='cutoff', Value=None, Delimiter='=', Prefix=''), # Minimum pairwise distance to consider for clustering 'precision': ValuedParameter( Name='precision', Value=None, Delimiter='=', Prefix=''), } _parameters = {} _parameters.update(_options) _input_handler = '_input_as_multiline_string' _command = 'mothur' def __init__(self, params=None, InputHandler=None, SuppressStderr=None, SuppressStdout=None, WorkingDir=None, TmpDir='/tmp', TmpNameLen=20, HALT_EXEC=False): """Initialize a Mothur application controller params: a dictionary mapping the Parameter id or synonym to its value (or None for FlagParameters or MixedParameters in flag mode) for Parameters that should be turned on InputHandler: this is the method to be run on data when it is passed into call. This should be a string containing the method name. The default is _input_as_string which casts data to a string before appending it to the command line argument SuppressStderr: if set to True, will route standard error to /dev/null, False by default SuppressStdout: if set to True, will route standard out to /dev/null, False by default WorkingDir: the directory where you want the application to run, default is the current working directory, but is useful to change in cases where the program being run creates output to its current working directory and you either don't want it to end up where you are running the program, or the user running the script doesn't have write access to the current working directory WARNING: WorkingDir MUST be an absolute path! TmpDir: the directory where temp files will be created, /tmp by default TmpNameLen: the length of the temp file name HALT_EXEC: if True, raises exception w/ command output just before execution, doesn't clean up temp files. Default False. """ super(Mothur, self).__init__( params=params, InputHandler=InputHandler, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout, WorkingDir='', TmpDir='', TmpNameLen=TmpNameLen, HALT_EXEC=HALT_EXEC) # Prevent self.WorkingDir from being explicitly cast as a # FilePath object. This behavior does not seem necessary in # the parent's __init__() method, since the casting is # repeated in _set_WorkingDir(). if WorkingDir is not None: working_dir = WorkingDir else: working_dir = self._working_dir or getcwd() self.WorkingDir = working_dir self.TmpDir = TmpDir @staticmethod def getHelp(): """Returns link to online manual""" help = ( 'See manual, available on the MOTHUR wiki:\n' 'http://schloss.micro.umass.edu/mothur/' ) return help def __call__(self, data=None, remove_tmp=True): """Run the application with the specified kwargs on data data: anything that can be cast into a string or written out to a file. Usually either a list of things or a single string or number. input_handler will be called on this data before it is passed as part of the command-line argument, so by creating your own input handlers you can customize what kind of data you want your application to accept remove_tmp: if True, removes tmp files """ # Process the input data. Input filepath is stored in # self._input_filename getattr(self, self.InputHandler)(data) if self.SuppressStdout: outfile = None else: outfile = open(self.getTmpFilename(self.TmpDir), 'w') if self.SuppressStderr: errfile = None else: errfile = open(self.getTmpFilename(self.TmpDir), 'w') args = [self._command, self._compile_mothur_script()] process = Popen( args, stdout=outfile, stderr=errfile, cwd=self.WorkingDir) exit_status = process.wait() if not self._accept_exit_status(exit_status): raise ApplicationError( 'Unacceptable application exit status: %s, command: %s' % \ (exit_status, args)) if outfile is not None: outfile.seek(0) if errfile is not None: errfile.seek(0) result = CommandLineAppResult( outfile, errfile, exit_status, result_paths=self._get_result_paths()) # Clean up the input file if one was created if remove_tmp: if self._input_filename: remove(self._input_filename) self._input_filename = None return result def _accept_exit_status(self, status): return int(status) == 0 def _compile_mothur_script(self): """Returns a Mothur batch script as a string""" def format_opts(*opts): """Formats a series of options for a Mothur script""" return ', '.join(filter(None, map(str, opts))) vars = { 'in': self._input_filename, 'unique': self._derive_unique_path(), 'dist': self._derive_dist_path(), 'names': self._derive_names_path(), 'cluster_opts' : format_opts( self.Parameters['method'], self.Parameters['cutoff'], self.Parameters['precision'], ), } script = ( '#' 'unique.seqs(fasta=%(in)s); ' 'dist.seqs(fasta=%(unique)s); ' 'read.dist(column=%(dist)s, name=%(names)s); ' 'cluster(%(cluster_opts)s)' % vars ) return script def _get_result_paths(self): paths = { 'distance matrix': self._derive_dist_path(), 'otu list': self._derive_list_path(), 'rank abundance': self._derive_rank_abundance_path(), 'species abundance': self._derive_species_abundance_path(), 'unique names': self._derive_names_path(), 'unique seqs': self._derive_unique_path(), 'log': self._derive_log_path(), } return dict([(k, ResultPath(v)) for (k,v) in paths.items()]) # Methods to derive/guess output pathnames produced by MOTHUR. # TODO: test for input files that do not have a filetype extension def _derive_log_path(self): """Guess logfile path produced by Mothur This method checks the working directory for log files generated by Mothur. It will raise an ApplicationError if no log file can be found. Mothur generates log files named in a nondeterministic way, using the current time. We return the log file with the most recent time, although this may lead to incorrect log file detection if you are running many instances of mothur simultaneously. """ filenames = listdir(self.WorkingDir) lognames = [x for x in filenames if re.match("^mothur\.\d+\.logfile$", x)] if not lognames: raise ApplicationError( 'No log file detected in directory %s. Contents: \n\t%s' % ( input_dir, '\n\t'.join(possible_logfiles))) most_recent_logname = sorted(lognames, reverse=True)[0] return path.join(self.WorkingDir, most_recent_logname) def _derive_unique_path(self): """Guess unique sequences path produced by Mothur""" base, ext = path.splitext(self._input_filename) return '%s.unique%s' % (base, ext) def _derive_dist_path(self): """Guess distance matrix path produced by Mothur""" base, ext = path.splitext(self._input_filename) return '%s.unique.dist' % base def _derive_names_path(self): """Guess unique names file path produced by Mothur""" base, ext = path.splitext(self._input_filename) return '%s.names' % base def __get_method_abbrev(self): """Abbreviated form of clustering method parameter. Used to guess output filenames for MOTHUR. """ abbrevs = { 'furthest': 'fn', 'nearest': 'nn', 'average': 'an', } if self.Parameters['method'].isOn(): method = self.Parameters['method'].Value else: method = self.Parameters['method'].Default return abbrevs[method] def _derive_list_path(self): """Guess otu list file path produced by Mothur""" base, ext = path.splitext(self._input_filename) return '%s.unique.%s.list' % (base, self.__get_method_abbrev()) def _derive_rank_abundance_path(self): """Guess rank abundance file path produced by Mothur""" base, ext = path.splitext(self._input_filename) return '%s.unique.%s.rabund' % (base, self.__get_method_abbrev()) def _derive_species_abundance_path(self): """Guess species abundance file path produced by Mothur""" base, ext = path.splitext(self._input_filename) return '%s.unique.%s.sabund' % (base, self.__get_method_abbrev()) def getTmpFilename(self, tmp_dir='/tmp', prefix='tmp', suffix='.txt'): """Returns a temporary filename Similar interface to tempfile.mktmp() """ # Override to change default constructor to str(). FilePath # objects muck up the Mothur script. return super(Mothur, self).getTmpFilename( tmp_dir=tmp_dir, prefix=prefix, suffix=suffix, result_constructor=str) # Temporary input file needs to be in the working directory, so we # override all input handlers. def _input_as_multiline_string(self, data): """Write multiline string to temp file, return filename data: a multiline string to be written to a file. """ self._input_filename = self.getTmpFilename(suffix='.fasta') with open(self._input_filename, 'w') as f: f.write(data) return self._input_filename def _input_as_lines(self, data): """Write sequence of lines to temp file, return filename data: a sequence to be written to a file, each element of the sequence will compose a line in the file * Note: '\n' will be stripped off the end of each sequence element before writing to a file in order to avoid multiple new lines accidentally be written to a file """ self._input_filename = self.getTmpFilename(suffix='.fasta') with open(self._input_filename, 'w') as f: # Use lazy iteration instead of list comprehension to # prevent reading entire file into memory for line in data: f.write(str(line).strip('\n')) f.write('\n') return self._input_filename def _input_as_path(self, data): """Copys the provided file to WorkingDir and returns the new filename data: path or filename """ self._input_filename = self.getTmpFilename(suffix='.fasta') copyfile(data, self._input_filename) return self._input_filename def _input_as_paths(self, data): raise NotImplementedError('Not applicable for MOTHUR controller.') def _input_as_string(self, data): raise NotImplementedError('Not applicable for MOTHUR controller.') # FilePath objects muck up the Mothur script, so we override the # property methods for self.WorkingDir def _get_WorkingDir(self): """Gets the working directory""" return self._curr_working_dir def _set_WorkingDir(self, path): """Sets the working directory """ self._curr_working_dir = path try: mkdir(self.WorkingDir) except OSError: # Directory already exists pass WorkingDir = property(_get_WorkingDir, _set_WorkingDir) def mothur_from_file(file): app = Mothur(InputHandler='_input_as_lines') result = app(file) # Force evaluation, so we can safely clean up files otus = list(parse_otu_list(result['otu list'])) result.cleanUp() return otus # Files with dashes currently break MOTHUR -- in the upcoming version # of the software, they may be escaped with a backslash. We implement # and test for this now, since it's broken anyway! class _MothurFilepathParameter(ValuedParameter): """Inserts escape characters in filepath parameters for Mothur.""" def _get_value(self): return self._Value def _set_value(self, val): if val: self._Value = str(val).replace("-", "\\-") else: self._Value = val Value = property(_get_value, _set_value) class MothurClassifySeqs(Mothur): _options = { 'reference': _MothurFilepathParameter( Name='reference', Value=None, Delimiter='=', Prefix=''), 'taxonomy': _MothurFilepathParameter( Name='taxonomy', Value=None, Delimiter='=', Prefix=''), 'cutoff': ValuedParameter( Name='cutoff', Value=None, Delimiter='=', Prefix=''), 'iters': ValuedParameter( Name='iters', Value=None, Delimiter='=', Prefix=''), 'ksize': ValuedParameter( Name='ksize', Value=None, Delimiter='=', Prefix=''), } _parameters = {} _parameters.update(_options) _filepath_parameters = set(['reference', 'taxonomy']) def _format_function_arguments(self, opts): """Format a series of function arguments in a Mothur script.""" params = [self.Parameters[x] for x in opts] return ', '.join(filter(None, map(str, params))) def _compile_mothur_script(self): """Returns a Mothur batch script as a string""" fasta = self._input_filename required_params = ["reference", "taxonomy"] for p in required_params: if self.Parameters[p].Value is None: raise ValueError("Must provide value for parameter %s" % p) optional_params = ["ksize", "cutoff", "iters"] args = self._format_function_arguments( required_params + optional_params) script = '#classify.seqs(fasta=%s, %s)' % (fasta, args) return script def _get_result_paths(self): input_base, ext = path.splitext(path.basename(self._input_filename)) result_by_suffix = { ".summary": "summary", ".taxonomy": "assignments", ".accnos": "accnos", } paths = {'log': self._derive_log_path()} input_dir = path.dirname(self._input_filename) for fn in listdir(input_dir): if fn.startswith(input_base): for suffix, result_key in result_by_suffix.items(): if fn.endswith(suffix): paths[result_key] = path.join(input_dir, fn) return dict([(k, ResultPath(v)) for (k,v) in paths.items()]) def parse_mothur_assignments(lines): for line in lines: line = line.strip() if not line: continue seq_id, _, assignment = line.partition("\t") # Special case: unidentified sequences should be given a # confidence of 0.0. Newer versions of MOTHUR return a real # value for the confidence -- maybe we should consider keeping # the value if present, because a sequence may conceivably be # unknown with 85% confidence. if re.match('unknown', assignment, re.IGNORECASE): yield seq_id, ["Unknown"], 0.0 continue toks = assignment.rstrip(";").split(";") lineage = [] conf = 0.0 for tok in toks: matchobj = re.match("(.+)\((\d+)\)$", tok) if matchobj: lineage.append(matchobj.group(1)) pct_conf = int(matchobj.group(2)) conf = pct_conf / 100.0 yield seq_id, lineage, conf def mothur_classify_file( query_file, ref_fp, tax_fp, cutoff=None, iters=None, ksize=None, output_fp=None): """Classify a set of sequences using Mothur's naive bayes method Dashes are used in Mothur to provide multiple filenames. A filepath with a dash typically breaks an otherwise valid command in Mothur. This wrapper script makes a copy of both files, ref_fp and tax_fp, to ensure that the path has no dashes. For convenience, we also ensure that each taxon list in the id-to-taxonomy file ends with a semicolon. """ ref_seq_ids = set() user_ref_file = open(ref_fp) tmp_ref_file = NamedTemporaryFile(suffix=".ref.fa") for seq_id, seq in MinimalFastaParser(user_ref_file): id_token = seq_id.split()[0] ref_seq_ids.add(id_token) tmp_ref_file.write(">%s\n%s\n" % (seq_id, seq)) tmp_ref_file.seek(0) user_tax_file = open(tax_fp) tmp_tax_file = NamedTemporaryFile(suffix=".tax.txt") for line in user_tax_file: line = line.rstrip() if not line: continue # MOTHUR is particular that each assignment end with a semicolon. if not line.endswith(";"): line = line + ";" id_token, _, _ = line.partition("\t") if id_token in ref_seq_ids: tmp_tax_file.write(line) tmp_tax_file.write("\n") tmp_tax_file.seek(0) params = {"reference": tmp_ref_file.name, "taxonomy": tmp_tax_file.name} if cutoff is not None: params["cutoff"] = cutoff if ksize is not None: params["ksize"] = ksize if iters is not None: params["iters"] = iters app = MothurClassifySeqs(params, InputHandler='_input_as_lines') result = app(query_file) # Force evaluation so we can safely clean up files assignments = list(parse_mothur_assignments(result['assignments'])) result.cleanUp() if output_fp is not None: f = open(output_fp, "w") for query_id, taxa, conf in assignments: taxa_str = ";".join(taxa) f.write("%s\t%s\t%.2f\n" % (query_id, taxa_str, conf)) f.close() return None return dict((a, (b, c)) for a, b, c in assignments) pycogent-1.9/cogent/app/msms.py000066400000000000000000000140131273014367000166050ustar00rootroot00000000000000#!/usr/bin/env python """Application controller and utility functions for MSMS (molecular surface calculation).""" import os import tempfile from cogent.app.util import CommandLineApplication, ResultPath from cogent.app.parameters import FlagParameter, ValuedParameter from cogent.format.xyzrn import XYZRNWriter from cogent.parse.msms import parse_VertFile __author__ = "Marcin Cieslik" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Marcin Cieslik"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Marcin Cieslik" __email__ = "mpc4p@virginia.edu" __status__ = "Development" class Msms(CommandLineApplication): """Application controller for MSMS. The default input is a ``Entity`` instance. Supported parameters: - probe_radius float : probe sphere radius, [1.5] - density float : surface points density, [1.0] - hdensity float : surface points high density, [3.0] - surface : triangulated or Analytical SES, [tses] - no_area : turns off the analytical surface area computation - noh : ignore atoms with radius 1.2 - no_rest_on_pbr : no restart if pb. during triangulation - no_rest : no restart if pb. are encountered - if filename : sphere input file - of filename : output for triangulated surface - af filename : area file - no_header : do not add comment line to the output - free_vertices : turns on computation for isolated RS vertices - all_components : compute all the surfaces components """ _parameters = { # -probe_radius float : probe sphere radius, [1.5] '-probe_radius':ValuedParameter(Prefix='-', Name='probe_radius', Delimiter=' '), # -density float : surface points density, [1.0] '-density':ValuedParameter(Prefix='-', Name='density', Delimiter=' '), # -hdensity float : surface points high density, [3.0] '-hdensity':ValuedParameter(Prefix='-', Name='hdensity', Delimiter=' '), # -surface : triangulated or Analytical SES, [tses] '-surface':ValuedParameter(Prefix='-', Name='surface', Delimiter=' '), # -no_area : turns off the analytical surface area computation '-no_area':FlagParameter(Prefix='-', Name='no_area', Value=False), # -noh : ignore atoms with radius 1.2 '-noh':FlagParameter(Prefix='-', Name='noh', Value=False), # -no_rest_on_pbr : no restart if pb. during triangulation '-no_rest_on_pbr':FlagParameter(Prefix='-', Name='no_rest_on_pbr', Value=False), # -no_rest : no restart if pb. are encountered '-no_rest':FlagParameter(Prefix='-', Name='no_rest', Value=False), # -if filename : sphere input file '-if':ValuedParameter(Prefix='-', Name='if', Delimiter=' ', IsPath=True), # -of filename : output for triangulated surface '-of':ValuedParameter(Prefix='-', Name='of', Delimiter=' ', IsPath=True), # -af filename : area file '-af':ValuedParameter(Prefix='-', Name='af', Delimiter=' ', IsPath=True), # -no_header : do not add comment line to the output '-no_header':FlagParameter(Prefix='-', Name='no_header', Value=False), # -free_vertices : turns on computation for isolated RS vertices '-free_vertices':FlagParameter(Prefix='-', Name='free_vertices', Value=False), # -all_components : compute all the surfaces components '-all_components':FlagParameter(Prefix='-', Name='all_components', Value=False), ####################### # -one_cavity #atoms at1 [at2][at3] : Compute the surface for an internal # cavity for which at least one atom is specified ####################### # -socketName servicename : socket connection from a client # -socketPort portNumber : socket connection from a client # -xdr : use xdr encoding over socket # -sinetd : inetd server connectio } _command = "msms" _input_handler = '_input_from_entity' def _input_from_entity(self, data): """This allows to feed entities to msms.""" if data: # create temporary files and names. fd, self._input_filename = tempfile.mkstemp() os.close(fd) # write XYZR data fh = open(self._input_filename, 'wb') XYZRNWriter(fh, data) fh.close() # self.Parameters['-if'].on(self._input_filename) self.Parameters['-of'].on(self._input_filename) # msms appends .vert .face self.Parameters['-af'].on(self._input_filename) # msms appends .area if (not self.Parameters['-if'].isOn()) or \ (not self.Parameters['-of'].isOn()) or \ (not self.Parameters['-af'].isOn()): raise ValueError('All of -if, -of and -af have to be specified.') return "" def _get_result_paths(self, data): result = {} vert_file = self.Parameters['-of'].Value + '.vert' result['VertFile'] = ResultPath(Path=vert_file, IsWritten=True) face_file = self.Parameters['-of'].Value + '.face' result['FaceFile'] = ResultPath(Path=face_file, IsWritten=True) if not self.Parameters['-no_area'].Value: area_file = self.Parameters['-af'].Value + '.area' result['AreaFile'] = ResultPath(Path=area_file, IsWritten=True) return result def surface_xtra(entity, **kwargs): """Runs the MSMS application to create the molecular surface, which is an a numpy array of 3D-coordinates. Arguments: * entity - an ``Entity`` instance. Additional keyworded arguments are for the ``Msms`` application controller. Returns the numpy array and put it into entity.xtra['MSMS_SURFACE']. """ msms = Msms(**kwargs) res = msms(entity) surface = parse_VertFile(res['VertFile']) entity.xtra['MSMS_SURFACE'] = surface res.cleanUp() # remove all temporary files return surface pycogent-1.9/cogent/app/muscle.py000066400000000000000000000706721273014367000171330ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for muscle 3.8 """ from os import remove from cogent.app.parameters import FlagParameter, ValuedParameter from cogent.app.util import CommandLineApplication, ResultPath, \ get_tmp_filename, guess_input_handler from random import choice from cogent.core.alignment import SequenceCollection, Alignment from cogent.parse.tree import DndParser from cogent.core.tree import PhyloNode from cogent.parse.fasta import MinimalFastaParser __author__ = "Rob Knight" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Micah Hamady", "Zongzhi Liu", "Mike Robeson", "Catherine Lozupone", "Rob Knight", "Daniel McDonald", "Jeremy Widmann", "Jai Ram Rideout"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Micah Hamady" __email__ = "hamady@colorado.edu" __status__ = "Prototype" class Muscle(CommandLineApplication): """Muscle application controller""" _options ={ # Minimum spacing between anchor columns. [Integer] '-anchorspacing':ValuedParameter('-',Name='anchorspacing',Delimiter=' '), # Center parameter. Should be negative [Float] '-center':ValuedParameter('-',Name='center',Delimiter=' '), # Clustering method. cluster1 is used in iteration 1 # and 2, cluster2 in later iterations '-cluster1':ValuedParameter('-',Name='cluster1',Delimiter=' '), '-cluster2':ValuedParameter('-',Name='cluster2',Delimiter=' '), # Minimum length of diagonal. '-diaglength':ValuedParameter('-',Name='diaglength',Delimiter=' '), # Discard this many positions at ends of diagonal. '-diagmargin':ValuedParameter('-',Name='diagmargin',Delimiter=' '), # Distance measure for iteration 1. '-distance1':ValuedParameter('-',Name='distance1',Delimiter=' '), # Distance measure for iterations 2, 3 ... '-distance2':ValuedParameter('-',Name='distance2',Delimiter=' '), # The gap open score. Must be negative. '-gapopen':ValuedParameter('-',Name='gapopen',Delimiter=' '), # Window size for determining whether a region is hydrophobic. '-hydro':ValuedParameter('-',Name='hydro',Delimiter=' '), # Multiplier for gap open/close penalties in hydrophobic regions. '-hydrofactor':ValuedParameter('-',Name='hydrofactor',Delimiter=' '), # Where to find the input sequences. '-in':ValuedParameter('-',Name='in',Delimiter=' ', Quote="\""), '-in1':ValuedParameter('-',Name='in1',Delimiter=' ', Quote="\""), '-in2':ValuedParameter('-',Name='in2',Delimiter=' ', Quote="\""), # Log file name (delete existing file). '-log':ValuedParameter('-',Name='log',Delimiter=' '), # Log file name (append to existing file). '-loga':ValuedParameter('-',Name='loga',Delimiter=' '), # Maximum distance between two diagonals that allows them to merge # into one diagonal. '-maxdiagbreak':ValuedParameter('-',Name='maxdiagbreak',Delimiter=' '), # Maximum time to run in hours. The actual time may exceed the # requested limit by a few minutes. Decimals are allowed, so 1.5 # means one hour and 30 minutes. '-maxhours':ValuedParameter('-',Name='maxhours',Delimiter=' '), # Maximum number of iterations. '-maxiters':ValuedParameter('-',Name='maxiters',Delimiter=' '), # Maximum memory in Mb '-maxmb': ValuedParameter('-', Name='maxmb', Delimiter=' '), # Maximum number of new trees to build in iteration 2. '-maxtrees':ValuedParameter('-',Name='maxtrees',Delimiter=' '), # Minimum score a column must have to be an anchor. '-minbestcolscore':ValuedParameter('-',Name='minbestcolscore',Delimiter=' '), # Minimum smoothed score a column must have to be an anchor. '-minsmoothscore':ValuedParameter('-',Name='minsmoothscore',Delimiter=' '), # Objective score used by tree dependent refinement. # sp=sum-of-pairs score. # spf=sum-of-pairs score (dimer approximation) # spm=sp for < 100 seqs, otherwise spf # dp=dynamic programming score. # ps=average profile-sequence score. # xp=cross profile score. '-objscore':ValuedParameter('-',Name='objscore',Delimiter=' '), # Where to write the alignment. '-out':ValuedParameter('-',Name='out',Delimiter=' ', Quote="\""), # Where to write the file in phylip sequenctial format (v3.6 only). '-physout':ValuedParameter('-',Name='physout',Delimiter=' '), # Where to write the file in phylip interleaved format (v3.6 only). '-phyiout':ValuedParameter('-',Name='phyiout',Delimiter=' '), # Set to profile for aligning two alignments and adding seqs to an # existing alignment '-profile':FlagParameter(Prefix='-',Name='profile'), # Method used to root tree; root1 is used in iteration 1 and 2, root2 # in later iterations. '-root1':ValuedParameter('-',Name='root1',Delimiter=' '), '-root2':ValuedParameter('-',Name='root2',Delimiter=' '), # Sequence type. '-seqtype':ValuedParameter('-',Name='seqtype',Delimiter=' '), # Maximum value of column score for smoothing purposes. '-smoothscoreceil':ValuedParameter('-',Name='smoothscoreceil',Delimiter=' '), # Constant used in UPGMB clustering. Determines the relative fraction # of average linkage (SUEFF) vs. nearest-neighbor linkage (1 . SUEFF). '-SUEFF':ValuedParameter('-',Name='SUEFF',Delimiter=' '), # Save tree produced in first or second iteration to given file in # Newick (Phylip-compatible) format. '-tree1':ValuedParameter('-',Name='tree1',Delimiter=' ', Quote="\""), '-tree2':ValuedParameter('-',Name='tree2',Delimiter=' ', Quote="\""), # Sequence weighting scheme. # weight1 is used in iterations 1 and 2. # weight2 is used for tree-dependent refinement. # none=all sequences have equal weight. # henikoff=Henikoff & Henikoff weighting scheme. # henikoffpb=Modified Henikoff scheme as used in PSI-BLAST. # clustalw=CLUSTALW method. # threeway=Gotoh three-way method. '-weight1':ValuedParameter('-',Name='weight1',Delimiter=' '), '-weight2':ValuedParameter('-',Name='weight2',Delimiter=' '), # Use anchor optimization in tree dependent refinement iterations '-anchors':FlagParameter(Prefix='-',Name='anchors'), # Write output in CLUSTALW format (default is FASTA). '-clw':FlagParameter(Prefix='-',Name='clw'), # Cluster sequences '-clusteronly':FlagParameter(Prefix='-',Name='clusteronly'), # neighborjoining is "unrecognized" #'-neighborjoining':FlagParameter(Prefix='-',Name='neighborjoining'), # Write output in CLUSTALW format with the "CLUSTAL W (1.81)" header # rather than the MUSCLE version. This is useful when a post-processing # step is picky about the file header. '-clwstrict':FlagParameter(Prefix='-',Name='clwstrict'), # Do not catch exceptions. '-core':FlagParameter(Prefix='-',Name='core'), # Write output in FASTA format. Alternatives include .clw, # .clwstrict, .msf and .html. '-fasta':FlagParameter(Prefix='-',Name='fasta'), # Group similar sequences together in the output. This is the default. # See also .stable. '-group':FlagParameter(Prefix='-',Name='group'), # Write output in HTML format (default is FASTA). '-html':FlagParameter(Prefix='-',Name='html'), # Use log-expectation profile score (VTML240). Alternatives are to use # -sp or -sv. This is the default for amino acid sequences. '-le':FlagParameter(Prefix='-',Name='le'), # Write output in MSF format (default is FASTA). '-msf':FlagParameter(Prefix='-',Name='msf'), # Disable anchor optimization. Default is -anchors. '-noanchors':FlagParameter(Prefix='-',Name='noanchors'), # Catch exceptions and give an error message if possible. '-nocore':FlagParameter(Prefix='-',Name='nocore'), # Do not display progress messages. '-quiet':FlagParameter(Prefix='-',Name='quiet'), # Input file is already aligned, skip first two iterations and begin # tree dependent refinement. '-refine':FlagParameter(Prefix='-',Name='refine'), # Use sum-of-pairs protein profile score (PAM200). Default is -le. '-sp':FlagParameter(Prefix='-',Name='sp'), # Use sum-of-pairs nucleotide profile score (BLASTZ parameters). This # is the only option for nucleotides, and is therefore the default. '-spn':FlagParameter(Prefix='-',Name='spn'), # Preserve input order of sequences in output file. Default is to group # sequences by similarity (-group). '-stable':FlagParameter(Prefix='-',Name='stable'), # Use sum-of-pairs profile score (VTML240). Default is -le. '-sv':FlagParameter(Prefix='-',Name='sv'), # Diagonal optimization '-diags':FlagParameter(Prefix='-',Name='diags'), '-diags1':FlagParameter(Prefix='-',Name='diags1'), '-diags2':FlagParameter(Prefix='-',Name='diags2'), # Terminal gaps penalized with full penalty. # [1] Not fully supported in this version. '-termgapsfull':FlagParameter(Prefix='-',Name='termgapsfull'), # Terminal gaps penalized with half penalty. # [1] Not fully supported in this version. '-termgapshalf':FlagParameter(Prefix='-',Name='termgapshalf'), # Terminal gaps penalized with half penalty if gap relative to # longer sequence, otherwise with full penalty. # [1] Not fully supported in this version. '-termgapshalflonger':FlagParameter(Prefix='-',Name='termgapshalflonger'), # Write parameter settings and progress messages to log file. '-verbose':FlagParameter(Prefix='-',Name='verbose'), # Write version string to stdout and exit. '-version':FlagParameter(Prefix='-',Name='version'), } _parameters = {} _parameters.update(_options) _command = "muscle" def _input_as_seqs(self,data): lines = [] for i,s in enumerate(data): #will number the sequences 1,2,3,etc. lines.append(''.join(['>',str(i+1)])) lines.append(s) return self._input_as_lines(lines) def _input_as_lines(self,data): if data: self.Parameters['-in']\ .on(super(Muscle,self)._input_as_lines(data)) return '' def _input_as_string(self,data): """Makes data the value of a specific parameter This method returns the empty string. The parameter will be printed automatically once set. """ if data: self.Parameters['-in'].on(str(data)) return '' def _input_as_multiline_string(self, data): if data: self.Parameters['-in']\ .on(super(Muscle,self)._input_as_multiline_string(data)) return '' def _input_as_multifile(self, data): """For use with the -profile option This input handler expects data to be a tuple containing two filenames. Index 0 will be set to -in1 and index 1 to -in2 """ if data: try: filename1, filename2 = data except: raise ValueError, "Expected two filenames" self.Parameters['-in'].off() self.Parameters['-in1'].on(filename1) self.Parameters['-in2'].on(filename2) return '' def _align_out_filename(self): if self.Parameters['-out'].isOn(): aln_filename = self._absolute(str(self.Parameters['-out'].Value)) else: raise ValueError, "No output file specified." return aln_filename def _tree1_out_filename(self): if self.Parameters['-tree1'].isOn(): aln_filename = self._absolute(str(self.Parameters['-tree1'].Value)) else: raise ValueError, "No tree output file specified." return aln_filename def _tree2_out_filename(self): if self.Parameters['-tree2'].isOn(): tree_filename = self._absolute(str(self.Parameters['-tree2'].Value)) else: raise ValueError, "No tree output file specified." return tree_filename def _get_result_paths(self,data): result = {} if self.Parameters['-out'].isOn(): out_name = self._align_out_filename() result['MuscleOut'] = ResultPath(Path=out_name,IsWritten=True) if self.Parameters['-tree1'].isOn(): out_name = self._tree1_out_filename() result['Tree1Out'] = ResultPath(Path=out_name,IsWritten=True) if self.Parameters['-tree2'].isOn(): out_name = self._tree2_out_filename() result['Tree2Out'] = ResultPath(Path=out_name,IsWritten=True) return result def getHelp(self): """Muscle help""" help_str = """ """ return help_str #SOME FUNCTIONS TO EXECUTE THE MOST COMMON TASKS def muscle_seqs(seqs, add_seq_names=False, out_filename=None, input_handler=None, params={}, WorkingDir=None, SuppressStderr=None, SuppressStdout=None): """Muscle align list of sequences. seqs: a list of sequences as strings or objects, you must set add_seq_names=True or sequences in a multiline string, as read() from a fasta file or sequences in a list of lines, as readlines() from a fasta file or a fasta seq filename. == for eg, testcode for guessing #guess_input_handler should correctly identify input gih = guess_input_handler self.assertEqual(gih('abc.txt'), '_input_as_string') self.assertEqual(gih('>ab\nTCAG'), '_input_as_multiline_string') self.assertEqual(gih(['ACC','TGA'], True), '_input_as_seqs') self.assertEqual(gih(['>a','ACC','>b','TGA']), '_input_as_lines') == docstring for blast_seqs, apply to muscle_seqs == seqs: either file name or list of sequence objects or list of strings or single multiline string containing sequences. WARNING: DECISION RULES FOR INPUT HANDLING HAVE CHANGED. Decision rules for data are as follows. If it's s list, treat as lines, unless add_seq_names is true (in which case treat as list of seqs). If it's a string, test whether it has newlines. If it doesn't have newlines, assume it's a filename. If it does have newlines, it can't be a filename, so assume it's a multiline string containing sequences. If you want to skip the detection and force a specific type of input handler, use input_handler='your_favorite_handler'. add_seq_names: boolean. if True, sequence names are inserted in the list of sequences. if False, it assumes seqs is a list of lines of some proper format that the program can handle Addl docs coming soon """ if out_filename: params["-out"] = out_filename #else: # params["-out"] = get_tmp_filename(WorkingDir) ih = input_handler or guess_input_handler(seqs, add_seq_names) muscle_app = Muscle( params=params, InputHandler=ih, WorkingDir=WorkingDir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout) return muscle_app(seqs) def cluster_seqs(seqs, neighbor_join=False, params={}, add_seq_names=True, WorkingDir=None, SuppressStderr=None, SuppressStdout=None, max_chars=1000000, max_hours=1.0, constructor=PhyloNode, clean_up=True ): """Muscle cluster list of sequences. seqs: either file name or list of sequence objects or list of strings or single multiline string containing sequences. Addl docs coming soon """ num_seqs = len(seqs) if num_seqs < 2: raise ValueError, "Muscle requres 2 or more sequences to cluster." num_chars = sum(map(len, seqs)) if num_chars > max_chars: params["-maxiters"] = 2 params["-diags1"] = True params["-sv"] = True #params["-distance1"] = "kmer6_6" #params["-distance1"] = "kmer20_3" #params["-distance1"] = "kbit20_3" print "lots of chars, using fast align", num_chars params["-maxhours"] = max_hours #params["-maxiters"] = 10 #cluster_type = "upgmb" #if neighbor_join: # cluster_type = "neighborjoining" params["-clusteronly"] = True params["-tree1"] = get_tmp_filename(WorkingDir) muscle_res = muscle_seqs(seqs, params=params, add_seq_names=add_seq_names, WorkingDir=WorkingDir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout) tree = DndParser(muscle_res["Tree1Out"], constructor=constructor) if clean_up: muscle_res.cleanUp() return tree def aln_tree_seqs(seqs, input_handler=None, tree_type='neighborjoining', params={}, add_seq_names=True, WorkingDir=None, SuppressStderr=None, SuppressStdout=None, max_hours=5.0, constructor=PhyloNode, clean_up=True ): """Muscle align sequences and report tree from iteration2. Unlike cluster_seqs, returns tree2 which is the tree made during the second muscle iteration (it should be more accurate that the cluster from the first iteration which is made fast based on k-mer words) seqs: either file name or list of sequence objects or list of strings or single multiline string containing sequences. tree_type: can be either neighborjoining (default) or upgmb for UPGMA clean_up: When true, will clean up output files """ params["-maxhours"] = max_hours if tree_type: params["-cluster2"] = tree_type params["-tree2"] = get_tmp_filename(WorkingDir) params["-out"] = get_tmp_filename(WorkingDir) muscle_res = muscle_seqs(seqs, input_handler=input_handler, params=params, add_seq_names=add_seq_names, WorkingDir=WorkingDir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout) tree = DndParser(muscle_res["Tree2Out"], constructor=constructor) aln = [line for line in muscle_res["MuscleOut"]] if clean_up: muscle_res.cleanUp() return tree, aln def fastest_aln_seqs(seqs, params={}, out_filename=None, add_seq_names=True, WorkingDir=None, SuppressStderr=None, SuppressStdout=None ): """Fastest (and least accurate) version of muscle seqs: either file name or list of sequence objects or list of strings or single multiline string containing sequences. Addl docs coming soon """ params["-maxiters"] = 1 params["-diags1"] = True params["-sv"] = True params["-distance1"] = "kbit20_3" muscle_res = muscle_seqs(seqs, params=params, add_seq_names=add_seq_names, out_filename=out_filename, WorkingDir=WorkingDir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout) return muscle_res def align_unaligned_seqs(seqs, moltype, params=None): """Returns an Alignment object from seqs. seqs: SequenceCollection object, or data that can be used to build one. moltype: a MolType object. DNA, RNA, or PROTEIN. params: dict of parameters to pass in to the Muscle app controller. Result will be an Alignment object. """ if not params: params = {} #create SequenceCollection object from seqs seq_collection = SequenceCollection(seqs,MolType=moltype) #Create mapping between abbreviated IDs and full IDs int_map, int_keys = seq_collection.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) #get temporary filename params.update({'-out':get_tmp_filename()}) #Create Muscle app. app = Muscle(InputHandler='_input_as_multiline_string',\ params=params) #Get results using int_map as input to app res = app(int_map.toFasta()) #Get alignment as dict out of results alignment = dict(MinimalFastaParser(res['MuscleOut'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): new_alignment[int_keys[k]]=v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment,MolType=moltype) #Clean up res.cleanUp() del(seq_collection,int_map,int_keys,app,res,alignment,params) return new_alignment def align_and_build_tree(seqs, moltype, best_tree=False, params=None): """Returns an alignment and a tree from Sequences object seqs. seqs: a cogent.core.alignment.SequenceCollection object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object best_tree: if True (default:False), uses a slower but more accurate algorithm to build the tree. params: dict of parameters to pass in to the Muscle app controller. The result will be a tuple containing a cogent.core.alignment.Alignment and a cogent.core.tree.PhyloNode object (or None for the alignment and/or tree if either fails). """ aln = align_unaligned_seqs(seqs, moltype=moltype, params=params) tree = build_tree_from_alignment(aln, moltype, best_tree, params) return {'Align':aln, 'Tree':tree} def build_tree_from_alignment(aln, moltype, best_tree=False, params=None): """Returns a tree from Alignment object aln. aln: a cogent.core.alignment.Alignment object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object best_tree: unsupported params: dict of parameters to pass in to the Muscle app controller. The result will be an cogent.core.tree.PhyloNode object, or None if tree fails. """ # Create instance of app controller, enable tree, disable alignment app = Muscle(InputHandler='_input_as_multiline_string', params=params, \ WorkingDir='/tmp') app.Parameters['-clusteronly'].on() app.Parameters['-tree1'].on(get_tmp_filename(app.WorkingDir)) app.Parameters['-seqtype'].on(moltype.label) seq_collection = SequenceCollection(aln, MolType=moltype) #Create mapping between abbreviated IDs and full IDs int_map, int_keys = seq_collection.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) # Collect result result = app(int_map.toFasta()) # Build tree tree = DndParser(result['Tree1Out'].read(), constructor=PhyloNode) for tip in tree.tips(): tip.Name = int_keys[tip.Name] # Clean up result.cleanUp() del(seq_collection, app, result) return tree def add_seqs_to_alignment(seqs, aln, params=None): """Returns an Alignment object from seqs and existing Alignment. seqs: a cogent.core.alignment.SequenceCollection object, or data that can be used to build one. aln: a cogent.core.alignment.Alignment object, or data that can be used to build one params: dict of parameters to pass in to the Muscle app controller. """ if not params: params = {} #create SequenceCollection object from seqs seqs_collection = SequenceCollection(seqs) #Create mapping between abbreviated IDs and full IDs seqs_int_map, seqs_int_keys = seqs_collection.getIntMap(prefix='seq_') #Create SequenceCollection from int_map. seqs_int_map = SequenceCollection(seqs_int_map) #create SequenceCollection object from aln aln_collection = SequenceCollection(aln) #Create mapping between abbreviated IDs and full IDs aln_int_map, aln_int_keys = aln_collection.getIntMap(prefix='aln_') #Create SequenceCollection from int_map. aln_int_map = SequenceCollection(aln_int_map) #set output and profile options params.update({'-out':get_tmp_filename(), '-profile':True}) #save seqs to tmp file seqs_filename = get_tmp_filename() seqs_out = open(seqs_filename,'w') seqs_out.write(seqs_int_map.toFasta()) seqs_out.close() #save aln to tmp file aln_filename = get_tmp_filename() aln_out = open(aln_filename, 'w') aln_out.write(aln_int_map.toFasta()) aln_out.close() #Create Muscle app and get results app = Muscle(InputHandler='_input_as_multifile', params=params) res = app((aln_filename, seqs_filename)) #Get alignment as dict out of results alignment = dict(MinimalFastaParser(res['MuscleOut'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): if k in seqs_int_keys: new_alignment[seqs_int_keys[k]] = v else: new_alignment[aln_int_keys[k]] = v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment) #Clean up res.cleanUp() del(seqs_collection, seqs_int_map, seqs_int_keys) del(aln_collection, aln_int_map, aln_int_keys) del(app, res, alignment, params) remove(seqs_filename) remove(aln_filename) return new_alignment def align_two_alignments(aln1, aln2, params=None): """Returns an Alignment object from two existing Alignments. aln1, aln2: cogent.core.alignment.Alignment objects, or data that can be used to build them. params: dict of parameters to pass in to the Muscle app controller. """ if not params: params = {} #create SequenceCollection object from aln1 aln1_collection = SequenceCollection(aln1) #Create mapping between abbreviated IDs and full IDs aln1_int_map, aln1_int_keys = aln1_collection.getIntMap(prefix='aln1_') #Create SequenceCollection from int_map. aln1_int_map = SequenceCollection(aln1_int_map) #create SequenceCollection object from aln2 aln2_collection = SequenceCollection(aln2) #Create mapping between abbreviated IDs and full IDs aln2_int_map, aln2_int_keys = aln2_collection.getIntMap(prefix='aln2_') #Create SequenceCollection from int_map. aln2_int_map = SequenceCollection(aln2_int_map) #set output and profile options params.update({'-out':get_tmp_filename(), '-profile':True}) #save aln1 to tmp file aln1_filename = get_tmp_filename() aln1_out = open(aln1_filename,'w') aln1_out.write(aln1_int_map.toFasta()) aln1_out.close() #save aln2 to tmp file aln2_filename = get_tmp_filename() aln2_out = open(aln2_filename, 'w') aln2_out.write(aln2_int_map.toFasta()) aln2_out.close() #Create Muscle app and get results app = Muscle(InputHandler='_input_as_multifile', params=params) res = app((aln1_filename, aln2_filename)) #Get alignment as dict out of results alignment = dict(MinimalFastaParser(res['MuscleOut'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): if k in aln1_int_keys: new_alignment[aln1_int_keys[k]] = v else: new_alignment[aln2_int_keys[k]] = v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment) #Clean up res.cleanUp() del(aln1_collection, aln1_int_map, aln1_int_keys) del(aln2_collection, aln2_int_map, aln2_int_keys) del(app, res, alignment, params) remove(aln1_filename) remove(aln2_filename) return new_alignment pycogent-1.9/cogent/app/muscle_v38.py000066400000000000000000000706721273014367000176330ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for muscle 3.8 """ from os import remove from cogent.app.parameters import FlagParameter, ValuedParameter from cogent.app.util import CommandLineApplication, ResultPath, \ get_tmp_filename, guess_input_handler from random import choice from cogent.core.alignment import SequenceCollection, Alignment from cogent.parse.tree import DndParser from cogent.core.tree import PhyloNode from cogent.parse.fasta import MinimalFastaParser __author__ = "Rob Knight" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Micah Hamady", "Zongzhi Liu", "Mike Robeson", "Catherine Lozupone", "Rob Knight", "Daniel McDonald", "Jeremy Widmann", "Jai Ram Rideout"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Micah Hamady" __email__ = "hamady@colorado.edu" __status__ = "Prototype" class Muscle(CommandLineApplication): """Muscle application controller""" _options ={ # Minimum spacing between anchor columns. [Integer] '-anchorspacing':ValuedParameter('-',Name='anchorspacing',Delimiter=' '), # Center parameter. Should be negative [Float] '-center':ValuedParameter('-',Name='center',Delimiter=' '), # Clustering method. cluster1 is used in iteration 1 # and 2, cluster2 in later iterations '-cluster1':ValuedParameter('-',Name='cluster1',Delimiter=' '), '-cluster2':ValuedParameter('-',Name='cluster2',Delimiter=' '), # Minimum length of diagonal. '-diaglength':ValuedParameter('-',Name='diaglength',Delimiter=' '), # Discard this many positions at ends of diagonal. '-diagmargin':ValuedParameter('-',Name='diagmargin',Delimiter=' '), # Distance measure for iteration 1. '-distance1':ValuedParameter('-',Name='distance1',Delimiter=' '), # Distance measure for iterations 2, 3 ... '-distance2':ValuedParameter('-',Name='distance2',Delimiter=' '), # The gap open score. Must be negative. '-gapopen':ValuedParameter('-',Name='gapopen',Delimiter=' '), # Window size for determining whether a region is hydrophobic. '-hydro':ValuedParameter('-',Name='hydro',Delimiter=' '), # Multiplier for gap open/close penalties in hydrophobic regions. '-hydrofactor':ValuedParameter('-',Name='hydrofactor',Delimiter=' '), # Where to find the input sequences. '-in':ValuedParameter('-',Name='in',Delimiter=' ', Quote="\""), '-in1':ValuedParameter('-',Name='in1',Delimiter=' ', Quote="\""), '-in2':ValuedParameter('-',Name='in2',Delimiter=' ', Quote="\""), # Log file name (delete existing file). '-log':ValuedParameter('-',Name='log',Delimiter=' '), # Log file name (append to existing file). '-loga':ValuedParameter('-',Name='loga',Delimiter=' '), # Maximum distance between two diagonals that allows them to merge # into one diagonal. '-maxdiagbreak':ValuedParameter('-',Name='maxdiagbreak',Delimiter=' '), # Maximum time to run in hours. The actual time may exceed the # requested limit by a few minutes. Decimals are allowed, so 1.5 # means one hour and 30 minutes. '-maxhours':ValuedParameter('-',Name='maxhours',Delimiter=' '), # Maximum number of iterations. '-maxiters':ValuedParameter('-',Name='maxiters',Delimiter=' '), # Maximum memory in Mb '-maxmb': ValuedParameter('-', Name='maxmb', Delimiter=' '), # Maximum number of new trees to build in iteration 2. '-maxtrees':ValuedParameter('-',Name='maxtrees',Delimiter=' '), # Minimum score a column must have to be an anchor. '-minbestcolscore':ValuedParameter('-',Name='minbestcolscore',Delimiter=' '), # Minimum smoothed score a column must have to be an anchor. '-minsmoothscore':ValuedParameter('-',Name='minsmoothscore',Delimiter=' '), # Objective score used by tree dependent refinement. # sp=sum-of-pairs score. # spf=sum-of-pairs score (dimer approximation) # spm=sp for < 100 seqs, otherwise spf # dp=dynamic programming score. # ps=average profile-sequence score. # xp=cross profile score. '-objscore':ValuedParameter('-',Name='objscore',Delimiter=' '), # Where to write the alignment. '-out':ValuedParameter('-',Name='out',Delimiter=' ', Quote="\""), # Where to write the file in phylip sequenctial format (v3.6 only). '-physout':ValuedParameter('-',Name='physout',Delimiter=' '), # Where to write the file in phylip interleaved format (v3.6 only). '-phyiout':ValuedParameter('-',Name='phyiout',Delimiter=' '), # Set to profile for aligning two alignments and adding seqs to an # existing alignment '-profile':FlagParameter(Prefix='-',Name='profile'), # Method used to root tree; root1 is used in iteration 1 and 2, root2 # in later iterations. '-root1':ValuedParameter('-',Name='root1',Delimiter=' '), '-root2':ValuedParameter('-',Name='root2',Delimiter=' '), # Sequence type. '-seqtype':ValuedParameter('-',Name='seqtype',Delimiter=' '), # Maximum value of column score for smoothing purposes. '-smoothscoreceil':ValuedParameter('-',Name='smoothscoreceil',Delimiter=' '), # Constant used in UPGMB clustering. Determines the relative fraction # of average linkage (SUEFF) vs. nearest-neighbor linkage (1 . SUEFF). '-SUEFF':ValuedParameter('-',Name='SUEFF',Delimiter=' '), # Save tree produced in first or second iteration to given file in # Newick (Phylip-compatible) format. '-tree1':ValuedParameter('-',Name='tree1',Delimiter=' ', Quote="\""), '-tree2':ValuedParameter('-',Name='tree2',Delimiter=' ', Quote="\""), # Sequence weighting scheme. # weight1 is used in iterations 1 and 2. # weight2 is used for tree-dependent refinement. # none=all sequences have equal weight. # henikoff=Henikoff & Henikoff weighting scheme. # henikoffpb=Modified Henikoff scheme as used in PSI-BLAST. # clustalw=CLUSTALW method. # threeway=Gotoh three-way method. '-weight1':ValuedParameter('-',Name='weight1',Delimiter=' '), '-weight2':ValuedParameter('-',Name='weight2',Delimiter=' '), # Use anchor optimization in tree dependent refinement iterations '-anchors':FlagParameter(Prefix='-',Name='anchors'), # Write output in CLUSTALW format (default is FASTA). '-clw':FlagParameter(Prefix='-',Name='clw'), # Cluster sequences '-clusteronly':FlagParameter(Prefix='-',Name='clusteronly'), # neighborjoining is "unrecognized" #'-neighborjoining':FlagParameter(Prefix='-',Name='neighborjoining'), # Write output in CLUSTALW format with the "CLUSTAL W (1.81)" header # rather than the MUSCLE version. This is useful when a post-processing # step is picky about the file header. '-clwstrict':FlagParameter(Prefix='-',Name='clwstrict'), # Do not catch exceptions. '-core':FlagParameter(Prefix='-',Name='core'), # Write output in FASTA format. Alternatives include .clw, # .clwstrict, .msf and .html. '-fasta':FlagParameter(Prefix='-',Name='fasta'), # Group similar sequences together in the output. This is the default. # See also .stable. '-group':FlagParameter(Prefix='-',Name='group'), # Write output in HTML format (default is FASTA). '-html':FlagParameter(Prefix='-',Name='html'), # Use log-expectation profile score (VTML240). Alternatives are to use # -sp or -sv. This is the default for amino acid sequences. '-le':FlagParameter(Prefix='-',Name='le'), # Write output in MSF format (default is FASTA). '-msf':FlagParameter(Prefix='-',Name='msf'), # Disable anchor optimization. Default is -anchors. '-noanchors':FlagParameter(Prefix='-',Name='noanchors'), # Catch exceptions and give an error message if possible. '-nocore':FlagParameter(Prefix='-',Name='nocore'), # Do not display progress messages. '-quiet':FlagParameter(Prefix='-',Name='quiet'), # Input file is already aligned, skip first two iterations and begin # tree dependent refinement. '-refine':FlagParameter(Prefix='-',Name='refine'), # Use sum-of-pairs protein profile score (PAM200). Default is -le. '-sp':FlagParameter(Prefix='-',Name='sp'), # Use sum-of-pairs nucleotide profile score (BLASTZ parameters). This # is the only option for nucleotides, and is therefore the default. '-spn':FlagParameter(Prefix='-',Name='spn'), # Preserve input order of sequences in output file. Default is to group # sequences by similarity (-group). '-stable':FlagParameter(Prefix='-',Name='stable'), # Use sum-of-pairs profile score (VTML240). Default is -le. '-sv':FlagParameter(Prefix='-',Name='sv'), # Diagonal optimization '-diags':FlagParameter(Prefix='-',Name='diags'), '-diags1':FlagParameter(Prefix='-',Name='diags1'), '-diags2':FlagParameter(Prefix='-',Name='diags2'), # Terminal gaps penalized with full penalty. # [1] Not fully supported in this version. '-termgapsfull':FlagParameter(Prefix='-',Name='termgapsfull'), # Terminal gaps penalized with half penalty. # [1] Not fully supported in this version. '-termgapshalf':FlagParameter(Prefix='-',Name='termgapshalf'), # Terminal gaps penalized with half penalty if gap relative to # longer sequence, otherwise with full penalty. # [1] Not fully supported in this version. '-termgapshalflonger':FlagParameter(Prefix='-',Name='termgapshalflonger'), # Write parameter settings and progress messages to log file. '-verbose':FlagParameter(Prefix='-',Name='verbose'), # Write version string to stdout and exit. '-version':FlagParameter(Prefix='-',Name='version'), } _parameters = {} _parameters.update(_options) _command = "muscle" def _input_as_seqs(self,data): lines = [] for i,s in enumerate(data): #will number the sequences 1,2,3,etc. lines.append(''.join(['>',str(i+1)])) lines.append(s) return self._input_as_lines(lines) def _input_as_lines(self,data): if data: self.Parameters['-in']\ .on(super(Muscle,self)._input_as_lines(data)) return '' def _input_as_string(self,data): """Makes data the value of a specific parameter This method returns the empty string. The parameter will be printed automatically once set. """ if data: self.Parameters['-in'].on(str(data)) return '' def _input_as_multiline_string(self, data): if data: self.Parameters['-in']\ .on(super(Muscle,self)._input_as_multiline_string(data)) return '' def _input_as_multifile(self, data): """For use with the -profile option This input handler expects data to be a tuple containing two filenames. Index 0 will be set to -in1 and index 1 to -in2 """ if data: try: filename1, filename2 = data except: raise ValueError, "Expected two filenames" self.Parameters['-in'].off() self.Parameters['-in1'].on(filename1) self.Parameters['-in2'].on(filename2) return '' def _align_out_filename(self): if self.Parameters['-out'].isOn(): aln_filename = self._absolute(str(self.Parameters['-out'].Value)) else: raise ValueError, "No output file specified." return aln_filename def _tree1_out_filename(self): if self.Parameters['-tree1'].isOn(): aln_filename = self._absolute(str(self.Parameters['-tree1'].Value)) else: raise ValueError, "No tree output file specified." return aln_filename def _tree2_out_filename(self): if self.Parameters['-tree2'].isOn(): tree_filename = self._absolute(str(self.Parameters['-tree2'].Value)) else: raise ValueError, "No tree output file specified." return tree_filename def _get_result_paths(self,data): result = {} if self.Parameters['-out'].isOn(): out_name = self._align_out_filename() result['MuscleOut'] = ResultPath(Path=out_name,IsWritten=True) if self.Parameters['-tree1'].isOn(): out_name = self._tree1_out_filename() result['Tree1Out'] = ResultPath(Path=out_name,IsWritten=True) if self.Parameters['-tree2'].isOn(): out_name = self._tree2_out_filename() result['Tree2Out'] = ResultPath(Path=out_name,IsWritten=True) return result def getHelp(self): """Muscle help""" help_str = """ """ return help_str #SOME FUNCTIONS TO EXECUTE THE MOST COMMON TASKS def muscle_seqs(seqs, add_seq_names=False, out_filename=None, input_handler=None, params={}, WorkingDir=None, SuppressStderr=None, SuppressStdout=None): """Muscle align list of sequences. seqs: a list of sequences as strings or objects, you must set add_seq_names=True or sequences in a multiline string, as read() from a fasta file or sequences in a list of lines, as readlines() from a fasta file or a fasta seq filename. == for eg, testcode for guessing #guess_input_handler should correctly identify input gih = guess_input_handler self.assertEqual(gih('abc.txt'), '_input_as_string') self.assertEqual(gih('>ab\nTCAG'), '_input_as_multiline_string') self.assertEqual(gih(['ACC','TGA'], True), '_input_as_seqs') self.assertEqual(gih(['>a','ACC','>b','TGA']), '_input_as_lines') == docstring for blast_seqs, apply to muscle_seqs == seqs: either file name or list of sequence objects or list of strings or single multiline string containing sequences. WARNING: DECISION RULES FOR INPUT HANDLING HAVE CHANGED. Decision rules for data are as follows. If it's s list, treat as lines, unless add_seq_names is true (in which case treat as list of seqs). If it's a string, test whether it has newlines. If it doesn't have newlines, assume it's a filename. If it does have newlines, it can't be a filename, so assume it's a multiline string containing sequences. If you want to skip the detection and force a specific type of input handler, use input_handler='your_favorite_handler'. add_seq_names: boolean. if True, sequence names are inserted in the list of sequences. if False, it assumes seqs is a list of lines of some proper format that the program can handle Addl docs coming soon """ if out_filename: params["-out"] = out_filename #else: # params["-out"] = get_tmp_filename(WorkingDir) ih = input_handler or guess_input_handler(seqs, add_seq_names) muscle_app = Muscle( params=params, InputHandler=ih, WorkingDir=WorkingDir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout) return muscle_app(seqs) def cluster_seqs(seqs, neighbor_join=False, params={}, add_seq_names=True, WorkingDir=None, SuppressStderr=None, SuppressStdout=None, max_chars=1000000, max_hours=1.0, constructor=PhyloNode, clean_up=True ): """Muscle cluster list of sequences. seqs: either file name or list of sequence objects or list of strings or single multiline string containing sequences. Addl docs coming soon """ num_seqs = len(seqs) if num_seqs < 2: raise ValueError, "Muscle requres 2 or more sequences to cluster." num_chars = sum(map(len, seqs)) if num_chars > max_chars: params["-maxiters"] = 2 params["-diags1"] = True params["-sv"] = True #params["-distance1"] = "kmer6_6" #params["-distance1"] = "kmer20_3" #params["-distance1"] = "kbit20_3" print "lots of chars, using fast align", num_chars params["-maxhours"] = max_hours #params["-maxiters"] = 10 #cluster_type = "upgmb" #if neighbor_join: # cluster_type = "neighborjoining" params["-clusteronly"] = True params["-tree1"] = get_tmp_filename(WorkingDir) muscle_res = muscle_seqs(seqs, params=params, add_seq_names=add_seq_names, WorkingDir=WorkingDir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout) tree = DndParser(muscle_res["Tree1Out"], constructor=constructor) if clean_up: muscle_res.cleanUp() return tree def aln_tree_seqs(seqs, input_handler=None, tree_type='neighborjoining', params={}, add_seq_names=True, WorkingDir=None, SuppressStderr=None, SuppressStdout=None, max_hours=5.0, constructor=PhyloNode, clean_up=True ): """Muscle align sequences and report tree from iteration2. Unlike cluster_seqs, returns tree2 which is the tree made during the second muscle iteration (it should be more accurate that the cluster from the first iteration which is made fast based on k-mer words) seqs: either file name or list of sequence objects or list of strings or single multiline string containing sequences. tree_type: can be either neighborjoining (default) or upgmb for UPGMA clean_up: When true, will clean up output files """ params["-maxhours"] = max_hours if tree_type: params["-cluster2"] = tree_type params["-tree2"] = get_tmp_filename(WorkingDir) params["-out"] = get_tmp_filename(WorkingDir) muscle_res = muscle_seqs(seqs, input_handler=input_handler, params=params, add_seq_names=add_seq_names, WorkingDir=WorkingDir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout) tree = DndParser(muscle_res["Tree2Out"], constructor=constructor) aln = [line for line in muscle_res["MuscleOut"]] if clean_up: muscle_res.cleanUp() return tree, aln def fastest_aln_seqs(seqs, params={}, out_filename=None, add_seq_names=True, WorkingDir=None, SuppressStderr=None, SuppressStdout=None ): """Fastest (and least accurate) version of muscle seqs: either file name or list of sequence objects or list of strings or single multiline string containing sequences. Addl docs coming soon """ params["-maxiters"] = 1 params["-diags1"] = True params["-sv"] = True params["-distance1"] = "kbit20_3" muscle_res = muscle_seqs(seqs, params=params, add_seq_names=add_seq_names, out_filename=out_filename, WorkingDir=WorkingDir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout) return muscle_res def align_unaligned_seqs(seqs, moltype, params=None): """Returns an Alignment object from seqs. seqs: SequenceCollection object, or data that can be used to build one. moltype: a MolType object. DNA, RNA, or PROTEIN. params: dict of parameters to pass in to the Muscle app controller. Result will be an Alignment object. """ if not params: params = {} #create SequenceCollection object from seqs seq_collection = SequenceCollection(seqs,MolType=moltype) #Create mapping between abbreviated IDs and full IDs int_map, int_keys = seq_collection.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) #get temporary filename params.update({'-out':get_tmp_filename()}) #Create Muscle app. app = Muscle(InputHandler='_input_as_multiline_string',\ params=params) #Get results using int_map as input to app res = app(int_map.toFasta()) #Get alignment as dict out of results alignment = dict(MinimalFastaParser(res['MuscleOut'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): new_alignment[int_keys[k]]=v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment,MolType=moltype) #Clean up res.cleanUp() del(seq_collection,int_map,int_keys,app,res,alignment,params) return new_alignment def align_and_build_tree(seqs, moltype, best_tree=False, params=None): """Returns an alignment and a tree from Sequences object seqs. seqs: a cogent.core.alignment.SequenceCollection object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object best_tree: if True (default:False), uses a slower but more accurate algorithm to build the tree. params: dict of parameters to pass in to the Muscle app controller. The result will be a tuple containing a cogent.core.alignment.Alignment and a cogent.core.tree.PhyloNode object (or None for the alignment and/or tree if either fails). """ aln = align_unaligned_seqs(seqs, moltype=moltype, params=params) tree = build_tree_from_alignment(aln, moltype, best_tree, params) return {'Align':aln, 'Tree':tree} def build_tree_from_alignment(aln, moltype, best_tree=False, params=None): """Returns a tree from Alignment object aln. aln: a cogent.core.alignment.Alignment object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object best_tree: unsupported params: dict of parameters to pass in to the Muscle app controller. The result will be an cogent.core.tree.PhyloNode object, or None if tree fails. """ # Create instance of app controller, enable tree, disable alignment app = Muscle(InputHandler='_input_as_multiline_string', params=params, \ WorkingDir='/tmp') app.Parameters['-clusteronly'].on() app.Parameters['-tree1'].on(get_tmp_filename(app.WorkingDir)) app.Parameters['-seqtype'].on(moltype.label) seq_collection = SequenceCollection(aln, MolType=moltype) #Create mapping between abbreviated IDs and full IDs int_map, int_keys = seq_collection.getIntMap() #Create SequenceCollection from int_map. int_map = SequenceCollection(int_map,MolType=moltype) # Collect result result = app(int_map.toFasta()) # Build tree tree = DndParser(result['Tree1Out'].read(), constructor=PhyloNode) for tip in tree.tips(): tip.Name = int_keys[tip.Name] # Clean up result.cleanUp() del(seq_collection, app, result) return tree def add_seqs_to_alignment(seqs, aln, params=None): """Returns an Alignment object from seqs and existing Alignment. seqs: a cogent.core.alignment.SequenceCollection object, or data that can be used to build one. aln: a cogent.core.alignment.Alignment object, or data that can be used to build one params: dict of parameters to pass in to the Muscle app controller. """ if not params: params = {} #create SequenceCollection object from seqs seqs_collection = SequenceCollection(seqs) #Create mapping between abbreviated IDs and full IDs seqs_int_map, seqs_int_keys = seqs_collection.getIntMap(prefix='seq_') #Create SequenceCollection from int_map. seqs_int_map = SequenceCollection(seqs_int_map) #create SequenceCollection object from aln aln_collection = SequenceCollection(aln) #Create mapping between abbreviated IDs and full IDs aln_int_map, aln_int_keys = aln_collection.getIntMap(prefix='aln_') #Create SequenceCollection from int_map. aln_int_map = SequenceCollection(aln_int_map) #set output and profile options params.update({'-out':get_tmp_filename(), '-profile':True}) #save seqs to tmp file seqs_filename = get_tmp_filename() seqs_out = open(seqs_filename,'w') seqs_out.write(seqs_int_map.toFasta()) seqs_out.close() #save aln to tmp file aln_filename = get_tmp_filename() aln_out = open(aln_filename, 'w') aln_out.write(aln_int_map.toFasta()) aln_out.close() #Create Muscle app and get results app = Muscle(InputHandler='_input_as_multifile', params=params) res = app((aln_filename, seqs_filename)) #Get alignment as dict out of results alignment = dict(MinimalFastaParser(res['MuscleOut'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): if k in seqs_int_keys: new_alignment[seqs_int_keys[k]] = v else: new_alignment[aln_int_keys[k]] = v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment) #Clean up res.cleanUp() del(seqs_collection, seqs_int_map, seqs_int_keys) del(aln_collection, aln_int_map, aln_int_keys) del(app, res, alignment, params) remove(seqs_filename) remove(aln_filename) return new_alignment def align_two_alignments(aln1, aln2, params=None): """Returns an Alignment object from two existing Alignments. aln1, aln2: cogent.core.alignment.Alignment objects, or data that can be used to build them. params: dict of parameters to pass in to the Muscle app controller. """ if not params: params = {} #create SequenceCollection object from aln1 aln1_collection = SequenceCollection(aln1) #Create mapping between abbreviated IDs and full IDs aln1_int_map, aln1_int_keys = aln1_collection.getIntMap(prefix='aln1_') #Create SequenceCollection from int_map. aln1_int_map = SequenceCollection(aln1_int_map) #create SequenceCollection object from aln2 aln2_collection = SequenceCollection(aln2) #Create mapping between abbreviated IDs and full IDs aln2_int_map, aln2_int_keys = aln2_collection.getIntMap(prefix='aln2_') #Create SequenceCollection from int_map. aln2_int_map = SequenceCollection(aln2_int_map) #set output and profile options params.update({'-out':get_tmp_filename(), '-profile':True}) #save aln1 to tmp file aln1_filename = get_tmp_filename() aln1_out = open(aln1_filename,'w') aln1_out.write(aln1_int_map.toFasta()) aln1_out.close() #save aln2 to tmp file aln2_filename = get_tmp_filename() aln2_out = open(aln2_filename, 'w') aln2_out.write(aln2_int_map.toFasta()) aln2_out.close() #Create Muscle app and get results app = Muscle(InputHandler='_input_as_multifile', params=params) res = app((aln1_filename, aln2_filename)) #Get alignment as dict out of results alignment = dict(MinimalFastaParser(res['MuscleOut'].readlines())) #Make new dict mapping original IDs new_alignment = {} for k,v in alignment.items(): if k in aln1_int_keys: new_alignment[aln1_int_keys[k]] = v else: new_alignment[aln2_int_keys[k]] = v #Create an Alignment object from alignment dict new_alignment = Alignment(new_alignment) #Clean up res.cleanUp() del(aln1_collection, aln1_int_map, aln1_int_keys) del(aln2_collection, aln2_int_map, aln2_int_keys) del(app, res, alignment, params) remove(aln1_filename) remove(aln2_filename) return new_alignment pycogent-1.9/cogent/app/nupack.py000066400000000000000000000141471273014367000171170ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for NUPACK v1.2 application """ import shutil from os import remove, system, environ from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath, FilePath, ApplicationError from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters, _find_synonym, is_not_None __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" if 'NUPACK_DATA' not in environ: raise RuntimeError, \ 'NUPACK app controller requires the NUPACK_DATA environment variable' nupack_data_dir = environ['NUPACK_DATA'] nupack_data_dna = 'dataS_G.dna' nupack_data_rna = 'dataS_G.rna' class Nupack(CommandLineApplication): """Application controller for Nupack_1.2 application Predicts RNA secondary structure All pseudoknot-free secondary structures are allowed, as well as simple pseudoknots. """ _command = 'Fold.out' _input_handler = '_input_as_string' def _input_as_lines(self,data): """ Write a seq of lines to a temp file and return the filename string data: a sequence to be written to a file, each element of the sequence will compose a line in the file Note: '\n' will be stripped off the end of each sequence element before writing to a file in order to avoid multiple new lines accidentally be written to a file """ filename = self._input_filename = self.getTmpFilename(self.WorkingDir) data_file = open(filename,'w') data_to_file = '\n'.join([str(d).strip('\n') for d in data]) data_file.write(data_to_file) data_file.write('\n') #needs a new line att the end of input data_file.close() return filename def _get_result_paths(self,data): """Return a dict of ResultPath objects representing all possible output This dictionary will have keys based on the name that you'd like to access the file by in the CommandLineAppResult object that will be created, and the values which are ResultPath objects. """ result = {} try: f = open((self.WorkingDir+'out.pair')) f.close() result['pair'] =\ ResultPath(Path=(self.WorkingDir+'out.pair')) except IOError: pass try: f = open((self.WorkingDir+'out.ene')) f.close() result['ene'] =\ ResultPath(Path=(self.WorkingDir+'out.ene')) except IOError: pass return result def __call__(self,data=None, remove_tmp=True): """Run the application with the specified kwargs on data data: anything that can be cast into a string or written out to a file. Usually either a list of things or a single string or number. input_handler will be called on this data before it is passed as part of the command-line argument, so by creating your own input handlers you can customize what kind of data you want your application to accept remove_tmp: if True, removes tmp files """ input_handler = self.InputHandler suppress_stdout = self.SuppressStdout suppress_stderr = self.SuppressStderr if suppress_stdout: outfile = FilePath('/dev/null') else: outfile = self.getTmpFilename(self.TmpDir) if suppress_stderr: errfile = FilePath('/dev/null') else: errfile = FilePath(self.getTmpFilename(self.TmpDir)) if data is None: input_arg = '' else: input_arg = getattr(self,input_handler)(data) # Build up the command, consisting of a BaseCommand followed by # input and output (file) specifications command = self._command_delimiter.join(filter(None,\ [self.BaseCommand,str(input_arg),'>',str(outfile),'2>',\ str(errfile)])) if self.HaltExec: raise AssertionError, "Halted exec with command:\n" + command # copy over data files nupack_data_dna_src = '/'.join([nupack_data_dir, nupack_data_dna]) nupack_data_rna_src = '/'.join([nupack_data_dir, nupack_data_rna]) shutil.copy(nupack_data_dna_src, self.WorkingDir) shutil.copy(nupack_data_rna_src, self.WorkingDir) # The return value of system is a 16-bit number containing the signal # number that killed the process, and then the exit status. # We only want to keep the exit status so do a right bitwise shift to # get rid of the signal number byte # NOTE: we copy the data files to the working directory first exit_status = system(command) >> 8 # remove data files nupack_data_dna_dst = ''.join([self.WorkingDir, nupack_data_dna]) nupack_data_rna_dst = ''.join([self.WorkingDir, nupack_data_rna]) remove(nupack_data_dna_dst) remove(nupack_data_rna_dst) # Determine if error should be raised due to exit status of # appliciation if not self._accept_exit_status(exit_status): raise ApplicationError, \ 'Unacceptable application exit status: %s, command: %s'\ % (str(exit_status),command) # open the stdout and stderr if not being suppressed out = None if not suppress_stdout: out = open(outfile,"r") err = None if not suppress_stderr: err = open(errfile,"r") result = CommandLineAppResult(out,err,exit_status,\ result_paths=self._get_result_paths(data)) # Clean up the input file if one was created if remove_tmp: if self._input_filename: remove(self._input_filename) self._input_filename = None return result pycogent-1.9/cogent/app/pandaseq.py000066400000000000000000000146031273014367000174270ustar00rootroot00000000000000#!/usr/bin/env python # file: pandaseq.py # Application controller for pandaseq (v2.4) # https://github.com/neufeld/pandaseq # from cogent.app.parameters import ValuedParameter, FlagParameter from cogent.app.util import CommandLineApplication, ResultPath, \ ApplicationError import os import tempfile __author__ = "Michael Robeson" __copyright__ = "Copyright 2007-2013, The Cogent Project" __credits__ = ["Michael Robeson"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Michael Robeson" __email__ = "robesonms@ornl.gov" __status__ = "Development" class PandaSeq(CommandLineApplication): """pandaseq application controller for joining paired-end reads """ _command = 'pandaseq' _parameters = { # pandaseq 2.4 # Usage: pandaseq -f forward.fastq -r reverse.fastq [-6] [-a] [-B] # [-C module1 -C module2 ...] [-d flags] [-F] [-j] [-L maxlen] # [-l minlen] [-N] [-o minoverlap] [-p forwardprimer] # [-q reverseprimer] [-T threads] [-t threshold] > assembled.fastq # -6 Use PHRED+64 (CASAVA 1.3-1.7) instead of PHRED+33 (CASAVA 1.8+). '-6':FlagParameter(Prefix='-', Name='6'), # -a Strip the primers after assembly, rather than before. '-a':FlagParameter(Prefix='-', Name='a'), # -B Allow unbarcoded sequences (try this for BADID errors). '-B':FlagParameter(Prefix='-', Name='B'), # -C module Load a sequence validation module. '-C':FlagParameter(Prefix='-', Name='C'), # -d flags Control the logging messages. Capital to enable; small to disable. # (R)econstruction detail. # Sequence (b)uilding information. # (F)ile processing. # (k)-mer table construction. # Show every (m)ismatch. '-d':ValuedParameter(Prefix='-', Delimiter=' ', Name='d'), # Optional (s)tatistics. # -f Input FASTQ file containing forward reads. '-f':ValuedParameter(Prefix='-', Delimiter=' ', Name='f'), # -F Output FASTQ instead of FASTA. '-F':FlagParameter(Prefix='-', Name='F'), # -j Input files are bzipped. '-j':FlagParameter(Prefix='-', Name='j'), # -k kmers The number of k-mers in the table. '-k':ValuedParameter(Prefix='-', Delimiter=' ', Name='k'), # -L maxlen Maximum length for a sequence '-L':ValuedParameter(Prefix='-', Delimiter=' ', Name='L'), # -l minlen Minimum length for a sequence '-l':ValuedParameter(Prefix='-', Delimiter=' ', Name='l'), # -N Eliminate all sequences with unknown nucleotides in the output. '-N':FlagParameter(Prefix='-', Name='N'), # -o minoverlap Minimum overlap between forward and reverse reads (default = 1) '-o':ValuedParameter(Prefix='-', Delimiter=' ', Name='o'), # -p Forward primer sequence or number of bases to be removed. '-p':ValuedParameter(Prefix='-', Delimiter=' ', Name='p'), # -q Reverse primer sequence or number of bases to be removed. '-q':ValuedParameter(Prefix='-', Delimiter=' ', Name='q'), # -r Input FASTQ file containing reverse reads. '-r':ValuedParameter(Prefix='-', Delimiter=' ', Name='r'), # -T thread Run with a number of parallel threads. '-T':ValuedParameter(Prefix='-', Delimiter=' ', Name='T'), # -t The minimum probability that a sequence must have to match a primer. # (default = 6.000000e-01) '-t':ValuedParameter(Prefix='-', Delimiter=' ', Name='t'), } # No _get_results_path needed as all results (the merged paired-ends) # are sent to STDOUT. def getHelp(self): """pandaseq help""" help_Str = """ For basic help, type the following at the command line: 'pandaseq' or 'pandaseq -h' Website: https://github.com/neufeld/pandaseq """ def join_paired_end_reads_pandaseq( reads1_infile_path, reads2_infile_path, outfile_label='pandaseq', phred_64=False, fastq=True, threads=1, params={}, working_dir=tempfile.gettempdir(), SuppressStderr=True, SuppressStdout=False, HALT_EXEC=False): """ Runs pandaseq with default parameters to assemble paired-end reads. -reads1_infile_path : reads1.fastq infile path -reads2_infile_path : reads2.fastq infile path -outfile_label : base name for outfile -fastq : output assembly as fastq (True) or Fasta (False) -threads : number of cpus to use. Default 1. -phred_64 : if you are using phred 64 scores instead of phred 33 -params : other optional pandaseq parameters """ abs_r1_path = os.path.abspath(reads1_infile_path) abs_r2_path = os.path.abspath(reads2_infile_path) infile_paths = [abs_r1_path, abs_r2_path] # check / make absolute infile paths for p in infile_paths: if not os.path.exists(p): raise IOError, 'Infile not found at: %s' % p # required by pandaseq to assemble params['-f'] = abs_r1_path params['-r'] = abs_r2_path params['-T'] = threads # set up controller pandaseq_app = PandaSeq( params=params, WorkingDir=working_dir, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout, HALT_EXEC=HALT_EXEC) # Fastq? if fastq: pandaseq_app.Parameters['-F'].on() # if using phred 64: if phred_64: pandaseq_app.Parameters['-6'].on() # run assembler result = pandaseq_app() # write STDOUT (assembly) to file # NOTE: res['StdOut'] will be empty after this. # We do this so that the actual output remains saved to # disk and can be accessed outside python. #assembled_output_file_name = get_tmp_filename(prefix='assembled_pandaseq_') assembled_output_file_name = os.path.join(working_dir, outfile_label) + '_joined.fastq' pandaseq_outfile_handle = open(assembled_output_file_name,'w') for line in result['StdOut']: pandaseq_outfile_handle.write(line) pandaseq_outfile_handle.close() result.cleanUp() # We store ouput file path within a dictionary in order to kepp the # expected output between various paired-end assembly wrappers # identical. path_dict = {} path_dict['Assembled'] = assembled_output_file_name # sanity check that files actually exist in path lcoations for path in path_dict.values(): if not os.path.exists(path): raise IOError, 'Output file not found at: %s' % path return path_dict pycogent-1.9/cogent/app/parameters.py000066400000000000000000000450011273014367000177720ustar00rootroot00000000000000#!/usr/bin/env python """ Provides Parameter, FlagParameter, ValuedParameter, MixedParameter, Parameters. These are intended to be used with the Application class and its subclasses """ from cogent.util.misc import MappedDict, FunctionWrapper from copy import deepcopy __author__ = "Rob Knight" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Sandra Smit", "Greg Caporaso", "Rob Knight"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Sandra Smit" __email__ = "sandra.smit@colorado.edu" __status__ = "Development" def is_not_None(x): """Returns True if x is not None""" return x is not None class ParameterError(ValueError): """Error raised when field in parameter is bad""" pass class FilePath(str): """ Hold paths for proper handling Paths in this sense are filenames, directory paths, or filepaths. Some examples include: file.txt ./path/to/file.txt ./path/to/dir/ /path/to/file.txt . / The purpose of this class is to allow all paths to be handled the same since they sometimes need to be treated differently than simple strings. For example, if a path has a space in it, and it is being passed to system, it needs to be wrapped in quotes. But, you wouldn't want it as a string wrapped in quotes b/c, e.g., isabs('"/absolute/path"') == False, b/c the first char is a ", not a /. * This would make more sense to call Path, but that conflicts with the ResultPath.Path attribute. I'm not sure what to do about this and want to see what others think. Once finalized, a global replace should take care of making the switch. """ def __new__(cls,path): try: return str.__new__(cls, path.strip('"')) except AttributeError: return str.__new__(cls,'') def __str__(self): """ wrap self in quotes, or return the empty string if self == '' """ if self == '': return '' return ''.join(['"',self,'"']) def __add__(self,other): return FilePath(''.join([self,other])) class Parameter(object): """Stores information regarding a parameter to an application. An abstract class. """ def __init__(self,Prefix,Name,Value=None,Delimiter=None,\ Quote=None,IsPath=None): """Initialize the Parameter object. Prefix: the character(s) preceding the name of the parameter (eg. '-' for a '-a' parameter) Name: the name of the parameter (eg. 'a' for a '-a' parameter) Value: the value of the parameter (eg. '9' in a '-t=9' parameter) The value is also used in subclasses to turn parameters on and off Delimiter: the character separating the identifier and the value, (eg. '=' for a '-t=9' command or ' ' for a '-t 9' parameter) Quote: the character to use when quoting the value (eg. "\"" for a '-l="hello" parameter). At this point asymmetrical quotes are not possible (ie. [4]) WARNING: You must escape the quote in most cases. IsPath: boolean indicating whether Value is a file path, and should therefore be cast to a FilePath object WARNING: Don't set Quote='"' and set IsPath=True. This would result in two sets of double quotes being wrapped around the path when it is printed, and the application would most likely fail. We explicitly disallow this with: if self.IsPath and self.Quote == '"': self.Quote = None Id: The combination of Prefix and Name is called the identifier (Id) of the parameter. (eg. '-a' for a '-a' parameter, or '-t' for a '-t=9' parameter) This is intended to be an abstract class and has no use otherwise. To subclass Parameter, the subclass should implement the following methods: __str__(): returns the parameter as a string when turned on, or as an empty string when turned off on(): turns the parameter on isOn(): return True if a parameter is on, otherwise False off(): turns the parameter off isOff(): return True if a parameter is off, otherwise False Whether a parameter is on or off can be specified in different ways in subclasses, your isOn() and isOff() methods should define this. Optionally you can overwrite __init__, but you should be sure to either call the superclass init or handle the setting of the self._default attribute (or things will break!) """ self.Name = Name self.Prefix = Prefix self.Delimiter = Delimiter self.Quote = Quote self.Value = Value self.IsPath = IsPath if self.IsPath and self.Quote == '"': self.Quote = None def _get_id(self): """Construct and return the identifier""" return ''.join(map(str,filter(is_not_None,[self.Prefix,self.Name]))) Id = property(_get_id) def __eq__(self,other): """Return True if two parameters are equal""" return (self.IsPath == other.IsPath) and\ (self.Name == other.Name) and\ (self.Prefix == other.Prefix) and\ (self.Delimiter == other.Delimiter) and \ (self.Quote == other.Quote) and \ (self.Value == other.Value) def __ne__(self,other): """Return True if two parameters are not equal to each other""" return not self == other class FlagParameter(Parameter): """Stores information regarding a flag parameter to an application""" def __init__(self,Prefix,Name,Value=False): """Initialize a FlagParameter object Prefix: the character(s) preceding the name of the parameter (eg. '-' for a '-a' parameter) Name: the name of the parameter (eg. 'a' for a '-a' parameter) Value: determines whether the flag is turned on or not; should be True to turn on, or False to turn off, False by default Id: The combination of Prefix and Name is called the identifier (Id) of the parameter. (eg. '-a' for a '-a' parameter, or '-t' for a '-t=9' parameter) Usage: f = FlagParameter(Prefix='-',Name='a') Parameter f is turned off by default, so it won't be used by the application until turned on. or f = FlagParameter(Prefix='+',Name='d',Value=True) Parameter f is turned on. It will be used by the application. """ super(FlagParameter,self).__init__(Name=Name,Prefix=Prefix,\ Value=Value,Delimiter=None,Quote=None) def __str__(self): """Return the parameter as a string. When turned on: string representation of the parameter When turned off: empty string """ if self.isOff(): return '' else: return ''.join(map(str,[self.Prefix,self.Name])) def isOn(self): """Returns True if the FlagParameter is turned on. A FlagParameter is turned on if its Value is True or evaluates to True. A FlagParameter is turned off if its Value is False or evaluates to False. """ if self.Value: return True return False def isOff(self): """Returns True if the parameter is turned off A FlagParameter is turned on if its Value is True or evaluates to True. A FlagParameter is turned off if its Value is False or evaluates to False. """ return not self.isOn() def on(self): """Turns the FlagParameter ON by setting its Value to True""" self.Value = True def off(self): """Turns the FlagParameter OFF by setting its Value to False""" self.Value = False class ValuedParameter(Parameter): """Stores information regarding a valued parameter to an application""" def __init__(self,Prefix,Name,Value=None,Delimiter=None,Quote=None,\ IsPath=False): """Initialize a ValuedParameter object. Prefix: the character(s) preceding the name of the parameter (eg. '-' for a '-a' parameter) Name: the name of the parameter (eg. 'a' for a '-a' parameter) Value: the value of the parameter (eg. '9' in a '-t=9' parameter) Delimiter: the character separating the identifier and the value, (eg. '=' for a '-t=9' command or ' ' for a '-t 9' parameter) Quote: the character to use when quoting the value (eg. "\"" for a '-l="hello" parameter). At this point asymmetrical quotes are not possible (ie. [4]) WARNING: You must escape the quote in most cases. IsPath: boolean indicating whether Value is a file path, and should therefore be cast to a FilePath object Id: The combination of Prefix and Name is called the identifier (Id) of the parameter. (eg. '-a' for a '-a' parameter, or '-t' for a '-t=9' parameter) Default: the default value of the parameter; this is defined as what is passed into init for Value and can not be changed after object initialization Usage: v = ValuedParameter(Prefix='-',Name='a',Delimiter=' ',Value=3) the parameter is turned on by default (value=3) and will be used by the application as '-a 3'. or v = ValuedParameter(Prefix='-',Name='d',Delimiter='=') the parameter is turned off by default and won't be used by the application unless turned on with some value. """ if IsPath and Value: Value=FilePath(Value) super(ValuedParameter,self).__init__(Name=Name,Prefix=Prefix,\ Value=Value,Delimiter=Delimiter,Quote=Quote,IsPath=IsPath) self._default = Value def __str__(self): """Return the parameter as a string When turned on: string representation of the parameter When turned off: empty string """ if self.isOff(): return '' else: parts = [self.Prefix,self.Name,self.Delimiter,\ self.Quote,self.Value,self.Quote] return ''.join(map(str,filter(is_not_None,parts))) def __eq__(self,other): """Return True if two parameters are equal""" return (self.Name == other.Name) and\ (self.Prefix == other.Prefix) and\ (self.Delimiter == other.Delimiter) and \ (self.Quote == other.Quote) and \ (self.Value == other.Value) and\ (self._default == other._default) def _get_default(self): """Get the default value of the ValuedParameter Accessed as a property to avoid the user changing this after initialization. """ return self._default Default = property(_get_default) def reset(self): """Reset Value of the ValuedParameter to the default""" self.Value = self._default def isOn(self): """Returns True if the ValuedParameter is turned on A ValuedParameter is turned on if its Value is not None. A ValuedParameter is turned off if its Value is None. """ if self.Value is not None: return True return False def isOff(self): """Returns True if the ValuedParameter is turned off A ValuedParameter is turned on if its Value is not None. A ValuedParameter is turned off if its Value is None. """ return not self.isOn() def on(self,val): """Turns the ValuedParameter ON by setting its Value to val An attempt to turn the parameter on with value 'None' will result in an error, since this is the same as turning the parameter off. """ if val is None: raise ParameterError,\ "Turning the ValuedParameter on with value None is the same as "+\ "turning it off. Use another value." elif self.IsPath: self.Value = FilePath(val) else: self.Value = val def off(self): """Turns the ValuedParameter OFF by setting its Value to None""" self.Value = None class MixedParameter(ValuedParameter): """Stores information regarding a mixed parameter to an application A mixed parameter is a mix between a FlagParameter and a ValuedParameter. When its Value is False, the parameter will be turned off. When its Value is set to None, the parameter will behave like a flag. When its Value is set to anything but None or False, it will behave like a ValuedParameter. Example: RNAfold [-d[0|1]] You can give either '-d' or '-d0' or '-d1' as input. """ def __init__(self,Prefix,Name,Value=False,Delimiter=None,Quote=None,\ IsPath=False): """Initialize a MixedParameter object Prefix: the character(s) preceding the name of the parameter (eg. '-' for a '-a' parameter) Name: the name of the parameter (eg. 'a' for a '-a' parameter) Value: the value of the parameter (eg. '9' in a '-t=9' parameter) Delimiter: the character separating the identifier and the value, (eg. '=' for a '-t=9' command or ' ' for a '-t 9' parameter) Quote: the character to use when quoting the value (eg. "\"" for a '-l="hello" parameter). At this point asymmetrical quotes are not possible (ie. [4]) WARNING: You must escape the quote in most cases. IsPath: boolean indicating whether Value is a file path, and should therefore be cast to a FilePath object Id: The combination of Prefix and Name is called the identifier (Id) of the parameter. (eg. '-a' for a '-a' parameter, or '-t' for a '-t=9' parameter) Default: the default value of the parameter; this is defined as what is passed into init for Value and can not be changed after object initialization Usage: m = MixedParameter(Prefix='-',Name='a',Delimiter=' ',Value=3) the parameter is turned on by default (value=3) and will be used by the application as '-a 3'. or m = MixedParameter(Prefix='-',Name='d',Delimiter='=',Value=None) the parameter is turned on by default as a flag parameter and will be used by the application as '-d'. or m = MixedParameter(Prefix='-',Name='d',Delimiter='=') the parameter is turned off by default (Value=False) and won't be used by the application unless turned on with some value. """ if IsPath and Value: Value=FilePath(Value) super(MixedParameter,self).__init__(Name=Name,Prefix=Prefix,\ Value=Value,Delimiter=Delimiter,Quote=Quote,IsPath=IsPath) def __str__(self): """Return the parameter as a string When turned on: string representation of the parameter When turned off: empty string """ if self.isOff(): return '' elif self.Value is None: return ''.join(map(str,[self.Prefix,self.Name])) else: parts = [self.Prefix,self.Name,self.Delimiter,\ self.Quote,self.Value,self.Quote] return ''.join(map(str,filter(is_not_None,parts))) def isOn(self): """Returns True if the MixedParameter is turned on A MixedParameter is turned on if its Value is not False. A MixedParameter is turned off if its Value is False. A MixedParameter is used as flag when its Value is None. A MixedParameter is used as ValuedParameter when its Value is anything but None or False. """ if self.Value is not False: return True return False def isOff(self): """Returns True if the MixedParameter is turned off A MixedParameter is turned on if its Value is not False. A MixedParameter is turned off if its Value is False. """ return not self.isOn() def on(self,val=None): """Turns the MixedParameter ON by setting its Value to val An attempt to turn the parameter on with value 'False' will result in an error, since this is the same as turning the parameter off. Turning the MixedParameter ON without a value or with value 'None' will let the parameter behave as a flag. """ if val is False: raise ParameterError,\ "Turning the ValuedParameter on with value False is the same as "+\ "turning it off. Use another value." elif self.IsPath: self.Value = FilePath(val) else: self.Value = val def off(self): """Turns the MixedParameter OFF by setting its Value to False""" self.Value = False def _find_synonym(synonyms): """ Returns function to lookup a key in synonyms dictionary. Inteded for use by the Parameters object. """ def check_key(key): if key in synonyms: return synonyms[key] return key return check_key class Parameters(MappedDict): """Parameters is a dictionary of Parameter objects. Parameters provides a mask that lets the user lookup and access parameters by its synonyms. """ def __init__(self,parameters={},synonyms={}): """Initialize the Parameters object. parameters: a dictionary of Parameter objects keyed by their identifier synonyms: a dictionary of synonyms. Keys are synonyms, values are parameter identifiers. """ mask = FunctionWrapper(_find_synonym(synonyms)) super(Parameters,self).__init__(data=deepcopy(parameters),Mask=mask) self.__setitem__ = self.setdefault = self.update =\ self.__delitem__ = self._raiseNotImplemented def _raiseNotImplemented(self,*args): """Raises an error for an attempt to change a Parameters object""" raise NotImplementedError, 'Parameters object is immutable' def all_off(self): """Turns all parameters in the dictionary off""" for v in self.values(): v.off() pycogent-1.9/cogent/app/parsinsert.py000066400000000000000000000064171273014367000200310ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for ParsInsert designed for ParsInsert v1.03 """ __author__ = "Jesse Stombaugh" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Jesse Stombaugh"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Jesse Stombaugh" __email__ = "jesse.stombaugh@colorado.edu" __status__ = "Production" from cogent.app.parameters import ValuedParameter, FlagParameter, \ MixedParameter from cogent.app.util import CommandLineApplication, FilePath, system, \ CommandLineAppResult, ResultPath, remove, ApplicationError from cogent.core.tree import PhyloNode from cogent.parse.tree import DndParser from cogent.core.moltype import DNA, RNA, PROTEIN from cogent.core.alignment import SequenceCollection,Alignment from os.path import splitext, join,abspath from cogent.parse.phylip import get_align_for_phylip from StringIO import StringIO class ParsInsert(CommandLineApplication): """ParsInsert application Controller""" _command = 'ParsInsert' _input_handler = '_input_as_multiline_string' _parameters = { # read mask from this file '-m':ValuedParameter('-',Name='m',Delimiter=' '), # read core tree sequences from this file '-s':ValuedParameter('-',Name='s',Delimiter=' '), # read core tree from this file '-t':ValuedParameter('-',Name='t',Delimiter=' '), # read core tree taxomony from this file '-x':ValuedParameter('-',Name='x',Delimiter=' '), # output taxonomy for each insert sequence to this file '-o':ValuedParameter('-',Name='o',Delimiter=' '), # create log file '-l':ValuedParameter('-',Name='l',Delimiter=' '), # number of best matches to display '-n':ValuedParameter('-',Name='n',Delimiter=' '), #percent threshold cutoff '-c':ValuedParameter('-',Name='c',Delimiter=' '), } def _handle_app_result_build_failure(self,out,err,exit_status,result_paths): """ Catch the error when files are not produced """ raise ApplicationError, \ 'ParsInsert failed to produce an output file due to the following error: \n\n%s ' \ % err.read() def _get_result_paths(self,data): """ Get the resulting tree""" result = {} result['Tree'] = ResultPath(Path=splitext(self._input_filename)[0] + \ '.tree') return result def insert_sequences_into_tree(aln, moltype, params={}): """Returns a tree from placement of sequences """ # convert aln to phy since seq_names need fixed to run through parsinsert new_aln=get_align_for_phylip(StringIO(aln)) # convert aln to fasta in case it is not already a fasta file aln2 = Alignment(new_aln) seqs = aln2.toFasta() parsinsert_app = ParsInsert(params=params) result = parsinsert_app(seqs) # parse tree tree = DndParser(result['Tree'].read(), constructor=PhyloNode) # cleanup files result.cleanUp() return tree pycogent-1.9/cogent/app/pfold.py000066400000000000000000000104041273014367000167320ustar00rootroot00000000000000#!/usr/bin/env python """Application controllers for pfold application package Run in the same order as the order in this file(instructions from pfold author) [fasta2col,findphyl,mltree,scfg] """ import os from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" #IMPORTANT!!!! #pfold_path must be set manually to the bin dir in the install dir of pfold if 'PFOLD_BIN_DIR' not in os.environ: raise RuntimeError, \ "The pfold app controller requires PFOLD_BIN_DIR environment variable" else: pfold_path = os.environ['PFOLD_BIN_DIR'] class fasta2col(CommandLineApplication): """Application controller for fasta2col in Pfold package""" _command = 'fasta2col' _input_handler = '_input_as_string' def _input_as_string(self,filename): """Overrides _input_as_string in CommandLineApplication Input file need to be modified by sed""" sed = '| sed \'s/arbitrary/RNA/g\'' data = '%s %s' % (filename,sed) return data def _input_as_lines(self,data): """Overrides _input_as_lines in CommandLineApplication Input file need to be modified by sed""" filename = super(fasta2col,self)._input_as_lines(data) sed = '| sed \'s/arbitrary/RNA/g\'' data = '%s %s' % (filename,sed) return data class findphyl(CommandLineApplication): """Application controller for findphyl in Pfold package Find the phylogeny of the sequences using the neighbour joining approach""" _command = 'findphyl' _input_handler = '_input_as_string' def _input_as_string(self,filename): """Overrides _input_as_string in CommandLineApplication scfg.rate file need to be specified along with the input file""" file = '%s%s' % (pfold_path,'scfg.rate') data = '%s %s' % (file,filename) return data def _input_as_lines(self,data): """Overrides _input_as_lines in CommandLineApplication scfg.rate file need to be specified along with the input file""" filename = super(findphyl,self)._input_as_lines(data) file = '%s%s' % (pfold_path,'scfg.rate') data = '%s %s' % (file,filename) return data class mltree(CommandLineApplication): """Application controller for mltree in pfold package Performs a maximum likelihood estimate of the branch lengths""" _command = 'mltree' _input_handler = '_input_as_string' def _input_as_string(self,filename): """Overrides _input_as_string in CommandLineApplication scfg.rate file need to be specified along with the input file""" file = '%s%s' % (pfold_path,'scfg.rate') data = '%s %s' % (file,filename) return data def _input_as_lines(self,data): """Overrides _input_as_lines in CommandLineApplication scfg.rate file need to be specified along with the input file""" filename = super(mltree,self)._input_as_lines(data) file = '%s%s' % (pfold_path,'scfg.rate') data = '%s %s' % (file,filename) return data class scfg(CommandLineApplication): """Application controller for scfg in Pfold package Performs the analysis The file `article.grm' has the grammar and evolutionary model that is used for the analysis""" _command = 'scfg' _input_handler = '_input_as_string' def _input_as_string(self,filename): """Overrides _input_as_string in CommandLineApplication Additional input information about tree needed from article.grm file""" file = '%s %s%s' % ('--treeinfile',pfold_path,'article.grm') data = '%s %s' % (file,filename) return data def _input_as_lines(self,data): """Overrides _input_as_lines in CommandLineApplication Additional input information about tree needed from article.grm file""" filename = super(scfg,self)._input_as_lines(data) file = '%s %s%s' % ('--treeinfile',pfold_path,'article.grm') data = '%s %s' % (file,filename) return data pycogent-1.9/cogent/app/pknotsrg.py000066400000000000000000000044501273014367000175010ustar00rootroot00000000000000#!/usr/bin/env python from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class PknotsRG(CommandLineApplication): """Application controller for PknotsRG v1.2 application Input: plain seqeunce pknotsRG is a tool for thermodynamic folding of RNA secondary structures, including the class of canonical simple recursive pseudoknots. Options: -m Use mfe strategy -f Use enf strategy -l Use loc strategy -s Show suboptimals -u no dangling bases (implies -s) -o no suboptimals inside pknots (implies -s -l) -e Set energy range for suboptimals (kcal/mole) -c Set energy range for suboptimals (%) [10] -n Set npp-value [0.3] -p Set pkinit-value [9] -k Set maximal pknot-length """ _parameters = { '-m':FlagParameter(Prefix='-',Name='m'), '-f':FlagParameter(Prefix='-',Name='f'), '-l':FlagParameter(Prefix='-',Name='l'), '-s':FlagParameter(Prefix='-',Name='s'), '-u':FlagParameter(Prefix='-',Name='u'), '-o':FlagParameter(Prefix='-',Name='o'), '-e':ValuedParameter(Prefix='-',Name='e',Delimiter=' '), '-c':ValuedParameter(Prefix='-',Name='c',Delimiter=' '), '-n':ValuedParameter(Prefix='-',Name='n',Delimiter=' '), '-p':ValuedParameter(Prefix='-',Name='p',Delimiter=' '), '-k':ValuedParameter(Prefix='-',Name='k',Delimiter=' ')} _command = 'pknotsRG-1.2-i386-linux-static' _input_handler = '_input_as_string' def _input_as_string(self,filename): """Returns '>filename' to redirect input to stdin""" return ''.join(['<',super(PknotsRG,self)._input_as_string(filename)]) def _input_as_lines(self,data): """Returns '>temp_filename to redirect input to stdin""" return ''.join(['<',super(PknotsRG,self)._input_as_lines(data)]) pycogent-1.9/cogent/app/pplacer.py000066400000000000000000000207611273014367000172630ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for pplacer 1.1""" __author__ = "Kyle Bittinger" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Kyle Bittinger","Jesse Stombaugh"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Kyle Bittinger" __email__ = "kylebittinger@gmail.com" __status__ = "Production" from cogent.app.parameters import ValuedParameter, FlagParameter from cogent.app.util import CommandLineApplication, FilePath, system, \ CommandLineAppResult, ResultPath, remove, ApplicationError, \ get_tmp_filename from cogent.core.alignment import Alignment from cogent.app.guppy import build_tree_from_json_using_params from os.path import splitext,abspath,join,split from StringIO import StringIO from cogent.parse.phylip import get_align_for_phylip from cogent.parse.tree import DndParser from cogent.core.tree import PhyloNode class Pplacer(CommandLineApplication): """pplacer Application Controller """ _command = 'pplacer' _input_handler = '_input_as_multiline_string' _parameters = { # -c Specify the path to the reference package. '-c': ValuedParameter('-', Name='c', Delimiter=' ', IsPath=True), # -t Specify the reference tree filename. '-t': ValuedParameter('-', Name='t', Delimiter=' ', IsPath=True), # -r Specify the reference alignment filename. '-r': ValuedParameter('-', Name='r', Delimiter=' ', IsPath=True), # -s Supply a phyml stats.txt or a RAxML info file giving the model parameters. '-s': ValuedParameter('-', Name='s', Delimiter=' ', IsPath=True), # -d Specify the directory containing the reference information. '-d': ValuedParameter('-', Name='d', Delimiter=' ', IsPath=True), # -p Calculate posterior probabilities. '-p': FlagParameter('-', Name='p'), # -m Substitution model. Protein: are LG, WAG, or JTT. Nucleotides: GTR. '-m': ValuedParameter('-', Name='m', Delimiter=' '), # --model-freqs Use model frequencies instead of reference alignment frequencies. '--model-freqs': FlagParameter('--', Name='model-freqs'), # --gamma-cats Number of categories for discrete gamma model. '--gamma-cats': ValuedParameter('--', Name='gamma-cats', Delimiter=' '), # --gamma-alpha Specify the shape parameter for a discrete gamma model. '--gamma-alpha': ValuedParameter('--', Name='gamma-alpha', Delimiter=' '), # --ml-tolerance 1st stage branch len optimization tolerance (2nd stage to 1e-5). Default: 0.01. '--ml-tolerance': ValuedParameter('--', Name='ml-tolerance', Delimiter=' '), # --pp-rel-err Relative error for the posterior probability calculation. Default is 0.01. '--pp-rel-err': ValuedParameter('--', Name='pp-rel-err', Delimiter=' '), # --unif-prior Use a uniform prior rather than exponential. '--unif-prior': FlagParameter('--', Name='unif-prior'), # --start-pend Starting pendant branch length. Default is 0.1. '--start-pend': ValuedParameter('--', Name='start-pend', Delimiter=' '), # --max-pend Set the maximum ML pendant branch length. Default is 2. '--max-pend': ValuedParameter('--', Name='max-pend', Delimiter=' '), # --max-strikes Maximum number of strikes for baseball. 0 -> no ball playing. Default is 6. '--max-strikes': ValuedParameter('--', Name='max-strikes', Delimiter=' '), # --strike-box Set the size of the strike box in log likelihood units. Default is 3. '--strike-box': ValuedParameter('--', Name='strike-box', Delimiter=' '), # --max-pitches Set the maximum number of pitches for baseball. Default is 40. '--max-pitches': ValuedParameter('--', Name='max-pitches', Delimiter=' '), # --fantasy Desired likelihood cutoff for fantasy baseball mode. 0 -> no fantasy. '--fantasy': ValuedParameter('--', Name='fantasy', Delimiter=' '), # --fantasy-frac Fraction of fragments to use when running fantasy baseball. Default is 0.1. '--fantasy-frac': ValuedParameter('--', Name='fantasy-frac', Delimiter=' '), # --write-masked Write alignment masked to the region without gaps in the query. '--write-masked': FlagParameter('--', Name='write-masked'), # --verbosity Set verbosity level. 0 is silent, and 2 is quite a lot. Default is 1. '--verbosity': ValuedParameter('--', Name='verbosity', Delimiter=' '), # --unfriendly Do not run friend finder pre-analysis. '--unfriendly': FlagParameter('--', Name='unfriendly'), # --out-dir Specify the directory to write place files to. '--out-dir': ValuedParameter('--', Name='out-dir', Delimiter=' ', IsPath=True), # --pretend Only check out the files then report. Do not run the analysis. '--pretend': FlagParameter('--', Name='pretend'), # --csv Make a CSV file with the results. '--csv': FlagParameter('--', Name='csv'), # --old-format Make an old-format placefile with the resuls. '--old-format': FlagParameter('--', Name='old-format'), # --diagnostic Write file describing the 'diagnostic' mutations for various clades. '--diagnostic': FlagParameter('--', Name='diagnostic'), # --check-like Write out the likelihood of the reference tree, calculated two ways. '--check-like': FlagParameter('--', Name='check-like'), # --version Write out the version number and exit. '--version': FlagParameter('--', Name='version'), # --help Display this list of options '--help': FlagParameter('--', Name='help'), } def getTmpFilename(self, tmp_dir="/tmp",prefix='tmp',suffix='.fasta',\ include_class_id=False,result_constructor=FilePath): """ Define Tmp filename to contain .fasta suffix, since pplacer requires the suffix to be .fasta """ return super(Pplacer,self).getTmpFilename(tmp_dir=tmp_dir, prefix=prefix, suffix=suffix, include_class_id=include_class_id, result_constructor=result_constructor) def _handle_app_result_build_failure(self,out,err,exit_status,result_paths): """ Catch the error when files are not produced """ raise ApplicationError, \ 'Pplacer failed to produce an output file due to the following error: \n\n%s ' \ % out.read() def _get_result_paths(self,data): """ Define the output filepaths """ output_dir = self.Parameters['--out-dir'].Value result = {} result['json'] = ResultPath(Path=join(output_dir, splitext(split(self._input_filename)[-1])[0] + \ '.jplace')) return result def insert_sequences_into_tree(aln, moltype, params={}, write_log=True): """Returns a tree from Alignment object aln. aln: an xxx.Alignment object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object params: dict of parameters to pass in to the RAxML app controller. The result will be an xxx.Alignment object, or None if tree fails. """ # convert aln to phy since seq_names need fixed to run through pplacer new_aln=get_align_for_phylip(StringIO(aln)) # convert aln to fasta in case it is not already a fasta file aln2 = Alignment(new_aln) seqs = aln2.toFasta() ih = '_input_as_multiline_string' pplacer_app = Pplacer(params=params, InputHandler=ih, WorkingDir=None, SuppressStderr=False, SuppressStdout=False) pplacer_result = pplacer_app(seqs) # write a log file if write_log: log_fp = join(params["--out-dir"],'log_pplacer_' + \ split(get_tmp_filename())[-1]) log_file=open(log_fp,'w') log_file.write(pplacer_result['StdOut'].read()) log_file.close() # use guppy to convert json file into a placement tree guppy_params={'tog':None} new_tree=build_tree_from_json_using_params(pplacer_result['json'].name, \ output_dir=params['--out-dir'], \ params=guppy_params) pplacer_result.cleanUp() return new_tree pycogent-1.9/cogent/app/raxml.py000066400000000000000000001177701273014367000167670ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for RAxML (v7.3.0). WARNING: Because of the use of the -x option, this version is no longer compatible with RAxML version VI. """ from cogent.app.parameters import FlagParameter, ValuedParameter, FilePath from cogent.app.util import CommandLineApplication, ResultPath, \ get_tmp_filename,ApplicationError from cogent.core.tree import PhyloNode from cogent.core.alignment import Alignment from cogent.core.moltype import DNA, RNA, PROTEIN from random import choice, randint from os import walk,listdir from os.path import isabs,join,split from cogent.parse.tree import DndParser import re from cogent.app.guppy import build_tree_from_json_using_params __author__ = "Micah Hamady" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Micah Hamady", "Catherine Lozupone", "Rob Knight", \ "Daniel McDonald","Jesse Stombaugh"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Jesse Stombaugh" __email__ = "jesse.stombaugh@colorado.edu" __status__ = "Production" class Raxml(CommandLineApplication): """RAxML application controller""" _options ={ # Specify a column weight file name to assign individual wieghts to # each column of the alignment. Those weights must be integers # separated by any number and type of whitespaces whithin a separate # file, see file "example_weights" for an example. '-a':ValuedParameter('-',Name='a',Delimiter=' '), # Specify one of the secondary structure substitution models implemented # in RAxML. The same nomenclature as in the PHASE manual is used, # available models: S6A, S6B, S6C, S6D, S6E, S7A, S7B, S7C, S7D, S7E, # S7F, S16, S16A, S16B # DEFAULT: 16-state GTR model (S16) '-A':ValuedParameter('-',Name='A',Delimiter=' '), # Specify an integer number (random seed) for bootstrapping '-b':ValuedParameter('-',Name='b',Delimiter=' '), # specify a floating point number between 0.0 and 1.0 that will be used # as cutoff threshold for the MR-based bootstopping criteria. The # recommended setting is 0.03. '-B':ValuedParameter('-',Name='B',Delimiter=' '), # Specify number of distinct rate catgories for raxml when # ModelOfEvolution is set to GTRCAT or HKY85CAT. # Individual per-site rates are categorized into numberOfCategories # rate categories to accelerate computations. (Default = 50) '-c':ValuedParameter('-',Name='c',Delimiter=' '), # Conduct model parameter optimization on gappy, partitioned multi-gene # alignments with per-partition branch length estimates (-M enabled) # using the fast method with pointer meshes described in: # Stamatakis and Ott: "Efficient computation of the phylogenetic # likelihood function on multi-gene alignments and multi-core # processors" # WARNING: We can not conduct useful tree searches using this method # yet! Does not work with Pthreads version. '-C':ValuedParameter('-',Name='C',Delimiter=' '), # This option allows you to start the RAxML search with a complete # random starting tree instead of the default Maximum Parsimony # Starting tree. On smaller datasets (around 100-200 taxa) it has # been observed that this might sometimes yield topologies of distinct # local likelihood maxima which better correspond to empirical # expectations. '-d':FlagParameter('-',Name='d'), # ML search convergence criterion. This will break off ML searches if # the relative Robinson-Foulds distance between the trees obtained from # two consecutive lazy SPR cycles is smaller or equal to 1%. Usage # recommended for very large datasets in terms of taxa. On trees with # more than 500 taxa this will yield execution time improvements of # approximately 50% While yielding only slightly worse trees. # DEFAULT: OFF '-D':ValuedParameter('-',Name='D'), # This allows you to specify up to which likelihood difference. # Default is 0.1 log likelihood units, author recommends 1 or 2 to # rapidly evaluate different trees. '-e':ValuedParameter('-',Name='e',Delimiter=' '), # specify an exclude file name, that contains a specification of # alignment positions you wish to exclude. Format is similar to Nexus, # the file shall contain entries like "100-200 300-400", to exclude a # single column write, e.g., "100-100", if you use a mixed model, an # appropriatly adapted model file will be written. '-E':ValuedParameter('-',Name='E',Delimiter=' '), # select search algorithm: # a rapid Bootstrap analysis and search for best-scoring ML tree in # one program run # A compute marginal ancestral states on a ROOTED reference tree # provided with "t" - ONLY IN 7.3.0 # b draw bipartition information on a tree provided with "-t" based on # multiple trees (e.g., from a bootstrap) in a file specifed by # "-z" # c check if the alignment can be properly read by RAxML # d for normal hill-climbing search (Default) # when -f option is omitted this algorithm will be used # e optimize model+branch lengths for given input tree under # GAMMA/GAMMAI only # E execute very fast experimental tree search, at present only for # testing # F execute fast experimental tree search, at present only for testing # g compute per site log Likelihoods for one ore more trees passed via # "-z" and write them to a file that can be read by CONSEL # WARNING: does not print likelihoods in the original column order # h compute log likelihood test (SH-test) between best tree passed via # "-t" and a bunch of other trees passed via "-z" # i EXPERIMENTAL do not use for real tree inferences: conducts a # single cycle of fast lazy SPR moves on a given input tree, to be # used in combination with -C and -M # I EXPERIMENTAL do not use for real tree inferences: conducts a # single cycle of thorough lazy SPR moves on a given input tree, # to be used in combination with -C and -M # j generate a bunch of bootstrapped alignment files from an original # alignemnt file. You need to specify a seed with "-b" and the # number of replicates with "-#" # following "J" is for version 7.2.8 # J Compute SH-like support values on a given tree passed via "-t". # m compare bipartitions between two bunches of trees passed via "-t" # and "-z" respectively. This will return the Pearson correlation # between all bipartitions found in the two tree files. A file # called RAxML_bipartitionFrequencies.outpuFileName will be # printed that contains the pair-wise bipartition frequencies of # the two sets # n compute the log likelihood score of all trees contained in a tree # file provided by "-z" under GAMMA or GAMMA+P-Invar # o old (slower) algorithm from v. 2.1.3 # p perform pure stepwise MP addition of new sequences to an # incomplete starting tree and exit # r compute pairwise Robinson-Foulds (RF) distances between all pairs # of trees in a tree file passed via "-z" if the trees have node # labales represented as integer support values the program will # also compute two flavors of the weighted Robinson-Foulds (WRF) # distance # following "R" is for version 7.2.8 # R compute rogue taxa using new statistical method based on the # evolutionary placement algorithm # WARNING: this is experimental code - DEPRECATED IN 7.3.0 # s (split) splits into individual genes, provided with model file # following "S" is for version 7.2.8 # S compute site-specific placement bias using a leave one out test # inspired by the evolutionary placement algorithm # t do randomized tree searches on one fixed starting tree # u execute morphological weight calibration using maximum likelihood, # this will return a weight vector. you need to provide a # morphological alignment and a reference tree via "-t" # U execute morphological wieght calibration using parsimony, this # will return a weight vector. you need to provide a morphological # alignment and a reference tree via "-t" - DEPRECATED IN 7.3.0 # v classify a bunch of environmental sequences into a reference tree # using the slow heuristics without dynamic alignment you will # need to start RAxML with a non-comprehensive reference tree and # an alignment containing all sequences (reference + query) # w compute ELW test on a bunch of trees passed via "-z" # x compute pair-wise ML distances, ML model parameters will be # estimated on an MP starting tree or a user-defined tree passed # via "-t", only allowed for GAMMA-based models of rate # heterogeneity # y classify a bunch of environmental sequences into a reference tree # using the fast heuristics without dynamic alignment you will # need to start RAxML with a non-comprehensive reference tree and # an alignment containing all sequences (reference + query) '-f':ValuedParameter('-',Name='f',Delimiter=' ', Value="d"), # enable ML tree searches under CAT model for very large trees without # switching to GAMMA in the end (saves memory). This option can also be # used with the GAMMA models in order to avoid the thorough optimization # of the best-scoring ML tree in the end. # DEFAULT: OFF '-F':FlagParameter('-',Name='F'), # select grouping file name: allows incomplete multifurcating constraint # tree in newick format -- resolves multifurcations randomly, adds # other taxa using parsimony insertion '-g':ValuedParameter('-', Name='g',Delimiter=' '), # enable the ML-based evolutionary placement algorithm heuristics by # specifiyng a threshold value (fraction of insertion branches to be # evaluated using slow insertions under ML). '-G':FlagParameter('-', Name='G'), # prints help and exits '-h':FlagParameter('-', Name='h'), # enable the MP-based evolutionary placement algorithm heuristics # by specifiyng a threshold value (fraction of insertion branches to be # evaluated using slow insertions under ML) - DEPRECATED IN 7.3.0 #'-H':ValuedParameter('-', Name='H',Delimiter=' '), # allows initial rearrangement to be constrained, e.g. 10 means # insertion will not be more than 10 nodes away from original. # default is to pick a "good" setting. '-i':ValuedParameter('-', Name='i', Delimiter=' '), # a posteriori bootstopping analysis. Use: # "-I autoFC" for the frequency-based criterion # "-I autoMR" for the majority-rule consensus tree criterion # "-I autoMRE" for the extended majority-rule consensus tree criterion # "-I autoMRE_IGN" for metrics similar to MRE, but include # bipartitions under the threshold whether they are compatible # or not. This emulates MRE but is faster to compute. # You also need to pass a tree file containg several bootstrap # replicates via "-z" '-I':ValuedParameter('-', Name='I', Delimiter=' '), # writes checkpoints (off by default) '-j':FlagParameter('-', Name='j'), # Compute majority rule consensus tree with "-J MR" or extended majority # rule consensus tree with "-J MRE" or strict consensus tree with "-J # STRICT" You will need to provide a tree file containing several # UNROOTED trees via "-z" '-J':ValuedParameter('-', Name='J', Delimiter=' '), #specifies that RAxML will optimize model parameters (for GTRMIX and # GTRGAMMA) as well as calculating likelihoods for bootstrapped trees. '-k':FlagParameter('-', Name='k'), # Specify one of the multi-state substitution models (max 32 states) # implemented in RAxML. Available models are: ORDERED, MK, GTR '-K':ValuedParameter('-', Name='K', Delimiter=' '), # Model of Binary (Morphological), Nucleotide, Multi-State, or Amino # Acid Substitution:: # BINARY: # -m BINCAT : Optimization of site-specific evolutionary rates which # are categorized into numberOfCategories distinct rate categories # for greater computational efficiency. Final tree might be # evaluated automatically under BINGAMMA, depending on the tree # search option # -m BINCATI : Optimization of site-specific evolutionary rates which # are categorized into numberOfCategories distinct rate categories # for greater computational efficiency. Final tree might be # evaluated automatically under BINGAMMAI, depending on the tree # search option # -m BINGAMMA : GAMMA model of rate heterogeneity (alpha parameter # will be estimated) # -m BINGAMMAI : Same as BINGAMMA, but with estimate of proportion of # invariable sites # NUCLEOTIDES # -m GTRCAT: GTR + Optimization of substitution rates + Optimization # of site-specific evolutionary rates which are categorized into # numberOfCategories distinct rate categories for greater # computational efficiency # -m GTRCAT_FLOAT : Same as above but uses single-precision floating # point arithemtics instead of double-precision Usage only # recommened for testing, the code will run slower, but can save # almost 50% of memory. If you have problems with phylogenomic # datasets and large memory requirements you may give it a shot. # Keep in mind that numerical stability seems to be okay but needs # further testing. - DEPRECATED IN 7.3.0 # -m GTRCATI : GTR + Optimization of substitution rates + Optimization # of site-specific evolutionary rates which are categorized into # numberOfCategories distinct rate categories for greater # computational efficiency. Final tree might be evaluated under # GTRGAMMAI, depending on the tree search option # -m GTRGAMMA: GTR + Optimization of substitution rates + Gamma # -m GTRGAMMA_FLOAT : Same as GTRGAMMA, but also with # single-precision arithmetics, same cautionary notes as for # GTRCAT_FLOAT apply. - DEPRECATED IN 7.3.0 # -m GTRGAMMAI : Same as GTRGAMMA, but with estimate of proportion of # invariable sites # MULTI-STATE: # -m MULTICAT : Optimization of site-specific evolutionary rates which # are categorized into numberOfCategories distinct rate categories # for greater computational efficiency. Final tree might be # evaluated automatically under MULTIGAMMA, depending on the tree # search option # -m MULTICATI : Optimization of site-specific evolutionary rates # which are categorized into numberOfCategories distinct rate # categories for greater computational efficiency. Final tree # might be evaluated automatically under MULTIGAMMAI, depending on # the tree search option # -m MULTIGAMMA : GAMMA model of rate heterogeneity (alpha parameter # will be estimated) # -m MULTIGAMMAI : Same as MULTIGAMMA, but with estimate of proportion # of invariable sites # You can use up to 32 distinct character states to encode multi-state # regions, they must be used in the following order: 0, 1, 2, 3, 4, 5, # 6, 7, 8, 9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, # T, U, V i.e., if you have 6 distinct character states you would use 0, # 1, 2, 3, 4, 5 to encode these. The substitution model for the # multi-state regions can be selected via the "-K" option # Amino Acid Models: # -m PROTCATmatrixName[F] : specified AA matrix + Optimization of # substitution rates + Optimization of site-specific evolutionary # rates which are categorized into numberOfCategories distinct # rate categories for greater computational efficiency. Final # tree might be evaluated automatically under # PROTGAMMAmatrixName[f], depending on the tree search option # -m PROTCATmatrixName[F]_FLOAT : PROTCAT with single precision # arithmetics, same cautionary notes as for GTRCAT_FLOAT apply # - DEPRECATED IN 7.3.0 # -m PROTCATImatrixName[F] : specified AA matrix + Optimization of # substitution rates + Optimization of site-specific # evolutionary rates which are categorized into numberOfCategories # distinct rate categories for greater computational efficiency. # Final tree might be evaluated automatically under # PROTGAMMAImatrixName[f], depending on the tree search option # -m PROTGAMMAmatrixName[F] : specified AA matrix + Optimization of # substitution rates + GAMMA model of rate heterogeneity (alpha # parameter will be estimated) # -m PROTGAMMAmatrixName[F]_FLOAT : PROTGAMMA with single precision # arithmetics, same cautionary notes as for GTRCAT_FLOAT apply # - DEPRECATED IN 7.3.0 # -m PROTGAMMAImatrixName[F] : Same as PROTGAMMAmatrixName[F], but # with estimate of proportion of invariable sites # Available AA substitution models: DAYHOFF, DCMUT, JTT, MTREV, WAG, # RTREV, CPREV, VT, BLOSUM62, MTMAM, LG, GTR. With the optional "F" # appendix you can specify if you want to use empirical base frequencies # Please note that for mixed models you can in addition specify the # per-gene AA model in the mixed model file (see manual for details). # Also note that if you estimate AA GTR parameters on a partitioned # dataset, they will be linked (estimated jointly) across all partitions # to avoid over-parametrization '-m':ValuedParameter('-',Name='m',Delimiter=' '), # Switch on estimation of individual per-partition branch lengths. Only # has effect when used in combination with "-q". Branch lengths for # individual partitions will be printed to separate files. A weighted # average of the branch lengths is computed by using the respective # partition lengths. # DEFAULT: OFF '-M':FlagParameter('-',Name='M'), # Specifies the name of the output file. '-n':ValuedParameter('-',Name='n',Delimiter=' '), # Specifies the name of the outgroup (or outgroups: comma-delimited, # no spaces, should be monophyletic). '-o':ValuedParameter('-',Name='o',Delimiter=' '), # Enable checkpointing using the dmtcp library available at # http://dmtcp.sourceforge.net/. This only works if you call the program # by preceded by the command "dmtcp_checkpoint" and if you compile a # dedicated binary using the appropriate Makefile. With "-O" you can # specify the interval between checkpoints in seconds. # DEFAULT: 3600.0 seconds - DEPRECATED IN 7.3.0 #'-O':ValuedParameter('-',Name='O',Delimiter=' ',Value=3600.0), # Specify a random number seed for the parsimony inferences. This allows # you to reproduce your results and will help me debug the program. '-p':ValuedParameter('-',Name='p',Delimiter=' '), # Specify the file name of a user-defined AA (Protein) substitution # model. This file must contain 420 entries, the first 400 being the AA # substitution rates (this must be a symmetric matrix) and the last 20 # are the empirical base frequencies '-P':ValuedParameter('-',Name='P',Delimiter=' '), # Specified MultipleModel file name, in format: # gene1 = 1-500 # gene2 = 501-1000 # (note: ranges can also be discontiguous, e.g. 1-100, 200-300, # or can specify codon ranges as e.g. 1-100/3, 2-100/3, 3-100/3)) '-q':ValuedParameter('-', Name='q', Delimiter=' '), # THE FOLLOWING "Q" is DEPRECATED IN 7.2.8 # Turn on computation of SH-like support values on tree. # DEFAULT: OFF '-Q':FlagParameter('-', Name='Q'), # Constraint file name: allows a bifurcating Newick tree to be passed # in as a constraint file, other taxa will be added by parsimony. '-r':ValuedParameter('-',Name='r',Delimiter=' '), # THE FOLLOWING "R" is IN 7.2.8 # Specify the file name of a binary model parameter file that has # previously been generated with RAxML using the -f e tree evaluation # option. The file name should be: RAxML_binaryModelParameters.runID '-R':ValuedParameter('-',Name='R',Delimiter=' '), # specify the name of the alignment data file, in relaxed PHYLIP # format. '-s':ValuedParameter('-',Name='s',Delimiter=' '), # Specify the name of a secondary structure file. The file can contain # "." for alignment columns that do not form part of a stem and # characters "()<>[]{}" to define stem regions and pseudoknots '-S':ValuedParameter('-',Name='S',Delimiter=' '), # Specify a user starting tree file name in Newick format '-t':ValuedParameter('-',Name='t',Delimiter=' '), # PTHREADS VERSION ONLY! Specify the number of threads you want to run. # Make sure to set "-T" to at most the number of CPUs you have on your # machine, otherwise, there will be a huge performance decrease! '-T':ValuedParameter('-',Name='T',Delimiter=' '), # THE FOLLOWING "U" is IN 7.2.8 # Try to save memory by using SEV-based implementation for gap columns # on large gappy alignments # WARNING: this will only work for DNA under GTRGAMMA and is still in an # experimental state. '-U':ValuedParameter('-',Name='U',Delimiter=' '), # Print the version '-v':FlagParameter('-',Name='v'), # Name of the working directory where RAxML-V will write its output # files. '-w':ValuedParameter('-',Name='w',Delimiter=' '), # THE FOLLOWING "W" is IN 7.2.8 # Sliding window size for leave-one-out site-specific placement bias # algorithm only effective when used in combination with "-f S" # DEFAULT: 100 sites '-W':ValuedParameter('-',Name='W',Delimiter=' '), # Specify an integer number (random seed) and turn on rapid # bootstrapping. CAUTION: unlike in version 7.0.4 RAxML will conduct # rapid BS replicates under the model of rate heterogeneity you # specified via "-m" and not by default under CAT '-x':ValuedParameter('-',Name='x',Delimiter=' '), # EXPERIMENTAL OPTION: This option will do a per-site estimate of # protein substitution models by looping over all given, fixed models # LG, WAG, JTT, etc and using their respective base frequencies to # independently assign a prot subst. model to each site via ML # optimization. At present this option only works with the GTR+GAMMA # model, unpartitioned datasets, and in the sequential version only. # DEFAULT: OFF '-X':FlagParameter('-', Name='X'), # Compute only randomized starting parsimony tree with RAxML, do not # optimize an ML analysis of the tree '-y':FlagParameter('-', Name='y'), # Do a more thorough parsimony tree search using a parsimony ratchet and # exit. Specify the number of ratchet searches via "-#" or "-N". This # has just been implemented for completeness, if you want a fast MP # implementation use TNT # DEFAULT: OFF - DEPRECATED IN 7.3.0 #'-Y':FlagParameter('-', Name='Y'), # Multiple tree file, for use with -f b (to draw bipartitions onto the # common tree specified with -t) '-z':ValuedParameter('-', Name='z', Delimiter=' '), # Specifies number of runs on distinct starting trees. '-#':ValuedParameter('-', Name='#', Delimiter=' ',Value=1), # Specifies number of runs on distinct starting trees. '-N':ValuedParameter('-', Name='N', Delimiter=' '), } _parameters = {} _parameters.update(_options) _command = "raxmlHPC" _out_format = "RAxML_%s.%s" def _format_output(self, outfile_name, out_type): """ Prepend proper output prefix to output filename """ outfile_name = self._absolute(outfile_name) outparts = outfile_name.split("/") outparts[-1] = self._out_format % (out_type, outparts[-1] ) return '/'.join(outparts) def _input_as_seqs(self,data): lines = [] for i,s in enumerate(data): #will number the sequences 1,2,3,etc. lines.append(''.join(['>',str(i+1)])) lines.append(s) return self._input_as_lines(lines) def _input_as_lines(self,data): if data: self.Parameters['-s']\ .on(super(Raxml,self)._input_as_lines(data)) return '' def _input_as_string(self,data): """Makes data the value of a specific parameter This method returns the empty string. The parameter will be printed automatically once set. """ if data: self.Parameters['-in'].on(str(data)) return '' def _input_as_multiline_string(self, data): if data: self.Parameters['-s']\ .on(super(Raxml,self)._input_as_multiline_string(data)) return '' def _absolute(self,path): path = FilePath(path) if isabs(path): return path elif self.Parameters['-w'].isOn(): return self.Parameters['-w'].Value + path else: return self.WorkingDir + path def _log_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), "log") else: raise ValueError, "No output file specified." def _info_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), "info") else: raise ValueError, "No output file specified." def _parsimony_tree_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "parsimonyTree") else: raise ValueError, "No output file specified." # added for tree-insertion def _originallabelled_tree_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "originalLabelledTree") else: raise ValueError, "No output file specified." # added for tree-insertion def _labelled_tree_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "labelledTree") else: raise ValueError, "No output file specified." # added for tree-insertion def _classification_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "classification") else: raise ValueError, "No output file specified." # added for tree-insertion def _classificationlikelihoodweights_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "classificationLikelihoodWeights") else: raise ValueError, "No output file specified." # added for tree-insertion def _best_tree_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "bestTree") else: raise ValueError, "No output file specified." # added for tree-insertion def _entropy_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "entropy") else: raise ValueError, "No output file specified." # added for tree-insertion def _json_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "portableTree") else: raise ValueError, "No output file specified." # added for tree-insertion def _parsimony_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "equallyParsimoniousPlacements") else: raise ValueError, "No output file specified." def _result_tree_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "result") else: raise ValueError, "No output file specified." def _result_bootstrap_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "bootstrap") else: raise ValueError, "No output file specified" def _checkpoint_out_filenames(self): """ RAxML generates a crapload of checkpoint files so need to walk directory to collect names of all of them. """ out_filenames = [] if self.Parameters['-n'].isOn(): out_name = str(self.Parameters['-n'].Value) walk_root = self.WorkingDir if self.Parameters['-w'].isOn(): walk_root = str(self.Parameters['-w'].Value) for tup in walk(walk_root): dpath, dnames, dfiles = tup if dpath == walk_root: for gen_file in dfiles: if out_name in gen_file and "checkpoint" in gen_file: out_filenames.append(walk_root + gen_file) break else: raise ValueError, "No output file specified." return out_filenames def _handle_app_result_build_failure(self,out,err,exit_status,result_paths): """ Catch the error when files are not produced """ try: raise ApplicationError, \ 'RAxML failed to produce an output file due to the following error: \n\n%s ' \ % err.read() except: raise ApplicationError,\ 'RAxML failed to run properly.' def _get_result_paths(self,data): result = {} result['Info'] = ResultPath(Path=self._info_out_filename(), IsWritten=True) if self.Parameters['-k'].isOn(): result['Bootstrap'] = ResultPath( Path=self._result_bootstrap_out_filename(), IsWritten=True) elif self.Parameters["-f"].Value == 'v': #these were added to handle the results from tree-insertion result['Classification'] = ResultPath( Path=self._classification_out_filename(), IsWritten=True) result['ClassificationLikelihoodWeights'] = ResultPath( Path=self._classificationlikelihoodweights_out_filename(), IsWritten=True) result['OriginalLabelledTree'] = ResultPath( Path=self._originallabelled_tree_out_filename(), IsWritten=True) result['Result'] = ResultPath( Path=self._labelled_tree_out_filename(),IsWritten=True) result['entropy'] = ResultPath( Path=self._entropy_out_filename(),IsWritten=True) result['json'] = ResultPath( Path=self._json_out_filename()+'.jplace',IsWritten=True) elif self.Parameters["-f"].Value == 'y': #these were added to handle the results from tree-insertion result['Parsimony'] = ResultPath( Path=self._parsimony_out_filename(), IsWritten=True) result['OriginalLabelledTree'] = ResultPath( Path=self._originallabelled_tree_out_filename(), IsWritten=True) result['json'] = ResultPath( Path=self._json_out_filename()+'.jplace',IsWritten=True) else: result['Log'] = ResultPath(Path=self._log_out_filename(), IsWritten=True) result['ParsimonyTree'] = ResultPath( Path=self._parsimony_tree_out_filename(), IsWritten=True) result['Result'] = ResultPath( Path=self._result_tree_out_filename(), IsWritten=True) # result['besttree'] = ResultPath( Path=self._best_tree_out_filename(), IsWritten=True) for checkpoint_file in self._checkpoint_out_filenames(): checkpoint_num = checkpoint_file.split(".")[-1] try: checkpoint_num = int(checkpoint_num) except Exception, e: raise ValueError, "%s does not appear to be a valid checkpoint file" result['Checkpoint%d' % checkpoint_num] = ResultPath( Path=checkpoint_file, IsWritten=True) return result #SOME FUNCTIONS TO EXECUTE THE MOST COMMON TASKS def raxml_alignment(align_obj, raxml_model="GTRCAT", params={}, SuppressStderr=True, SuppressStdout=True): """Run raxml on alignment object align_obj: Alignment object params: you can set any params except -w and -n returns: tuple (phylonode, parsimonyphylonode, log likelihood, total exec time) """ # generate temp filename for output params["-w"] = "/tmp/" params["-n"] = get_tmp_filename().split("/")[-1] params["-m"] = raxml_model params["-p"] = randint(1,100000) ih = '_input_as_multiline_string' seqs, align_map = align_obj.toPhylip() #print params["-n"] # set up command raxml_app = Raxml( params=params, InputHandler=ih, WorkingDir=None, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout) # run raxml ra = raxml_app(seqs) # generate tree tree_node = DndParser(ra["Result"]) # generate parsimony tree parsimony_tree_node = DndParser(ra["ParsimonyTree"]) # extract log likelihood from log file log_file = ra["Log"] total_exec_time = exec_time = log_likelihood = 0.0 for line in log_file: exec_time, log_likelihood = map(float, line.split()) total_exec_time += exec_time # remove output files ra.cleanUp() return tree_node, parsimony_tree_node, log_likelihood, total_exec_time def build_tree_from_alignment(aln, moltype, best_tree=False, params={}): """Returns a tree from Alignment object aln. aln: an xxx.Alignment object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object best_tree: best_tree suppport is currently not implemented params: dict of parameters to pass in to the RAxML app controller. The result will be an xxx.Alignment object, or None if tree fails. """ if best_tree: raise NotImplementedError if '-m' not in params: if moltype == DNA or moltype == RNA: #params["-m"] = 'GTRMIX' # in version 7.2.3, GTRMIX is no longer supported but says GTRCAT # behaves like GTRMIX (http://www.phylo.org/tools/raxmlhpc2.html) params["-m"] = 'GTRGAMMA' elif moltype == PROTEIN: params["-m"] = 'PROTGAMMAmatrixName' else: raise ValueError, "Moltype must be either DNA, RNA, or PROTEIN" if not hasattr(aln, 'toPhylip'): aln = Alignment(aln) seqs, align_map = aln.toPhylip() # generate temp filename for output params["-w"] = "/tmp/" params["-n"] = get_tmp_filename().split("/")[-1] params["-k"] = True params["-p"] = randint(1,100000) params["-x"] = randint(1,100000) ih = '_input_as_multiline_string' raxml_app = Raxml(params=params, InputHandler=ih, WorkingDir=None, SuppressStderr=True, SuppressStdout=True) raxml_result = raxml_app(seqs) tree = DndParser(raxml_result['Bootstrap'], constructor=PhyloNode) for node in tree.tips(): node.Name = align_map[node.Name] raxml_result.cleanUp() return tree def insert_sequences_into_tree(seqs, moltype, params={}, write_log=True): """Insert sequences into Tree. aln: an xxx.Alignment object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object params: dict of parameters to pass in to the RAxML app controller. The result will be a tree. """ ih = '_input_as_multiline_string' raxml_app = Raxml(params=params, InputHandler=ih, WorkingDir=None, SuppressStderr=False, SuppressStdout=False, HALT_EXEC=False) raxml_result = raxml_app(seqs) # write a log file if write_log: log_fp = join(params["-w"],'log_raxml_'+split(get_tmp_filename())[-1]) log_file=open(log_fp,'w') log_file.write(raxml_result['StdOut'].read()) log_file.close() ''' # getting setup since parsimony doesn't output tree..only jplace, however # it is currently corrupt # use guppy to convert json file into a placement tree guppy_params={'tog':None} new_tree=build_tree_from_json_using_params(raxml_result['json'].name, \ output_dir=params["-w"], \ params=guppy_params) ''' # get tree from 'Result Names' new_tree=raxml_result['Result'].readlines() filtered_tree=re.sub('\[I\d+\]','',str(new_tree)) tree = DndParser(filtered_tree, constructor=PhyloNode) raxml_result.cleanUp() return tree pycogent-1.9/cogent/app/raxml_v730.py000066400000000000000000001177701273014367000175460ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for RAxML (v7.3.0). WARNING: Because of the use of the -x option, this version is no longer compatible with RAxML version VI. """ from cogent.app.parameters import FlagParameter, ValuedParameter, FilePath from cogent.app.util import CommandLineApplication, ResultPath, \ get_tmp_filename,ApplicationError from cogent.core.tree import PhyloNode from cogent.core.alignment import Alignment from cogent.core.moltype import DNA, RNA, PROTEIN from random import choice, randint from os import walk,listdir from os.path import isabs,join,split from cogent.parse.tree import DndParser import re from cogent.app.guppy import build_tree_from_json_using_params __author__ = "Micah Hamady" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Micah Hamady", "Catherine Lozupone", "Rob Knight", \ "Daniel McDonald","Jesse Stombaugh"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Jesse Stombaugh" __email__ = "jesse.stombaugh@colorado.edu" __status__ = "Production" class Raxml(CommandLineApplication): """RAxML application controller""" _options ={ # Specify a column weight file name to assign individual wieghts to # each column of the alignment. Those weights must be integers # separated by any number and type of whitespaces whithin a separate # file, see file "example_weights" for an example. '-a':ValuedParameter('-',Name='a',Delimiter=' '), # Specify one of the secondary structure substitution models implemented # in RAxML. The same nomenclature as in the PHASE manual is used, # available models: S6A, S6B, S6C, S6D, S6E, S7A, S7B, S7C, S7D, S7E, # S7F, S16, S16A, S16B # DEFAULT: 16-state GTR model (S16) '-A':ValuedParameter('-',Name='A',Delimiter=' '), # Specify an integer number (random seed) for bootstrapping '-b':ValuedParameter('-',Name='b',Delimiter=' '), # specify a floating point number between 0.0 and 1.0 that will be used # as cutoff threshold for the MR-based bootstopping criteria. The # recommended setting is 0.03. '-B':ValuedParameter('-',Name='B',Delimiter=' '), # Specify number of distinct rate catgories for raxml when # ModelOfEvolution is set to GTRCAT or HKY85CAT. # Individual per-site rates are categorized into numberOfCategories # rate categories to accelerate computations. (Default = 50) '-c':ValuedParameter('-',Name='c',Delimiter=' '), # Conduct model parameter optimization on gappy, partitioned multi-gene # alignments with per-partition branch length estimates (-M enabled) # using the fast method with pointer meshes described in: # Stamatakis and Ott: "Efficient computation of the phylogenetic # likelihood function on multi-gene alignments and multi-core # processors" # WARNING: We can not conduct useful tree searches using this method # yet! Does not work with Pthreads version. '-C':ValuedParameter('-',Name='C',Delimiter=' '), # This option allows you to start the RAxML search with a complete # random starting tree instead of the default Maximum Parsimony # Starting tree. On smaller datasets (around 100-200 taxa) it has # been observed that this might sometimes yield topologies of distinct # local likelihood maxima which better correspond to empirical # expectations. '-d':FlagParameter('-',Name='d'), # ML search convergence criterion. This will break off ML searches if # the relative Robinson-Foulds distance between the trees obtained from # two consecutive lazy SPR cycles is smaller or equal to 1%. Usage # recommended for very large datasets in terms of taxa. On trees with # more than 500 taxa this will yield execution time improvements of # approximately 50% While yielding only slightly worse trees. # DEFAULT: OFF '-D':ValuedParameter('-',Name='D'), # This allows you to specify up to which likelihood difference. # Default is 0.1 log likelihood units, author recommends 1 or 2 to # rapidly evaluate different trees. '-e':ValuedParameter('-',Name='e',Delimiter=' '), # specify an exclude file name, that contains a specification of # alignment positions you wish to exclude. Format is similar to Nexus, # the file shall contain entries like "100-200 300-400", to exclude a # single column write, e.g., "100-100", if you use a mixed model, an # appropriatly adapted model file will be written. '-E':ValuedParameter('-',Name='E',Delimiter=' '), # select search algorithm: # a rapid Bootstrap analysis and search for best-scoring ML tree in # one program run # A compute marginal ancestral states on a ROOTED reference tree # provided with "t" - ONLY IN 7.3.0 # b draw bipartition information on a tree provided with "-t" based on # multiple trees (e.g., from a bootstrap) in a file specifed by # "-z" # c check if the alignment can be properly read by RAxML # d for normal hill-climbing search (Default) # when -f option is omitted this algorithm will be used # e optimize model+branch lengths for given input tree under # GAMMA/GAMMAI only # E execute very fast experimental tree search, at present only for # testing # F execute fast experimental tree search, at present only for testing # g compute per site log Likelihoods for one ore more trees passed via # "-z" and write them to a file that can be read by CONSEL # WARNING: does not print likelihoods in the original column order # h compute log likelihood test (SH-test) between best tree passed via # "-t" and a bunch of other trees passed via "-z" # i EXPERIMENTAL do not use for real tree inferences: conducts a # single cycle of fast lazy SPR moves on a given input tree, to be # used in combination with -C and -M # I EXPERIMENTAL do not use for real tree inferences: conducts a # single cycle of thorough lazy SPR moves on a given input tree, # to be used in combination with -C and -M # j generate a bunch of bootstrapped alignment files from an original # alignemnt file. You need to specify a seed with "-b" and the # number of replicates with "-#" # following "J" is for version 7.2.8 # J Compute SH-like support values on a given tree passed via "-t". # m compare bipartitions between two bunches of trees passed via "-t" # and "-z" respectively. This will return the Pearson correlation # between all bipartitions found in the two tree files. A file # called RAxML_bipartitionFrequencies.outpuFileName will be # printed that contains the pair-wise bipartition frequencies of # the two sets # n compute the log likelihood score of all trees contained in a tree # file provided by "-z" under GAMMA or GAMMA+P-Invar # o old (slower) algorithm from v. 2.1.3 # p perform pure stepwise MP addition of new sequences to an # incomplete starting tree and exit # r compute pairwise Robinson-Foulds (RF) distances between all pairs # of trees in a tree file passed via "-z" if the trees have node # labales represented as integer support values the program will # also compute two flavors of the weighted Robinson-Foulds (WRF) # distance # following "R" is for version 7.2.8 # R compute rogue taxa using new statistical method based on the # evolutionary placement algorithm # WARNING: this is experimental code - DEPRECATED IN 7.3.0 # s (split) splits into individual genes, provided with model file # following "S" is for version 7.2.8 # S compute site-specific placement bias using a leave one out test # inspired by the evolutionary placement algorithm # t do randomized tree searches on one fixed starting tree # u execute morphological weight calibration using maximum likelihood, # this will return a weight vector. you need to provide a # morphological alignment and a reference tree via "-t" # U execute morphological wieght calibration using parsimony, this # will return a weight vector. you need to provide a morphological # alignment and a reference tree via "-t" - DEPRECATED IN 7.3.0 # v classify a bunch of environmental sequences into a reference tree # using the slow heuristics without dynamic alignment you will # need to start RAxML with a non-comprehensive reference tree and # an alignment containing all sequences (reference + query) # w compute ELW test on a bunch of trees passed via "-z" # x compute pair-wise ML distances, ML model parameters will be # estimated on an MP starting tree or a user-defined tree passed # via "-t", only allowed for GAMMA-based models of rate # heterogeneity # y classify a bunch of environmental sequences into a reference tree # using the fast heuristics without dynamic alignment you will # need to start RAxML with a non-comprehensive reference tree and # an alignment containing all sequences (reference + query) '-f':ValuedParameter('-',Name='f',Delimiter=' ', Value="d"), # enable ML tree searches under CAT model for very large trees without # switching to GAMMA in the end (saves memory). This option can also be # used with the GAMMA models in order to avoid the thorough optimization # of the best-scoring ML tree in the end. # DEFAULT: OFF '-F':FlagParameter('-',Name='F'), # select grouping file name: allows incomplete multifurcating constraint # tree in newick format -- resolves multifurcations randomly, adds # other taxa using parsimony insertion '-g':ValuedParameter('-', Name='g',Delimiter=' '), # enable the ML-based evolutionary placement algorithm heuristics by # specifiyng a threshold value (fraction of insertion branches to be # evaluated using slow insertions under ML). '-G':FlagParameter('-', Name='G'), # prints help and exits '-h':FlagParameter('-', Name='h'), # enable the MP-based evolutionary placement algorithm heuristics # by specifiyng a threshold value (fraction of insertion branches to be # evaluated using slow insertions under ML) - DEPRECATED IN 7.3.0 #'-H':ValuedParameter('-', Name='H',Delimiter=' '), # allows initial rearrangement to be constrained, e.g. 10 means # insertion will not be more than 10 nodes away from original. # default is to pick a "good" setting. '-i':ValuedParameter('-', Name='i', Delimiter=' '), # a posteriori bootstopping analysis. Use: # "-I autoFC" for the frequency-based criterion # "-I autoMR" for the majority-rule consensus tree criterion # "-I autoMRE" for the extended majority-rule consensus tree criterion # "-I autoMRE_IGN" for metrics similar to MRE, but include # bipartitions under the threshold whether they are compatible # or not. This emulates MRE but is faster to compute. # You also need to pass a tree file containg several bootstrap # replicates via "-z" '-I':ValuedParameter('-', Name='I', Delimiter=' '), # writes checkpoints (off by default) '-j':FlagParameter('-', Name='j'), # Compute majority rule consensus tree with "-J MR" or extended majority # rule consensus tree with "-J MRE" or strict consensus tree with "-J # STRICT" You will need to provide a tree file containing several # UNROOTED trees via "-z" '-J':ValuedParameter('-', Name='J', Delimiter=' '), #specifies that RAxML will optimize model parameters (for GTRMIX and # GTRGAMMA) as well as calculating likelihoods for bootstrapped trees. '-k':FlagParameter('-', Name='k'), # Specify one of the multi-state substitution models (max 32 states) # implemented in RAxML. Available models are: ORDERED, MK, GTR '-K':ValuedParameter('-', Name='K', Delimiter=' '), # Model of Binary (Morphological), Nucleotide, Multi-State, or Amino # Acid Substitution:: # BINARY: # -m BINCAT : Optimization of site-specific evolutionary rates which # are categorized into numberOfCategories distinct rate categories # for greater computational efficiency. Final tree might be # evaluated automatically under BINGAMMA, depending on the tree # search option # -m BINCATI : Optimization of site-specific evolutionary rates which # are categorized into numberOfCategories distinct rate categories # for greater computational efficiency. Final tree might be # evaluated automatically under BINGAMMAI, depending on the tree # search option # -m BINGAMMA : GAMMA model of rate heterogeneity (alpha parameter # will be estimated) # -m BINGAMMAI : Same as BINGAMMA, but with estimate of proportion of # invariable sites # NUCLEOTIDES # -m GTRCAT: GTR + Optimization of substitution rates + Optimization # of site-specific evolutionary rates which are categorized into # numberOfCategories distinct rate categories for greater # computational efficiency # -m GTRCAT_FLOAT : Same as above but uses single-precision floating # point arithemtics instead of double-precision Usage only # recommened for testing, the code will run slower, but can save # almost 50% of memory. If you have problems with phylogenomic # datasets and large memory requirements you may give it a shot. # Keep in mind that numerical stability seems to be okay but needs # further testing. - DEPRECATED IN 7.3.0 # -m GTRCATI : GTR + Optimization of substitution rates + Optimization # of site-specific evolutionary rates which are categorized into # numberOfCategories distinct rate categories for greater # computational efficiency. Final tree might be evaluated under # GTRGAMMAI, depending on the tree search option # -m GTRGAMMA: GTR + Optimization of substitution rates + Gamma # -m GTRGAMMA_FLOAT : Same as GTRGAMMA, but also with # single-precision arithmetics, same cautionary notes as for # GTRCAT_FLOAT apply. - DEPRECATED IN 7.3.0 # -m GTRGAMMAI : Same as GTRGAMMA, but with estimate of proportion of # invariable sites # MULTI-STATE: # -m MULTICAT : Optimization of site-specific evolutionary rates which # are categorized into numberOfCategories distinct rate categories # for greater computational efficiency. Final tree might be # evaluated automatically under MULTIGAMMA, depending on the tree # search option # -m MULTICATI : Optimization of site-specific evolutionary rates # which are categorized into numberOfCategories distinct rate # categories for greater computational efficiency. Final tree # might be evaluated automatically under MULTIGAMMAI, depending on # the tree search option # -m MULTIGAMMA : GAMMA model of rate heterogeneity (alpha parameter # will be estimated) # -m MULTIGAMMAI : Same as MULTIGAMMA, but with estimate of proportion # of invariable sites # You can use up to 32 distinct character states to encode multi-state # regions, they must be used in the following order: 0, 1, 2, 3, 4, 5, # 6, 7, 8, 9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, # T, U, V i.e., if you have 6 distinct character states you would use 0, # 1, 2, 3, 4, 5 to encode these. The substitution model for the # multi-state regions can be selected via the "-K" option # Amino Acid Models: # -m PROTCATmatrixName[F] : specified AA matrix + Optimization of # substitution rates + Optimization of site-specific evolutionary # rates which are categorized into numberOfCategories distinct # rate categories for greater computational efficiency. Final # tree might be evaluated automatically under # PROTGAMMAmatrixName[f], depending on the tree search option # -m PROTCATmatrixName[F]_FLOAT : PROTCAT with single precision # arithmetics, same cautionary notes as for GTRCAT_FLOAT apply # - DEPRECATED IN 7.3.0 # -m PROTCATImatrixName[F] : specified AA matrix + Optimization of # substitution rates + Optimization of site-specific # evolutionary rates which are categorized into numberOfCategories # distinct rate categories for greater computational efficiency. # Final tree might be evaluated automatically under # PROTGAMMAImatrixName[f], depending on the tree search option # -m PROTGAMMAmatrixName[F] : specified AA matrix + Optimization of # substitution rates + GAMMA model of rate heterogeneity (alpha # parameter will be estimated) # -m PROTGAMMAmatrixName[F]_FLOAT : PROTGAMMA with single precision # arithmetics, same cautionary notes as for GTRCAT_FLOAT apply # - DEPRECATED IN 7.3.0 # -m PROTGAMMAImatrixName[F] : Same as PROTGAMMAmatrixName[F], but # with estimate of proportion of invariable sites # Available AA substitution models: DAYHOFF, DCMUT, JTT, MTREV, WAG, # RTREV, CPREV, VT, BLOSUM62, MTMAM, LG, GTR. With the optional "F" # appendix you can specify if you want to use empirical base frequencies # Please note that for mixed models you can in addition specify the # per-gene AA model in the mixed model file (see manual for details). # Also note that if you estimate AA GTR parameters on a partitioned # dataset, they will be linked (estimated jointly) across all partitions # to avoid over-parametrization '-m':ValuedParameter('-',Name='m',Delimiter=' '), # Switch on estimation of individual per-partition branch lengths. Only # has effect when used in combination with "-q". Branch lengths for # individual partitions will be printed to separate files. A weighted # average of the branch lengths is computed by using the respective # partition lengths. # DEFAULT: OFF '-M':FlagParameter('-',Name='M'), # Specifies the name of the output file. '-n':ValuedParameter('-',Name='n',Delimiter=' '), # Specifies the name of the outgroup (or outgroups: comma-delimited, # no spaces, should be monophyletic). '-o':ValuedParameter('-',Name='o',Delimiter=' '), # Enable checkpointing using the dmtcp library available at # http://dmtcp.sourceforge.net/. This only works if you call the program # by preceded by the command "dmtcp_checkpoint" and if you compile a # dedicated binary using the appropriate Makefile. With "-O" you can # specify the interval between checkpoints in seconds. # DEFAULT: 3600.0 seconds - DEPRECATED IN 7.3.0 #'-O':ValuedParameter('-',Name='O',Delimiter=' ',Value=3600.0), # Specify a random number seed for the parsimony inferences. This allows # you to reproduce your results and will help me debug the program. '-p':ValuedParameter('-',Name='p',Delimiter=' '), # Specify the file name of a user-defined AA (Protein) substitution # model. This file must contain 420 entries, the first 400 being the AA # substitution rates (this must be a symmetric matrix) and the last 20 # are the empirical base frequencies '-P':ValuedParameter('-',Name='P',Delimiter=' '), # Specified MultipleModel file name, in format: # gene1 = 1-500 # gene2 = 501-1000 # (note: ranges can also be discontiguous, e.g. 1-100, 200-300, # or can specify codon ranges as e.g. 1-100/3, 2-100/3, 3-100/3)) '-q':ValuedParameter('-', Name='q', Delimiter=' '), # THE FOLLOWING "Q" is DEPRECATED IN 7.2.8 # Turn on computation of SH-like support values on tree. # DEFAULT: OFF '-Q':FlagParameter('-', Name='Q'), # Constraint file name: allows a bifurcating Newick tree to be passed # in as a constraint file, other taxa will be added by parsimony. '-r':ValuedParameter('-',Name='r',Delimiter=' '), # THE FOLLOWING "R" is IN 7.2.8 # Specify the file name of a binary model parameter file that has # previously been generated with RAxML using the -f e tree evaluation # option. The file name should be: RAxML_binaryModelParameters.runID '-R':ValuedParameter('-',Name='R',Delimiter=' '), # specify the name of the alignment data file, in relaxed PHYLIP # format. '-s':ValuedParameter('-',Name='s',Delimiter=' '), # Specify the name of a secondary structure file. The file can contain # "." for alignment columns that do not form part of a stem and # characters "()<>[]{}" to define stem regions and pseudoknots '-S':ValuedParameter('-',Name='S',Delimiter=' '), # Specify a user starting tree file name in Newick format '-t':ValuedParameter('-',Name='t',Delimiter=' '), # PTHREADS VERSION ONLY! Specify the number of threads you want to run. # Make sure to set "-T" to at most the number of CPUs you have on your # machine, otherwise, there will be a huge performance decrease! '-T':ValuedParameter('-',Name='T',Delimiter=' '), # THE FOLLOWING "U" is IN 7.2.8 # Try to save memory by using SEV-based implementation for gap columns # on large gappy alignments # WARNING: this will only work for DNA under GTRGAMMA and is still in an # experimental state. '-U':ValuedParameter('-',Name='U',Delimiter=' '), # Print the version '-v':FlagParameter('-',Name='v'), # Name of the working directory where RAxML-V will write its output # files. '-w':ValuedParameter('-',Name='w',Delimiter=' '), # THE FOLLOWING "W" is IN 7.2.8 # Sliding window size for leave-one-out site-specific placement bias # algorithm only effective when used in combination with "-f S" # DEFAULT: 100 sites '-W':ValuedParameter('-',Name='W',Delimiter=' '), # Specify an integer number (random seed) and turn on rapid # bootstrapping. CAUTION: unlike in version 7.0.4 RAxML will conduct # rapid BS replicates under the model of rate heterogeneity you # specified via "-m" and not by default under CAT '-x':ValuedParameter('-',Name='x',Delimiter=' '), # EXPERIMENTAL OPTION: This option will do a per-site estimate of # protein substitution models by looping over all given, fixed models # LG, WAG, JTT, etc and using their respective base frequencies to # independently assign a prot subst. model to each site via ML # optimization. At present this option only works with the GTR+GAMMA # model, unpartitioned datasets, and in the sequential version only. # DEFAULT: OFF '-X':FlagParameter('-', Name='X'), # Compute only randomized starting parsimony tree with RAxML, do not # optimize an ML analysis of the tree '-y':FlagParameter('-', Name='y'), # Do a more thorough parsimony tree search using a parsimony ratchet and # exit. Specify the number of ratchet searches via "-#" or "-N". This # has just been implemented for completeness, if you want a fast MP # implementation use TNT # DEFAULT: OFF - DEPRECATED IN 7.3.0 #'-Y':FlagParameter('-', Name='Y'), # Multiple tree file, for use with -f b (to draw bipartitions onto the # common tree specified with -t) '-z':ValuedParameter('-', Name='z', Delimiter=' '), # Specifies number of runs on distinct starting trees. '-#':ValuedParameter('-', Name='#', Delimiter=' ',Value=1), # Specifies number of runs on distinct starting trees. '-N':ValuedParameter('-', Name='N', Delimiter=' '), } _parameters = {} _parameters.update(_options) _command = "raxmlHPC" _out_format = "RAxML_%s.%s" def _format_output(self, outfile_name, out_type): """ Prepend proper output prefix to output filename """ outfile_name = self._absolute(outfile_name) outparts = outfile_name.split("/") outparts[-1] = self._out_format % (out_type, outparts[-1] ) return '/'.join(outparts) def _input_as_seqs(self,data): lines = [] for i,s in enumerate(data): #will number the sequences 1,2,3,etc. lines.append(''.join(['>',str(i+1)])) lines.append(s) return self._input_as_lines(lines) def _input_as_lines(self,data): if data: self.Parameters['-s']\ .on(super(Raxml,self)._input_as_lines(data)) return '' def _input_as_string(self,data): """Makes data the value of a specific parameter This method returns the empty string. The parameter will be printed automatically once set. """ if data: self.Parameters['-in'].on(str(data)) return '' def _input_as_multiline_string(self, data): if data: self.Parameters['-s']\ .on(super(Raxml,self)._input_as_multiline_string(data)) return '' def _absolute(self,path): path = FilePath(path) if isabs(path): return path elif self.Parameters['-w'].isOn(): return self.Parameters['-w'].Value + path else: return self.WorkingDir + path def _log_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), "log") else: raise ValueError, "No output file specified." def _info_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), "info") else: raise ValueError, "No output file specified." def _parsimony_tree_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "parsimonyTree") else: raise ValueError, "No output file specified." # added for tree-insertion def _originallabelled_tree_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "originalLabelledTree") else: raise ValueError, "No output file specified." # added for tree-insertion def _labelled_tree_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "labelledTree") else: raise ValueError, "No output file specified." # added for tree-insertion def _classification_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "classification") else: raise ValueError, "No output file specified." # added for tree-insertion def _classificationlikelihoodweights_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "classificationLikelihoodWeights") else: raise ValueError, "No output file specified." # added for tree-insertion def _best_tree_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "bestTree") else: raise ValueError, "No output file specified." # added for tree-insertion def _entropy_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "entropy") else: raise ValueError, "No output file specified." # added for tree-insertion def _json_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "portableTree") else: raise ValueError, "No output file specified." # added for tree-insertion def _parsimony_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "equallyParsimoniousPlacements") else: raise ValueError, "No output file specified." def _result_tree_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "result") else: raise ValueError, "No output file specified." def _result_bootstrap_out_filename(self): if self.Parameters['-n'].isOn(): return self._format_output(str(self.Parameters['-n'].Value), \ "bootstrap") else: raise ValueError, "No output file specified" def _checkpoint_out_filenames(self): """ RAxML generates a crapload of checkpoint files so need to walk directory to collect names of all of them. """ out_filenames = [] if self.Parameters['-n'].isOn(): out_name = str(self.Parameters['-n'].Value) walk_root = self.WorkingDir if self.Parameters['-w'].isOn(): walk_root = str(self.Parameters['-w'].Value) for tup in walk(walk_root): dpath, dnames, dfiles = tup if dpath == walk_root: for gen_file in dfiles: if out_name in gen_file and "checkpoint" in gen_file: out_filenames.append(walk_root + gen_file) break else: raise ValueError, "No output file specified." return out_filenames def _handle_app_result_build_failure(self,out,err,exit_status,result_paths): """ Catch the error when files are not produced """ try: raise ApplicationError, \ 'RAxML failed to produce an output file due to the following error: \n\n%s ' \ % err.read() except: raise ApplicationError,\ 'RAxML failed to run properly.' def _get_result_paths(self,data): result = {} result['Info'] = ResultPath(Path=self._info_out_filename(), IsWritten=True) if self.Parameters['-k'].isOn(): result['Bootstrap'] = ResultPath( Path=self._result_bootstrap_out_filename(), IsWritten=True) elif self.Parameters["-f"].Value == 'v': #these were added to handle the results from tree-insertion result['Classification'] = ResultPath( Path=self._classification_out_filename(), IsWritten=True) result['ClassificationLikelihoodWeights'] = ResultPath( Path=self._classificationlikelihoodweights_out_filename(), IsWritten=True) result['OriginalLabelledTree'] = ResultPath( Path=self._originallabelled_tree_out_filename(), IsWritten=True) result['Result'] = ResultPath( Path=self._labelled_tree_out_filename(),IsWritten=True) result['entropy'] = ResultPath( Path=self._entropy_out_filename(),IsWritten=True) result['json'] = ResultPath( Path=self._json_out_filename()+'.jplace',IsWritten=True) elif self.Parameters["-f"].Value == 'y': #these were added to handle the results from tree-insertion result['Parsimony'] = ResultPath( Path=self._parsimony_out_filename(), IsWritten=True) result['OriginalLabelledTree'] = ResultPath( Path=self._originallabelled_tree_out_filename(), IsWritten=True) result['json'] = ResultPath( Path=self._json_out_filename()+'.jplace',IsWritten=True) else: result['Log'] = ResultPath(Path=self._log_out_filename(), IsWritten=True) result['ParsimonyTree'] = ResultPath( Path=self._parsimony_tree_out_filename(), IsWritten=True) result['Result'] = ResultPath( Path=self._result_tree_out_filename(), IsWritten=True) # result['besttree'] = ResultPath( Path=self._best_tree_out_filename(), IsWritten=True) for checkpoint_file in self._checkpoint_out_filenames(): checkpoint_num = checkpoint_file.split(".")[-1] try: checkpoint_num = int(checkpoint_num) except Exception, e: raise ValueError, "%s does not appear to be a valid checkpoint file" result['Checkpoint%d' % checkpoint_num] = ResultPath( Path=checkpoint_file, IsWritten=True) return result #SOME FUNCTIONS TO EXECUTE THE MOST COMMON TASKS def raxml_alignment(align_obj, raxml_model="GTRCAT", params={}, SuppressStderr=True, SuppressStdout=True): """Run raxml on alignment object align_obj: Alignment object params: you can set any params except -w and -n returns: tuple (phylonode, parsimonyphylonode, log likelihood, total exec time) """ # generate temp filename for output params["-w"] = "/tmp/" params["-n"] = get_tmp_filename().split("/")[-1] params["-m"] = raxml_model params["-p"] = randint(1,100000) ih = '_input_as_multiline_string' seqs, align_map = align_obj.toPhylip() #print params["-n"] # set up command raxml_app = Raxml( params=params, InputHandler=ih, WorkingDir=None, SuppressStderr=SuppressStderr, SuppressStdout=SuppressStdout) # run raxml ra = raxml_app(seqs) # generate tree tree_node = DndParser(ra["Result"]) # generate parsimony tree parsimony_tree_node = DndParser(ra["ParsimonyTree"]) # extract log likelihood from log file log_file = ra["Log"] total_exec_time = exec_time = log_likelihood = 0.0 for line in log_file: exec_time, log_likelihood = map(float, line.split()) total_exec_time += exec_time # remove output files ra.cleanUp() return tree_node, parsimony_tree_node, log_likelihood, total_exec_time def build_tree_from_alignment(aln, moltype, best_tree=False, params={}): """Returns a tree from Alignment object aln. aln: an xxx.Alignment object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object best_tree: best_tree suppport is currently not implemented params: dict of parameters to pass in to the RAxML app controller. The result will be an xxx.Alignment object, or None if tree fails. """ if best_tree: raise NotImplementedError if '-m' not in params: if moltype == DNA or moltype == RNA: #params["-m"] = 'GTRMIX' # in version 7.2.3, GTRMIX is no longer supported but says GTRCAT # behaves like GTRMIX (http://www.phylo.org/tools/raxmlhpc2.html) params["-m"] = 'GTRGAMMA' elif moltype == PROTEIN: params["-m"] = 'PROTGAMMAmatrixName' else: raise ValueError, "Moltype must be either DNA, RNA, or PROTEIN" if not hasattr(aln, 'toPhylip'): aln = Alignment(aln) seqs, align_map = aln.toPhylip() # generate temp filename for output params["-w"] = "/tmp/" params["-n"] = get_tmp_filename().split("/")[-1] params["-k"] = True params["-p"] = randint(1,100000) params["-x"] = randint(1,100000) ih = '_input_as_multiline_string' raxml_app = Raxml(params=params, InputHandler=ih, WorkingDir=None, SuppressStderr=True, SuppressStdout=True) raxml_result = raxml_app(seqs) tree = DndParser(raxml_result['Bootstrap'], constructor=PhyloNode) for node in tree.tips(): node.Name = align_map[node.Name] raxml_result.cleanUp() return tree def insert_sequences_into_tree(seqs, moltype, params={}, write_log=True): """Insert sequences into Tree. aln: an xxx.Alignment object, or data that can be used to build one. moltype: cogent.core.moltype.MolType object params: dict of parameters to pass in to the RAxML app controller. The result will be a tree. """ ih = '_input_as_multiline_string' raxml_app = Raxml(params=params, InputHandler=ih, WorkingDir=None, SuppressStderr=False, SuppressStdout=False, HALT_EXEC=False) raxml_result = raxml_app(seqs) # write a log file if write_log: log_fp = join(params["-w"],'log_raxml_'+split(get_tmp_filename())[-1]) log_file=open(log_fp,'w') log_file.write(raxml_result['StdOut'].read()) log_file.close() ''' # getting setup since parsimony doesn't output tree..only jplace, however # it is currently corrupt # use guppy to convert json file into a placement tree guppy_params={'tog':None} new_tree=build_tree_from_json_using_params(raxml_result['json'].name, \ output_dir=params["-w"], \ params=guppy_params) ''' # get tree from 'Result Names' new_tree=raxml_result['Result'].readlines() filtered_tree=re.sub('\[I\d+\]','',str(new_tree)) tree = DndParser(filtered_tree, constructor=PhyloNode) raxml_result.cleanUp() return tree pycogent-1.9/cogent/app/rdp_classifier.py000066400000000000000000000545371273014367000206360ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for rdp_classifier-2.0 """ __author__ = "Kyle Bittinger" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Kyle Bittinger","Greg Caporaso"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Kyle Bittinger" __email__ = "kylebittinger@gmail.com" __status__ = "Prototype" import os.path import re from os import remove, environ, getenv, path from optparse import OptionParser from shutil import rmtree import tempfile import warnings from cogent.app.parameters import Parameter, ValuedParameter, Parameters from cogent.parse.fasta import MinimalFastaParser from cogent.app.util import CommandLineApplication, CommandLineAppResult, \ FilePath, ResultPath, guess_input_handler, system,\ ApplicationNotFoundError, ApplicationError from cogent.util.misc import app_path class RdpClassifier(CommandLineApplication): """RDP Classifier application controller The RDP Classifier program is distributed as a java archive (.jar) file. If the file 'rdp_classifier-2.2.jar' is not found in the current directory, the app controller uses the JAR file specified by the environment variable RDP_JAR_PATH. If this variable is not set, and 'rdp_classifier-2.2.jar' is not found in the current directory, the application controller raises an ApplicationNotFoundError. The RDP Classifier often requires memory in excess of Java's default 64M. To correct this situation, the authors recommend increasing the maximum heap size for the java virtual machine. An option '-Xmx' (default 1000M) is provided for this purpose. Details on this option may be found at http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/java.html The classifier may optionally use a custom training set. The full path to the training set may be provided in the option '-training-data'. """ _input_handler = '_input_as_lines' _command = "rdp_classifier-2.2.jar" _options = { # output file name for classification assignment '-o': ValuedParameter('-', Name='o', Delimiter=' ', IsPath=True), # a property file contains the mapping of the training # files. Note: the training files and the property file should # be in the same directory. The default property file is set # to data/classifier/rRNAClassifier.properties. '-t': ValuedParameter('-', Name='t', Delimiter=' ', IsPath=True), # all tab delimited output format: [allrank|fixrank|db]. # Default is allrank. # # allrank: outputs the results for all ranks applied for # each sequence: seqname, orientation, taxon name, rank, # conf, ... # # fixrank: only outputs the results for fixed ranks in # order: no rank, domain, phylum, class, order, family, # genus # # db: outputs the seqname, trainset_no, tax_id, conf. This # is good for storing in a database '-f': ValuedParameter('-', Name='f', Delimiter=' '), } # The following are available in the attributes JvmParameters, # JarParameters, and PositionalParameters _jvm_synonyms = {} _jvm_parameters = { # Maximum heap size for JVM. '-Xmx': ValuedParameter('-', Name='Xmx', Delimiter='', Value='1000m'), } _parameters = {} _parameters.update(_options) _parameters.update(_jvm_parameters) def getHelp(self): """Returns documentation string""" # Summary paragraph copied from rdp_classifier-2.0, which is # licensed under the GPL 2.0 and Copyright 2008 Michigan State # University Board of Trustees help_str = """\ usage: ClassifierCmd [-f ] [-o ] [-q ] [-t ] -f,--format all tab delimited output format: [allrank|fixrank|db]. Default is allrank. allrank: outputs the results for all ranks applied for each sequence: seqname, orientation, taxon name, rank, conf, ... fixrank: only outputs the results for fixed ranks in order: no rank, domain, phylum, class, order, family, genus db: outputs the seqname, trainset_no, tax_id, conf. This is good for storing in a database -o,--outputFile output file name for classification assignment -q,--queryFile query file contains sequences in one of the following formats: Fasta, Genbank and EMBL -t,--train_propfile a property file contains the mapping of the training files. Note: the training files and the property file should be in the same directory. The default property file is set to data/classifier/rRNAClassifier.properties.""" return help_str def _accept_exit_status(self, status): """Returns false if an error occurred in execution """ return (status == 0) def _error_on_missing_application(self,params): """Raise an ApplicationNotFoundError if the app is not accessible In this case, checks for the java runtime and the RDP jar file. """ if not (os.path.exists('java') or app_path('java')): raise ApplicationNotFoundError( "Cannot find java runtime. Is it installed? Is it in your " "path?") jar_fp = self._get_jar_fp() if jar_fp is None: raise ApplicationNotFoundError( "JAR file not found in current directory and the RDP_JAR_PATH " "environment variable is not set. Please set RDP_JAR_PATH to " "the full pathname of the JAR file.") if not os.path.exists(jar_fp): raise ApplicationNotFoundError( "JAR file %s does not exist." % jar_fp) def _get_jar_fp(self): """Returns the full path to the JAR file. If the JAR file cannot be found in the current directory and the environment variable RDP_JAR_PATH is not set, returns None. """ # handles case where the jar file is in the current working directory if os.path.exists(self._command): return self._command # handles the case where the user has specified the location via # an environment variable elif 'RDP_JAR_PATH' in environ: return getenv('RDP_JAR_PATH') else: return None # Overridden to pull out JVM-specific command-line arguments. def _get_base_command(self): """Returns the base command plus command-line options. Does not include input file, output file, and training set. """ cd_command = ''.join(['cd ', str(self.WorkingDir), ';']) jvm_command = "java" jvm_arguments = self._commandline_join( [self.Parameters[k] for k in self._jvm_parameters]) jar_arguments = '-jar "%s"' % self._get_jar_fp() rdp_arguments = self._commandline_join( [self.Parameters[k] for k in self._options]) command_parts = [ cd_command, jvm_command, jvm_arguments, jar_arguments, rdp_arguments, '-q'] return self._commandline_join(command_parts).strip() BaseCommand = property(_get_base_command) def _commandline_join(self, tokens): """Formats a list of tokens as a shell command This seems to be a repeated pattern; may be useful in superclass. """ commands = filter(None, map(str, tokens)) return self._command_delimiter.join(commands).strip() def _get_result_paths(self,data): """ Return a dict of ResultPath objects representing all possible output """ assignment_fp = str(self.Parameters['-o'].Value).strip('"') if not os.path.isabs(assignment_fp): assignment_fp = os.path.relpath(assignment_fp, self.WorkingDir) return {'Assignments': ResultPath(assignment_fp, IsWritten=True)} class RdpTrainer(RdpClassifier): _input_handler = '_input_as_lines' TrainingClass = 'edu.msu.cme.rdp.classifier.train.ClassifierTraineeMaker' PropertiesFile = 'RdpClassifier.properties' _parameters = { 'taxonomy_file': ValuedParameter(None, None, IsPath=True), 'model_output_dir': ValuedParameter(None, None, IsPath=True), 'training_set_id': ValuedParameter(None, None, Value='1'), 'taxonomy_version': ValuedParameter(None, None, Value='version1'), 'modification_info': ValuedParameter(None, None, Value='cogent'), } _jvm_parameters = { # Maximum heap size for JVM. '-Xmx': ValuedParameter('-', Name='Xmx', Delimiter='', Value='1000m'), } _parameters.update(_jvm_parameters) def _get_base_command(self): """Returns the base command plus command-line options. Handles everything up to and including the classpath. The positional training parameters are added by the _input_handler_decorator method. """ cd_command = ''.join(['cd ', str(self.WorkingDir), ';']) jvm_command = "java" jvm_args = self._commandline_join( [self.Parameters[k] for k in self._jvm_parameters]) cp_args = '-cp "%s" %s' % (self._get_jar_fp(), self.TrainingClass) command_parts = [cd_command, jvm_command, jvm_args, cp_args] return self._commandline_join(command_parts).strip() BaseCommand = property(_get_base_command) def _set_input_handler(self, method_name): """Stores the selected input handler in a private attribute. """ self.__InputHandler = method_name def _get_input_handler(self): """Returns decorator that wraps the requested input handler. """ return '_input_handler_decorator' InputHandler = property(_get_input_handler, _set_input_handler) @property def ModelDir(self): """Absolute FilePath to the training output directory. """ model_dir = self.Parameters['model_output_dir'].Value absolute_model_dir = os.path.abspath(model_dir) return FilePath(absolute_model_dir) def _input_handler_decorator(self, data): """Adds positional parameters to selected input_handler's results. """ input_handler = getattr(self, self.__InputHandler) input_parts = [ self.Parameters['taxonomy_file'], input_handler(data), self.Parameters['training_set_id'], self.Parameters['taxonomy_version'], self.Parameters['modification_info'], self.ModelDir, ] return self._commandline_join(input_parts) def _get_result_paths(self, output_dir): """Return a dict of output files. """ # Only include the properties file here. Add the other result # paths in the __call__ method, so we can catch errors if an # output file is not written. self._write_properties_file() properties_fp = os.path.join(self.ModelDir, self.PropertiesFile) result_paths = { 'properties': ResultPath(properties_fp, IsWritten=True,) } return result_paths def _write_properties_file(self): """Write an RDP training properties file manually. """ # The properties file specifies the names of the files in the # training directory. We use the example properties file # directly from the rdp_classifier distribution, which lists # the default set of files created by the application. We # must write this file manually after generating the # training data. properties_fp = os.path.join(self.ModelDir, self.PropertiesFile) properties_file = open(properties_fp, 'w') properties_file.write( "# Sample ResourceBundle properties file\n" "bergeyTree=bergeyTrainingTree.xml\n" "probabilityList=genus_wordConditionalProbList.txt\n" "probabilityIndex=wordConditionalProbIndexArr.txt\n" "wordPrior=logWordPrior.txt\n" "classifierVersion=Naive Bayesian rRNA Classifier Version 1.0, " "November 2003\n" ) properties_file.close() def __call__(self, data=None, remove_tmp=True): """Run the application with the specified kwargs on data data: anything that can be cast into a string or written out to a file. Usually either a list of things or a single string or number. input_handler will be called on this data before it is passed as part of the command-line argument, so by creating your own input handlers you can customize what kind of data you want your application to accept remove_tmp: if True, removes tmp files """ result = super(RdpClassifier, self).__call__(data=data, remove_tmp=remove_tmp) training_files = { 'bergeyTree': 'bergeyTrainingTree.xml', 'probabilityList': 'genus_wordConditionalProbList.txt', 'probabilityIndex': 'wordConditionalProbIndexArr.txt', 'wordPrior': 'logWordPrior.txt', } for key, training_fn in sorted(training_files.items()): training_fp = os.path.join(self.ModelDir, training_fn) if not os.path.exists(training_fp): exception_msg = ( "Training output file %s not found. This may " "happen if an error occurred during the RDP training " "process. More details may be available in the " "standard error, printed below.\n\n" % training_fp ) stderr_msg = result["StdErr"].read() result["StdErr"].seek(0) raise ApplicationError(exception_msg + stderr_msg) # Not in try/except clause because we already know the # file exists. Failure would be truly exceptional, and we # want to maintain the original exception in that case. result[key] = open(training_fp) return result def parse_command_line_parameters(argv=None): """ Parses command line arguments """ usage =\ 'usage: %prog [options] input_sequences_filepath' version = 'Version: %prog ' + __version__ parser = OptionParser(usage=usage, version=version) parser.add_option('-o','--output_fp',action='store',\ type='string',dest='output_fp',help='Path to store '+\ 'output file [default: generated from input_sequences_filepath]') parser.add_option('-c','--min_confidence',action='store',\ type='float',dest='min_confidence',help='minimum confidence '+\ 'level to return a classification [default: %default]') parser.set_defaults(verbose=False, min_confidence=0.80) opts, args = parser.parse_args(argv) if len(args) != 1: parser.error('Exactly one argument is required.') return opts, args def assign_taxonomy( data, min_confidence=0.80, output_fp=None, training_data_fp=None, fixrank=True, max_memory=None, tmp_dir=None): """Assign taxonomy to each sequence in data with the RDP classifier data: open fasta file object or list of fasta lines confidence: minimum support threshold to assign taxonomy to a sequence output_fp: path to write output; if not provided, result will be returned in a dict of {seq_id:(taxonomy_assignment,confidence)} """ # Going to iterate through this twice in succession, best to force # evaluation now data = list(data) # RDP classifier doesn't preserve identifiers with spaces # Use lookup table seq_id_lookup = {} for seq_id, seq in MinimalFastaParser(data): seq_id_lookup[seq_id.split()[0]] = seq_id app_kwargs = {} if tmp_dir is not None: app_kwargs['TmpDir'] = tmp_dir app = RdpClassifier(**app_kwargs) if max_memory is not None: app.Parameters['-Xmx'].on(max_memory) temp_output_file = tempfile.NamedTemporaryFile( prefix='RdpAssignments_', suffix='.txt', dir=tmp_dir) app.Parameters['-o'].on(temp_output_file.name) if training_data_fp is not None: app.Parameters['-t'].on(training_data_fp) if fixrank: app.Parameters['-f'].on('fixrank') else: app.Parameters['-f'].on('allrank') app_result = app(data) assignments = {} # ShortSequenceException messages are written to stdout # Tag these ID's as unassignable for line in app_result['StdOut']: excep = parse_rdp_exception(line) if excep is not None: _, rdp_id = excep orig_id = seq_id_lookup[rdp_id] assignments[orig_id] = ('Unassignable', 1.0) for line in app_result['Assignments']: rdp_id, direction, taxa = parse_rdp_assignment(line) if taxa[0][0] == "Root": taxa = taxa[1:] orig_id = seq_id_lookup[rdp_id] lineage, confidence = get_rdp_lineage(taxa, min_confidence) if lineage: assignments[orig_id] = (';'.join(lineage), confidence) else: assignments[orig_id] = ('Unclassified', 1.0) if output_fp: try: output_file = open(output_fp, 'w') except OSError: raise OSError("Can't open output file for writing: %s" % output_fp) for seq_id, assignment in assignments.items(): lineage, confidence = assignment output_file.write( '%s\t%s\t%1.3f\n' % (seq_id, lineage, confidence)) output_file.close() return None else: return assignments def train_rdp_classifier( training_seqs_file, taxonomy_file, model_output_dir, max_memory=None, tmp_dir=None): """ Train RDP Classifier, saving to model_output_dir training_seqs_file, taxonomy_file: file-like objects used to train the RDP Classifier (see RdpTrainer documentation for format of training data) model_output_dir: directory in which to save the files necessary to classify sequences according to the training data Once the model data has been generated, the RDP Classifier may """ app_kwargs = {} if tmp_dir is not None: app_kwargs['TmpDir'] = tmp_dir app = RdpTrainer(**app_kwargs) if max_memory is not None: app.Parameters['-Xmx'].on(max_memory) temp_taxonomy_file = tempfile.NamedTemporaryFile( prefix='RdpTaxonomy_', suffix='.txt', dir=tmp_dir) temp_taxonomy_file.write(taxonomy_file.read()) temp_taxonomy_file.seek(0) app.Parameters['taxonomy_file'].on(temp_taxonomy_file.name) app.Parameters['model_output_dir'].on(model_output_dir) return app(training_seqs_file) def train_rdp_classifier_and_assign_taxonomy( training_seqs_file, taxonomy_file, seqs_to_classify, min_confidence=0.80, model_output_dir=None, classification_output_fp=None, max_memory=None, tmp_dir=None): """ Train RDP Classifier and assign taxonomy in one fell swoop The file objects training_seqs_file and taxonomy_file are used to train the RDP Classifier (see RdpTrainer documentation for details). Model data is stored in model_output_dir. If model_output_dir is not provided, a temporary directory is created and removed after classification. The sequences in seqs_to_classify are classified according to the model and filtered at the desired confidence level (default: 0.80). The results are saved to classification_output_fp if provided, otherwise a dict of {seq_id:(taxonomy_assignment,confidence)} is returned. """ if model_output_dir is None: training_dir = tempfile.mkdtemp(prefix='RdpTrainer_', dir=tmp_dir) else: training_dir = model_output_dir training_results = train_rdp_classifier( training_seqs_file, taxonomy_file, training_dir, max_memory=max_memory, tmp_dir=tmp_dir) training_data_fp = training_results['properties'].name assignment_results = assign_taxonomy( seqs_to_classify, min_confidence=min_confidence, output_fp=classification_output_fp, training_data_fp=training_data_fp, max_memory=max_memory, fixrank=False, tmp_dir=tmp_dir) if model_output_dir is None: # Forum user reported an error on the call to os.rmtree: # https://groups.google.com/d/topic/qiime-forum/MkNe7-JtSBw/discussion # We were not able to replicate the problem and fix it # properly. However, even if an error occurs, we would like # to return results, along with a warning. try: rmtree(training_dir) except OSError: msg = ( "Temporary training directory %s not removed" % training_dir) if os.path.isdir(training_dir): training_dir_files = os.listdir(training_dir) msg += "\nDetected files %s" % training_dir_files warnings.warn(msg, RuntimeWarning) return assignment_results def get_rdp_lineage(rdp_taxa, min_confidence): lineage = [] obs_confidence = 1.0 for taxon, rank, confidence in rdp_taxa: if confidence >= min_confidence: obs_confidence = confidence lineage.append(taxon) else: break return lineage, obs_confidence def parse_rdp_exception(line): if line.startswith('ShortSequenceException'): matchobj = re.search('recordID=(\S+)', line) if matchobj: rdp_id = matchobj.group(1) return ('ShortSequenceException', rdp_id) return None def parse_rdp_assignment(line): """Returns a list of assigned taxa from an RDP classification line """ toks = line.strip().split('\t') seq_id = toks.pop(0) direction = toks.pop(0) if ((len(toks) % 3) != 0): raise ValueError( "Expected assignments in a repeating series of (rank, name, " "confidence), received %s" % toks) assignments = [] # Fancy way to create list of triples using consecutive items from # input. See grouper function in documentation for itertools for # more general example. itoks = iter(toks) for taxon, rank, confidence_str in zip(itoks, itoks, itoks): if not taxon: continue assignments.append((taxon.strip('"'), rank, float(confidence_str))) return seq_id, direction, assignments if __name__ == "__main__": opts, args = parse_command_line_parameters() assign_taxonomy( open(args[0]), min_confidence=opts.min_confidence, output_fp=opts.output_fp) pycogent-1.9/cogent/app/rdp_classifier20.py000066400000000000000000000656121273014367000207740ustar00rootroot00000000000000#!/usr/bin/env python """Application controller for rdp_classifier-2.0 """ __author__ = "Kyle Bittinger" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Kyle Bittinger","Greg Caporaso"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Kyle Bittinger" __email__ = "kylebittinger@gmail.com" __status__ = "Prototype" import re from os import remove, environ, getenv, path from os.path import exists from optparse import OptionParser from shutil import rmtree from tempfile import mkdtemp from cogent.app.parameters import Parameter, ValuedParameter, Parameters from cogent.parse.fasta import MinimalFastaParser from cogent.app.rdp_classifier import RdpClassifier from cogent.app.util import CommandLineApplication, CommandLineAppResult, \ FilePath, ResultPath, guess_input_handler, system,\ ApplicationNotFoundError, ApplicationError class RdpClassifier20(CommandLineApplication): """RDP Classifier version 2.0 application controller The RDP Classifier program is distributed as a java archive (.jar) file. If the file 'rdp_classifier-2.0.jar' is not found in the current directory, the app controller looks in the directory specified by the environment variable RDP_JAR_PATH. If this variable is not set, and 'rdp_classifier-2.0.jar' is not found in the current directory, the application controller raises an ApplicationNotFoundError. The RDP Classifier often requires memory in excess of Java's default 64M. To correct this situation, the authors recommend increasing the maximum heap size for the java virtual machine. An option '-Xmx' (default 1000M) is provided for this purpose. Details on this option may be found at http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/java.html The classifier may optionally use a custom training set. The full path to the training set may be provided in the option '-training-data'. """ _input_handler = '_input_as_multiline_string' _command = "rdp_classifier-2.0.jar" _options ={} # The following are available in the attributes JvmParameters, # JarParameters, and PositionalParameters _jvm_synonyms = {} _jvm_parameters = { # Maximum heap size for JVM. '-Xmx': ValuedParameter('-', Name='Xmx', Delimiter='', Value='1000m'), } _positional_synonyms = {} _positional_parameters = { '-training-data': ValuedParameter('', Name='', Delimiter='', Value='', IsPath=True), } _parameters = {} _parameters.update(_options) _parameters.update(_jvm_parameters) _parameters.update(_positional_parameters) def getHelp(self): """Returns documentation string""" # Summary paragraph copied from rdp_classifier-2.0, which is # licensed under the GPL 2.0 and Copyright 2008 Michigan State # University Board of Trustees help_str =\ """ Ribosomal Database Project - Classifier http://rdp.cme.msu.edu/classifier/ The RDP Classifier is a naive Bayesian classifier which was developed to provide rapid taxonomic placement based on rRNA sequence data. The RDP Classifier can rapidly and accurately classify bacterial 16s rRNA sequences into the new higher-order taxonomy proposed by Bergey's Trust. It provides taxonomic assignments from domain to genus, with confidence estimates for each assignment. The RDP Classifier is not limited to using the bacterial taxonomy proposed by the Bergey's editors. It worked equally well when trained on the NCBI taxonomy. The RDP Classifier likely can be adapted to additional phylogenetically coherent bacterial taxonomies. The following paper should be cited if this resource is used: Wang, Q, G. M. Garrity, J. M. Tiedje, and J. R. Cole. 2007. Naive Bayesian Classifier for Rapid Assignment of rRNA Sequences into the New Bacterial Taxonomy. Appl Environ Microbiol. 73(16):5261-7. """ return help_str def __call__(self, data=None, remove_tmp=True): """Run the application with the specified kwargs on data data: anything that can be cast into a string or written out to a file. Usually either a list of things or a single string or number. input_handler will be called on this data before it is passed as part of the command-line argument, so by creating your own input handlers you can customize what kind of data you want your application to accept remove_tmp: if True, removes tmp files """ input_handler = self.InputHandler suppress_stdout = self.SuppressStdout suppress_stderr = self.SuppressStderr assignment_fp = FilePath(self.getTmpFilename(self.TmpDir)) if suppress_stdout: outfile = FilePath('/dev/null') else: outfile = FilePath(self.getTmpFilename(self.TmpDir)) if suppress_stderr: errfile = FilePath('/dev/null') else: errfile = FilePath(self.getTmpFilename(self.TmpDir)) if data is None: input_arg = '' else: input_arg = getattr(self,input_handler)(data) training_data = self.PositionalParameters['-training-data'] # Build up the command, consisting of a BaseCommand followed by # input and output (file) specifications command = self._commandline_join( [self.BaseCommand, input_arg, assignment_fp, training_data, '>', outfile, '2>', errfile,] ) if self.HaltExec: raise AssertionError, "Halted exec with command:\n" + command # The return value of system is a 16-bit number containing the signal # number that killed the process, and then the exit status. # We only want to keep the exit status so do a right bitwise shift to # get rid of the signal number byte exit_status = system(command) >> 8 # Determine if error should be raised due to exit status of # appliciation if not self._accept_exit_status(exit_status): raise ApplicationError, \ 'Unacceptable application exit status: %s, command: %s'\ % (str(exit_status),command) # open the stdout and stderr if not being suppressed out = None if not suppress_stdout: out = open(outfile,"r") err = None if not suppress_stderr: err = open(errfile,"r") result_paths = self._get_result_paths(data) result_paths['Assignments'] = ResultPath(assignment_fp) result = CommandLineAppResult( out, err, exit_status, result_paths=result_paths) # Clean up the input file if one was created if remove_tmp: if self._input_filename: remove(self._input_filename) self._input_filename = None return result def _accept_exit_status(self, status): """Returns false if an error occurred in execution """ return (status == 0) def _error_on_missing_application(self,params): """Raise an ApplicationNotFoundError if the app is not accessible """ command = self._get_jar_fp() if not exists(command): raise ApplicationNotFoundError,\ "Cannot find jar file. Is it installed? Is $RDP_JAR_PATH"+\ " set correctly?" def _get_jar_fp(self): """Returns the full path to the JAR file. Raises an ApplicationError if the JAR file cannot be found in the (1) current directory or (2) the path specified in the RDP_JAR_PATH environment variable. """ # handles case where the jar file is in the current working directory if exists(self._command): return self._command # handles the case where the user has specified the location via # an environment variable elif 'RDP_JAR_PATH' in environ: return getenv('RDP_JAR_PATH') # error otherwise else: raise ApplicationError,\ "$RDP_JAR_PATH is not set -- this must be set to use the"+\ " RDP classifier application controller." # Overridden to pull out JVM-specific command-line arguments. def _get_base_command(self): """Returns the base command plus command-line options. Does not include input file, output file, and training set. """ # Necessary? Preserve for consistency. if self._command is None: raise ApplicationError, '_command has not been set.' # Append a change directory to the beginning of the command to change # to self.WorkingDir before running the command # WorkingDir should be in quotes -- filenames might contain spaces cd_command = ''.join(['cd ',str(self.WorkingDir),';']) jvm_command = "java" jvm_arguments = self._commandline_join(self.JvmParameters.values()) jar_arguments = '-jar "%s"' % self._get_jar_fp() result = self._commandline_join( [cd_command, jvm_command, jvm_arguments, jar_arguments] ) return result BaseCommand = property(_get_base_command) def _commandline_join(self, tokens): """Formats a list of tokens as a shell command This seems to be a repeated pattern; may be useful in superclass. """ commands = filter(None, map(str, tokens)) return self._command_delimiter.join(commands).strip() @property def JvmParameters(self): return self.__extract_parameters('jvm') @property def PositionalParameters(self): return self.__extract_parameters('positional') def __extract_parameters(self, name): """Extracts parameters in self.__parameters from self.Parameters Allows the program to conveniently access a subset of user- adjusted parameters, which are stored in the Parameters attribute. Relies on the convention of providing dicts named according to "__parameters" and "__synonyms". The main parameters object is expected to be initialized with the contents of these dicts. This method will throw an exception if either convention is not adhered to. """ parameters = getattr(self, '_' + name + '_parameters') synonyms = getattr(self, '_' + name + '_synonyms') result = Parameters(parameters, synonyms) for key in result.keys(): result[key] = self.Parameters[key] return result class RdpTrainer20(RdpClassifier20): _input_handler = '_input_as_lines' TrainingClass = 'edu/msu/cme/rdp/classifier/train/ClassifierTraineeMaker' PropertiesFile = 'RdpClassifier.properties' def __call__(self, training_seqs_file, taxonomy_file, model_output_dir, remove_tmp=True): return self._train_with_rdp_files( training_seqs_file, taxonomy_file, model_output_dir, remove_tmp) def _train_with_mapping_file(self, training_seqs_file, lineage_file, model_output_dir, remove_tmp=True): """Creates a set of training data for the RDP Classifier training_seqs_file: The set of training sequences, in fasta format. lineage_file: A File-like object that specifies a lineage for each sequence. Each line must contain a Sequence ID, followed by a tab, then followed by the assigned lineage. The taxa comprising the lineage must be separated with a comma. model_output_dir: Directory in which to store training data. remove_tmp: if True, removes tmp files To use the resulting model with the RdpClassifier, set '-training_data' to the following path: model_output_dir + RdpClassifier.PropertiesFile """ def _train_with_rdp_files(self, training_seqs_file, taxonomy_file, model_output_dir, remove_tmp=True): """Creates a set of training data for the RDP Classifier training_seqs_file: A pre-classified set of training sequences, in fasta-like format. Each sequence must be labelled with an identifier (no spaces) and an assigned lineage (taxa separated by ';'). Example of a valid label: ">seq1 ROOT;Ph1;Fam1;G1;" taxonomy_file: A File-like object that specifies a taxonomic heirarchy. Each line in the file must contain a '*'-separated list of the following items: Taxon ID, Taxon Name, Parent Taxon ID, Depth, and Rank. IDs should have an integer format. Example of a valid line: "1*Bacteria*0*0*domain" model_output_dir: Directory in which to store training data. remove_tmp: if True, removes tmp files To use the resulting model with the RdpClassifier, set '-training_data' to the following path: model_output_dir + RdpClassifier.PropertiesFile """ # Three extra pieces of information are required to create # training data. Unless we want built-in support for # versioned training sets, these may be set to sensible # defaults. training_set_id = '1' taxonomy_version = 'version1' modification_info = 'cogent' # The properties file specifies the names of the files in the # training directory. We use the example properties file # directly from the rdp_classifier distribution, which lists # the default set of files created by the application. We # must write this file explicitly after generating the # training data. properties = ( "# Sample ResourceBundle properties file\n" "bergeyTree=bergeyTrainingTree.xml\n" "probabilityList=genus_wordConditionalProbList.txt\n" "probabilityIndex=wordConditionalProbIndexArr.txt\n" "wordPrior=logWordPrior.txt\n" "classifierVersion=Naive Bayesian rRNA Classifier Version 1.0, November 2003\n" ) input_handler = self.InputHandler suppress_stdout = self.SuppressStdout suppress_stderr = self.SuppressStderr if suppress_stdout: outfile = FilePath('/dev/null') else: outfile = self.getTmpFilename(self.TmpDir) if suppress_stderr: errfile = FilePath('/dev/null') else: errfile = FilePath(self.getTmpFilename(self.TmpDir)) input_handler_function = getattr(self, input_handler) taxonomy_filename = input_handler_function(taxonomy_file) training_seqs_filename = input_handler_function(training_seqs_file) # Build up the command, consisting of a BaseCommand followed # by input and output (file) specifications # Example from rdp_classifier/sampledata/README: # java -Xmx400m -cp rdp_classifier-2.0.jar # edu/msu/cme/rdp/classifier/train/ClassifierTraineeMaker # mydata/mytaxon.txt mydata/mytrainseq.fasta 1 version1 test # mydata command = self._commandline_join( [self.BaseCommand, taxonomy_filename, training_seqs_filename, training_set_id, taxonomy_version, modification_info, model_output_dir, '>', outfile, '2>', errfile] ) if self.HaltExec: raise AssertionError, "Halted exec with command:\n" + command # The return value of system is a 16-bit number containing the signal # number that killed the process, and then the exit status. # We only want to keep the exit status so do a right bitwise shift to # get rid of the signal number byte exit_status = system(command) >> 8 # Determine if error should be raised due to exit status of # appliciation if not self._accept_exit_status(exit_status): raise ApplicationError, \ 'Unacceptable application exit status: %s, command: %s'\ % (str(exit_status),command) # must write properties file to output directory manually properties_fp = path.join(model_output_dir, self.PropertiesFile) properties_file = open(properties_fp, 'w') properties_file.write(properties) properties_file.close() # open the stdout and stderr if not being suppressed out = None if not suppress_stdout: out = open(outfile,"r") err = None if not suppress_stderr: err = open(errfile,"r") result = CommandLineAppResult(out, err, exit_status, result_paths=self._get_result_paths(model_output_dir)) # Clean up the input files if remove_tmp: remove(taxonomy_filename) remove(training_seqs_filename) return result def _input_as_lines(self, data): """ Write a seq of lines to a temp file and return the filename string. This method has been overridden for RdpTrainer so that the _input_filename attribute is not assigned. data: a sequence to be written to a file, each element of the sequence will compose a line in the file * Note: the result will be the filename as a FilePath object (which is a string subclass). * Note: '\n' will be stripped off the end of each sequence element before writing to a file in order to avoid multiple new lines accidentally be written to a file """ filename = FilePath(self.getTmpFilename(self.TmpDir)) data_file = open(filename, 'w') # Parent method does not take advantage of laziness, due to # temporary variable that contains entire file contents -- # better to write explicit loop over lines in the data source, # storing only each line in turn. for line in data: line = str(line).strip('\n') data_file.write(line) data_file.write('\n') data_file.close() return filename def _get_result_paths(self, output_dir): files = { 'bergeyTree': 'bergeyTrainingTree.xml', 'probabilityList': 'genus_wordConditionalProbList.txt', 'probabilityIndex': 'wordConditionalProbIndexArr.txt', 'wordPrior': 'logWordPrior.txt', 'properties': self.PropertiesFile, } result_paths = {} for name, file in files.iteritems(): result_paths[name] = ResultPath( Path=path.join(output_dir, file), IsWritten=True) return result_paths # Overridden to pull out JVM-specific command-line arguments. def _get_base_command(self): """Returns the base command plus command-line options. Does not include input file, output file, and training set. """ # Necessary? Preserve for consistency. if self._command is None: raise ApplicationError, '_command has not been set.' # Append a change directory to the beginning of the command to change # to self.WorkingDir before running the command # WorkingDir should be in quotes -- filenames might contain spaces cd_command = ''.join(['cd ',str(self.WorkingDir),';']) jvm_command = "java" jvm_arguments = self._commandline_join(self.JvmParameters.values()) jar_arguments = '-cp "%s"' % self._get_jar_fp() result = self._commandline_join( [cd_command, jvm_command, jvm_arguments, jar_arguments, self.TrainingClass] ) return result BaseCommand = property(_get_base_command) def parse_command_line_parameters(): """ Parses command line arguments """ usage =\ 'usage: %prog [options] input_sequences_filepath' version = 'Version: %prog ' + __version__ parser = OptionParser(usage=usage, version=version) parser.add_option('-o','--output_fp',action='store',\ type='string',dest='output_fp',help='Path to store '+\ 'output file [default: generated from input_sequences_filepath]') parser.add_option('-c','--min_confidence',action='store',\ type='float',dest='min_confidence',help='minimum confidence '+\ 'level to return a classification [default: %default]') parser.set_defaults(verbose=False,min_confidence=0.80) opts,args = parser.parse_args() num_args = 1 if len(args) != num_args: parser.error('Exactly one argument is required.') return opts,args def assign_taxonomy(data, min_confidence=0.80, output_fp=None, training_data_fp=None, max_memory=None): """ Assign taxonomy to each sequence in data with the RDP classifier data: open fasta file object or list of fasta lines confidence: minimum support threshold to assign taxonomy to a sequence output_fp: path to write output; if not provided, result will be returned in a dict of {seq_id:(taxonomy_assignment,confidence)} """ data = list(data) # build a map of seq identifiers as the RDP classifier doesn't # preserve these perfectly identifier_lookup = {} for seq_id, seq in MinimalFastaParser(data): identifier_lookup[seq_id.split()[0]] = seq_id # build the classifier object app = RdpClassifier20() if max_memory is not None: app.Parameters['-Xmx'].on(max_memory) if training_data_fp is not None: app.Parameters['-training-data'].on(training_data_fp) # apply the rdp app controller rdp_result = app('\n'.join(data)) # grab assignment output result_lines = rdp_result['Assignments'] # start a list to store the assignments results = {} # ShortSequenceException messages are written to stdout # Tag these ID's as unassignable stdout_lines = rdp_result['StdOut'] for line in stdout_lines: if line.startswith('ShortSequenceException'): matchobj = re.search('recordID=(\S+)', line) if matchobj: rdp_id = matchobj.group(1) orig_id = identifier_lookup[rdp_id] results[orig_id] = ('Unassignable', 1.0) # iterate over the identifier, assignment strings (this is a bit # of an abuse of the MinimalFastaParser, as these are not truely # fasta lines) for identifier, assignment_str in MinimalFastaParser(result_lines): # get the original identifier from the one in the rdp result identifier = identifier_lookup[\ identifier[:identifier.index('reverse=')].strip()] # build a list to store the assignments we're confident in # (i.e., the ones that have a confidence greater than min_confidence) confident_assignments = [] # keep track of the lowest acceptable confidence value that # has been encountered lowest_confidence = 0.0 # split the taxonomy assignment string assignment_fields = assignment_str.split(';') # iterate over (assignment, assignment confidence) pairs for i in range(0,len(assignment_fields),2): assignment = assignment_fields[i] try: assignment_confidence = float(assignment_fields[i+1]) except IndexError: break # check the confidence of the current assignment if assignment_confidence >= min_confidence: # if the current assignment confidence is greater than # the min, store the assignment and confidence value confident_assignments.append(assignment.strip()) lowest_confidence = assignment_confidence else: # otherwise, we've made it to the lowest assignment that # met the confidence threshold, so bail out of the loop break # store the identifier, the semi-colon-separated assignments, and the # confidence for the last assignment results[identifier] = \ (';'.join(confident_assignments),lowest_confidence) if output_fp: try: output_file = open(output_fp,'w') except OSError: raise OSError, "Can't open output file for writing: %s" % output_fp for seq_id, values in results.items(): output_file.write('%s\t%s\t%1.3f\n' % (seq_id,values[0],values[1])) output_file.close() return None else: return results def train_rdp_classifier(training_seqs_file, taxonomy_file, model_output_dir, max_memory=None): """ Train RDP Classifier, saving to model_output_dir training_seqs_file, taxonomy_file: file-like objects used to train the RDP Classifier (see RdpTrainer documentation for format of training data) model_output_dir: directory in which to save the files necessary to classify sequences according to the training data Once the model data has been generated, the RDP Classifier may """ app = RdpTrainer20() if max_memory is not None: app.Parameters['-Xmx'].on(max_memory) return app(training_seqs_file, taxonomy_file, model_output_dir) def train_rdp_classifier_and_assign_taxonomy( training_seqs_file, taxonomy_file, seqs_to_classify, min_confidence=0.80, model_output_dir=None, classification_output_fp=None, max_memory=None): """ Train RDP Classifier and assign taxonomy in one fell swoop The file objects training_seqs_file and taxonomy_file are used to train the RDP Classifier (see RdpTrainer documentation for details). Model data is stored in model_output_dir. If model_output_dir is not provided, a temporary directory is created and removed after classification. The sequences in seqs_to_classify are classified according to the model and filtered at the desired confidence level (default: 0.80). The results are saved to classification_output_fp if provided, otherwise a dict of {seq_id:(taxonomy_assignment,confidence)} is returned. """ if model_output_dir is None: training_dir = mkdtemp(prefix='RdpTrainer_') else: training_dir = model_output_dir trainer = RdpTrainer20() if max_memory is not None: trainer.Parameters['-Xmx'].on(max_memory) training_results = trainer( training_seqs_file, taxonomy_file, training_dir) training_data_fp = training_results['properties'].name assignment_results = assign_taxonomy( seqs_to_classify, min_confidence=min_confidence, output_fp=classification_output_fp, training_data_fp=training_data_fp, max_memory=max_memory) if model_output_dir is None: rmtree(training_dir) return assignment_results if __name__ == "__main__": opts,args = parse_command_line_parameters() assign_taxonomy(open(args[0]),min_confidence=opts.min_confidence,\ output_fp=opts.output_fp) pycogent-1.9/cogent/app/rnaalifold.py000066400000000000000000000116731273014367000177520ustar00rootroot00000000000000#!/usr/bin/env python from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters, _find_synonym from cogent.core.alignment import Alignment from cogent.core.moltype import RNA from cogent.parse.fasta import MinimalFastaParser from cogent.parse.rnaalifold import rnaalifold_parser, MinimalRnaalifoldParser from cogent.format.clustal import clustal_from_alignment from cogent.struct.rna2d import ViennaStructure __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman","Jeremy Widmann"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class RNAalifold(CommandLineApplication): """Application controller for RNAalifold application reads aligned RNA sequences from stdin or file.aln and calculates their minimum free energy (mfe) structure, partition function (pf) and base pairing probability matrix. OPTIONS -cv Set the weight of the covariance term in the energy function to factor. Default is 1. -nc Set the penalty for non-compatible sequences in the covariance term of the energy function to factor. Default is 1. -E Score pairs with endgaps same as gap-gap pairs. -mis Output \"most informative sequence\" instead of simple consensus: For each column of the alignment output the set of nucleotides with frequence greater than average in IUPAC notation. -p Calculate the partition function and base pairing probability matrix in addition to the mfe structure. Default is calculation of mfe structure only. -noLP Avoid structures without lonely pairs (helices of length 1). In the mfe case structures with lonely pairs are strictly forbid- den. For partition function folding this disallows pairs that can only occur isolated. Setting this option provides a signif- icant speedup. The -T, -d, -4, -noGU, -noCloseGU, -e, -P, -nsp, options should work as in RNAfold If using -C constraints will be read from stdin, the alignment has to given as a filename on the command line. For more info see respective man pages. """ _parameters = { '-cv':ValuedParameter(Prefix='-',Name='cv',Delimiter=' '), '-nc':ValuedParameter(Prefix='-',Name='nc',Delimiter=' '), '-E':FlagParameter(Prefix='-',Name='E'), '-mis':FlagParameter(Prefix='-',Name='mis'), '-noLP':FlagParameter(Prefix='-',Name='noLP'), '-T':ValuedParameter(Prefix='-',Name='T',Value=37,Delimiter=' '), '-4':FlagParameter(Prefix='-',Name=4), '-d':MixedParameter(Prefix='-',Name='d',Delimiter=''), '-noGU':FlagParameter(Prefix='-',Name='noGU'), '-noCloseGU':FlagParameter(Prefix='-',Name='noCloseGU'), '-e':ValuedParameter(Prefix='-',Name='e',Delimiter=' '), '-P':ValuedParameter(Prefix='-',Name='P',Delimiter=' '), '-nsp':ValuedParameter(Prefix='-',Name='nsp',Delimiter=' '), '-C':FlagParameter(Prefix='-',Name='C')} _synonyms = {'Temperature':'-T','Temp':'-T','EnergyRange':'-e'} _command = 'RNAalifold' _input_handler = '_input_as_string' def _get_result_paths(self, data): """Specify the paths of the output files generated by the application You always get back: StdOut, StdErr, and ExitStatus. In addition RNAalifold writes a file: alirna.ps. It seems that this file is always written (no exceptions found so far. The documentation says the application can produce a dotplot (alidot.ps), but it is unclear when this file is produced, and thus it is not added to the results dictionary. """ result = {} result['SS'] = ResultPath(Path=self.WorkingDir+'alirna.ps',\ IsWritten=True) return result def rnaalifold_from_alignment(aln,moltype=RNA,params=None): """Returns seq, pairs, folding energy for alignment. """ #Create Alignment object. Object will handle if seqs are unaligned. aln = Alignment(aln,MolType=RNA) int_map, int_keys = aln.getIntMap() app = RNAalifold(WorkingDir='/tmp',\ InputHandler='_input_as_multiline_string',params=params) res = app(clustal_from_alignment(int_map)) #seq,pairs,energy = rnaalifold_parser(res['StdOut'].readlines()) pairs_list = MinimalRnaalifoldParser(res['StdOut'].readlines()) res.cleanUp() return pairs_list if __name__ == "__main__": from sys import argv aln_file = argv[1] aln = dict(MinimalFastaParser(open(aln_file,'U'))) res = rnaalifold_from_alignment(aln) print res pycogent-1.9/cogent/app/rnaforester.py000066400000000000000000000143151273014367000201650ustar00rootroot00000000000000#!/usr/bin/env python from os import mkdir,getcwd,system,remove,close from random import choice from cogent.util.misc import app_path from cogent.app.util import CommandLineApplication, CommandLineAppResult,\ ResultPath, ApplicationNotFoundError, ApplicationError from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters, _find_synonym, is_not_None __author__ = "Shandy Wikman" __copyright__ = "Copyright 2007-2016, The Cogent Project" __contributors__ = ["Shandy Wikman","Greg Caporaso"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class RNAforester(CommandLineApplication): """Application controller for RNAforester application""" #Not all parameters added!! _parameters = { '-d':FlagParameter(Prefix='-',Name='d',Value=False), '-r':FlagParameter(Prefix='-',Name='r',Value=False), '-m':FlagParameter(Prefix='-',Name='m',Value=True), '-p':FlagParameter(Prefix='-',Name='p',Value=False)} _command1 = 'RNAshapes -C -c 20 -f' _command2 = 'RNAforester' _input_handler = '_input_as_string' def _input_as_lines(self,data): """ """ data = ' '.join([super(RNAforester,self)._input_as_lines(data),'-o f','|']) return data def _input_as_string(self,data): """Makes data the value of a specific parameter This method returns the empty string. The parameter will be printed automatically once set. """ data = ' '.join([data,'-o f','|']) return data def _error_on_missing_application(self,params): """ Raise an ApplicationNotFoundError if the app is not accessible """ if not app_path('RNAforester'): raise ApplicationNotFoundError,\ "Cannot find RNAforester. Is it installed? Is it in your path?" if not app_path('RNAshapes'): raise ApplicationNotFoundError,\ "Cannot find RNAshapes. Is it installed? Is it in your path?" #Override these functions to biuld up the command def __call__(self,data=None, remove_tmp=True): """Run the application with the specified args on data data: anything that can be cast into a string or written out to a file. Usually either a list of things or a single string or number. input_handler will be called on this data before it is passed as part of the command-line argument, so by creating your own input handlers you can customize what kind of data you want you application to accept """ input_handler = self.InputHandler suppress_stdout = self.SuppressStdout suppress_stderr = self.SuppressStderr if suppress_stdout: outfile = '/dev/null' else: outfile = self.getTmpFilename(self.WorkingDir) if suppress_stderr: errfile = '/dev/null' else: errfile = self.getTmpFilename(self.WorkingDir) if data is None: input_arg = '' else: input_arg = getattr(self,input_handler)(data) # Build up the command, consisting of a BaseCommand followed by # input and output (file) specifications first,second = self.BaseCommand command = self._command_delimiter.join(filter(None,\ [first,input_arg,second,'>',outfile,'2>',errfile])) #print 'COMMAND',command if self.HaltExec: raise AssertionError, "Halted exec with command:\n" + command # The return value of system is a 16-bit number containing the signal # number that killed the process, and then the exit status. # We only want to keep the exit status so do a right bitwise shift to # get rid of the signal number byte exit_status = system(command) >> 8 # Determine if error should be raised due to exit status of # appliciation if not self._accept_exit_status(exit_status): raise ApplicationError, \ 'Unacceptable application exit status: %s, command: %s'\ % (str(exit_status),command) # open the stdout and stderr if not being suppressed out = None if not suppress_stdout: out = open(outfile,"r") err = None if not suppress_stderr: err = open(errfile,"r") result = CommandLineAppResult(out,err,exit_status,\ result_paths=self._get_result_paths(data)) # Clean up the input file if one was created if remove_tmp: if self._input_filename: remove(self._input_filename) self._input_filename = None remove(''.join([self.WorkingDir, 'cluster.dot'])) remove(''.join([self.WorkingDir, 'test.out'])) remove(''.join([self.WorkingDir, 'ShapesStderr'])) return result def _get_base_command(self): """ Returns the full command string input_arg: the argument to the command which represents the input to the program, this will be a string, either representing input or a filename to get input from """ command_part1 = [] command_part2 = [] # Append a change directory to the beginning of the command to change # to self.WorkingDir before running the command cd_command = ''.join(['cd ',self.WorkingDir,';']) if self._command1 is None: raise ApplicationError, '_command has not been set.' parameters = self.Parameters command1 = self._command1 command2 = self._command2 command_part1.append(cd_command) command_part1.append(command1) command_part1.append(''.join(['2> ', self.WorkingDir, 'ShapesStderr'])) command_part2.append(command2) command_part2.append(self._command_delimiter.join(filter(\ None,(map(str,parameters.values()))))) return self._command_delimiter.join(command_part1).strip(),\ self._command_delimiter.join(command_part2).strip() BaseCommand = property(_get_base_command) pycogent-1.9/cogent/app/rnashapes.py000066400000000000000000000125721273014367000176220ustar00rootroot00000000000000#!/usr/bin/env python #file: RNAshaper.py """ Author: Shandy Wikman (ens01svn@cs.umu.se) Application controller for RNAshapes application Revision History: 2006 Shandy Wikman created file """ from cogent.app.util import CommandLineApplication,\ CommandLineAppResult, ResultPath from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\ MixedParameter,Parameters, _find_synonym, is_not_None __author__ = "Daniel McDonald and Greg Caporaso" __copyright__ = "Copyright 2007-2016, The Cogent Project" __credits__ = ["Shandy Wikman"] __license__ = "GPL" __version__ = "1.9" __maintainer__ = "Shandy Wikman" __email__ = "ens01svn@cs.umu.se" __status__ = "Development" class RNAshapes(CommandLineApplication): """Application controller for RNAshapes application Options: -h Display this information -H