├── .github └── workflows │ ├── linux-self-hosted.yml │ ├── mac-self-hosted.yml │ ├── main.yml │ └── self-hosted-toy.yml ├── .gitignore ├── .gitmodules ├── 3rd_party ├── ketopt.h ├── kseq.h ├── prebuild.bat ├── pybind11-2.11.1.old │ ├── LICENSE │ ├── MANIFEST.in │ ├── PKG-INFO │ ├── README.rst │ ├── SECURITY.md │ ├── pybind11.egg-info │ │ ├── PKG-INFO │ │ ├── SOURCES.txt │ │ ├── dependency_links.txt │ │ ├── entry_points.txt │ │ ├── not-zip-safe │ │ ├── requires.txt │ │ └── top_level.txt │ ├── pybind11 │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── _version.py │ │ ├── commands.py │ │ ├── include │ │ │ └── pybind11 │ │ │ │ ├── attr.h │ │ │ │ ├── buffer_info.h │ │ │ │ ├── cast.h │ │ │ │ ├── chrono.h │ │ │ │ ├── common.h │ │ │ │ ├── complex.h │ │ │ │ ├── detail │ │ │ │ ├── class.h │ │ │ │ ├── common.h │ │ │ │ ├── descr.h │ │ │ │ ├── init.h │ │ │ │ ├── internals.h │ │ │ │ ├── type_caster_base.h │ │ │ │ └── typeid.h │ │ │ │ ├── eigen.h │ │ │ │ ├── eigen │ │ │ │ ├── common.h │ │ │ │ ├── matrix.h │ │ │ │ └── tensor.h │ │ │ │ ├── embed.h │ │ │ │ ├── eval.h │ │ │ │ ├── functional.h │ │ │ │ ├── gil.h │ │ │ │ ├── iostream.h │ │ │ │ ├── numpy.h │ │ │ │ ├── operators.h │ │ │ │ ├── options.h │ │ │ │ ├── pybind11.h │ │ │ │ ├── pytypes.h │ │ │ │ ├── stl.h │ │ │ │ ├── stl │ │ │ │ └── filesystem.h │ │ │ │ ├── stl_bind.h │ │ │ │ └── type_caster_pyobject_ptr.h │ │ ├── py.typed │ │ ├── setup_helpers.py │ │ └── share │ │ │ ├── cmake │ │ │ └── pybind11 │ │ │ │ ├── FindPythonLibsNew.cmake │ │ │ │ ├── pybind11Common.cmake │ │ │ │ ├── pybind11Config.cmake │ │ │ │ ├── pybind11ConfigVersion.cmake │ │ │ │ ├── pybind11NewTools.cmake │ │ │ │ ├── pybind11Targets.cmake │ │ │ │ └── pybind11Tools.cmake │ │ │ └── pkgconfig │ │ │ └── pybind11.pc │ ├── pyproject.toml │ ├── setup.cfg │ └── setup.py └── refresh │ ├── compression │ └── lib │ │ ├── file_wrapper.h │ │ └── gz_wrapper.h │ └── string_operations │ └── lib │ └── string_operations.h ├── LICENSE ├── README.md ├── agc-dev.sln ├── agc-dev.vcxproj.filters ├── makefile ├── prebuild ├── prebuild.vcxproj ├── prebuild.vcxproj.filters └── prebuild.vcxproj.user ├── refresh.mk ├── src ├── app │ ├── agc-dev.vcxproj │ ├── agc-dev.vcxproj.filters │ ├── agc-dev.vcxproj.user │ ├── application.cpp │ ├── application.h │ └── main.cpp ├── common │ ├── agc_basic.cpp │ ├── agc_basic.h │ ├── agc_decompressor_lib.cpp │ ├── agc_decompressor_lib.h │ ├── archive.cpp │ ├── archive.h │ ├── collection.cpp │ ├── collection.h │ ├── collection_v1.cpp │ ├── collection_v1.h │ ├── collection_v2.cpp │ ├── collection_v2.h │ ├── collection_v3.cpp │ ├── collection_v3.h │ ├── defs.h │ ├── io.h │ ├── lz_diff.cpp │ ├── lz_diff.h │ ├── queue.h │ ├── segment.cpp │ ├── segment.h │ ├── utils.cpp │ └── utils.h ├── core │ ├── agc_compressor.cpp │ ├── agc_compressor.h │ ├── agc_decompressor.cpp │ ├── agc_decompressor.h │ ├── genome_io.cpp │ ├── genome_io.h │ ├── hs.h │ ├── kmer.h │ └── utils_adv.h ├── examples │ ├── example-agc-lib-c.c │ ├── example-agc-lib-cpp.cpp │ └── makefile ├── lib-cxx │ ├── agc-api.h │ ├── lib-cxx.cpp │ ├── lib-cxx.vcxproj │ ├── lib-cxx.vcxproj.filters │ └── lib-cxx.vcxproj.user └── py_agc_api │ ├── py_agc_api.cpp │ ├── py_agc_test.py │ └── set_path.sh └── toy_ex ├── a.fa ├── b.fa ├── c.fa ├── ref.fa ├── ref2.fa └── toy_ex.agc /.gitignore: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio. 3 | ################################################################################ 4 | 5 | /.vs/agc-dev/v16/ipch/AutoPCH 6 | *.db 7 | *.db-shm 8 | *.db-wal 9 | *.opendb 10 | /x64/Release/agc-dev.tlog 11 | /x64/Release 12 | /x64/Debug/agc-dev.tlog 13 | /x64/Debug 14 | /.vs/agc-dev/v16 15 | /.vs 16 | *.obj 17 | x64 18 | *.o 19 | /agc 20 | /bin/obj/libzstd_x64_Release 21 | /bin/x64_Release 22 | /3rd_party/nasm 23 | /bin 24 | /obj 25 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3rd_party/zstd"] 2 | path = 3rd_party/zstd 3 | url = https://github.com/refresh-bio-dependencies/zstd.git 4 | [submodule "3rd_party/mimalloc"] 5 | path = 3rd_party/mimalloc 6 | url = https://github.com/refresh-bio-dependencies/mimalloc.git 7 | [submodule "3rd_party/raduls-inplace"] 8 | path = 3rd_party/raduls-inplace 9 | url = https://github.com/refresh-bio-sandbox/RADULS-inplace-dev.git 10 | [submodule "3rd_party/isa-l"] 11 | path = 3rd_party/isa-l 12 | url = https://github.com/refresh-bio-dependencies/isa-l.git 13 | [submodule "3rd_party/zlib-ng"] 14 | path = 3rd_party/zlib-ng 15 | url = https://github.com/refresh-bio-dependencies/zlib-ng.git 16 | [submodule "3rd_party/libdeflate"] 17 | path = 3rd_party/libdeflate 18 | url = https://github.com/refresh-bio-dependencies/libdeflate.git 19 | [submodule "3rd_party/pybind11"] 20 | path = 3rd_party/pybind11 21 | url = https://github.com/refresh-bio-dependencies/pybind11.git 22 | -------------------------------------------------------------------------------- /3rd_party/ketopt.h: -------------------------------------------------------------------------------- 1 | #ifndef KETOPT_H 2 | #define KETOPT_H 3 | 4 | #include /* for strchr() and strncmp() */ 5 | 6 | #define ko_no_argument 0 7 | #define ko_required_argument 1 8 | #define ko_optional_argument 2 9 | 10 | typedef struct { 11 | int ind; /* equivalent to optind */ 12 | int opt; /* equivalent to optopt */ 13 | const char *arg; /* equivalent to optarg */ 14 | int longidx; /* index of a long option; or -1 if short */ 15 | /* private variables not intended for external uses */ 16 | int i, pos, n_args; 17 | } ketopt_t; 18 | 19 | typedef struct { 20 | char *name; 21 | int has_arg; 22 | int val; 23 | } ko_longopt_t; 24 | 25 | static ketopt_t KETOPT_INIT = { 1, 0, 0, -1, 1, 0, 0 }; 26 | 27 | static void ketopt_permute(const char *argv[], int j, int n) /* move argv[j] over n elements to the left */ 28 | { 29 | int k; 30 | const char *p = argv[j]; 31 | for (k = 0; k < n; ++k) 32 | argv[j - k] = argv[j - k - 1]; 33 | argv[j - k] = p; 34 | } 35 | 36 | /** 37 | * Parse command-line options and arguments 38 | * 39 | * This fuction has a similar interface to GNU's getopt_long(). Each call 40 | * parses one option and returns the option name. s->arg points to the option 41 | * argument if present. The function returns -1 when all command-line arguments 42 | * are parsed. In this case, s->ind is the index of the first non-option 43 | * argument. 44 | * 45 | * @param s status; shall be initialized to KETOPT_INIT on the first call 46 | * @param argc length of argv[] 47 | * @param argv list of command-line arguments; argv[0] is ignored 48 | * @param permute non-zero to move options ahead of non-option arguments 49 | * @param ostr option string 50 | * @param longopts long options 51 | * 52 | * @return ASCII for a short option; ko_longopt_t::val for a long option; -1 if 53 | * argv[] is fully processed; '?' for an unknown option or an ambiguous 54 | * long option; ':' if an option argument is missing 55 | */ 56 | static int ketopt(ketopt_t *s, int argc, const char *argv[], int permute, const char *ostr, const ko_longopt_t *longopts) 57 | { 58 | int opt = -1, i0, j; 59 | if (permute) { 60 | while (s->i < argc && (argv[s->i][0] != '-' || argv[s->i][1] == '\0')) 61 | ++s->i, ++s->n_args; 62 | } 63 | s->arg = 0, s->longidx = -1, i0 = s->i; 64 | if (s->i >= argc || argv[s->i][0] != '-' || argv[s->i][1] == '\0') { 65 | s->ind = s->i - s->n_args; 66 | return -1; 67 | } 68 | if (argv[s->i][0] == '-' && argv[s->i][1] == '-') { /* "--" or a long option */ 69 | if (argv[s->i][2] == '\0') { /* a bare "--" */ 70 | ketopt_permute(argv, s->i, s->n_args); 71 | ++s->i, s->ind = s->i - s->n_args; 72 | return -1; 73 | } 74 | s->opt = 0, opt = '?', s->pos = -1; 75 | if (longopts) { /* parse long options */ 76 | int k, n_exact = 0, n_partial = 0; 77 | const ko_longopt_t *o = 0, *o_exact = 0, *o_partial = 0; 78 | for (j = 2; argv[s->i][j] != '\0' && argv[s->i][j] != '='; ++j) {} /* find the end of the option name */ 79 | for (k = 0; longopts[k].name != 0; ++k) 80 | if (strncmp(&argv[s->i][2], longopts[k].name, j - 2) == 0) { 81 | if (longopts[k].name[j - 2] == 0) ++n_exact, o_exact = &longopts[k]; 82 | else ++n_partial, o_partial = &longopts[k]; 83 | } 84 | if (n_exact > 1 || (n_exact == 0 && n_partial > 1)) return '?'; 85 | o = n_exact == 1? o_exact : n_partial == 1? o_partial : 0; 86 | if (o) { 87 | s->opt = opt = o->val, s->longidx = o - longopts; 88 | if (argv[s->i][j] == '=') s->arg = &argv[s->i][j + 1]; 89 | if (o->has_arg == 1 && argv[s->i][j] == '\0') { 90 | if (s->i < argc - 1) s->arg = argv[++s->i]; 91 | else opt = ':'; /* missing option argument */ 92 | } 93 | } 94 | } 95 | } else { /* a short option */ 96 | char *p; 97 | if (s->pos == 0) s->pos = 1; 98 | opt = s->opt = argv[s->i][s->pos++]; 99 | p = strchr((char*)ostr, opt); 100 | if (p == 0) { 101 | opt = '?'; /* unknown option */ 102 | } else if (p[1] == ':') { 103 | if (argv[s->i][s->pos] == 0) { 104 | if (s->i < argc - 1) s->arg = argv[++s->i]; 105 | else opt = ':'; /* missing option argument */ 106 | } else s->arg = &argv[s->i][s->pos]; 107 | s->pos = -1; 108 | } 109 | } 110 | if (s->pos < 0 || argv[s->i][s->pos] == 0) { 111 | ++s->i, s->pos = 0; 112 | if (s->n_args > 0) /* permute */ 113 | for (j = i0; j < s->i; ++j) 114 | ketopt_permute(argv, j, s->n_args); 115 | } 116 | s->ind = s->i - s->n_args; 117 | return opt; 118 | } 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /3rd_party/prebuild.bat: -------------------------------------------------------------------------------- 1 | rem %1 - $(SolutionDir) 2 | rem %2 - $(Configuration) 3 | 4 | cd %1\3rd_party 5 | 6 | @echo "nasm" 7 | 8 | if exist nasm/nasm.exe ( 9 | @echo "nasm.exe already exists" 10 | cd nasm 11 | ) else ( 12 | rmdir /S /Q nasm 13 | mkdir nasm 14 | cd nasm 15 | curl -L --ssl-no-revoke https://github.com/refresh-bio-dependencies/nasm/releases/download/v2.16.01/nasm-2.16.01-win64.zip --output nasm-2.16.01-win64.zip 16 | tar -xf nasm-2.16.01-win64.zip --strip-components 1 17 | ) 18 | 19 | set PATH=%PATH%;%cd% 20 | cd .. 21 | 22 | @echo %PATH% 23 | 24 | @echo "zlib-ng" 25 | cd zlib-ng 26 | cmake -B build-vs -S . -DZLIB_COMPAT=ON 27 | cmake --build build-vs --config %2 28 | cd .. 29 | 30 | 31 | @echo "isa-l" 32 | cd isa-l 33 | nmake -f Makefile.nmake 34 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Wenzel Jakob , All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | 3. Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | Please also refer to the file .github/CONTRIBUTING.md, which clarifies licensing of 29 | external contributions to this project including patches, pull requests, etc. 30 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/MANIFEST.in: -------------------------------------------------------------------------------- 1 | prune tests 2 | recursive-include pybind11/include/pybind11 *.h 3 | recursive-include pybind11 *.py 4 | recursive-include pybind11 py.typed 5 | include pybind11/share/cmake/pybind11/*.cmake 6 | include LICENSE README.rst SECURITY.md pyproject.toml setup.py setup.cfg 7 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/README.rst: -------------------------------------------------------------------------------- 1 | .. figure:: https://github.com/pybind/pybind11/raw/master/docs/pybind11-logo.png 2 | :alt: pybind11 logo 3 | 4 | **pybind11 — Seamless operability between C++11 and Python** 5 | 6 | |Latest Documentation Status| |Stable Documentation Status| |Gitter chat| |GitHub Discussions| |CI| |Build status| 7 | 8 | |Repology| |PyPI package| |Conda-forge| |Python Versions| 9 | 10 | `Setuptools example `_ 11 | • `Scikit-build example `_ 12 | • `CMake example `_ 13 | 14 | .. start 15 | 16 | 17 | **pybind11** is a lightweight header-only library that exposes C++ types 18 | in Python and vice versa, mainly to create Python bindings of existing 19 | C++ code. Its goals and syntax are similar to the excellent 20 | `Boost.Python `_ 21 | library by David Abrahams: to minimize boilerplate code in traditional 22 | extension modules by inferring type information using compile-time 23 | introspection. 24 | 25 | The main issue with Boost.Python—and the reason for creating such a 26 | similar project—is Boost. Boost is an enormously large and complex suite 27 | of utility libraries that works with almost every C++ compiler in 28 | existence. This compatibility has its cost: arcane template tricks and 29 | workarounds are necessary to support the oldest and buggiest of compiler 30 | specimens. Now that C++11-compatible compilers are widely available, 31 | this heavy machinery has become an excessively large and unnecessary 32 | dependency. 33 | 34 | Think of this library as a tiny self-contained version of Boost.Python 35 | with everything stripped away that isn't relevant for binding 36 | generation. Without comments, the core header files only require ~4K 37 | lines of code and depend on Python (3.6+, or PyPy) and the C++ 38 | standard library. This compact implementation was possible thanks to 39 | some of the new C++11 language features (specifically: tuples, lambda 40 | functions and variadic templates). Since its creation, this library has 41 | grown beyond Boost.Python in many ways, leading to dramatically simpler 42 | binding code in many common situations. 43 | 44 | Tutorial and reference documentation is provided at 45 | `pybind11.readthedocs.io `_. 46 | A PDF version of the manual is available 47 | `here `_. 48 | And the source code is always available at 49 | `github.com/pybind/pybind11 `_. 50 | 51 | 52 | Core features 53 | ------------- 54 | 55 | 56 | pybind11 can map the following core C++ features to Python: 57 | 58 | - Functions accepting and returning custom data structures per value, 59 | reference, or pointer 60 | - Instance methods and static methods 61 | - Overloaded functions 62 | - Instance attributes and static attributes 63 | - Arbitrary exception types 64 | - Enumerations 65 | - Callbacks 66 | - Iterators and ranges 67 | - Custom operators 68 | - Single and multiple inheritance 69 | - STL data structures 70 | - Smart pointers with reference counting like ``std::shared_ptr`` 71 | - Internal references with correct reference counting 72 | - C++ classes with virtual (and pure virtual) methods can be extended 73 | in Python 74 | 75 | Goodies 76 | ------- 77 | 78 | In addition to the core functionality, pybind11 provides some extra 79 | goodies: 80 | 81 | - Python 3.6+, and PyPy3 7.3 are supported with an implementation-agnostic 82 | interface (pybind11 2.9 was the last version to support Python 2 and 3.5). 83 | 84 | - It is possible to bind C++11 lambda functions with captured 85 | variables. The lambda capture data is stored inside the resulting 86 | Python function object. 87 | 88 | - pybind11 uses C++11 move constructors and move assignment operators 89 | whenever possible to efficiently transfer custom data types. 90 | 91 | - It's easy to expose the internal storage of custom data types through 92 | Pythons' buffer protocols. This is handy e.g. for fast conversion 93 | between C++ matrix classes like Eigen and NumPy without expensive 94 | copy operations. 95 | 96 | - pybind11 can automatically vectorize functions so that they are 97 | transparently applied to all entries of one or more NumPy array 98 | arguments. 99 | 100 | - Python's slice-based access and assignment operations can be 101 | supported with just a few lines of code. 102 | 103 | - Everything is contained in just a few header files; there is no need 104 | to link against any additional libraries. 105 | 106 | - Binaries are generally smaller by a factor of at least 2 compared to 107 | equivalent bindings generated by Boost.Python. A recent pybind11 108 | conversion of PyRosetta, an enormous Boost.Python binding project, 109 | `reported `_ 110 | a binary size reduction of **5.4x** and compile time reduction by 111 | **5.8x**. 112 | 113 | - Function signatures are precomputed at compile time (using 114 | ``constexpr``), leading to smaller binaries. 115 | 116 | - With little extra effort, C++ types can be pickled and unpickled 117 | similar to regular Python objects. 118 | 119 | Supported compilers 120 | ------------------- 121 | 122 | 1. Clang/LLVM 3.3 or newer (for Apple Xcode's clang, this is 5.0.0 or 123 | newer) 124 | 2. GCC 4.8 or newer 125 | 3. Microsoft Visual Studio 2017 or newer 126 | 4. Intel classic C++ compiler 18 or newer (ICC 20.2 tested in CI) 127 | 5. Cygwin/GCC (previously tested on 2.5.1) 128 | 6. NVCC (CUDA 11.0 tested in CI) 129 | 7. NVIDIA PGI (20.9 tested in CI) 130 | 131 | About 132 | ----- 133 | 134 | This project was created by `Wenzel 135 | Jakob `_. Significant features and/or 136 | improvements to the code were contributed by Jonas Adler, Lori A. Burns, 137 | Sylvain Corlay, Eric Cousineau, Aaron Gokaslan, Ralf Grosse-Kunstleve, Trent Houliston, Axel 138 | Huebl, @hulucc, Yannick Jadoul, Sergey Lyskov, Johan Mabille, Tomasz Miąsko, 139 | Dean Moldovan, Ben Pritchard, Jason Rhinelander, Boris Schäling, Pim 140 | Schellart, Henry Schreiner, Ivan Smirnov, Boris Staletic, and Patrick Stewart. 141 | 142 | We thank Google for a generous financial contribution to the continuous 143 | integration infrastructure used by this project. 144 | 145 | 146 | Contributing 147 | ~~~~~~~~~~~~ 148 | 149 | See the `contributing 150 | guide `_ 151 | for information on building and contributing to pybind11. 152 | 153 | License 154 | ~~~~~~~ 155 | 156 | pybind11 is provided under a BSD-style license that can be found in the 157 | `LICENSE `_ 158 | file. By using, distributing, or contributing to this project, you agree 159 | to the terms and conditions of this license. 160 | 161 | .. |Latest Documentation Status| image:: https://readthedocs.org/projects/pybind11/badge?version=latest 162 | :target: http://pybind11.readthedocs.org/en/latest 163 | .. |Stable Documentation Status| image:: https://img.shields.io/badge/docs-stable-blue.svg 164 | :target: http://pybind11.readthedocs.org/en/stable 165 | .. |Gitter chat| image:: https://img.shields.io/gitter/room/gitterHQ/gitter.svg 166 | :target: https://gitter.im/pybind/Lobby 167 | .. |CI| image:: https://github.com/pybind/pybind11/workflows/CI/badge.svg 168 | :target: https://github.com/pybind/pybind11/actions 169 | .. |Build status| image:: https://ci.appveyor.com/api/projects/status/riaj54pn4h08xy40?svg=true 170 | :target: https://ci.appveyor.com/project/wjakob/pybind11 171 | .. |PyPI package| image:: https://img.shields.io/pypi/v/pybind11.svg 172 | :target: https://pypi.org/project/pybind11/ 173 | .. |Conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/pybind11.svg 174 | :target: https://github.com/conda-forge/pybind11-feedstock 175 | .. |Repology| image:: https://repology.org/badge/latest-versions/python:pybind11.svg 176 | :target: https://repology.org/project/python:pybind11/versions 177 | .. |Python Versions| image:: https://img.shields.io/pypi/pyversions/pybind11.svg 178 | :target: https://pypi.org/project/pybind11/ 179 | .. |GitHub Discussions| image:: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github 180 | :target: https://github.com/pybind/pybind11/discussions 181 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Security updates are applied only to the latest release. 6 | 7 | ## Reporting a Vulnerability 8 | 9 | If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released. 10 | 11 | Please disclose it at [security advisory](https://github.com/pybind/pybind11/security/advisories/new). 12 | 13 | This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure. 14 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | LICENSE 2 | MANIFEST.in 3 | README.rst 4 | SECURITY.md 5 | pyproject.toml 6 | setup.cfg 7 | setup.py 8 | pybind11/__init__.py 9 | pybind11/__main__.py 10 | pybind11/_version.py 11 | pybind11/commands.py 12 | pybind11/py.typed 13 | pybind11/setup_helpers.py 14 | pybind11.egg-info/PKG-INFO 15 | pybind11.egg-info/SOURCES.txt 16 | pybind11.egg-info/dependency_links.txt 17 | pybind11.egg-info/entry_points.txt 18 | pybind11.egg-info/not-zip-safe 19 | pybind11.egg-info/requires.txt 20 | pybind11.egg-info/top_level.txt 21 | pybind11/include/pybind11/attr.h 22 | pybind11/include/pybind11/buffer_info.h 23 | pybind11/include/pybind11/cast.h 24 | pybind11/include/pybind11/chrono.h 25 | pybind11/include/pybind11/common.h 26 | pybind11/include/pybind11/complex.h 27 | pybind11/include/pybind11/eigen.h 28 | pybind11/include/pybind11/embed.h 29 | pybind11/include/pybind11/eval.h 30 | pybind11/include/pybind11/functional.h 31 | pybind11/include/pybind11/gil.h 32 | pybind11/include/pybind11/iostream.h 33 | pybind11/include/pybind11/numpy.h 34 | pybind11/include/pybind11/operators.h 35 | pybind11/include/pybind11/options.h 36 | pybind11/include/pybind11/pybind11.h 37 | pybind11/include/pybind11/pytypes.h 38 | pybind11/include/pybind11/stl.h 39 | pybind11/include/pybind11/stl_bind.h 40 | pybind11/include/pybind11/type_caster_pyobject_ptr.h 41 | pybind11/include/pybind11/detail/class.h 42 | pybind11/include/pybind11/detail/common.h 43 | pybind11/include/pybind11/detail/descr.h 44 | pybind11/include/pybind11/detail/init.h 45 | pybind11/include/pybind11/detail/internals.h 46 | pybind11/include/pybind11/detail/type_caster_base.h 47 | pybind11/include/pybind11/detail/typeid.h 48 | pybind11/include/pybind11/eigen/common.h 49 | pybind11/include/pybind11/eigen/matrix.h 50 | pybind11/include/pybind11/eigen/tensor.h 51 | pybind11/include/pybind11/stl/filesystem.h 52 | pybind11/share/cmake/pybind11/FindPythonLibsNew.cmake 53 | pybind11/share/cmake/pybind11/pybind11Common.cmake 54 | pybind11/share/cmake/pybind11/pybind11Config.cmake 55 | pybind11/share/cmake/pybind11/pybind11ConfigVersion.cmake 56 | pybind11/share/cmake/pybind11/pybind11NewTools.cmake 57 | pybind11/share/cmake/pybind11/pybind11Targets.cmake 58 | pybind11/share/cmake/pybind11/pybind11Tools.cmake 59 | pybind11/share/pkgconfig/pybind11.pc -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11.egg-info/entry_points.txt: -------------------------------------------------------------------------------- 1 | [console_scripts] 2 | pybind11-config = pybind11.__main__:main 3 | 4 | [pipx.run] 5 | pybind11 = pybind11.__main__:main 6 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11.egg-info/not-zip-safe: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | 2 | [global] 3 | pybind11_global==2.11.1 4 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | pybind11 2 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | if sys.version_info < (3, 6): # noqa: UP036 4 | msg = "pybind11 does not support Python < 3.6. 2.9 was the last release supporting Python 2.7 and 3.5." 5 | raise ImportError(msg) 6 | 7 | 8 | from ._version import __version__, version_info 9 | from .commands import get_cmake_dir, get_include, get_pkgconfig_dir 10 | 11 | __all__ = ( 12 | "version_info", 13 | "__version__", 14 | "get_include", 15 | "get_cmake_dir", 16 | "get_pkgconfig_dir", 17 | ) 18 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/__main__.py: -------------------------------------------------------------------------------- 1 | # pylint: disable=missing-function-docstring 2 | 3 | import argparse 4 | import sys 5 | import sysconfig 6 | 7 | from ._version import __version__ 8 | from .commands import get_cmake_dir, get_include, get_pkgconfig_dir 9 | 10 | 11 | def print_includes() -> None: 12 | dirs = [ 13 | sysconfig.get_path("include"), 14 | sysconfig.get_path("platinclude"), 15 | get_include(), 16 | ] 17 | 18 | # Make unique but preserve order 19 | unique_dirs = [] 20 | for d in dirs: 21 | if d and d not in unique_dirs: 22 | unique_dirs.append(d) 23 | 24 | print(" ".join("-I" + d for d in unique_dirs)) 25 | 26 | 27 | def main() -> None: 28 | parser = argparse.ArgumentParser() 29 | parser.add_argument( 30 | "--version", 31 | action="version", 32 | version=__version__, 33 | help="Print the version and exit.", 34 | ) 35 | parser.add_argument( 36 | "--includes", 37 | action="store_true", 38 | help="Include flags for both pybind11 and Python headers.", 39 | ) 40 | parser.add_argument( 41 | "--cmakedir", 42 | action="store_true", 43 | help="Print the CMake module directory, ideal for setting -Dpybind11_ROOT in CMake.", 44 | ) 45 | parser.add_argument( 46 | "--pkgconfigdir", 47 | action="store_true", 48 | help="Print the pkgconfig directory, ideal for setting $PKG_CONFIG_PATH.", 49 | ) 50 | args = parser.parse_args() 51 | if not sys.argv[1:]: 52 | parser.print_help() 53 | if args.includes: 54 | print_includes() 55 | if args.cmakedir: 56 | print(get_cmake_dir()) 57 | if args.pkgconfigdir: 58 | print(get_pkgconfig_dir()) 59 | 60 | 61 | if __name__ == "__main__": 62 | main() 63 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/_version.py: -------------------------------------------------------------------------------- 1 | from typing import Union 2 | 3 | 4 | def _to_int(s: str) -> Union[int, str]: 5 | try: 6 | return int(s) 7 | except ValueError: 8 | return s 9 | 10 | 11 | __version__ = "2.11.1" 12 | version_info = tuple(_to_int(s) for s in __version__.split(".")) 13 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/commands.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | DIR = os.path.abspath(os.path.dirname(__file__)) 4 | 5 | 6 | def get_include(user: bool = False) -> str: # noqa: ARG001 7 | """ 8 | Return the path to the pybind11 include directory. The historical "user" 9 | argument is unused, and may be removed. 10 | """ 11 | installed_path = os.path.join(DIR, "include") 12 | source_path = os.path.join(os.path.dirname(DIR), "include") 13 | return installed_path if os.path.exists(installed_path) else source_path 14 | 15 | 16 | def get_cmake_dir() -> str: 17 | """ 18 | Return the path to the pybind11 CMake module directory. 19 | """ 20 | cmake_installed_path = os.path.join(DIR, "share", "cmake", "pybind11") 21 | if os.path.exists(cmake_installed_path): 22 | return cmake_installed_path 23 | 24 | msg = "pybind11 not installed, installation required to access the CMake files" 25 | raise ImportError(msg) 26 | 27 | 28 | def get_pkgconfig_dir() -> str: 29 | """ 30 | Return the path to the pybind11 pkgconfig directory. 31 | """ 32 | pkgconfig_installed_path = os.path.join(DIR, "share", "pkgconfig") 33 | if os.path.exists(pkgconfig_installed_path): 34 | return pkgconfig_installed_path 35 | 36 | msg = "pybind11 not installed, installation required to access the pkgconfig files" 37 | raise ImportError(msg) 38 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/buffer_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/buffer_info.h: Python buffer object interface 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/common.h" 13 | 14 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 15 | 16 | PYBIND11_NAMESPACE_BEGIN(detail) 17 | 18 | // Default, C-style strides 19 | inline std::vector c_strides(const std::vector &shape, ssize_t itemsize) { 20 | auto ndim = shape.size(); 21 | std::vector strides(ndim, itemsize); 22 | if (ndim > 0) { 23 | for (size_t i = ndim - 1; i > 0; --i) { 24 | strides[i - 1] = strides[i] * shape[i]; 25 | } 26 | } 27 | return strides; 28 | } 29 | 30 | // F-style strides; default when constructing an array_t with `ExtraFlags & f_style` 31 | inline std::vector f_strides(const std::vector &shape, ssize_t itemsize) { 32 | auto ndim = shape.size(); 33 | std::vector strides(ndim, itemsize); 34 | for (size_t i = 1; i < ndim; ++i) { 35 | strides[i] = strides[i - 1] * shape[i - 1]; 36 | } 37 | return strides; 38 | } 39 | 40 | template 41 | struct compare_buffer_info; 42 | 43 | PYBIND11_NAMESPACE_END(detail) 44 | 45 | /// Information record describing a Python buffer object 46 | struct buffer_info { 47 | void *ptr = nullptr; // Pointer to the underlying storage 48 | ssize_t itemsize = 0; // Size of individual items in bytes 49 | ssize_t size = 0; // Total number of entries 50 | std::string format; // For homogeneous buffers, this should be set to 51 | // format_descriptor::format() 52 | ssize_t ndim = 0; // Number of dimensions 53 | std::vector shape; // Shape of the tensor (1 entry per dimension) 54 | std::vector strides; // Number of bytes between adjacent entries 55 | // (for each per dimension) 56 | bool readonly = false; // flag to indicate if the underlying storage may be written to 57 | 58 | buffer_info() = default; 59 | 60 | buffer_info(void *ptr, 61 | ssize_t itemsize, 62 | const std::string &format, 63 | ssize_t ndim, 64 | detail::any_container shape_in, 65 | detail::any_container strides_in, 66 | bool readonly = false) 67 | : ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim), 68 | shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) { 69 | if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size()) { 70 | pybind11_fail("buffer_info: ndim doesn't match shape and/or strides length"); 71 | } 72 | for (size_t i = 0; i < (size_t) ndim; ++i) { 73 | size *= shape[i]; 74 | } 75 | } 76 | 77 | template 78 | buffer_info(T *ptr, 79 | detail::any_container shape_in, 80 | detail::any_container strides_in, 81 | bool readonly = false) 82 | : buffer_info(private_ctr_tag(), 83 | ptr, 84 | sizeof(T), 85 | format_descriptor::format(), 86 | static_cast(shape_in->size()), 87 | std::move(shape_in), 88 | std::move(strides_in), 89 | readonly) {} 90 | 91 | buffer_info(void *ptr, 92 | ssize_t itemsize, 93 | const std::string &format, 94 | ssize_t size, 95 | bool readonly = false) 96 | : buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}, readonly) {} 97 | 98 | template 99 | buffer_info(T *ptr, ssize_t size, bool readonly = false) 100 | : buffer_info(ptr, sizeof(T), format_descriptor::format(), size, readonly) {} 101 | 102 | template 103 | buffer_info(const T *ptr, ssize_t size, bool readonly = true) 104 | : buffer_info( 105 | const_cast(ptr), sizeof(T), format_descriptor::format(), size, readonly) {} 106 | 107 | explicit buffer_info(Py_buffer *view, bool ownview = true) 108 | : buffer_info( 109 | view->buf, 110 | view->itemsize, 111 | view->format, 112 | view->ndim, 113 | {view->shape, view->shape + view->ndim}, 114 | /* Though buffer::request() requests PyBUF_STRIDES, ctypes objects 115 | * ignore this flag and return a view with NULL strides. 116 | * When strides are NULL, build them manually. */ 117 | view->strides 118 | ? std::vector(view->strides, view->strides + view->ndim) 119 | : detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize), 120 | (view->readonly != 0)) { 121 | // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer) 122 | this->m_view = view; 123 | // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer) 124 | this->ownview = ownview; 125 | } 126 | 127 | buffer_info(const buffer_info &) = delete; 128 | buffer_info &operator=(const buffer_info &) = delete; 129 | 130 | buffer_info(buffer_info &&other) noexcept { (*this) = std::move(other); } 131 | 132 | buffer_info &operator=(buffer_info &&rhs) noexcept { 133 | ptr = rhs.ptr; 134 | itemsize = rhs.itemsize; 135 | size = rhs.size; 136 | format = std::move(rhs.format); 137 | ndim = rhs.ndim; 138 | shape = std::move(rhs.shape); 139 | strides = std::move(rhs.strides); 140 | std::swap(m_view, rhs.m_view); 141 | std::swap(ownview, rhs.ownview); 142 | readonly = rhs.readonly; 143 | return *this; 144 | } 145 | 146 | ~buffer_info() { 147 | if (m_view && ownview) { 148 | PyBuffer_Release(m_view); 149 | delete m_view; 150 | } 151 | } 152 | 153 | Py_buffer *view() const { return m_view; } 154 | Py_buffer *&view() { return m_view; } 155 | 156 | /* True if the buffer item type is equivalent to `T`. */ 157 | // To define "equivalent" by example: 158 | // `buffer_info::item_type_is_equivalent_to(b)` and 159 | // `buffer_info::item_type_is_equivalent_to(b)` may both be true 160 | // on some platforms, but `int` and `unsigned` will never be equivalent. 161 | // For the ground truth, please inspect `detail::compare_buffer_info<>`. 162 | template 163 | bool item_type_is_equivalent_to() const { 164 | return detail::compare_buffer_info::compare(*this); 165 | } 166 | 167 | private: 168 | struct private_ctr_tag {}; 169 | 170 | buffer_info(private_ctr_tag, 171 | void *ptr, 172 | ssize_t itemsize, 173 | const std::string &format, 174 | ssize_t ndim, 175 | detail::any_container &&shape_in, 176 | detail::any_container &&strides_in, 177 | bool readonly) 178 | : buffer_info( 179 | ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {} 180 | 181 | Py_buffer *m_view = nullptr; 182 | bool ownview = false; 183 | }; 184 | 185 | PYBIND11_NAMESPACE_BEGIN(detail) 186 | 187 | template 188 | struct compare_buffer_info { 189 | static bool compare(const buffer_info &b) { 190 | // NOLINTNEXTLINE(bugprone-sizeof-expression) Needed for `PyObject *` 191 | return b.format == format_descriptor::format() && b.itemsize == (ssize_t) sizeof(T); 192 | } 193 | }; 194 | 195 | template 196 | struct compare_buffer_info::value>> { 197 | static bool compare(const buffer_info &b) { 198 | return (size_t) b.itemsize == sizeof(T) 199 | && (b.format == format_descriptor::value 200 | || ((sizeof(T) == sizeof(long)) 201 | && b.format == (std::is_unsigned::value ? "L" : "l")) 202 | || ((sizeof(T) == sizeof(size_t)) 203 | && b.format == (std::is_unsigned::value ? "N" : "n"))); 204 | } 205 | }; 206 | 207 | PYBIND11_NAMESPACE_END(detail) 208 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 209 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/common.h: -------------------------------------------------------------------------------- 1 | #include "detail/common.h" 2 | #warning "Including 'common.h' is deprecated. It will be removed in v3.0. Use 'pybind11.h'." 3 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/complex.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/complex.h: Complex number support 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "pybind11.h" 13 | 14 | #include 15 | 16 | /// glibc defines I as a macro which breaks things, e.g., boost template names 17 | #ifdef I 18 | # undef I 19 | #endif 20 | 21 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 22 | 23 | template 24 | struct format_descriptor, detail::enable_if_t::value>> { 25 | static constexpr const char c = format_descriptor::c; 26 | static constexpr const char value[3] = {'Z', c, '\0'}; 27 | static std::string format() { return std::string(value); } 28 | }; 29 | 30 | #ifndef PYBIND11_CPP17 31 | 32 | template 33 | constexpr const char 34 | format_descriptor, 35 | detail::enable_if_t::value>>::value[3]; 36 | 37 | #endif 38 | 39 | PYBIND11_NAMESPACE_BEGIN(detail) 40 | 41 | template 42 | struct is_fmt_numeric, detail::enable_if_t::value>> { 43 | static constexpr bool value = true; 44 | static constexpr int index = is_fmt_numeric::index + 3; 45 | }; 46 | 47 | template 48 | class type_caster> { 49 | public: 50 | bool load(handle src, bool convert) { 51 | if (!src) { 52 | return false; 53 | } 54 | if (!convert && !PyComplex_Check(src.ptr())) { 55 | return false; 56 | } 57 | Py_complex result = PyComplex_AsCComplex(src.ptr()); 58 | if (result.real == -1.0 && PyErr_Occurred()) { 59 | PyErr_Clear(); 60 | return false; 61 | } 62 | value = std::complex((T) result.real, (T) result.imag); 63 | return true; 64 | } 65 | 66 | static handle 67 | cast(const std::complex &src, return_value_policy /* policy */, handle /* parent */) { 68 | return PyComplex_FromDoubles((double) src.real(), (double) src.imag()); 69 | } 70 | 71 | PYBIND11_TYPE_CASTER(std::complex, const_name("complex")); 72 | }; 73 | PYBIND11_NAMESPACE_END(detail) 74 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 75 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/detail/descr.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/detail/descr.h: Helper type for concatenating type signatures at compile time 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "common.h" 13 | 14 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 15 | PYBIND11_NAMESPACE_BEGIN(detail) 16 | 17 | #if !defined(_MSC_VER) 18 | # define PYBIND11_DESCR_CONSTEXPR static constexpr 19 | #else 20 | # define PYBIND11_DESCR_CONSTEXPR const 21 | #endif 22 | 23 | /* Concatenate type signatures at compile time */ 24 | template 25 | struct descr { 26 | char text[N + 1]{'\0'}; 27 | 28 | constexpr descr() = default; 29 | // NOLINTNEXTLINE(google-explicit-constructor) 30 | constexpr descr(char const (&s)[N + 1]) : descr(s, make_index_sequence()) {} 31 | 32 | template 33 | constexpr descr(char const (&s)[N + 1], index_sequence) : text{s[Is]..., '\0'} {} 34 | 35 | template 36 | // NOLINTNEXTLINE(google-explicit-constructor) 37 | constexpr descr(char c, Chars... cs) : text{c, static_cast(cs)..., '\0'} {} 38 | 39 | static constexpr std::array types() { 40 | return {{&typeid(Ts)..., nullptr}}; 41 | } 42 | }; 43 | 44 | template 45 | constexpr descr plus_impl(const descr &a, 46 | const descr &b, 47 | index_sequence, 48 | index_sequence) { 49 | PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(b); 50 | return {a.text[Is1]..., b.text[Is2]...}; 51 | } 52 | 53 | template 54 | constexpr descr operator+(const descr &a, 55 | const descr &b) { 56 | return plus_impl(a, b, make_index_sequence(), make_index_sequence()); 57 | } 58 | 59 | template 60 | constexpr descr const_name(char const (&text)[N]) { 61 | return descr(text); 62 | } 63 | constexpr descr<0> const_name(char const (&)[1]) { return {}; } 64 | 65 | template 66 | struct int_to_str : int_to_str {}; 67 | template 68 | struct int_to_str<0, Digits...> { 69 | // WARNING: This only works with C++17 or higher. 70 | static constexpr auto digits = descr(('0' + Digits)...); 71 | }; 72 | 73 | // Ternary description (like std::conditional) 74 | template 75 | constexpr enable_if_t> const_name(char const (&text1)[N1], char const (&)[N2]) { 76 | return const_name(text1); 77 | } 78 | template 79 | constexpr enable_if_t> const_name(char const (&)[N1], char const (&text2)[N2]) { 80 | return const_name(text2); 81 | } 82 | 83 | template 84 | constexpr enable_if_t const_name(const T1 &d, const T2 &) { 85 | return d; 86 | } 87 | template 88 | constexpr enable_if_t const_name(const T1 &, const T2 &d) { 89 | return d; 90 | } 91 | 92 | template 93 | auto constexpr const_name() -> remove_cv_t::digits)> { 94 | return int_to_str::digits; 95 | } 96 | 97 | template 98 | constexpr descr<1, Type> const_name() { 99 | return {'%'}; 100 | } 101 | 102 | // If "_" is defined as a macro, py::detail::_ cannot be provided. 103 | // It is therefore best to use py::detail::const_name universally. 104 | // This block is for backward compatibility only. 105 | // (The const_name code is repeated to avoid introducing a "_" #define ourselves.) 106 | #ifndef _ 107 | # define PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY 108 | template 109 | constexpr descr _(char const (&text)[N]) { 110 | return const_name(text); 111 | } 112 | template 113 | constexpr enable_if_t> _(char const (&text1)[N1], char const (&text2)[N2]) { 114 | return const_name(text1, text2); 115 | } 116 | template 117 | constexpr enable_if_t> _(char const (&text1)[N1], char const (&text2)[N2]) { 118 | return const_name(text1, text2); 119 | } 120 | template 121 | constexpr enable_if_t _(const T1 &d1, const T2 &d2) { 122 | return const_name(d1, d2); 123 | } 124 | template 125 | constexpr enable_if_t _(const T1 &d1, const T2 &d2) { 126 | return const_name(d1, d2); 127 | } 128 | 129 | template 130 | auto constexpr _() -> remove_cv_t::digits)> { 131 | return const_name(); 132 | } 133 | template 134 | constexpr descr<1, Type> _() { 135 | return const_name(); 136 | } 137 | #endif // #ifndef _ 138 | 139 | constexpr descr<0> concat() { return {}; } 140 | 141 | template 142 | constexpr descr concat(const descr &descr) { 143 | return descr; 144 | } 145 | 146 | #ifdef __cpp_fold_expressions 147 | template 148 | constexpr descr operator,(const descr &a, 149 | const descr &b) { 150 | return a + const_name(", ") + b; 151 | } 152 | 153 | template 154 | constexpr auto concat(const descr &d, const Args &...args) { 155 | return (d, ..., args); 156 | } 157 | #else 158 | template 159 | constexpr auto concat(const descr &d, const Args &...args) 160 | -> decltype(std::declval>() + concat(args...)) { 161 | return d + const_name(", ") + concat(args...); 162 | } 163 | #endif 164 | 165 | template 166 | constexpr descr type_descr(const descr &descr) { 167 | return const_name("{") + descr + const_name("}"); 168 | } 169 | 170 | PYBIND11_NAMESPACE_END(detail) 171 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 172 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/detail/typeid.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/detail/typeid.h: Compiler-independent access to type identifiers 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | #if defined(__GNUG__) 16 | # include 17 | #endif 18 | 19 | #include "common.h" 20 | 21 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 22 | PYBIND11_NAMESPACE_BEGIN(detail) 23 | 24 | /// Erase all occurrences of a substring 25 | inline void erase_all(std::string &string, const std::string &search) { 26 | for (size_t pos = 0;;) { 27 | pos = string.find(search, pos); 28 | if (pos == std::string::npos) { 29 | break; 30 | } 31 | string.erase(pos, search.length()); 32 | } 33 | } 34 | 35 | PYBIND11_NOINLINE void clean_type_id(std::string &name) { 36 | #if defined(__GNUG__) 37 | int status = 0; 38 | std::unique_ptr res{ 39 | abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free}; 40 | if (status == 0) { 41 | name = res.get(); 42 | } 43 | #else 44 | detail::erase_all(name, "class "); 45 | detail::erase_all(name, "struct "); 46 | detail::erase_all(name, "enum "); 47 | #endif 48 | detail::erase_all(name, "pybind11::"); 49 | } 50 | 51 | inline std::string clean_type_id(const char *typeid_name) { 52 | std::string name(typeid_name); 53 | detail::clean_type_id(name); 54 | return name; 55 | } 56 | 57 | PYBIND11_NAMESPACE_END(detail) 58 | 59 | /// Return a string representation of a C++ type 60 | template 61 | static std::string type_id() { 62 | return detail::clean_type_id(typeid(T).name()); 63 | } 64 | 65 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 66 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/eigen.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/eigen.h: Transparent conversion for dense and sparse Eigen matrices 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "eigen/matrix.h" 13 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/eigen/common.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 The pybind Community. 2 | 3 | #pragma once 4 | 5 | // Common message for `static_assert()`s, which are useful to easily 6 | // preempt much less obvious errors. 7 | #define PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED \ 8 | "Pointer types (in particular `PyObject *`) are not supported as scalar types for Eigen " \ 9 | "types." 10 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/eval.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/eval.h: Support for evaluating Python expressions and statements 3 | from strings and files 4 | 5 | Copyright (c) 2016 Klemens Morgenstern and 6 | Wenzel Jakob 7 | 8 | All rights reserved. Use of this source code is governed by a 9 | BSD-style license that can be found in the LICENSE file. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include "pybind11.h" 15 | 16 | #include 17 | 18 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 19 | PYBIND11_NAMESPACE_BEGIN(detail) 20 | 21 | inline void ensure_builtins_in_globals(object &global) { 22 | #if defined(PYPY_VERSION) || PY_VERSION_HEX < 0x03080000 23 | // Running exec and eval adds `builtins` module under `__builtins__` key to 24 | // globals if not yet present. Python 3.8 made PyRun_String behave 25 | // similarly. Let's also do that for older versions, for consistency. This 26 | // was missing from PyPy3.8 7.3.7. 27 | if (!global.contains("__builtins__")) 28 | global["__builtins__"] = module_::import(PYBIND11_BUILTINS_MODULE); 29 | #else 30 | (void) global; 31 | #endif 32 | } 33 | 34 | PYBIND11_NAMESPACE_END(detail) 35 | 36 | enum eval_mode { 37 | /// Evaluate a string containing an isolated expression 38 | eval_expr, 39 | 40 | /// Evaluate a string containing a single statement. Returns \c none 41 | eval_single_statement, 42 | 43 | /// Evaluate a string containing a sequence of statement. Returns \c none 44 | eval_statements 45 | }; 46 | 47 | template 48 | object eval(const str &expr, object global = globals(), object local = object()) { 49 | if (!local) { 50 | local = global; 51 | } 52 | 53 | detail::ensure_builtins_in_globals(global); 54 | 55 | /* PyRun_String does not accept a PyObject / encoding specifier, 56 | this seems to be the only alternative */ 57 | std::string buffer = "# -*- coding: utf-8 -*-\n" + (std::string) expr; 58 | 59 | int start = 0; 60 | switch (mode) { 61 | case eval_expr: 62 | start = Py_eval_input; 63 | break; 64 | case eval_single_statement: 65 | start = Py_single_input; 66 | break; 67 | case eval_statements: 68 | start = Py_file_input; 69 | break; 70 | default: 71 | pybind11_fail("invalid evaluation mode"); 72 | } 73 | 74 | PyObject *result = PyRun_String(buffer.c_str(), start, global.ptr(), local.ptr()); 75 | if (!result) { 76 | throw error_already_set(); 77 | } 78 | return reinterpret_steal(result); 79 | } 80 | 81 | template 82 | object eval(const char (&s)[N], object global = globals(), object local = object()) { 83 | /* Support raw string literals by removing common leading whitespace */ 84 | auto expr = (s[0] == '\n') ? str(module_::import("textwrap").attr("dedent")(s)) : str(s); 85 | return eval(expr, std::move(global), std::move(local)); 86 | } 87 | 88 | inline void exec(const str &expr, object global = globals(), object local = object()) { 89 | eval(expr, std::move(global), std::move(local)); 90 | } 91 | 92 | template 93 | void exec(const char (&s)[N], object global = globals(), object local = object()) { 94 | eval(s, std::move(global), std::move(local)); 95 | } 96 | 97 | #if defined(PYPY_VERSION) 98 | template 99 | object eval_file(str, object, object) { 100 | pybind11_fail("eval_file not supported in PyPy3. Use eval"); 101 | } 102 | template 103 | object eval_file(str, object) { 104 | pybind11_fail("eval_file not supported in PyPy3. Use eval"); 105 | } 106 | template 107 | object eval_file(str) { 108 | pybind11_fail("eval_file not supported in PyPy3. Use eval"); 109 | } 110 | #else 111 | template 112 | object eval_file(str fname, object global = globals(), object local = object()) { 113 | if (!local) { 114 | local = global; 115 | } 116 | 117 | detail::ensure_builtins_in_globals(global); 118 | 119 | int start = 0; 120 | switch (mode) { 121 | case eval_expr: 122 | start = Py_eval_input; 123 | break; 124 | case eval_single_statement: 125 | start = Py_single_input; 126 | break; 127 | case eval_statements: 128 | start = Py_file_input; 129 | break; 130 | default: 131 | pybind11_fail("invalid evaluation mode"); 132 | } 133 | 134 | int closeFile = 1; 135 | std::string fname_str = (std::string) fname; 136 | FILE *f = _Py_fopen_obj(fname.ptr(), "r"); 137 | if (!f) { 138 | PyErr_Clear(); 139 | pybind11_fail("File \"" + fname_str + "\" could not be opened!"); 140 | } 141 | 142 | if (!global.contains("__file__")) { 143 | global["__file__"] = std::move(fname); 144 | } 145 | 146 | PyObject *result 147 | = PyRun_FileEx(f, fname_str.c_str(), start, global.ptr(), local.ptr(), closeFile); 148 | 149 | if (!result) { 150 | throw error_already_set(); 151 | } 152 | return reinterpret_steal(result); 153 | } 154 | #endif 155 | 156 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 157 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/functional.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/functional.h: std::function<> support 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "pybind11.h" 13 | 14 | #include 15 | 16 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 17 | PYBIND11_NAMESPACE_BEGIN(detail) 18 | 19 | template 20 | struct type_caster> { 21 | using type = std::function; 22 | using retval_type = conditional_t::value, void_type, Return>; 23 | using function_type = Return (*)(Args...); 24 | 25 | public: 26 | bool load(handle src, bool convert) { 27 | if (src.is_none()) { 28 | // Defer accepting None to other overloads (if we aren't in convert mode): 29 | if (!convert) { 30 | return false; 31 | } 32 | return true; 33 | } 34 | 35 | if (!isinstance(src)) { 36 | return false; 37 | } 38 | 39 | auto func = reinterpret_borrow(src); 40 | 41 | /* 42 | When passing a C++ function as an argument to another C++ 43 | function via Python, every function call would normally involve 44 | a full C++ -> Python -> C++ roundtrip, which can be prohibitive. 45 | Here, we try to at least detect the case where the function is 46 | stateless (i.e. function pointer or lambda function without 47 | captured variables), in which case the roundtrip can be avoided. 48 | */ 49 | if (auto cfunc = func.cpp_function()) { 50 | auto *cfunc_self = PyCFunction_GET_SELF(cfunc.ptr()); 51 | if (cfunc_self == nullptr) { 52 | PyErr_Clear(); 53 | } else if (isinstance(cfunc_self)) { 54 | auto c = reinterpret_borrow(cfunc_self); 55 | 56 | function_record *rec = nullptr; 57 | // Check that we can safely reinterpret the capsule into a function_record 58 | if (detail::is_function_record_capsule(c)) { 59 | rec = c.get_pointer(); 60 | } 61 | 62 | while (rec != nullptr) { 63 | if (rec->is_stateless 64 | && same_type(typeid(function_type), 65 | *reinterpret_cast(rec->data[1]))) { 66 | struct capture { 67 | function_type f; 68 | }; 69 | value = ((capture *) &rec->data)->f; 70 | return true; 71 | } 72 | rec = rec->next; 73 | } 74 | } 75 | // PYPY segfaults here when passing builtin function like sum. 76 | // Raising an fail exception here works to prevent the segfault, but only on gcc. 77 | // See PR #1413 for full details 78 | } 79 | 80 | // ensure GIL is held during functor destruction 81 | struct func_handle { 82 | function f; 83 | #if !(defined(_MSC_VER) && _MSC_VER == 1916 && defined(PYBIND11_CPP17)) 84 | // This triggers a syntax error under very special conditions (very weird indeed). 85 | explicit 86 | #endif 87 | func_handle(function &&f_) noexcept 88 | : f(std::move(f_)) { 89 | } 90 | func_handle(const func_handle &f_) { operator=(f_); } 91 | func_handle &operator=(const func_handle &f_) { 92 | gil_scoped_acquire acq; 93 | f = f_.f; 94 | return *this; 95 | } 96 | ~func_handle() { 97 | gil_scoped_acquire acq; 98 | function kill_f(std::move(f)); 99 | } 100 | }; 101 | 102 | // to emulate 'move initialization capture' in C++11 103 | struct func_wrapper { 104 | func_handle hfunc; 105 | explicit func_wrapper(func_handle &&hf) noexcept : hfunc(std::move(hf)) {} 106 | Return operator()(Args... args) const { 107 | gil_scoped_acquire acq; 108 | // casts the returned object as a rvalue to the return type 109 | return hfunc.f(std::forward(args)...).template cast(); 110 | } 111 | }; 112 | 113 | value = func_wrapper(func_handle(std::move(func))); 114 | return true; 115 | } 116 | 117 | template 118 | static handle cast(Func &&f_, return_value_policy policy, handle /* parent */) { 119 | if (!f_) { 120 | return none().release(); 121 | } 122 | 123 | auto result = f_.template target(); 124 | if (result) { 125 | return cpp_function(*result, policy).release(); 126 | } 127 | return cpp_function(std::forward(f_), policy).release(); 128 | } 129 | 130 | PYBIND11_TYPE_CASTER(type, 131 | const_name("Callable[[") + concat(make_caster::name...) 132 | + const_name("], ") + make_caster::name 133 | + const_name("]")); 134 | }; 135 | 136 | PYBIND11_NAMESPACE_END(detail) 137 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 138 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/options.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/options.h: global settings that are configurable at runtime. 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/common.h" 13 | 14 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 15 | 16 | class options { 17 | public: 18 | // Default RAII constructor, which leaves settings as they currently are. 19 | options() : previous_state(global_state()) {} 20 | 21 | // Class is non-copyable. 22 | options(const options &) = delete; 23 | options &operator=(const options &) = delete; 24 | 25 | // Destructor, which restores settings that were in effect before. 26 | ~options() { global_state() = previous_state; } 27 | 28 | // Setter methods (affect the global state): 29 | 30 | options &disable_user_defined_docstrings() & { 31 | global_state().show_user_defined_docstrings = false; 32 | return *this; 33 | } 34 | 35 | options &enable_user_defined_docstrings() & { 36 | global_state().show_user_defined_docstrings = true; 37 | return *this; 38 | } 39 | 40 | options &disable_function_signatures() & { 41 | global_state().show_function_signatures = false; 42 | return *this; 43 | } 44 | 45 | options &enable_function_signatures() & { 46 | global_state().show_function_signatures = true; 47 | return *this; 48 | } 49 | 50 | options &disable_enum_members_docstring() & { 51 | global_state().show_enum_members_docstring = false; 52 | return *this; 53 | } 54 | 55 | options &enable_enum_members_docstring() & { 56 | global_state().show_enum_members_docstring = true; 57 | return *this; 58 | } 59 | 60 | // Getter methods (return the global state): 61 | 62 | static bool show_user_defined_docstrings() { 63 | return global_state().show_user_defined_docstrings; 64 | } 65 | 66 | static bool show_function_signatures() { return global_state().show_function_signatures; } 67 | 68 | static bool show_enum_members_docstring() { 69 | return global_state().show_enum_members_docstring; 70 | } 71 | 72 | // This type is not meant to be allocated on the heap. 73 | void *operator new(size_t) = delete; 74 | 75 | private: 76 | struct state { 77 | bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings. 78 | bool show_function_signatures = true; //< Include auto-generated function signatures 79 | // in docstrings. 80 | bool show_enum_members_docstring = true; //< Include auto-generated member list in enum 81 | // docstrings. 82 | }; 83 | 84 | static state &global_state() { 85 | static state instance; 86 | return instance; 87 | } 88 | 89 | state previous_state; 90 | }; 91 | 92 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 93 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/stl/filesystem.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 The Pybind Development Team. 2 | // All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | #pragma once 6 | 7 | #include "../pybind11.h" 8 | #include "../detail/common.h" 9 | #include "../detail/descr.h" 10 | #include "../cast.h" 11 | #include "../pytypes.h" 12 | 13 | #include 14 | 15 | #ifdef __has_include 16 | # if defined(PYBIND11_CPP17) 17 | # if __has_include() && \ 18 | PY_VERSION_HEX >= 0x03060000 19 | # include 20 | # define PYBIND11_HAS_FILESYSTEM 1 21 | # elif __has_include() 22 | # include 23 | # define PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM 1 24 | # endif 25 | # endif 26 | #endif 27 | 28 | #if !defined(PYBIND11_HAS_FILESYSTEM) && !defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM) \ 29 | && !defined(PYBIND11_HAS_FILESYSTEM_IS_OPTIONAL) 30 | # error \ 31 | "Neither #include nor #include 39 | struct path_caster { 40 | 41 | private: 42 | static PyObject *unicode_from_fs_native(const std::string &w) { 43 | # if !defined(PYPY_VERSION) 44 | return PyUnicode_DecodeFSDefaultAndSize(w.c_str(), ssize_t(w.size())); 45 | # else 46 | // PyPy mistakenly declares the first parameter as non-const. 47 | return PyUnicode_DecodeFSDefaultAndSize(const_cast(w.c_str()), ssize_t(w.size())); 48 | # endif 49 | } 50 | 51 | static PyObject *unicode_from_fs_native(const std::wstring &w) { 52 | return PyUnicode_FromWideChar(w.c_str(), ssize_t(w.size())); 53 | } 54 | 55 | public: 56 | static handle cast(const T &path, return_value_policy, handle) { 57 | if (auto py_str = unicode_from_fs_native(path.native())) { 58 | return module_::import("pathlib") 59 | .attr("Path")(reinterpret_steal(py_str)) 60 | .release(); 61 | } 62 | return nullptr; 63 | } 64 | 65 | bool load(handle handle, bool) { 66 | // PyUnicode_FSConverter and PyUnicode_FSDecoder normally take care of 67 | // calling PyOS_FSPath themselves, but that's broken on PyPy (PyPy 68 | // issue #3168) so we do it ourselves instead. 69 | PyObject *buf = PyOS_FSPath(handle.ptr()); 70 | if (!buf) { 71 | PyErr_Clear(); 72 | return false; 73 | } 74 | PyObject *native = nullptr; 75 | if constexpr (std::is_same_v) { 76 | if (PyUnicode_FSConverter(buf, &native) != 0) { 77 | if (auto *c_str = PyBytes_AsString(native)) { 78 | // AsString returns a pointer to the internal buffer, which 79 | // must not be free'd. 80 | value = c_str; 81 | } 82 | } 83 | } else if constexpr (std::is_same_v) { 84 | if (PyUnicode_FSDecoder(buf, &native) != 0) { 85 | if (auto *c_str = PyUnicode_AsWideCharString(native, nullptr)) { 86 | // AsWideCharString returns a new string that must be free'd. 87 | value = c_str; // Copies the string. 88 | PyMem_Free(c_str); 89 | } 90 | } 91 | } 92 | Py_XDECREF(native); 93 | Py_DECREF(buf); 94 | if (PyErr_Occurred()) { 95 | PyErr_Clear(); 96 | return false; 97 | } 98 | return true; 99 | } 100 | 101 | PYBIND11_TYPE_CASTER(T, const_name("os.PathLike")); 102 | }; 103 | 104 | #endif // PYBIND11_HAS_FILESYSTEM || defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM) 105 | 106 | #if defined(PYBIND11_HAS_FILESYSTEM) 107 | template <> 108 | struct type_caster : public path_caster {}; 109 | #elif defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM) 110 | template <> 111 | struct type_caster 112 | : public path_caster {}; 113 | #endif 114 | 115 | PYBIND11_NAMESPACE_END(detail) 116 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 117 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/include/pybind11/type_caster_pyobject_ptr.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 The pybind Community. 2 | 3 | #pragma once 4 | 5 | #include "detail/common.h" 6 | #include "detail/descr.h" 7 | #include "cast.h" 8 | #include "pytypes.h" 9 | 10 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 11 | PYBIND11_NAMESPACE_BEGIN(detail) 12 | 13 | template <> 14 | class type_caster { 15 | public: 16 | static constexpr auto name = const_name("object"); // See discussion under PR #4601. 17 | 18 | // This overload is purely to guard against accidents. 19 | template ::value, int> = 0> 21 | static handle cast(T &&, return_value_policy, handle /*parent*/) { 22 | static_assert(is_same_ignoring_cvref::value, 23 | "Invalid C++ type T for to-Python conversion (type_caster)."); 24 | return nullptr; // Unreachable. 25 | } 26 | 27 | static handle cast(PyObject *src, return_value_policy policy, handle /*parent*/) { 28 | if (src == nullptr) { 29 | throw error_already_set(); 30 | } 31 | if (PyErr_Occurred()) { 32 | raise_from(PyExc_SystemError, "src != nullptr but PyErr_Occurred()"); 33 | throw error_already_set(); 34 | } 35 | if (policy == return_value_policy::take_ownership) { 36 | return src; 37 | } 38 | if (policy == return_value_policy::reference 39 | || policy == return_value_policy::automatic_reference) { 40 | return handle(src).inc_ref(); 41 | } 42 | pybind11_fail("type_caster::cast(): unsupported return_value_policy: " 43 | + std::to_string(static_cast(policy))); 44 | } 45 | 46 | bool load(handle src, bool) { 47 | value = reinterpret_borrow(src); 48 | return true; 49 | } 50 | 51 | template 52 | using cast_op_type = PyObject *; 53 | 54 | explicit operator PyObject *() { return value.ptr(); } 55 | 56 | private: 57 | object value; 58 | }; 59 | 60 | PYBIND11_NAMESPACE_END(detail) 61 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 62 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/refresh-bio/agc/f0fef1ca444926debdb6970f33a3a985795a8df4/3rd_party/pybind11-2.11.1.old/pybind11/py.typed -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/share/cmake/pybind11/pybind11ConfigVersion.cmake: -------------------------------------------------------------------------------- 1 | # This is a basic version file for the Config-mode of find_package(). 2 | # It is used by write_basic_package_version_file() as input file for configure_file() 3 | # to create a version-file which can be installed along a config.cmake file. 4 | # 5 | # The created file sets PACKAGE_VERSION_EXACT if the current version string and 6 | # the requested version string are exactly the same and it sets 7 | # PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version. 8 | # The variable CVF_VERSION must be set before calling configure_file(). 9 | 10 | set(PACKAGE_VERSION "2.11.1") 11 | 12 | if (PACKAGE_FIND_VERSION_RANGE) 13 | # Package version must be in the requested version range 14 | if ((PACKAGE_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MIN) 15 | OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_GREATER PACKAGE_FIND_VERSION_MAX) 16 | OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION_MAX))) 17 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 18 | else() 19 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 20 | endif() 21 | else() 22 | if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) 23 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 24 | else() 25 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 26 | if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) 27 | set(PACKAGE_VERSION_EXACT TRUE) 28 | endif() 29 | endif() 30 | endif() 31 | 32 | 33 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/share/cmake/pybind11/pybind11Targets.cmake: -------------------------------------------------------------------------------- 1 | # Generated by CMake 2 | 3 | if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.8) 4 | message(FATAL_ERROR "CMake >= 2.8.0 required") 5 | endif() 6 | if(CMAKE_VERSION VERSION_LESS "2.8.3") 7 | message(FATAL_ERROR "CMake >= 2.8.3 required") 8 | endif() 9 | cmake_policy(PUSH) 10 | cmake_policy(VERSION 2.8.3...3.24) 11 | #---------------------------------------------------------------- 12 | # Generated CMake target import file. 13 | #---------------------------------------------------------------- 14 | 15 | # Commands may need to know the format version. 16 | set(CMAKE_IMPORT_FILE_VERSION 1) 17 | 18 | # Protect against multiple inclusion, which would fail when already imported targets are added once more. 19 | set(_cmake_targets_defined "") 20 | set(_cmake_targets_not_defined "") 21 | set(_cmake_expected_targets "") 22 | foreach(_cmake_expected_target IN ITEMS pybind11::pybind11_headers) 23 | list(APPEND _cmake_expected_targets "${_cmake_expected_target}") 24 | if(TARGET "${_cmake_expected_target}") 25 | list(APPEND _cmake_targets_defined "${_cmake_expected_target}") 26 | else() 27 | list(APPEND _cmake_targets_not_defined "${_cmake_expected_target}") 28 | endif() 29 | endforeach() 30 | unset(_cmake_expected_target) 31 | if(_cmake_targets_defined STREQUAL _cmake_expected_targets) 32 | unset(_cmake_targets_defined) 33 | unset(_cmake_targets_not_defined) 34 | unset(_cmake_expected_targets) 35 | unset(CMAKE_IMPORT_FILE_VERSION) 36 | cmake_policy(POP) 37 | return() 38 | endif() 39 | if(NOT _cmake_targets_defined STREQUAL "") 40 | string(REPLACE ";" ", " _cmake_targets_defined_text "${_cmake_targets_defined}") 41 | string(REPLACE ";" ", " _cmake_targets_not_defined_text "${_cmake_targets_not_defined}") 42 | message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_cmake_targets_defined_text}\nTargets not yet defined: ${_cmake_targets_not_defined_text}\n") 43 | endif() 44 | unset(_cmake_targets_defined) 45 | unset(_cmake_targets_not_defined) 46 | unset(_cmake_expected_targets) 47 | 48 | 49 | # Compute the installation prefix relative to this file. 50 | get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) 51 | get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) 52 | get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) 53 | get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) 54 | if(_IMPORT_PREFIX STREQUAL "/") 55 | set(_IMPORT_PREFIX "") 56 | endif() 57 | 58 | # Create imported target pybind11::pybind11_headers 59 | add_library(pybind11::pybind11_headers INTERFACE IMPORTED) 60 | 61 | set_target_properties(pybind11::pybind11_headers PROPERTIES 62 | INTERFACE_COMPILE_FEATURES "cxx_inheriting_constructors;cxx_user_literals;cxx_right_angle_brackets" 63 | INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include" 64 | ) 65 | 66 | if(CMAKE_VERSION VERSION_LESS 3.0.0) 67 | message(FATAL_ERROR "This file relies on consumers using CMake 3.0.0 or greater.") 68 | endif() 69 | 70 | # Load information for each installed configuration. 71 | file(GLOB _cmake_config_files "${CMAKE_CURRENT_LIST_DIR}/pybind11Targets-*.cmake") 72 | foreach(_cmake_config_file IN LISTS _cmake_config_files) 73 | include("${_cmake_config_file}") 74 | endforeach() 75 | unset(_cmake_config_file) 76 | unset(_cmake_config_files) 77 | 78 | # Cleanup temporary variables. 79 | set(_IMPORT_PREFIX) 80 | 81 | # Loop over all imported files and verify that they actually exist 82 | foreach(_cmake_target IN LISTS _cmake_import_check_targets) 83 | foreach(_cmake_file IN LISTS "_cmake_import_check_files_for_${_cmake_target}") 84 | if(NOT EXISTS "${_cmake_file}") 85 | message(FATAL_ERROR "The imported target \"${_cmake_target}\" references the file 86 | \"${_cmake_file}\" 87 | but this file does not exist. Possible reasons include: 88 | * The file was deleted, renamed, or moved to another location. 89 | * An install or uninstall procedure did not complete successfully. 90 | * The installation package was faulty and contained 91 | \"${CMAKE_CURRENT_LIST_FILE}\" 92 | but not all the files it references. 93 | ") 94 | endif() 95 | endforeach() 96 | unset(_cmake_file) 97 | unset("_cmake_import_check_files_for_${_cmake_target}") 98 | endforeach() 99 | unset(_cmake_target) 100 | unset(_cmake_import_check_targets) 101 | 102 | # This file does not depend on other imported targets which have 103 | # been exported from the same project but in a separate export set. 104 | 105 | # Commands beyond this point should not need to know the version. 106 | set(CMAKE_IMPORT_FILE_VERSION) 107 | cmake_policy(POP) 108 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pybind11/share/pkgconfig/pybind11.pc: -------------------------------------------------------------------------------- 1 | prefix=${pcfiledir}/../../ 2 | includedir=${prefix}/include 3 | 4 | Name: pybind11 5 | Description: Seamless operability between C++11 and Python 6 | Version: 2.11.1 7 | Cflags: -I${includedir} 8 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=42", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | long_description = file: README.rst 3 | long_description_content_type = text/x-rst 4 | description = Seamless operability between C++11 and Python 5 | author = Wenzel Jakob 6 | author_email = wenzel.jakob@epfl.ch 7 | url = https://github.com/pybind/pybind11 8 | license = BSD 9 | classifiers = 10 | Development Status :: 5 - Production/Stable 11 | Intended Audience :: Developers 12 | Topic :: Software Development :: Libraries :: Python Modules 13 | Topic :: Utilities 14 | Programming Language :: C++ 15 | Programming Language :: Python :: 3 :: Only 16 | Programming Language :: Python :: 3.6 17 | Programming Language :: Python :: 3.7 18 | Programming Language :: Python :: 3.8 19 | Programming Language :: Python :: 3.9 20 | Programming Language :: Python :: 3.10 21 | Programming Language :: Python :: 3.11 22 | Programming Language :: Python :: 3.12 23 | License :: OSI Approved :: BSD License 24 | Programming Language :: Python :: Implementation :: PyPy 25 | Programming Language :: Python :: Implementation :: CPython 26 | Programming Language :: C++ 27 | Topic :: Software Development :: Libraries :: Python Modules 28 | keywords = 29 | C++11 30 | Python bindings 31 | project_urls = 32 | Documentation = https://pybind11.readthedocs.io/ 33 | Bug Tracker = https://github.com/pybind/pybind11/issues 34 | Discussions = https://github.com/pybind/pybind11/discussions 35 | Changelog = https://pybind11.readthedocs.io/en/latest/changelog.html 36 | Chat = https://gitter.im/pybind/Lobby 37 | 38 | [options] 39 | python_requires = >=3.6 40 | zip_safe = False 41 | 42 | [egg_info] 43 | tag_build = 44 | tag_date = 0 45 | 46 | -------------------------------------------------------------------------------- /3rd_party/pybind11-2.11.1.old/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Setup script (in the sdist or in tools/setup_main.py in the repository) 4 | 5 | from setuptools import setup 6 | 7 | cmdclass = {} 8 | 9 | 10 | setup( 11 | name="pybind11", 12 | version="2.11.1", 13 | download_url='https://github.com/pybind/pybind11/tarball/v2.11.1', 14 | packages=[ 15 | "pybind11", 16 | "pybind11.include.pybind11", 17 | "pybind11.include.pybind11.detail", 18 | "pybind11.include.pybind11.eigen", 19 | "pybind11.include.pybind11.stl", 20 | "pybind11.share.cmake.pybind11", 21 | "pybind11.share.pkgconfig", 22 | ], 23 | package_data={ 24 | "pybind11": ["py.typed"], 25 | "pybind11.include.pybind11": ["*.h"], 26 | "pybind11.include.pybind11.detail": ["*.h"], 27 | "pybind11.include.pybind11.eigen": ["*.h"], 28 | "pybind11.include.pybind11.stl": ["*.h"], 29 | "pybind11.share.cmake.pybind11": ["*.cmake"], 30 | "pybind11.share.pkgconfig": ["*.pc"], 31 | }, 32 | extras_require={ 33 | "global": ["pybind11_global==2.11.1"] 34 | }, 35 | entry_points={ 36 | "console_scripts": [ 37 | "pybind11-config = pybind11.__main__:main", 38 | ], 39 | "pipx.run": [ 40 | "pybind11 = pybind11.__main__:main", 41 | ] 42 | }, 43 | cmdclass=cmdclass 44 | ) 45 | -------------------------------------------------------------------------------- /3rd_party/refresh/compression/lib/gz_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef _GZ_WRAPPER_H 2 | #define _GZ_WRAPPER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace refresh 11 | { 12 | // ********************************************************************************** 13 | class gz_in_memory 14 | { 15 | static const int min_compression_level = 1; 16 | static const int max_compression_level = 12; 17 | 18 | int compression_level; 19 | bool low_memory; 20 | 21 | libdeflate_compressor *ld_comp = nullptr; 22 | libdeflate_decompressor *ld_decomp = nullptr; 23 | 24 | enum class mode_t { none, buffer }; 25 | 26 | mode_t working_mode = mode_t::none; 27 | 28 | void ensure_comp() 29 | { 30 | if (!ld_comp) 31 | ld_comp = libdeflate_alloc_compressor(compression_level); 32 | } 33 | 34 | void ensure_decomp() 35 | { 36 | if (!ld_decomp) 37 | ld_decomp = libdeflate_alloc_decompressor(); 38 | } 39 | 40 | void free_comp() 41 | { 42 | if (ld_comp) 43 | { 44 | libdeflate_free_compressor(ld_comp); 45 | ld_comp = nullptr; 46 | } 47 | } 48 | 49 | void free_decomp() 50 | { 51 | if (ld_decomp) 52 | { 53 | libdeflate_free_decompressor(ld_decomp); 54 | ld_decomp = nullptr; 55 | } 56 | } 57 | 58 | void check_and_set_compression_level(int _compression_level) 59 | { 60 | compression_level = _compression_level; 61 | 62 | if (compression_level < min_compression_level) 63 | compression_level = min_compression_level; 64 | 65 | if (compression_level > max_compression_level) 66 | compression_level = max_compression_level; 67 | } 68 | 69 | public: 70 | gz_in_memory(int _compression_level = 9, bool low_memory = false) : 71 | low_memory(low_memory) 72 | { 73 | check_and_set_compression_level(_compression_level); 74 | } 75 | 76 | gz_in_memory(gz_in_memory&& rhs) noexcept 77 | { 78 | compression_level = rhs.compression_level; 79 | low_memory = rhs.low_memory; 80 | 81 | working_mode = rhs.working_mode; 82 | rhs.working_mode = mode_t::none; 83 | 84 | ld_comp = rhs.ld_comp; 85 | rhs.ld_comp = nullptr; 86 | 87 | ld_decomp = rhs.ld_decomp; 88 | rhs.ld_decomp = nullptr; 89 | }; 90 | 91 | gz_in_memory& operator=(gz_in_memory&& rhs) noexcept 92 | { 93 | compression_level = rhs.compression_level; 94 | low_memory = rhs.low_memory; 95 | 96 | working_mode = rhs.working_mode; 97 | rhs.working_mode = mode_t::none; 98 | 99 | free_comp(); 100 | ld_comp = rhs.ld_comp; 101 | rhs.ld_comp = nullptr; 102 | 103 | free_decomp(); 104 | ld_decomp = rhs.ld_decomp; 105 | rhs.ld_decomp = nullptr; 106 | 107 | return *this; 108 | } 109 | 110 | ~gz_in_memory() 111 | { 112 | free_comp(); 113 | free_decomp(); 114 | } 115 | 116 | void set_compression_level(size_t _compression_level) 117 | { 118 | check_and_set_compression_level(_compression_level); 119 | 120 | free_comp(); 121 | } 122 | 123 | static int get_min_compression_level() 124 | { 125 | return min_compression_level; 126 | } 127 | 128 | static int get_max_compression_level() 129 | { 130 | return max_compression_level; 131 | } 132 | 133 | size_t get_overhead(size_t to_compress_size) 134 | { 135 | ensure_comp(); 136 | 137 | auto r = libdeflate_gzip_compress_bound(ld_comp, to_compress_size) - to_compress_size; 138 | 139 | if (low_memory) 140 | free_comp(); 141 | 142 | return r; 143 | } 144 | 145 | size_t compress(const void* src, const size_t src_size, void* dest, size_t dest_size, int level = 0) 146 | { 147 | if (working_mode == mode_t::none) 148 | working_mode = mode_t::buffer; 149 | else if (working_mode != mode_t::buffer) 150 | return 0; 151 | 152 | if (level == 0) 153 | level = compression_level; 154 | 155 | if (level != compression_level) 156 | { 157 | free_comp(); 158 | check_and_set_compression_level(level); 159 | } 160 | 161 | ensure_comp(); 162 | 163 | if (libdeflate_gzip_compress_bound(ld_comp, src_size) > dest_size) 164 | return 0; 165 | 166 | auto r = libdeflate_gzip_compress(ld_comp, src, src_size, dest, dest_size); 167 | 168 | if (low_memory) 169 | free_comp(); 170 | 171 | return r; 172 | } 173 | 174 | size_t decompress(const void* src, const size_t src_size, void* dest, size_t dest_size) 175 | { 176 | ensure_decomp(); 177 | 178 | size_t decoded_size; 179 | auto r = libdeflate_gzip_decompress(ld_decomp, src, src_size, dest, dest_size, &decoded_size); 180 | 181 | if (low_memory) 182 | free_decomp(); 183 | 184 | return decoded_size; 185 | } 186 | }; 187 | } 188 | 189 | #endif 190 | -------------------------------------------------------------------------------- /3rd_party/refresh/string_operations/lib/string_operations.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__x86_64__) || defined(_M_AMD64) 6 | #include 7 | #include 8 | #elif defined(__aarch64__) 9 | #include 10 | #endif 11 | 12 | 13 | namespace refresh 14 | { 15 | namespace details 16 | { 17 | template 18 | size_t matching_length_naive(Iter* first, Iter* second, size_t max_length) 19 | { 20 | size_t len; 21 | 22 | for (len = 0; len < max_length; ++len) 23 | if (first[len] != second[len]) 24 | break; 25 | 26 | return len; 27 | } 28 | 29 | #if defined(__x86_64__) || defined(_M_AMD64) 30 | // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html 31 | 32 | template 33 | size_t matching_length_avx(Iter* first, Iter* second, size_t max_length) 34 | { 35 | const size_t CHAR_SIZE = sizeof(*first); 36 | 37 | size_t len; 38 | 39 | if (max_length < 16 / CHAR_SIZE) 40 | return matching_length_naive(first, second, max_length); 41 | 42 | const uint32_t VEC_SIZE = 16 / CHAR_SIZE; 43 | 44 | for (len = 0; len + VEC_SIZE < max_length; len += VEC_SIZE) 45 | { 46 | const __m128i x = _mm_loadu_si128((__m128i const*) (first + len)); 47 | const __m128i y = _mm_loadu_si128((__m128i const*) (second + len)); 48 | 49 | uint32_t m = (uint32_t)(_mm_movemask_epi8(_mm_cmpeq_epi8(x, y)) ^ 0xffff); 50 | 51 | if (m != 0) 52 | return len + std::countr_zero(m) / CHAR_SIZE; 53 | } 54 | 55 | auto rest = max_length % VEC_SIZE; 56 | 57 | if(rest) 58 | len -= VEC_SIZE - rest; 59 | 60 | const __m128i x = _mm_loadu_si128((__m128i const*) (first + len)); 61 | const __m128i y = _mm_loadu_si128((__m128i const*) (second + len)); 62 | 63 | uint32_t m = (uint32_t)(_mm_movemask_epi8(_mm_cmpeq_epi8(x, y)) ^ 0xffff); 64 | 65 | if (m != 0) 66 | return len + std::countr_zero(m) / CHAR_SIZE; 67 | 68 | return max_length; 69 | } 70 | #endif 71 | 72 | #if defined(__aarch64__) 73 | // https://developer.arm.com/architectures/instruction-sets/intrinsics 74 | 75 | template 76 | size_t matching_length_neon(Iter* first, Iter* second, size_t max_length) 77 | { 78 | const size_t CHAR_SIZE = sizeof(*first); 79 | 80 | size_t len; 81 | 82 | if (max_length < 16 / CHAR_SIZE) 83 | return matching_length_naive(first, second, max_length); 84 | 85 | const uint32_t VEC_SIZE = 16 / CHAR_SIZE; 86 | 87 | for (len = 0; len + VEC_SIZE < max_length; len += VEC_SIZE) 88 | { 89 | const uint8x16_t x = vld1q_u8((uint8_t const*) (first + len)); 90 | const uint8x16_t y = vld1q_u8((uint8_t const*) (second + len)); 91 | 92 | uint8x16_t c = vceqq_u8(x, y); 93 | uint64x2_t m = vreinterpretq_u64_u8(c); 94 | 95 | if (~m[0]) 96 | return len + std::countr_zero(~m[0]) / 8 / CHAR_SIZE; 97 | else if(~m[1]) 98 | return len + 8 / CHAR_SIZE + std::countr_zero(~m[1]) / 8 / CHAR_SIZE; 99 | } 100 | 101 | auto rest = max_length % VEC_SIZE; 102 | 103 | if (rest) 104 | len -= VEC_SIZE - rest; 105 | 106 | const uint8x16_t x = vld1q_u8((uint8_t const*)(first + len)); 107 | const uint8x16_t y = vld1q_u8((uint8_t const*)(second + len)); 108 | 109 | uint8x16_t c = vceqq_u8(x, y); 110 | uint64x2_t m = vreinterpretq_u64_u8(c); 111 | 112 | if (~m[0]) 113 | return len + std::countr_zero(~m[0]) / 8 / CHAR_SIZE; 114 | else if (~m[1]) 115 | return len + 8 / CHAR_SIZE + std::countr_zero(~m[1]) / 8 / CHAR_SIZE; 116 | 117 | return max_length; 118 | } 119 | #endif 120 | } 121 | 122 | template 123 | size_t matching_length(Iter* first, Iter* second, size_t max_length) 124 | { 125 | 126 | #if defined(__x86_64__) || defined(_M_AMD64) 127 | if constexpr (sizeof(*first) == 1) 128 | return details::matching_length_avx(first, second, max_length); 129 | else if constexpr (sizeof(*first) == 2) 130 | return details::matching_length_avx(first, second, max_length); 131 | else if constexpr (sizeof(*first) == 4) 132 | return details::matching_length_avx(first, second, max_length); 133 | else if constexpr (sizeof(*first) == 8) 134 | return details::matching_length_avx(first, second, max_length); 135 | else 136 | return details::matching_length_naive(first, second, max_length); 137 | #elif defined(__aarch64__) 138 | if constexpr (sizeof(*first) == 1) 139 | return details::matching_length_neon(first, second, max_length); 140 | else if constexpr (sizeof(*first) == 2) 141 | return details::matching_length_neon(first, second, max_length); 142 | else if constexpr (sizeof(*first) == 4) 143 | return details::matching_length_neon(first, second, max_length); 144 | else if constexpr (sizeof(*first) == 8) 145 | return details::matching_length_neon(first, second, max_length); 146 | else 147 | return details::matching_length_naive(first, second, max_length); 148 | #else 149 | return details::matchin_length_naive(first, second, max_length); 150 | #endif 151 | 152 | } 153 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 REFRESH Bioinformatics Group 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /agc-dev.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31903.59 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "agc-dev", "src\app\agc-dev.vcxproj", "{5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib-cxx", "src\lib-cxx\lib-cxx.vcxproj", "{2ED76904-2299-4CFF-A406-00F77DEBF7B1}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libzstd", "3rd_party\zstd\build\VS2022\libzstd\libzstd.vcxproj", "{8BFD8150-94D5-4BF9-8A50-7BD9929A0850}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Raduls", "3rd_party\raduls-inplace\Raduls\Raduls.vcxproj", "{4C0F01B6-4967-40E6-A39A-90D9BB2281AD}" 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdeflate_static", "3rd_party\libdeflate\build-vs\libdeflate_static.vcxproj", "{0DF64642-6604-30B0-9FFA-1BB593BA2CB1}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|x64 = Debug|x64 19 | Debug|x86 = Debug|x86 20 | MinSizeRel|x64 = MinSizeRel|x64 21 | MinSizeRel|x86 = MinSizeRel|x86 22 | Release|x64 = Release|x64 23 | Release|x86 = Release|x86 24 | RelWithDebInfo|x64 = RelWithDebInfo|x64 25 | RelWithDebInfo|x86 = RelWithDebInfo|x86 26 | EndGlobalSection 27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 28 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.Debug|x64.ActiveCfg = Debug|x64 29 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.Debug|x64.Build.0 = Debug|x64 30 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.Debug|x86.ActiveCfg = Debug|Win32 31 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.Debug|x86.Build.0 = Debug|Win32 32 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.MinSizeRel|x64.ActiveCfg = Release|x64 33 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.MinSizeRel|x64.Build.0 = Release|x64 34 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.MinSizeRel|x86.ActiveCfg = Release|Win32 35 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.MinSizeRel|x86.Build.0 = Release|Win32 36 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.Release|x64.ActiveCfg = Release|x64 37 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.Release|x64.Build.0 = Release|x64 38 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.Release|x86.ActiveCfg = Release|Win32 39 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.Release|x86.Build.0 = Release|Win32 40 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.RelWithDebInfo|x64.ActiveCfg = Release|x64 41 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.RelWithDebInfo|x64.Build.0 = Release|x64 42 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 43 | {5B2AE1F5-5457-46A6-B9BD-A2AAAE076432}.RelWithDebInfo|x86.Build.0 = Release|Win32 44 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.Debug|x64.ActiveCfg = Debug|x64 45 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.Debug|x64.Build.0 = Debug|x64 46 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.Debug|x86.ActiveCfg = Debug|Win32 47 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.Debug|x86.Build.0 = Debug|Win32 48 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.MinSizeRel|x64.ActiveCfg = Release|x64 49 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.MinSizeRel|x64.Build.0 = Release|x64 50 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.MinSizeRel|x86.ActiveCfg = Release|Win32 51 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.MinSizeRel|x86.Build.0 = Release|Win32 52 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.Release|x64.ActiveCfg = Release|x64 53 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.Release|x64.Build.0 = Release|x64 54 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.Release|x86.ActiveCfg = Release|Win32 55 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.Release|x86.Build.0 = Release|Win32 56 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.RelWithDebInfo|x64.ActiveCfg = Release|x64 57 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.RelWithDebInfo|x64.Build.0 = Release|x64 58 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 59 | {2ED76904-2299-4CFF-A406-00F77DEBF7B1}.RelWithDebInfo|x86.Build.0 = Release|Win32 60 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.Debug|x64.ActiveCfg = Debug|x64 61 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.Debug|x64.Build.0 = Debug|x64 62 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.Debug|x86.ActiveCfg = Debug|Win32 63 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.Debug|x86.Build.0 = Debug|Win32 64 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.MinSizeRel|x64.ActiveCfg = Debug|x64 65 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.MinSizeRel|x64.Build.0 = Debug|x64 66 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.MinSizeRel|x86.ActiveCfg = Debug|Win32 67 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.MinSizeRel|x86.Build.0 = Debug|Win32 68 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.Release|x64.ActiveCfg = Release|x64 69 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.Release|x64.Build.0 = Release|x64 70 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.Release|x86.ActiveCfg = Release|Win32 71 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.Release|x86.Build.0 = Release|Win32 72 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.RelWithDebInfo|x64.ActiveCfg = Release|x64 73 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.RelWithDebInfo|x64.Build.0 = Release|x64 74 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 75 | {8BFD8150-94D5-4BF9-8A50-7BD9929A0850}.RelWithDebInfo|x86.Build.0 = Release|Win32 76 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.Debug|x64.ActiveCfg = Debug|x64 77 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.Debug|x64.Build.0 = Debug|x64 78 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.Debug|x86.ActiveCfg = Debug|Win32 79 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.Debug|x86.Build.0 = Debug|Win32 80 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.MinSizeRel|x64.ActiveCfg = Debug|x64 81 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.MinSizeRel|x64.Build.0 = Debug|x64 82 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.MinSizeRel|x86.ActiveCfg = Debug|Win32 83 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.MinSizeRel|x86.Build.0 = Debug|Win32 84 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.Release|x64.ActiveCfg = Release|x64 85 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.Release|x64.Build.0 = Release|x64 86 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.Release|x86.ActiveCfg = Release|Win32 87 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.Release|x86.Build.0 = Release|Win32 88 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.RelWithDebInfo|x64.ActiveCfg = Release|x64 89 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.RelWithDebInfo|x64.Build.0 = Release|x64 90 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 91 | {4C0F01B6-4967-40E6-A39A-90D9BB2281AD}.RelWithDebInfo|x86.Build.0 = Release|Win32 92 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.Debug|x64.ActiveCfg = Debug|x64 93 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.Debug|x64.Build.0 = Debug|x64 94 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.Debug|x86.ActiveCfg = Debug|x64 95 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.Debug|x86.Build.0 = Debug|x64 96 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 97 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 98 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.MinSizeRel|x86.ActiveCfg = MinSizeRel|x64 99 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.MinSizeRel|x86.Build.0 = MinSizeRel|x64 100 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.Release|x64.ActiveCfg = Release|x64 101 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.Release|x64.Build.0 = Release|x64 102 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.Release|x86.ActiveCfg = Release|x64 103 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.Release|x86.Build.0 = Release|x64 104 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 105 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 106 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 107 | {0DF64642-6604-30B0-9FFA-1BB593BA2CB1}.RelWithDebInfo|x86.Build.0 = RelWithDebInfo|x64 108 | EndGlobalSection 109 | GlobalSection(SolutionProperties) = preSolution 110 | HideSolutionNode = FALSE 111 | EndGlobalSection 112 | GlobalSection(ExtensibilityGlobals) = postSolution 113 | SolutionGuid = {21C1764D-6F99-4736-ABCB-242825AA9E40} 114 | EndGlobalSection 115 | EndGlobal 116 | -------------------------------------------------------------------------------- /agc-dev.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {99d14e4a-2ecf-4ebb-b815-51ee0856aff0} 18 | 19 | 20 | {dd1087be-e27f-4fcb-a612-979dfaf0c74a} 21 | 22 | 23 | {744cb08d-8a9e-40a4-91ff-83781380fcd8} 24 | 25 | 26 | 27 | 28 | Libs\Debug 29 | 30 | 31 | Libs\Debug 32 | 33 | 34 | Libs\Release 35 | 36 | 37 | Libs\Release 38 | 39 | 40 | Libs\Debug 41 | 42 | 43 | Libs\Release 44 | 45 | 46 | Libs\Release 47 | 48 | 49 | Libs\Debug 50 | 51 | 52 | 53 | 54 | Libs 55 | 56 | 57 | Libs 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | Header Files 79 | 80 | 81 | Header Files 82 | 83 | 84 | Header Files 85 | 86 | 87 | Header Files 88 | 89 | 90 | Header Files 91 | 92 | 93 | Header Files 94 | 95 | 96 | Header Files 97 | 98 | 99 | Header Files 100 | 101 | 102 | 103 | 104 | Source Files 105 | 106 | 107 | Source Files 108 | 109 | 110 | Source Files 111 | 112 | 113 | Source Files 114 | 115 | 116 | Source Files 117 | 118 | 119 | Source Files 120 | 121 | 122 | Source Files 123 | 124 | 125 | Source Files 126 | 127 | 128 | Source Files 129 | 130 | 131 | Source Files 132 | 133 | 134 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | # all: agc libagc py_agc_api 2 | all: agc libagc py_agc_api 3 | 4 | # *** REFRESH makefile utils 5 | include refresh.mk 6 | 7 | $(call INIT_SUBMODULES) 8 | $(call INIT_GLOBALS) 9 | $(call CHECK_OS_ARCH, $(PLATFORM)) 10 | 11 | # *** Project directories 12 | $(call SET_SRC_OBJ_BIN,src,obj,bin) 13 | 3RD_PARTY_DIR := ./3rd_party 14 | 15 | # *** Project configuration 16 | $(call CHECK_NASM) 17 | $(call ADD_MIMALLOC, $(3RD_PARTY_DIR)/mimalloc) 18 | $(call PROPOSE_ISAL, $(3RD_PARTY_DIR)/isa-l) 19 | $(call PROPOSE_ZLIB_NG, $(3RD_PARTY_DIR)/zlib-ng) 20 | $(call CHOOSE_GZIP_DECOMPRESSION) 21 | $(call ADD_LIBDEFLATE, $(3RD_PARTY_DIR)/libdeflate) 22 | $(call ADD_LIBZSTD, $(3RD_PARTY_DIR)/zstd) 23 | $(call ADD_RADULS_INPLACE,$(3RD_PARTY_DIR)/raduls-inplace) 24 | $(call ADD_PYBIND11,$(3RD_PARTY_DIR)/pybind11/include) 25 | $(call SET_STATIC, $(STATIC_LINK)) 26 | 27 | $(call SET_C_CPP_STANDARDS, c11, c++20) 28 | $(call ADD_REFRESH_LIB, $(3RD_PARTY_DIR)) 29 | 30 | $(call SET_GIT_COMMIT) 31 | 32 | $(call SET_FLAGS, $(TYPE)) 33 | 34 | $(call SET_COMPILER_VERSION_ALLOWED, GCC, Linux_x86_64, 10, 20) 35 | $(call SET_COMPILER_VERSION_ALLOWED, GCC, Linux_aarch64, 11, 20) 36 | $(call SET_COMPILER_VERSION_ALLOWED, GCC, Darwin_x86_64, 11, 13) 37 | $(call SET_COMPILER_VERSION_ALLOWED, GCC, Darwin_arm64, 11, 13) 38 | 39 | ifneq ($(MAKECMDGOALS),clean) 40 | $(call CHECK_COMPILER_VERSION) 41 | endif 42 | 43 | # *** Source files and rules 44 | $(eval $(call PREPARE_DEFAULT_COMPILE_RULE,APP,app)) 45 | $(eval $(call PREPARE_DEFAULT_COMPILE_RULE,CORE,core)) 46 | $(eval $(call PREPARE_DEFAULT_COMPILE_RULE,COMMON,common)) 47 | $(eval $(call PREPARE_DEFAULT_COMPILE_RULE,EXAMPLES,examples)) 48 | $(eval $(call PREPARE_DEFAULT_COMPILE_RULE,LIB_CXX,lib-cxx)) 49 | $(eval $(call PREPARE_DEFAULT_COMPILE_RULE,PY_AGC_API,py_agc_api,$(PY_FLAGS))) 50 | 51 | 52 | # *** Targets 53 | agc: $(OUT_BIN_DIR)/agc 54 | $(OUT_BIN_DIR)/agc: \ 55 | $(OBJ_APP) $(OBJ_CORE) $(OBJ_COMMON) 56 | -mkdir -p $(OUT_BIN_DIR) 57 | $(CXX) -o $@ \ 58 | $(MIMALLOC_OBJ) \ 59 | $(OBJ_APP) $(OBJ_CORE) $(OBJ_COMMON) \ 60 | $(LIBRARY_FILES) $(LINKER_FLAGS) $(LINKER_DIRS) 61 | 62 | libagc: $(OUT_BIN_DIR)/libagc 63 | $(OUT_BIN_DIR)/libagc: \ 64 | $(OBJ_LIB_CXX) $(OBJ_COMMON) 65 | -mkdir -p $(OUT_BIN_DIR) 66 | $(AR) $(AR_OPT) $@.a \ 67 | $(OBJ_LIB_CXX) $(OBJ_COMMON) 68 | 69 | 70 | #.PHONY:py_agc_api 71 | py_agc_api: $(OUT_BIN_DIR)/py_agc_api 72 | $(OUT_BIN_DIR)/py_agc_api: \ 73 | $(OBJ_PY_AGC_API) $(OBJ_LIB_CXX) $(OBJ_COMMON) 74 | -mkdir -p $(OUT_BIN_DIR) 75 | $(CXX) $(PY_FLAGS) $(INCLUDE_DIRS) \ 76 | $(OBJ_PY_AGC_API) $(OBJ_LIB_CXX) $(OBJ_COMMON) \ 77 | $(LIBRARY_FILES) $(LINKER_FLAGS) $(LINKER_DIRS) \ 78 | -o $@$(PY_EXTENSION_SUFFIX) 79 | 80 | 81 | # *** Cleaning 82 | .PHONY: clean init 83 | clean: clean-libzstd clean-zlib-ng clean-isa-l clean-libdeflate clean-mimalloc_obj 84 | -rm -r $(OBJ_DIR) 85 | -rm -r $(OUT_BIN_DIR) 86 | 87 | init: 88 | $(call INIT_SUBMODULES) 89 | -------------------------------------------------------------------------------- /prebuild/prebuild.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 17.0 23 | {939F5626-13ED-4481-B6C7-320F186C2453} 24 | Win32Proj 25 | 26 | 27 | 28 | Makefile 29 | true 30 | v143 31 | 32 | 33 | Makefile 34 | false 35 | v143 36 | 37 | 38 | Makefile 39 | true 40 | v143 41 | 42 | 43 | Makefile 44 | false 45 | v143 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | call "$(SolutionDir)3rd_party\prebuild.bat" "$(SolutionDir)" $(Configuration) 67 | prebuild.exe 68 | _DEBUG;$(NMakePreprocessorDefinitions) 69 | call "$(SolutionDir)3rd_party\prebuild.bat" "$(SolutionDir)" $(Configuration) 70 | 71 | 72 | prebuild.bat 3rd_party %{Solution 73 | prebuild.exe 74 | WIN32;_DEBUG;$(NMakePreprocessorDefinitions) 75 | 76 | 77 | prebuild.bat 3rd_party %{Solution 78 | prebuild.exe 79 | WIN32;NDEBUG;$(NMakePreprocessorDefinitions) 80 | 81 | 82 | call "$(SolutionDir)3rd_party\prebuild.bat" "$(SolutionDir)" $(Configuration) 83 | prebuild.exe 84 | NDEBUG;$(NMakePreprocessorDefinitions) 85 | call "$(SolutionDir)3rd_party\prebuild.bat" "$(SolutionDir)" $(Configuration) 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /prebuild/prebuild.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | -------------------------------------------------------------------------------- /prebuild/prebuild.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/app/agc-dev.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Source files 6 | 7 | 8 | Source files 9 | 10 | 11 | Source files 12 | 13 | 14 | Source files 15 | 16 | 17 | Source files 18 | 19 | 20 | Library files 21 | 22 | 23 | Source files 24 | 25 | 26 | Source files 27 | 28 | 29 | Source files 30 | 31 | 32 | Source files 33 | 34 | 35 | Source files 36 | 37 | 38 | Source files 39 | 40 | 41 | Source files 42 | 43 | 44 | Source files 45 | 46 | 47 | Source files 48 | 49 | 50 | Source files 51 | 52 | 53 | 54 | 55 | Header files 56 | 57 | 58 | Header files 59 | 60 | 61 | Header files 62 | 63 | 64 | Header files 65 | 66 | 67 | Header files 68 | 69 | 70 | Header files 71 | 72 | 73 | Header files 74 | 75 | 76 | Header files 77 | 78 | 79 | Header files 80 | 81 | 82 | Header files 83 | 84 | 85 | Header files 86 | 87 | 88 | Header files 89 | 90 | 91 | Header files 92 | 93 | 94 | Header files 95 | 96 | 97 | Header files 98 | 99 | 100 | Header files 101 | 102 | 103 | Header files 104 | 105 | 106 | Header files 107 | 108 | 109 | Header files 110 | 111 | 112 | Header files 113 | 114 | 115 | 116 | 117 | {e8fed254-fa42-4bc4-b55e-7d71abc425fc} 118 | 119 | 120 | {9e4517f0-f183-4e7d-8ee9-e5c975e4f7ba} 121 | 122 | 123 | {dae35935-931a-479e-85bb-e79d01aa7edd} 124 | 125 | 126 | -------------------------------------------------------------------------------- /src/app/agc-dev.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | create -a -o f50.agc -i fl50 -f 0.0001 -v 1 -t 32 col\100000_CHM13.pri.fa.gz 5 | j:\agc\heng 6 | WindowsLocalDebugger 7 | 8 | 9 | create -t 16 -i salmo.fl -o t.agc -a -k 17 -b 300 -s 3000 -v 1 -r salmonella_enterica__01/SAMEA104364886.fa -f 0.005 10 | k:\atb 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /src/app/application.h: -------------------------------------------------------------------------------- 1 | #ifndef _APPLICATION_H 2 | #define _APPLICATION_H 3 | 4 | // ******************************************************************************************* 5 | // This file is a part of AGC software distributed under MIT license. 6 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 7 | // 8 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 9 | // 10 | // Version: 3.2 11 | // Date : 2024-11-21 12 | // ******************************************************************************************* 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | // ******************************************************************************************* 23 | template class b_value 24 | { 25 | T value; 26 | T min_value; 27 | T max_value; 28 | 29 | public: 30 | b_value(const T _value, const T _min_value, const T _max_value) : value(_value), min_value(_min_value), max_value(_max_value) {}; 31 | 32 | void assign(const T _value) 33 | { 34 | value = clamp(_value, min_value, max_value); 35 | } 36 | 37 | string info() const 38 | { 39 | return "(default: " + to_string(value) + "; min: " + to_string(min_value) + "; max: " + to_string(max_value) + ")"; 40 | } 41 | 42 | T operator()() const 43 | { 44 | return value; 45 | } 46 | }; 47 | 48 | // ******************************************************************************************* 49 | struct CParams 50 | { 51 | vector input_names; 52 | string in_archive_name; 53 | string out_archive_name; 54 | string kmc_db_name; 55 | string reference_name; 56 | string splitters_name; 57 | string output_name; 58 | vector sample_names; 59 | vector contig_names; 60 | string contig_name; 61 | string mode; 62 | 63 | b_value k{ 31, 17, 32 }; 64 | b_value pack_cardinality{ 50, 1, 1'000'000'000 }; 65 | b_value segment_size{ 60'000, 100, 1'000'000 }; 66 | b_value min_match_length{ 20, 15, 32 }; 67 | b_value no_threads{ max(1, thread::hardware_concurrency() / 2), 1, max(16, thread::hardware_concurrency()) }; 68 | b_value line_length{ 80, 40, 2'000'000'000 }; 69 | b_value verbosity{ 0, 0, 2 }; 70 | b_value gzip_level{ 0, 0, 9 }; 71 | b_value fallback_frac{ 0, 0, 0.05 }; 72 | 73 | uint32_t no_segments = 0; 74 | bool concatenated_genomes = false; 75 | bool use_stdout = true; 76 | bool store_cmd_line = true; 77 | bool prefetch = true; 78 | bool adaptive_compression = false; 79 | bool no_ref = false; 80 | bool fast = false; 81 | bool streaming = false; 82 | 83 | CParams() = default; 84 | }; 85 | 86 | // ******************************************************************************************* 87 | class CApplication 88 | { 89 | CParams execution_params; 90 | string cmd_line; 91 | 92 | bool parse_params(const int argc, const char** argv); 93 | void usage() const; 94 | void usage_create() const; 95 | void usage_append() const; 96 | void usage_getcol() const; 97 | void usage_getset() const; 98 | void usage_getctg() const; 99 | void usage_listref() const; 100 | void usage_listset() const; 101 | void usage_listctg() const; 102 | void usage_info() const; 103 | 104 | bool load_file_names(const string & fn, vector& v_file_names); 105 | 106 | bool parse_params_create(const int argc, const char** argv); 107 | bool parse_params_append(const int argc, const char** argv); 108 | bool parse_params_getcol(const int argc, const char** argv); 109 | bool parse_params_getset(const int argc, const char** argv); 110 | bool parse_params_getctg(const int argc, const char** argv); 111 | bool parse_params_listref(const int argc, const char** argv); 112 | bool parse_params_listset(const int argc, const char** argv); 113 | bool parse_params_listctg(const int argc, const char** argv); 114 | bool parse_params_info(const int argc, const char** argv); 115 | 116 | void sanitize_input_file_names(vector &v_file_names); 117 | void remove_common_suffixes(string& sample_name); 118 | 119 | bool create(); 120 | bool append(); 121 | bool getcol(); 122 | bool getset(); 123 | bool getctg(); 124 | bool listref(); 125 | bool listset(); 126 | bool listctg(); 127 | bool info(); 128 | 129 | public: 130 | CApplication() = default; 131 | ~CApplication() = default; 132 | 133 | int Run(const int argc, const char** argv); 134 | }; 135 | 136 | // EOF 137 | #endif -------------------------------------------------------------------------------- /src/common/agc_basic.h: -------------------------------------------------------------------------------- 1 | #ifndef _AGC_BASIC_H 2 | #define _AGC_BASIC_H 3 | 4 | // ******************************************************************************************* 5 | // This file is a part of AGC software distributed under MIT license. 6 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 7 | // 8 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 9 | // 10 | // Version: 3.2 11 | // Date : 2024-11-21 12 | // ******************************************************************************************* 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "../common/archive.h" 23 | #include "../common/segment.h" 24 | #include "../common/collection_v1.h" 25 | #include "../common/collection_v2.h" 26 | #include "../common/collection_v3.h" 27 | #include "../common/queue.h" 28 | 29 | using namespace std; 30 | 31 | // ******************************************************************************************* 32 | // Basic compression class 33 | class CAGCBasic 34 | { 35 | friend class CAGCDecompressor; 36 | 37 | protected: 38 | enum class working_mode_t { none, compression, decompression, appending, pre_appending }; 39 | 40 | const uint8_t cnv_num[128] = { 41 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 42 | 'A', 'C', 'G', 'T', 'N', 'R', 'Y', 'S', 'W', 'K', 'M', 'B', 'D', 'H', 'V', 'U', 43 | ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 44 | ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 45 | ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 46 | ' ', 0, 11, 1, 12, 30, 30, 2, 13, 30, 30, 9, 30, 10, 4, 30, 47 | 30, 30, 5, 7, 3, 15, 14, 8, 30, 6, 30, 30, 30, 30, 30, 30, 48 | ' ', 0, 11, 1, 12, 30, 30, 2, 13, 30, 30, 9, 30, 10, 4, 30, 49 | 30, 30, 5, 7, 3, 15, 14, 8, 30, 6, 30, 30, 30, 30, 30, 30 50 | }; 51 | 52 | // ******************************************************************************************* 53 | struct compression_params_t 54 | { 55 | uint32_t kmer_length; 56 | uint32_t min_match_len; 57 | uint32_t pack_cardinality; 58 | uint32_t segment_size; 59 | }; 60 | 61 | working_mode_t working_mode; 62 | bool is_app_mode; 63 | 64 | uint32_t kmer_length; 65 | uint32_t min_match_len; 66 | uint32_t pack_cardinality; 67 | uint32_t segment_size; 68 | 69 | string in_archive_name; 70 | bool prefetch_archive = false; 71 | uint32_t archive_version; 72 | 73 | shared_ptr in_archive; // internal mutexes 74 | 75 | shared_ptr collection_desc; 76 | 77 | map m_file_type_info; 78 | 79 | compression_params_t compression_params; 80 | 81 | const uint32_t no_raw_groups = 16; 82 | 83 | uint32_t verbosity; 84 | 85 | // ******************************************************************************************* 86 | void read(vector::iterator& p, uint32_t& num) 87 | { 88 | num = 0; 89 | 90 | for (int i = 0; i < 4; ++i) 91 | num += ((uint32_t)p[i]) << (8 * i); 92 | 93 | p += 4; 94 | } 95 | 96 | // ******************************************************************************************* 97 | void read64(vector::iterator& p, uint64_t& num) 98 | { 99 | num = 0; 100 | 101 | for (int i = 0; i < 8; ++i) 102 | num += ((uint64_t)p[i]) << (8 * i); 103 | 104 | p += 8; 105 | } 106 | 107 | // ******************************************************************************************* 108 | void read(vector::iterator& p, string& str) 109 | { 110 | str.clear(); 111 | 112 | for (; *p != 0; ++p) 113 | str.push_back((char)*p); 114 | ++p; 115 | } 116 | 117 | // ******************************************************************************************* 118 | void join_threads(vector &v_threads); 119 | bool load_metadata_impl_v1(); 120 | bool load_metadata_impl_v2(); 121 | bool load_metadata_impl_v3(); 122 | 123 | bool load_metadata(); 124 | bool load_file_type_info(const string& archive_name); 125 | 126 | void reverse_complement(contig_t& contig); 127 | void reverse_complement_copy(contig_t& src_contig, contig_t& dest_contig); 128 | 129 | public: 130 | CAGCBasic(); 131 | ~CAGCBasic(); 132 | }; 133 | 134 | // EOF 135 | #endif -------------------------------------------------------------------------------- /src/common/agc_decompressor_lib.h: -------------------------------------------------------------------------------- 1 | #ifndef _AGC_DECOMPRESSOR_LIB_H 2 | #define _AGC_DECOMPRESSOR_LIB_H 3 | 4 | // ******************************************************************************************* 5 | // This file is a part of AGC software distributed under MIT license. 6 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 7 | // 8 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 9 | // 10 | // Version: 3.2 11 | // Date : 2024-11-21 12 | // ******************************************************************************************* 13 | 14 | #include 15 | #include "../common/agc_basic.h" 16 | 17 | // ******************************************************************************************* 18 | // Class supporting only decompression of AGC files - library version 19 | class CAGCDecompressorLibrary : public CAGCBasic 20 | { 21 | protected: 22 | class CNumAlphaConverter 23 | { 24 | static const inline uint8_t cnv_num[128] = { 25 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 26 | 'A', 'C', 'G', 'T', 'N', 'R', 'Y', 'S', 'W', 'K', 'M', 'B', 'D', 'H', 'V', 'U', 27 | ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 28 | ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 29 | ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 30 | ' ', 0, 11, 1, 12, 30, 30, 2, 13, 30, 30, 9, 30, 10, 4, 30, 31 | 30, 30, 5, 7, 3, 15, 14, 8, 30, 6, 30, 30, 30, 30, 30, 30, 32 | ' ', 0, 11, 1, 12, 30, 30, 2, 13, 30, 30, 9, 30, 10, 4, 30, 33 | 30, 30, 5, 7, 3, 15, 14, 8, 30, 6, 30, 30, 30, 30, 30, 30 34 | }; 35 | 36 | public: 37 | CNumAlphaConverter() = default; 38 | 39 | static void convert_to_alpha(contig_t& ctg); 40 | static size_t convert_and_split_into_lines(contig_t& ctg, contig_t& working_space, uint32_t line_len, uint32_t no_symbols_in_non_complete_line = 0, bool append_eol = true); 41 | }; 42 | 43 | 44 | // ******************************************************************************************* 45 | struct name_range_t 46 | { 47 | string name; 48 | int64_t from; 49 | int64_t to; 50 | 51 | name_range_t(const string _name = "", const int64_t _from = -1, const int64_t _to = -1) : 52 | name(_name), from(_from), to(_to) 53 | {} 54 | 55 | name_range_t(const name_range_t&) = default; 56 | name_range_t(name_range_t&&) noexcept = default; 57 | 58 | name_range_t& operator=(const name_range_t&) = default; 59 | name_range_t& operator=(name_range_t&&) noexcept = default; 60 | 61 | string str() const 62 | { 63 | if (from >= 0 && to >= 0) 64 | return name + ":" + to_string(from) + "-" + to_string(to); 65 | else 66 | return name; 67 | } 68 | }; 69 | 70 | class CStreamWrapper 71 | { 72 | // size_t buffer_size = 1 << 20; 73 | size_t buffer_size = 1024; 74 | FILE* stream = nullptr; 75 | contig_t buffer; 76 | contig_t working_space; 77 | uint32_t line_length; 78 | size_t no_symbols_in_last_line = 0; 79 | 80 | CNumAlphaConverter num_alpha_converter; 81 | 82 | bool store_buffer() 83 | { 84 | if (line_length == 0) 85 | num_alpha_converter.convert_to_alpha(buffer); 86 | else 87 | no_symbols_in_last_line = num_alpha_converter.convert_and_split_into_lines(buffer, working_space, line_length, no_symbols_in_last_line, false); 88 | 89 | return fwrite(buffer.data(), 1, buffer.size(), stream) == buffer.size(); 90 | } 91 | 92 | public: 93 | CStreamWrapper() = delete; 94 | 95 | CStreamWrapper(FILE* stream, uint32_t line_length, int gzip_level) : 96 | stream(stream), 97 | line_length(line_length)//, 98 | // gzip_compressor(gzip_level) 99 | {} 100 | 101 | bool start_contig(const string& name) 102 | { 103 | string to_save = ">" + name + "\n"; 104 | 105 | no_symbols_in_last_line = 0; 106 | 107 | return fwrite(to_save.c_str(), 1, to_save.size(), stream) == to_save.size(); 108 | } 109 | 110 | bool complete_contig() 111 | { 112 | return putc('\n', stream) != EOF; 113 | } 114 | 115 | template 116 | bool append(Iter first, Iter last) 117 | { 118 | if (!stream) 119 | return false; 120 | 121 | buffer.assign(first, last); 122 | 123 | return store_buffer(); 124 | } 125 | }; 126 | 127 | const regex re_csr = regex("(.+)@(.+):(.+)-(.+)"); 128 | const regex re_cs = regex("(.+)@(.+)"); 129 | const regex re_cr = regex("(.+):(.+)-(.+)"); 130 | const regex re_c = regex("(.+)"); 131 | 132 | struct sample_contig_data_t { 133 | string sample_name; 134 | string contig_name; 135 | contig_t contig_data; 136 | 137 | sample_contig_data_t() = default; 138 | sample_contig_data_t(const string &_sample_name, const string &_contig_name, const contig_t &_contig_data) : 139 | sample_name(_sample_name), contig_name(_contig_name), contig_data(_contig_data) {} 140 | 141 | sample_contig_data_t(const string &_sample_name, const string &_contig_name, contig_t &&_contig_data) : 142 | sample_name(_sample_name), contig_name(_contig_name), contig_data(move(_contig_data)) {} 143 | 144 | sample_contig_data_t(const sample_contig_data_t&) = default; 145 | sample_contig_data_t(sample_contig_data_t&&) = default; 146 | sample_contig_data_t& operator=(const sample_contig_data_t&) = default; 147 | sample_contig_data_t& operator=(sample_contig_data_t&&) = default; 148 | }; 149 | 150 | struct contig_task_t { 151 | size_t priority; 152 | string sample_name; 153 | name_range_t name_range; 154 | vector segments; 155 | 156 | contig_task_t() = default; 157 | contig_task_t(const size_t _priority, const string _sample_name, const name_range_t _name_range, const vector& _segments) : 158 | priority(_priority), sample_name(_sample_name), name_range(_name_range), segments(_segments) {}; 159 | contig_task_t(const contig_task_t&) = default; 160 | contig_task_t(contig_task_t&&) = default; 161 | contig_task_t& operator=(const contig_task_t&) = default; 162 | }; 163 | 164 | unique_ptr> q_contig_tasks; 165 | unique_ptr> pq_contigs_to_save; 166 | 167 | shared_mutex mtx_segment; 168 | map> v_segment; 169 | 170 | bool analyze_contig_query(const string& query, string& sample, name_range_t& name_range); 171 | bool decompress_segment(const uint32_t group_id, const uint32_t in_group_id, contig_t& ctg, ZSTD_DCtx* zstd_ctx); 172 | bool decompress_segment_fast(const uint32_t group_id, const uint32_t in_group_id, contig_t& ctg, ZSTD_DCtx* zstd_ctx); 173 | 174 | bool decompress_contig(contig_task_t& task, ZSTD_DCtx *zstd_ctx, contig_t& ctg, bool fast = false); 175 | bool decompress_contig_streaming(contig_task_t& task, ZSTD_DCtx *zstd_ctx, CStreamWrapper& stream_wrapper, bool fast = false); 176 | 177 | bool close_decompression(); 178 | 179 | public: 180 | CAGCDecompressorLibrary(bool _is_app_mode); 181 | ~CAGCDecompressorLibrary(); 182 | 183 | bool Open(const string& _archive_fn, const bool _prefetch_archive = false); 184 | 185 | void GetCmdLines(vector>& _cmd_lines); 186 | void GetParams(uint32_t& kmer_length, uint32_t& min_match_len, uint32_t& pack_cardinality, uint32_t& _segment_size); 187 | void GetReferenceSample(string& ref_name); 188 | 189 | bool Close(); 190 | 191 | int GetContigString(const string& sample_name, const string& contig_name, const int start, const int end, string& contig_data); 192 | int64_t GetContigLength(const string& sample_name, const string& contig_name); 193 | 194 | bool ListSamples(vector& v_sample_names); 195 | bool ListContigs(const string& sample_name, vector& v_contig_names); 196 | int32_t GetNoSamples(); 197 | int32_t GetNoContigs(const string& sample_name); 198 | 199 | void GetFileTypeInfo(map& _m_file_type_info); 200 | 201 | bool IsOpened(); 202 | }; 203 | 204 | // EOF 205 | #endif -------------------------------------------------------------------------------- /src/common/archive.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCHIVE_H 2 | #define _ARCHIVE_H 3 | 4 | // ******************************************************************************************* 5 | // This file is a part of AGC software distributed under MIT license. 6 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 7 | // 8 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 9 | // 10 | // Version: 3.2 11 | // Date : 2024-11-21 12 | // ******************************************************************************************* 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "../common/io.h" 23 | #include "../common/utils.h" 24 | 25 | using namespace std; 26 | 27 | class CArchive 28 | { 29 | bool input_mode; 30 | CInFile f_in; 31 | COutFile f_out; 32 | size_t io_buffer_size; 33 | 34 | size_t f_offset; 35 | 36 | struct part_t{ 37 | size_t offset; 38 | size_t size; 39 | 40 | part_t() : offset(0), size(0) 41 | {}; 42 | 43 | part_t(size_t _offset, size_t _size) : offset(_offset), size(_size) 44 | {}; 45 | }; 46 | 47 | typedef struct { 48 | string stream_name; 49 | size_t cur_id; 50 | size_t raw_size; 51 | size_t packed_size; 52 | size_t packed_data_size; 53 | vector parts; 54 | } stream_t; 55 | 56 | map, uint64_t>>> m_buffer; 57 | 58 | vector v_streams; 59 | unordered_map rm_streams; 60 | string lazy_prefix; 61 | 62 | mutex mtx; 63 | 64 | bool serialize(); 65 | bool deserialize(); 66 | 67 | // ******************************************************************************************* 68 | inline bool is_lazy_str(const string& str) 69 | { 70 | if (!input_mode) 71 | return false; 72 | 73 | if (lazy_prefix.empty()) 74 | return false; 75 | 76 | if (str.size() <= lazy_prefix.size()) 77 | return false; 78 | 79 | const char* p = str.c_str(); 80 | const char* q = lazy_prefix.c_str(); 81 | 82 | while (*p == *q) 83 | ++p, ++q; 84 | 85 | return *q == 0; 86 | } 87 | 88 | // ******************************************************************************************* 89 | void de_lazy() 90 | { 91 | rm_streams.reserve(2 * v_streams.size()); 92 | 93 | for(size_t i = 0; i < v_streams.size(); ++i) 94 | if(is_lazy_str(v_streams[i].stream_name)) 95 | rm_streams[v_streams[i].stream_name] = i; 96 | 97 | lazy_prefix.clear(); 98 | } 99 | 100 | // ******************************************************************************************* 101 | template 102 | size_t write_fixed(const T x) 103 | { 104 | f_out.WriteUInt(static_cast(x), 8); 105 | 106 | return 8; 107 | } 108 | 109 | // ******************************************************************************************* 110 | template 111 | size_t write(const T _x) 112 | { 113 | int no_bytes = 0; 114 | uint64_t x = static_cast(_x); 115 | 116 | for (size_t tmp = x; tmp; tmp >>= 8) 117 | ++no_bytes; 118 | 119 | f_out.Put(no_bytes); 120 | 121 | for (int i = no_bytes; i; --i) 122 | f_out.Put((x >> ((i - 1) * 8)) & 0xff); 123 | 124 | return no_bytes + 1; 125 | } 126 | 127 | // ******************************************************************************************* 128 | size_t write(const string &s); 129 | 130 | // ******************************************************************************************* 131 | template 132 | size_t read_fixed(T& x) 133 | { 134 | x = static_cast(f_in.ReadUInt(8)); 135 | 136 | return 8; 137 | } 138 | 139 | // ******************************************************************************************* 140 | size_t read(string& s); 141 | 142 | // ******************************************************************************************* 143 | template 144 | size_t read(T& x) 145 | { 146 | int no_bytes = f_in.Get(); 147 | 148 | x = 0; 149 | 150 | for (int i = 0; i < no_bytes; ++i) 151 | { 152 | x <<= 8; 153 | x += static_cast(f_in.Get()); 154 | } 155 | 156 | return no_bytes + 1; 157 | } 158 | 159 | // ******************************************************************************************* 160 | bool add_part(const int stream_id, const vector& v_data, const uint64_t metadata); 161 | bool flush_out_buffers(); 162 | int get_stream_id(const string& stream_name); 163 | bool get_part(const int stream_id, vector& v_data, uint64_t& metadata); 164 | bool get_part(const int stream_id, const int part_id, vector& v_data, uint64_t& metadata); 165 | int register_stream(const string& stream_name); 166 | 167 | public: 168 | CArchive(const bool _input_mode, const size_t _io_buffer_size = 64 << 20, const string& _lazy_prefix = ""); 169 | ~CArchive(); 170 | 171 | bool Open(const string &file_name); 172 | bool Close(); 173 | 174 | int RegisterStream(const string &stream_name); 175 | pair RegisterStreams(const string &stream_name1, const string& stream_name2); 176 | int GetStreamId(const string &stream_name); 177 | 178 | size_t GetStreamPackedSize(const int stream_id); 179 | size_t GetStreamPackedDataSize(const int stream_id); 180 | 181 | bool AddPart(const int stream_id, const vector& v_data, const uint64_t metadata = 0); 182 | int AddPartPrepare(const int stream_id); 183 | bool AddPartComplete(const int stream_id, const int part_id, const vector& v_data, const uint64_t metadata = 0); 184 | bool AddPartBuffered(const int stream_id, const vector& v_data, const uint64_t metadata = 0); 185 | 186 | bool FlushOutBuffers(); 187 | 188 | bool GetPart(const int stream_id, vector &v_data, uint64_t &metadata); 189 | bool GetPart(const int stream_id, const int part_id, vector& v_data, uint64_t& metadata); 190 | 191 | pair GetPart(const string &stream_name, vector &v_data, uint64_t &metadata); 192 | pair GetPart(const string& stream_name, const int part_id, vector &v_data, uint64_t &metadata); 193 | 194 | tuple GetParts( 195 | const string &stream_name1, vector &v_data1, uint64_t &metadata1, 196 | const string& stream_name2, vector& v_data2, uint64_t& metadata2); 197 | tuple GetParts( 198 | const string& stream_name1, const int part_id1, vector &v_data1, uint64_t &metadata1, 199 | const string& stream_name2, const int part_id2, vector &v_data2, uint64_t &metadata2); 200 | 201 | void SetRawSize(const int stream_id, const size_t raw_size); 202 | size_t GetRawSize(const int stream_id); 203 | 204 | size_t GetNoStreams(); 205 | size_t GetNoParts(const int stream_id); 206 | }; 207 | 208 | // EOF 209 | #endif -------------------------------------------------------------------------------- /src/common/collection.cpp: -------------------------------------------------------------------------------- 1 | // ******************************************************************************************* 2 | // This file is a part of AGC software distributed under MIT license. 3 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 4 | // 5 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 6 | // 7 | // Version: 3.2 8 | // Date : 2024-11-21 9 | // ******************************************************************************************* 10 | 11 | #include 12 | #include 13 | #include 14 | #include "collection.h" 15 | 16 | #include 17 | 18 | // ******************************************************************************************* 19 | string CCollection::extract_contig_name(const string& s) 20 | { 21 | string::const_iterator p; 22 | 23 | for (p = s.begin(); p != s.end(); ++p) 24 | if ((*p < '0') && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')) 25 | break; 26 | 27 | return string(s.begin(), p); 28 | } 29 | 30 | // ******************************************************************************************* 31 | bool CCollection::is_equal_sample_contig(const pair& x, const pair& y) 32 | { 33 | return x.first == y.first && extract_contig_name(x.second) == extract_contig_name(y.second); 34 | } 35 | 36 | // ******************************************************************************************* 37 | void CCollection::add_cmd_line(const string &cmd) 38 | { 39 | lock_guard lck(mtx); 40 | 41 | auto tc = time(nullptr); 42 | char tmp[64]; 43 | string s_time; 44 | 45 | if(strftime(tmp, sizeof(tmp), "%A %c", std::gmtime(&tc))) 46 | s_time = tmp; 47 | 48 | cmd_lines.emplace_back(cmd, s_time); 49 | } 50 | 51 | // ******************************************************************************************* 52 | void CCollection::get_cmd_lines(vector>& _cmd_lines) 53 | { 54 | lock_guard lck(mtx); 55 | 56 | _cmd_lines = cmd_lines; 57 | } 58 | 59 | // EOF 60 | -------------------------------------------------------------------------------- /src/common/collection.h: -------------------------------------------------------------------------------- 1 | #ifndef _COLLECTION_H 2 | #define _COLLECTION_H 3 | 4 | // ******************************************************************************************* 5 | // This file is a part of AGC software distributed under MIT license. 6 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 7 | // 8 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 9 | // 10 | // Version: 3.2 11 | // Date : 2024-11-21 12 | // ******************************************************************************************* 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "../common/utils.h" 21 | #include 22 | 23 | using namespace std; 24 | using namespace std::chrono; 25 | 26 | // ******************************************************************************************* 27 | struct segment_desc_t 28 | { 29 | uint32_t group_id; 30 | uint32_t in_group_id; 31 | bool is_rev_comp; 32 | uint32_t raw_length; 33 | 34 | segment_desc_t() : 35 | group_id(~0u), in_group_id(~0u), is_rev_comp(false), raw_length(0) 36 | {} 37 | 38 | segment_desc_t(const uint32_t _group_id, const uint32_t _in_group_id, const bool _is_rev_comp, const uint32_t _raw_length) : 39 | group_id(_group_id), in_group_id(_in_group_id), is_rev_comp(_is_rev_comp), raw_length(_raw_length) 40 | {} 41 | }; 42 | 43 | // ******************************************************************************************* 44 | struct pair_segment_desc_t 45 | { 46 | segment_desc_t first; 47 | segment_desc_t second; 48 | bool contains_second; 49 | 50 | pair_segment_desc_t(segment_desc_t _first, segment_desc_t _second = segment_desc_t{}, bool _contains_second = false) : 51 | first(_first), second(_second), contains_second(_contains_second) 52 | {} 53 | }; 54 | 55 | // ******************************************************************************************* 56 | struct contig_info_t 57 | { 58 | string sample_name; 59 | string contig_name; 60 | uint32_t id; 61 | uint32_t no_seg; 62 | 63 | contig_info_t(string _sample_name, string _contig_name, uint32_t _id, uint32_t _no_seg) : 64 | sample_name(_sample_name), contig_name(_contig_name), id(_id), no_seg(_no_seg) 65 | {}; 66 | }; 67 | 68 | // ******************************************************************************************* 69 | struct segments_to_place_t { 70 | string sample_name; 71 | string contig_name; 72 | uint32_t seg_part_no; 73 | int group_id; 74 | int in_group_id; 75 | bool is_rev_comp; 76 | uint32_t data_size; 77 | 78 | segments_to_place_t(string _sample_name, string _contig_name, uint32_t _seg_part_no, int _group_id, int _in_group_id, bool _is_rev_comp, uint32_t _data_size) : 79 | sample_name(_sample_name), 80 | contig_name(_contig_name), 81 | seg_part_no(_seg_part_no), 82 | group_id(_group_id), 83 | in_group_id(_in_group_id), 84 | is_rev_comp(_is_rev_comp), 85 | data_size(_data_size) {} 86 | 87 | segments_to_place_t() = default; 88 | segments_to_place_t(const segments_to_place_t&) = default; 89 | }; 90 | 91 | // ******************************************************************************************* 92 | using sample_desc_t = vector>>; 93 | 94 | // ******************************************************************************************* 95 | class CCollection 96 | { 97 | protected: 98 | mutex mtx; 99 | 100 | const uint32_t thr_1 = 1u << 7; 101 | const uint32_t thr_2 = thr_1 + (1u << 14); 102 | const uint32_t thr_3 = thr_2 + (1u << 21); 103 | const uint32_t thr_4 = thr_3 + (1u << 28); 104 | const uint8_t pref_1 = 0; 105 | const uint8_t pref_2 = 0b10000000u; 106 | const uint8_t pref_3 = 0b11000000u; 107 | const uint8_t pref_4 = 0b11100000u; 108 | const uint8_t pref_5 = 0b11110000u; 109 | const uint8_t mask_1 = 0b10000000u; 110 | const uint8_t mask_2 = 0b11000000u; 111 | const uint8_t mask_3 = 0b11100000u; 112 | const uint8_t mask_4 = 0b11110000u; 113 | 114 | const uint8_t pref_arr[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5}; 115 | 116 | ZSTD_DCtx* zstd_dctx = nullptr; 117 | 118 | vector> cmd_lines; 119 | 120 | void append(vector& data, const string& str) 121 | { 122 | data.insert(data.end(), str.begin(), str.end()); 123 | data.emplace_back(0); 124 | } 125 | 126 | void append(vector& data, uint32_t num) 127 | { 128 | if (num < thr_1) 129 | data.emplace_back(pref_1 + num); 130 | else if (num < thr_2) 131 | { 132 | num -= thr_1; 133 | data.emplace_back(pref_2 + (num >> 8)); 134 | data.emplace_back(num & 0xffu); 135 | } 136 | else if (num < thr_3) 137 | { 138 | num -= thr_2; 139 | data.emplace_back(pref_3 + (num >> 16)); 140 | data.emplace_back((num >> 8) & 0xffu); 141 | data.emplace_back(num & 0xffu); 142 | } 143 | else if (num < thr_4) 144 | { 145 | num -= thr_3; 146 | data.emplace_back(pref_4 + (num >> 24)); 147 | data.emplace_back((num >> 16) & 0xffu); 148 | data.emplace_back((num >> 8) & 0xffu); 149 | data.emplace_back(num & 0xffu); 150 | } 151 | else 152 | { 153 | num -= thr_4; 154 | data.emplace_back(pref_5); 155 | data.emplace_back((num >> 24) & 0xffu); 156 | data.emplace_back((num >> 16) & 0xffu); 157 | data.emplace_back((num >> 8) & 0xffu); 158 | data.emplace_back(num & 0xffu); 159 | } 160 | } 161 | 162 | void read(uint8_t*& p, string& str) 163 | { 164 | auto q = p; 165 | while (*q) 166 | ++q; 167 | 168 | str.assign((char*)p, q - p); 169 | 170 | p = q + 1; 171 | } 172 | 173 | void read(uint8_t*& p, uint32_t& num) 174 | { 175 | if ((*p & mask_1) == pref_1) 176 | num = *p++ - pref_1; 177 | else if ((*p & mask_2) == pref_2) 178 | { 179 | num = ((uint32_t)p[0] << 8) + p[1] + thr_1 - (pref_2 << 8); 180 | p += 2; 181 | } 182 | else if ((*p & mask_3) == pref_3) 183 | { 184 | num = ((uint32_t) p[0] << 16) + ((uint32_t) p[1] << 8) + p[2] + thr_2 - (pref_3 << 16); 185 | p += 3; 186 | } 187 | else if ((*p & mask_4) == pref_4) 188 | { 189 | num = ((uint32_t)p[0] << 24) + ((uint32_t)p[1] << 16) + ((uint32_t)p[2] << 8) + p[3] + thr_3 - (pref_4 << 24); 190 | p += 4; 191 | } 192 | else 193 | { 194 | p++; // skip pref_5 195 | num = *p++; 196 | num <<= 8; num += *p++; 197 | num <<= 8; num += *p++; 198 | num <<= 8; num += *p++; 199 | num += thr_4; 200 | } 201 | } 202 | 203 | void read_fixed32(vector::iterator& p, uint32_t& num) 204 | { 205 | num = 0; 206 | 207 | for (int i = 0; i < 4; ++i) 208 | num += ((uint32_t)p[i]) << (8 * i); 209 | 210 | p += 4; 211 | } 212 | 213 | void skip(uint8_t*& p) 214 | { 215 | auto x = pref_arr[*p >> 4]; 216 | p += x; 217 | } 218 | 219 | string extract_contig_name(const string& s); 220 | bool is_equal_sample_contig(const pair& x, const pair& y); 221 | 222 | public: 223 | CCollection() {}; 224 | virtual ~CCollection() { 225 | if (zstd_dctx) 226 | ZSTD_freeDCtx(zstd_dctx); 227 | }; 228 | 229 | virtual bool register_sample_contig(const string& sample_name, const string& contig_name) = 0; 230 | 231 | virtual void add_segment_placed(const string& sample_name, const string& contig_name, const uint32_t place, const uint32_t group_id, const uint32_t in_group_id, const bool is_rev_comp, const uint32_t raw_length) = 0; 232 | virtual void add_segments_placed(vector& segments_to_place) = 0; 233 | virtual bool get_reference_name(string& reference_name) = 0; 234 | virtual bool get_samples_list(vector& v_samples, bool sorted = true) = 0; 235 | virtual bool get_contig_list_in_sample(const string& sample_name, vector& v_contig_names) = 0; 236 | 237 | virtual bool get_sample_desc(const string& sample_name, vector>>& sample_desc) = 0; 238 | virtual bool get_contig_desc(const string& sample_name, string& contig_name, vector& contig_desc) = 0; 239 | 240 | virtual bool is_contig_desc(const string& sample_name, const string& contig_name) = 0; 241 | virtual vector get_samples_for_contig(const string& contig_name) = 0; 242 | 243 | void add_cmd_line(const string &cmd); 244 | void get_cmd_lines(vector>& _cmd_lines); 245 | 246 | virtual size_t get_no_samples() = 0; 247 | virtual int32_t get_no_contigs(const string& sample_name) = 0; 248 | }; 249 | 250 | // EOF 251 | #endif -------------------------------------------------------------------------------- /src/common/collection_v1.h: -------------------------------------------------------------------------------- 1 | #ifndef _COLLECTION_V1_H 2 | #define _COLLECTION_V1_H 3 | 4 | // ******************************************************************************************* 5 | // This file is a part of AGC software distributed under MIT license. 6 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 7 | // 8 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 9 | // 10 | // Version: 3.2 11 | // Date : 2024-11-21 12 | // ******************************************************************************************* 13 | 14 | #include "collection.h" 15 | 16 | class CCollection_V1 : public CCollection 17 | { 18 | protected: 19 | uint32_t details_batch_size = 1; 20 | 21 | typedef map>>> col_t; 22 | 23 | vector, size_t>> v_zstd_batches; 24 | 25 | col_t col; 26 | map, pair> contig_ids_no_seg; 27 | multimap mm_contig2sample; 28 | map sample_ids; 29 | vector v_sample_name; 30 | vector v_contig_info; 31 | bool maps_built = false; 32 | 33 | vector get_sample_original_order(); 34 | 35 | void decompress_sample_details(uint32_t i_sample); 36 | void deserialize_contig_details_group_id(uint8_t*& p, vector& contig_segments); 37 | void deserialize_contig_details_in_group_id(uint8_t*& p, vector& contig_segments); 38 | void deserialize_contig_details_raw_length(uint8_t*& p, vector& contig_segments); 39 | void deserialize_contig_details_orientation(uint8_t*& p, vector& contig_segments); 40 | 41 | vector& add_segment_basic(const string& sample_name, const string& contig_name, const uint32_t group_id, const uint32_t in_group_id, const bool is_rev_comp, const uint32_t raw_length); 42 | 43 | public: 44 | CCollection_V1() : CCollection() {} 45 | 46 | virtual ~CCollection_V1() {}; 47 | 48 | 49 | void serialize(vector& data, bool store_date_time); 50 | bool deserialize(vector& data); 51 | 52 | virtual bool register_sample_contig(const string& sample_name, const string& contig_name); 53 | virtual void add_segment_placed(const string& sample_name, const string& contig_name, const uint32_t place, const uint32_t group_id, const uint32_t in_group_id, const bool is_rev_comp, const uint32_t raw_length); 54 | virtual void add_segments_placed(vector& segments_to_place); 55 | virtual bool get_reference_name(string& reference_name); 56 | virtual bool get_samples_list(vector& v_samples, bool sorted = true); 57 | virtual bool get_contig_list_in_sample(const string& sample_name, vector& v_contig_names); 58 | virtual bool get_sample_desc(const string& sample_name, vector>>& sample_desc); 59 | virtual bool get_contig_desc(const string& sample_name, string& contig_name, vector& contig_desc); 60 | 61 | virtual bool is_contig_desc(const string& sample_name, const string& contig_name); 62 | virtual vector get_samples_for_contig(const string& contig_name); 63 | 64 | virtual size_t get_no_samples(); 65 | virtual int32_t get_no_contigs(const string& sample_name); 66 | }; 67 | 68 | // EOF 69 | #endif -------------------------------------------------------------------------------- /src/common/collection_v2.cpp: -------------------------------------------------------------------------------- 1 | // ******************************************************************************************* 2 | // This file is a part of AGC software distributed under MIT license. 3 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 4 | // 5 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 6 | // 7 | // Version: 3.2 8 | // Date : 2024-11-21 9 | // ******************************************************************************************* 10 | 11 | #include "collection_v2.h" 12 | 13 | // ******************************************************************************************* 14 | void CCollection_V2::serialize(vector& data_main, vector>& data_details, bool store_date_time, uint32_t _details_batch_size) 15 | { 16 | data_main.clear(); 17 | data_details.clear(); 18 | 19 | details_batch_size = _details_batch_size; 20 | 21 | auto col_order = get_sample_original_order(); 22 | 23 | append(data_main, details_batch_size); 24 | append(data_main, (uint32_t)col.size()); 25 | 26 | data_details.resize((col_order.size() + (details_batch_size - 1)) / details_batch_size); 27 | 28 | array, 4> v_det; 29 | size_t no_samples_in_batch = 0; 30 | uint32_t i_details_part = 0; 31 | 32 | for (auto& sample_name : col_order) 33 | { 34 | auto& sample = col[sample_name]; 35 | 36 | append(data_main, sample_name); 37 | append(data_main, (uint32_t)sample.size()); 38 | 39 | if (no_samples_in_batch == details_batch_size) 40 | { 41 | for (auto& v : v_det) 42 | { 43 | data_details[i_details_part].insert(data_details[i_details_part].end(), v.begin(), v.end()); 44 | v.clear(); 45 | } 46 | 47 | no_samples_in_batch = 0; 48 | ++i_details_part; 49 | } 50 | 51 | for (auto& contig : sample) 52 | { 53 | append(data_main, contig.first); 54 | append(data_main, (uint32_t)contig.second.size()); 55 | 56 | int32_t prev_group_id = 0; 57 | int32_t prev_in_group_id = 0; 58 | int32_t prev_raw_length = 0; 59 | 60 | for (auto& seg : contig.second) 61 | { 62 | uint32_t e_group_id = (uint32_t)zigzag_encode(seg.group_id, prev_group_id); 63 | uint32_t e_in_group_id = (uint32_t)zigzag_encode(seg.in_group_id, prev_in_group_id); 64 | uint32_t e_raw_length = (uint32_t)zigzag_encode(seg.raw_length, prev_raw_length); 65 | 66 | append(v_det[0], e_group_id); 67 | append(v_det[1], e_in_group_id); 68 | append(v_det[2], e_raw_length); 69 | append(v_det[3], (uint32_t)seg.is_rev_comp); 70 | 71 | prev_group_id = seg.group_id; 72 | prev_in_group_id = seg.in_group_id; 73 | prev_raw_length = seg.raw_length; 74 | } 75 | } 76 | 77 | ++no_samples_in_batch; 78 | } 79 | 80 | for (auto& v : v_det) 81 | data_details[i_details_part].insert(data_details[i_details_part].end(), v.begin(), v.end()); 82 | 83 | append(data_main, (uint32_t)cmd_lines.size()); 84 | 85 | for (auto& cmd : cmd_lines) 86 | { 87 | append(data_main, cmd.first); 88 | if (store_date_time) 89 | append(data_main, cmd.second); 90 | else 91 | append(data_main, ""); 92 | } 93 | } 94 | 95 | // ******************************************************************************************* 96 | bool CCollection_V2::deserialize_main(vector& data_main, bool create_maps) 97 | { 98 | uint8_t* p = data_main.data(); 99 | 100 | col.clear(); 101 | 102 | uint32_t no_samples; 103 | string sample_name; 104 | string contig_name; 105 | 106 | read(p, details_batch_size); 107 | read(p, no_samples); 108 | 109 | v_sample_name.reserve(no_samples); 110 | 111 | for (uint32_t i = 0; i < no_samples; ++i) 112 | { 113 | read(p, sample_name); 114 | 115 | v_sample_name.emplace_back(sample_name); 116 | 117 | uint32_t no_contigs; 118 | read(p, no_contigs); 119 | 120 | col[sample_name].resize(no_contigs); 121 | auto& col_sample = col[sample_name]; 122 | 123 | uint32_t sample_id = (uint32_t)sample_ids.size(); 124 | sample_ids[sample_name] = sample_id; 125 | 126 | for (uint32_t j = 0; j < no_contigs; ++j) 127 | { 128 | read(p, contig_name); 129 | 130 | uint32_t no_seg; 131 | read(p, no_seg); 132 | 133 | string short_contig_name = extract_contig_name(contig_name); 134 | 135 | if (create_maps) 136 | { 137 | contig_ids_no_seg[make_pair(sample_name, short_contig_name)] = make_pair(j, no_seg); 138 | mm_contig2sample.emplace(short_contig_name, sample_name); 139 | } 140 | else 141 | v_contig_info.emplace_back(sample_name, short_contig_name, j, no_seg); 142 | 143 | col_sample[j].first = contig_name; 144 | } 145 | } 146 | 147 | uint32_t no_cmds; 148 | 149 | read(p, no_cmds); 150 | cmd_lines.clear(); 151 | 152 | cmd_lines.resize(no_cmds); 153 | 154 | for (uint32_t i = 0; i < no_cmds; ++i) 155 | { 156 | read(p, cmd_lines[i].first); 157 | read(p, cmd_lines[i].second); 158 | } 159 | 160 | maps_built = create_maps; 161 | 162 | return true; 163 | } 164 | 165 | // ******************************************************************************************* 166 | bool CCollection_V2::deserialize_details(vector& zstd_data_details, size_t raw_size, bool deserialize_details) 167 | { 168 | v_zstd_batches.emplace_back(move(zstd_data_details), raw_size); 169 | 170 | if (deserialize_details) 171 | decompress_sample_details((v_zstd_batches.size() - 1) * details_batch_size); 172 | 173 | return true; 174 | } 175 | 176 | // EOF 177 | -------------------------------------------------------------------------------- /src/common/collection_v2.h: -------------------------------------------------------------------------------- 1 | #ifndef _COLLECTION_V2_H 2 | #define _COLLECTION_V2_H 3 | 4 | // ******************************************************************************************* 5 | // This file is a part of AGC software distributed under MIT license. 6 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 7 | // 8 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 9 | // 10 | // Version: 3.2 11 | // Date : 2024-11-21 12 | // ******************************************************************************************* 13 | 14 | #include "collection.h" 15 | #include "collection_v1.h" 16 | 17 | class CCollection_V2 : public CCollection_V1 18 | { 19 | 20 | public: 21 | CCollection_V2() : CCollection_V1() {} 22 | virtual ~CCollection_V2() {}; 23 | 24 | void serialize(vector& data_main, vector>& data_details, bool store_date_time, uint32_t _details_batch_size); 25 | bool deserialize_main(vector& data_main, bool create_maps); 26 | bool deserialize_details(vector& zstd_data_details, size_t raw_size, bool deserialize_details); 27 | }; 28 | 29 | // EOF 30 | #endif -------------------------------------------------------------------------------- /src/common/collection_v3.h: -------------------------------------------------------------------------------- 1 | #ifndef _COLLECTION_V3_H 2 | #define _COLLECTION_V3_H 3 | 4 | // ******************************************************************************************* 5 | // This file is a part of AGC software distributed under MIT license. 6 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 7 | // 8 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 9 | // 10 | // Version: 3.2 11 | // Date : 2024-11-21 12 | // ******************************************************************************************* 13 | 14 | #include "collection.h" 15 | #include "archive.h" 16 | 17 | class CCollection_V3 : public CCollection 18 | { 19 | struct contig_desc_t { 20 | string name; 21 | vector segments; 22 | 23 | contig_desc_t() : name("") {}; 24 | 25 | contig_desc_t(const contig_desc_t& x) { 26 | name = x.name; 27 | segments = x.segments; 28 | } 29 | 30 | contig_desc_t(contig_desc_t&& x) noexcept { 31 | name = move(x.name); 32 | segments = move(x.segments); 33 | } 34 | 35 | contig_desc_t(const string& _name) : name(_name) {}; 36 | 37 | contig_desc_t& operator=(const contig_desc_t& x) 38 | { 39 | name = x.name; 40 | segments = x.segments; 41 | 42 | return *this; 43 | } 44 | 45 | contig_desc_t& operator=(contig_desc_t&& x) noexcept 46 | { 47 | name = move(x.name); 48 | segments = move(x.segments); 49 | 50 | return *this; 51 | } 52 | }; 53 | 54 | struct sample_desc_t { 55 | string name; 56 | vector contigs; 57 | 58 | sample_desc_t() : name("") {}; 59 | sample_desc_t(const string& _name, const vector& _contigs) : name(_name), contigs(_contigs) {}; 60 | sample_desc_t(const sample_desc_t&x) { 61 | name = x.name; 62 | contigs = x.contigs; 63 | } 64 | 65 | sample_desc_t(sample_desc_t&&x) noexcept { 66 | name = move(x.name); 67 | contigs = move(x.contigs); 68 | } 69 | sample_desc_t(const string& _name) : name(_name) {}; 70 | 71 | sample_desc_t& operator=(const sample_desc_t& x) { 72 | name = x.name; 73 | contigs = x.contigs; 74 | 75 | return *this; 76 | } 77 | 78 | sample_desc_t& operator=(sample_desc_t&& x) noexcept { 79 | name = move(x.name); 80 | contigs = move(x.contigs); 81 | 82 | return *this; 83 | } 84 | }; 85 | 86 | ZSTD_CCtx* zstd_cctx_samples = nullptr; 87 | ZSTD_CCtx* zstd_cctx_contigs = nullptr; 88 | array zstd_cctx_details = { nullptr, nullptr, nullptr, nullptr, nullptr }; 89 | 90 | ZSTD_DCtx* zstd_dctx_samples = nullptr; 91 | ZSTD_DCtx* zstd_dctx_contigs = nullptr; 92 | array zstd_dctx_details = { nullptr, nullptr, nullptr, nullptr, nullptr }; 93 | 94 | unordered_map sample_ids; 95 | vector sample_desc; 96 | 97 | int unpacked_contig_data_batch_id = -1; 98 | 99 | uint32_t no_threads; 100 | 101 | size_t batch_size; 102 | uint32_t segment_size; 103 | uint32_t kmer_length; 104 | size_t no_samples_in_last_batch; 105 | string prev_sample_name; 106 | 107 | string placing_sample_name; 108 | uint32_t placing_sample_id; 109 | 110 | int collection_samples_id; 111 | int collection_contig_id; 112 | int collection_details_id; 113 | 114 | shared_ptr in_archive; 115 | shared_ptr out_archive; 116 | vector v_in_group_ids; 117 | 118 | void store_batch_sample_names(); 119 | void store_batch_contig_names(uint32_t id_from, uint32_t id_to); 120 | void store_batch_contig_details(uint32_t id_from, uint32_t id_to); 121 | 122 | void load_batch_sample_names(); 123 | void load_batch_contig_names(size_t id_batch); 124 | void load_batch_contig_details(size_t id_batch); 125 | void clear_batch_contig(size_t id_batch); 126 | 127 | void serialize_sample_names(vector &v_data); 128 | void serialize_contig_names(vector& v_data, uint32_t id_from, uint32_t id_to); 129 | void serialize_contig_details(array, 5>& v_data, uint32_t id_from, uint32_t id_to); 130 | 131 | void deserialize_sample_names(vector& v_data); 132 | void deserialize_contig_names(vector& v_data, size_t i_sample); 133 | void deserialize_contig_details(array, 5>& v_data, size_t i_sample); 134 | 135 | bool prepare_for_compression(); 136 | bool prepare_for_appending_copy(); 137 | bool prepare_for_decompression(); 138 | 139 | void zstd_compress(ZSTD_CCtx*& cctx, vector& v_input, vector& v_output, int level); 140 | void zstd_decompress(ZSTD_DCtx*& dctx, vector& v_input, vector& v_output, size_t raw_size); 141 | 142 | // Just check 143 | int get_in_group_id(int pos) 144 | { 145 | if ((size_t) pos >= v_in_group_ids.size()) 146 | return -1; 147 | return v_in_group_ids[pos]; 148 | } 149 | 150 | // Check but resize first if necessary 151 | int read_in_group_id(int pos) 152 | { 153 | if ((size_t) pos >= v_in_group_ids.size()) 154 | v_in_group_ids.resize((int)(pos * 1.2), -1); 155 | 156 | return v_in_group_ids[pos]; 157 | } 158 | 159 | void set_in_group_id(int pos, int val) 160 | { 161 | if ((size_t) pos >= v_in_group_ids.size()) 162 | v_in_group_ids.resize((int) (pos * 1.2) + 1, -1); 163 | 164 | v_in_group_ids[pos] = val; 165 | } 166 | 167 | void clear_in_group_ids() 168 | { 169 | v_in_group_ids.clear(); 170 | } 171 | 172 | void determine_collection_samples_id() 173 | { 174 | if (collection_samples_id >= 0) 175 | return; 176 | 177 | if(out_archive != nullptr) 178 | collection_samples_id = out_archive->GetStreamId("collection-samples"); 179 | else 180 | collection_samples_id = in_archive->GetStreamId("collection-samples"); 181 | } 182 | 183 | void determine_collection_contig_id() 184 | { 185 | if (collection_contig_id >= 0) 186 | return; 187 | 188 | if(out_archive != nullptr) 189 | collection_contig_id = out_archive->GetStreamId("collection-contigs"); 190 | else 191 | collection_contig_id = in_archive->GetStreamId("collection-contigs"); 192 | } 193 | 194 | void determnine_collection_details_id() 195 | { 196 | if (collection_details_id >= 0) 197 | return; 198 | 199 | if(out_archive != nullptr) 200 | collection_details_id = out_archive->GetStreamId("collection-details"); 201 | else 202 | collection_details_id = in_archive->GetStreamId("collection-details"); 203 | } 204 | 205 | vector split_string(const string& s); 206 | string encode_split(vector& prev_split, vector& curr_split); 207 | string decode_split(vector& prev_split, vector& curr_split); 208 | 209 | public: 210 | CCollection_V3() : CCollection() { 211 | batch_size = 1ull << 20; 212 | 213 | no_threads = 1; 214 | 215 | collection_samples_id = -1; 216 | collection_contig_id = -1; 217 | collection_details_id = -1; 218 | 219 | placing_sample_id = ~0u; 220 | placing_sample_name = ""; 221 | 222 | kmer_length = 0; 223 | no_samples_in_last_batch = 0; 224 | segment_size = 0; 225 | } 226 | virtual ~CCollection_V3() { 227 | if (zstd_cctx_samples) ZSTD_freeCCtx(zstd_cctx_samples); 228 | if (zstd_cctx_contigs) ZSTD_freeCCtx(zstd_cctx_contigs); 229 | for(auto &x : zstd_cctx_details) 230 | if (x) ZSTD_freeCCtx(x); 231 | 232 | if (zstd_dctx_samples) ZSTD_freeDCtx(zstd_dctx_samples); 233 | if (zstd_dctx_contigs) ZSTD_freeDCtx(zstd_dctx_contigs); 234 | for(auto &x : zstd_dctx_details) 235 | if (x) ZSTD_freeDCtx(x); 236 | }; 237 | 238 | bool set_archives(shared_ptr _in_archive, shared_ptr _out_archive, 239 | uint32_t _no_threads, size_t _batch_size, uint32_t _segment_size, uint32_t _kmer_length); 240 | 241 | void complete_serialization(); 242 | 243 | bool prepare_for_appending_load_last_batch(); 244 | 245 | virtual bool register_sample_contig(const string& sample_name, const string& contig_name); 246 | 247 | void reset_prev_sample_name(); 248 | virtual void add_segment_placed(const string &sample_name, const string& contig_name, const uint32_t place, const uint32_t group_id, const uint32_t in_group_id, const bool is_rev_comp, const uint32_t raw_length); 249 | void add_segments_placed(vector& segments_to_place); 250 | virtual bool get_reference_name(string& reference_name); 251 | virtual bool get_samples_list(vector& v_samples, bool sorted = true); 252 | virtual bool get_contig_list_in_sample(const string& sample_name, vector& v_contig_names); 253 | virtual bool get_sample_desc(const string& sample_name, vector>>& sample_desc_); 254 | virtual bool get_contig_desc(const string& sample_name, string& contig_name, vector& contig_desc); 255 | virtual bool is_contig_desc(const string& sample_name, const string& contig_name); 256 | virtual vector get_samples_for_contig(const string& contig_name); 257 | virtual size_t get_no_samples(); 258 | virtual int32_t get_no_contigs(const string& sample_name); 259 | 260 | void store_contig_batch(uint32_t id_from, uint32_t id_to); 261 | }; 262 | 263 | // EOF 264 | #endif 265 | -------------------------------------------------------------------------------- /src/common/defs.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEFS_H 2 | #define _DEFS_H 3 | 4 | // ******************************************************************************************* 5 | // This file is a part of AGC software distributed under MIT license. 6 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 7 | // 8 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 9 | // 10 | // Version: 3.2.1 11 | // Date : 2024-11-25 12 | // ******************************************************************************************* 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | using namespace std; 19 | 20 | typedef vector contig_t; 21 | typedef vector packed_block_t; 22 | 23 | const uint32_t AGC_VER_MAJOR = 3; 24 | const uint32_t AGC_VER_MINOR = 2; 25 | const uint32_t AGC_VER_BUGFIX = 1; 26 | const string AGC_VER_BUILD = "20241125.1"s; 27 | 28 | const uint32_t AGC_FILE_MAJOR = 3; 29 | const uint32_t AGC_FILE_MINOR = 0; 30 | 31 | const std::string AGC_VERSION = std::string("AGC (Assembled Genomes Compressor) v. ") + 32 | to_string(AGC_VER_MAJOR) + "." + to_string(AGC_VER_MINOR) + "." + to_string(AGC_VER_BUGFIX) + 33 | " [build " + AGC_VER_BUILD + "]"; 34 | 35 | #define IMPROVED_LZ_ENCODING 36 | 37 | #define USE_INCREMENTING_BARRIERS 38 | 39 | #include 40 | 41 | #if defined(_MSC_VER) /* Visual Studio */ 42 | #define REFRESH_FORCE_INLINE __forceinline 43 | #define REFRESH_NO_INLINE __declspec(noinline) 44 | #define ARCH_X64 45 | #elif defined(__GNUC__) 46 | #define REFRESH_FORCE_INLINE __inline__ __attribute__((always_inline, unused)) 47 | #define REFRESH_NO_INLINE __attribute__((noinline)) 48 | #else 49 | #define REFRESH_FORCE_INLINE 50 | #define REFRESH_NO_INLINE 51 | #endif 52 | 53 | // EOF 54 | #endif -------------------------------------------------------------------------------- /src/common/utils.cpp: -------------------------------------------------------------------------------- 1 | // ******************************************************************************************* 2 | // This file is a part of AGC software distributed under MIT license. 3 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 4 | // 5 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 6 | // 7 | // Version: 3.2 8 | // Date : 2024-11-21 9 | // ******************************************************************************************* 10 | 11 | #include "utils.h" 12 | #include 13 | 14 | // ******************************************************************************************* 15 | string int_to_hex(uint32_t n) 16 | { 17 | const char dig[] = "0123456789ABCDEF"; 18 | 19 | string res; 20 | 21 | do 22 | { 23 | res.push_back(dig[n & 0xfu]); 24 | n /= 16; 25 | } while (n); 26 | 27 | // res.reserve(); 28 | 29 | return res; 30 | } 31 | 32 | // ******************************************************************************************* 33 | string int_to_base64(uint32_t n) 34 | { 35 | const char dig[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_#"; 36 | 37 | string res; 38 | 39 | do 40 | { 41 | res.push_back(dig[n & 0x3fu]); 42 | n /= 64; 43 | } while (n); 44 | 45 | // res.reserve(); 46 | 47 | return res; 48 | } 49 | 50 | // ******************************************************************************************* 51 | string ss_prefix(uint32_t archive_version) 52 | { 53 | if (archive_version < 3000) 54 | return "seg-"; 55 | else 56 | return "x"; 57 | } 58 | 59 | // ******************************************************************************************* 60 | string ss_base(uint32_t archive_version, uint32_t n) 61 | { 62 | if (archive_version < 3000) 63 | return "seg-" + to_string(n); 64 | else 65 | return "x" + int_to_base64(n); 66 | } 67 | 68 | // ******************************************************************************************* 69 | string ss_ref_name(uint32_t archive_version, uint32_t n) 70 | { 71 | if (archive_version < 3000) 72 | return "seg-" + to_string(n) + "-ref"; 73 | else 74 | return "x" + int_to_base64(n) + "r"; 75 | } 76 | 77 | // ******************************************************************************************* 78 | string ss_delta_name(uint32_t archive_version, uint32_t n) 79 | { 80 | if (archive_version < 3000) 81 | return "seg-" + to_string(n) + "-delta"; 82 | else 83 | return "x" + int_to_base64(n) + "d"; 84 | } 85 | 86 | // ******************************************************************************************* 87 | string ss_ref_ext(uint32_t archive_version) 88 | { 89 | if (archive_version < 3000) 90 | return "-ref"; 91 | else 92 | return "r"; 93 | } 94 | 95 | // ******************************************************************************************* 96 | string ss_delta_ext(uint32_t archive_version) 97 | { 98 | if (archive_version < 3000) 99 | return "-delta"; 100 | else 101 | return "d"; 102 | } 103 | 104 | // EOF 105 | -------------------------------------------------------------------------------- /src/core/agc_decompressor.h: -------------------------------------------------------------------------------- 1 | #ifndef _AGC_DECOMPRESSOR_H 2 | #define _AGC_DECOMPRESSOR_H 3 | 4 | // ******************************************************************************************* 5 | // This file is a part of AGC software distributed under MIT license. 6 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 7 | // 8 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 9 | // 10 | // Version: 3.2 11 | // Date : 2024-11-21 12 | // ******************************************************************************************* 13 | 14 | #include "../common/agc_decompressor_lib.h" 15 | #include 16 | 17 | // ******************************************************************************************* 18 | // Class supporting only decompression of AGC files - extended version (can store also in gzipped files) 19 | class CAGCDecompressor : public CAGCDecompressorLibrary 20 | { 21 | void start_decompressing_threads(vector& v_threads, const uint32_t n_t, uint32_t gzip_level = 0, uint32_t line_len = 0, bool fast = false); 22 | 23 | void gzip_contig(contig_t& ctg, contig_t& working_space, refresh::gz_in_memory& gzip_compressor); 24 | 25 | public: 26 | CAGCDecompressor(bool _is_app_mode); 27 | ~CAGCDecompressor(); 28 | 29 | bool GetCollectionFiles(const string& _path, const uint32_t _line_length, const uint32_t no_threads, const uint32_t gzip_level, bool no_ref, bool fast, uint32_t verbosity); 30 | bool GetSampleFile(const string& _file_name, const vector& sample_names, const uint32_t _line_length, const uint32_t no_threads, const uint32_t gzip_level, uint32_t verbosity); 31 | bool GetContigFile(const string& _file_name, const vector& contig_names, const uint32_t _line_length, const uint32_t no_threads, const uint32_t gzip_level, uint32_t verbosity); 32 | bool GetSampleForStreaming(const string& _file_name, const vector& sample_names, const uint32_t _line_length, const uint32_t no_threads, const uint32_t gzip_level, uint32_t verbosity); 33 | bool GetContigForStreaming(const string& _file_name, const vector& contig_names, const uint32_t _line_length, const uint32_t no_threads, const uint32_t gzip_level, uint32_t verbosity); 34 | 35 | bool GetSampleSequences(const string& sample_name, vector>> &v_contig_seq, const uint32_t no_threads); 36 | 37 | bool AssignArchive(const CAGCBasic &agc_basic); 38 | }; 39 | 40 | // EOF 41 | #endif -------------------------------------------------------------------------------- /src/core/genome_io.h: -------------------------------------------------------------------------------- 1 | #ifndef _GENOME_IO_H 2 | #define _GENOME_IO_H 3 | 4 | // ******************************************************************************************* 5 | // This file is a part of AGC software distributed under MIT license. 6 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 7 | // 8 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 9 | // 10 | // Version: 3.2 11 | // Date : 2024-11-21 12 | // ******************************************************************************************* 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "../common/defs.h" 19 | #include 20 | #include 21 | 22 | #ifndef _WIN32 23 | #define my_fseek fseek 24 | #define my_ftell ftell 25 | #else 26 | #define my_fseek _fseeki64 27 | #define my_ftell _ftelli64 28 | #include 29 | #include 30 | #endif 31 | 32 | using namespace std; 33 | 34 | class CGenomeIO 35 | { 36 | const uint8_t cnv_num[128] = { 37 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 38 | 'A', 'C', 'G', 'T', 'N', 'R', 'Y', 'S', 'W', 'K', 'M', 'B', 'D', 'H', 'V', 'U', 39 | ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 40 | ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 41 | ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 42 | ' ', 0, 11, 1, 12, 30, 30, 2, 13, 30, 30, 9, 30, 10, 4, 30, 43 | 30, 30, 5, 7, 3, 15, 14, 8, 30, 6, 30, 30, 30, 30, 30, 30, 44 | ' ', 0, 11, 1, 12, 30, 30, 2, 13, 30, 30, 9, 30, 10, 4, 30, 45 | 30, 30, 5, 7, 3, 15, 14, 8, 30, 6, 30, 30, 30, 30, 30, 30 46 | }; 47 | 48 | string file_name; 49 | bool writing; 50 | 51 | FILE* out; 52 | bool is_gzipped; 53 | bool use_stdout; 54 | 55 | refresh::stream_in_file *sif = nullptr; 56 | refresh::stream_decompression* sdf = nullptr; 57 | 58 | refresh::gz_in_memory gzip_zero_compressor{ 1 }; 59 | vector gzip_zero_compressor_buffer; 60 | 61 | uint8_t* buffer; 62 | const size_t write_buffer_size = 32 << 20; 63 | const size_t read_buffer_size = 4 << 20; 64 | size_t buffer_filled; 65 | size_t buffer_pos; 66 | 67 | bool fill_buffer(); 68 | bool eof() { return buffer_pos == buffer_filled; } 69 | int find_contig_end(); 70 | 71 | bool read_contig(string& id, contig_t& contig, const bool converted); 72 | bool read_contig_raw(string& id, contig_t& contig); 73 | 74 | bool save_contig_directly(const string& id, const contig_t& contig, const uint32_t gzip_level); 75 | 76 | #if 0 77 | bool save_contig(const string& id, const contig_t& contig, const uint32_t line_length, const bool converted); 78 | 79 | void save_contig_imp(const contig_t& contig, const uint32_t line_length); 80 | void save_contig_imp_cnv(const contig_t& contig, const uint32_t line_length); 81 | #endif 82 | 83 | public: 84 | CGenomeIO(); 85 | ~CGenomeIO(); 86 | 87 | bool Open(const string &_file_name, const bool _writing); 88 | bool Close(); 89 | size_t FileSize(); 90 | 91 | bool ReadContig(string &id, contig_t&contig); 92 | bool ReadContigConverted(string& id, contig_t& contig); 93 | bool ReadContigRaw(string& id, contig_t& contig); 94 | 95 | bool SaveContigDirectly(const string& id, const contig_t& contig, const uint32_t gzip_level); 96 | #if 0 97 | bool SaveContig(const string& id, const contig_t& contig, const uint32_t line_length); 98 | bool SaveContigConverted(const string& id, const contig_t& contig, const uint32_t line_length); 99 | #endif 100 | }; 101 | #endif 102 | 103 | // EOF 104 | -------------------------------------------------------------------------------- /src/examples/example-agc-lib-c.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char **argv) 7 | { 8 | if(argc < 2) 9 | { 10 | printf("Usage: example-agc-lib-c \n"); 11 | return 0; 12 | } 13 | 14 | // *** Open agc file 15 | agc_t *agc = agc_open(argv[1], 0); 16 | if(!agc) 17 | { 18 | printf("Cannot open %s file\n", argv[1]); 19 | return 0; 20 | } 21 | 22 | // *** Check no. of samples 23 | printf("No. samples: %d\n", agc_n_sample(agc)); 24 | 25 | // *** List samples 26 | int n_sample; 27 | 28 | char **list_samples = agc_list_sample(agc, &n_sample); 29 | 30 | printf("Samples in file with no. of contigs\n"); 31 | for(char **p = list_samples; *p; ++p) 32 | printf("%s : %d\n", *p, agc_n_ctg(agc, *p)); 33 | 34 | // *** List contigs in 0th sample, together with 35 | printf("\nContents of sample: %s\n", list_samples[0]); 36 | 37 | int n_ctg; 38 | char **list_contigs = agc_list_ctg(agc, list_samples[0], &n_ctg); 39 | 40 | for(char **p = list_contigs; *p; ++p) 41 | printf("%s : %d\n", *p, agc_get_ctg_len(agc, list_samples[0], *p)); 42 | 43 | // *** Print part of 0th contig of 0th sample 44 | int part_len = 2000; 45 | int from = 1000000; 46 | int to = from + part_len - 1; 47 | 48 | char *seq = (char*) malloc(part_len + 1); 49 | 50 | int ctg_len = agc_get_ctg_len(agc, list_samples[0], list_contigs[0]); 51 | 52 | if(ctg_len <= to) 53 | { 54 | to = ctg_len - 1; 55 | if(ctg_len < part_len) 56 | from = 0; 57 | else 58 | from = to - (part_len - 1); 59 | } 60 | 61 | int seq_len = agc_get_ctg_seq(agc, list_samples[0], list_contigs[0], from, to, seq); 62 | 63 | printf("%d %d %d : %s\n", from, to, seq_len, seq); 64 | 65 | // Query without sample name 66 | seq_len = agc_get_ctg_seq(agc, NULL, list_contigs[0], from, to, seq); 67 | 68 | printf("%d %d %d : %s\n", from, to, seq_len, seq); 69 | 70 | free(seq); 71 | 72 | agc_list_destroy(list_samples); 73 | agc_list_destroy(list_contigs); 74 | 75 | agc_close(agc); 76 | 77 | return 0; 78 | } -------------------------------------------------------------------------------- /src/examples/example-agc-lib-cpp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void single_thread(const char *fn) 9 | { 10 | // *** Open agc file 11 | CAGCFile agc; 12 | 13 | if(!agc.Open(fn, false)) 14 | { 15 | std::cerr << "Cannot open " << fn << " file" << std::endl; 16 | return; 17 | } 18 | 19 | // *** Check no. of samples 20 | std::cout << "No. samples: " << agc.NSample() << std::endl; 21 | 22 | // *** List samples 23 | std::vector samples; 24 | int n_sample = agc.ListSample(samples); 25 | 26 | if(n_sample < 0) 27 | { 28 | std::cerr << "Error: cannot read list of samples" << std::endl; 29 | return; 30 | } 31 | 32 | std::cout << "Samples in file with no. of contigs" << std::endl; 33 | for(const auto &s : samples) 34 | std::cout << s << " : " << agc.NCtg(s) << std::endl; 35 | 36 | // *** List contigs in 0th sample, together with 37 | std::cout << "\nContents of sample: " << samples.front() << std::endl; 38 | 39 | std::vector contigs; 40 | int n_ctg = agc. ListCtg(samples.front(), contigs); 41 | 42 | if(n_ctg < 0) 43 | { 44 | std::cerr << "Error: cannot read list of contigs" << std::endl; 45 | return; 46 | } 47 | 48 | for(const auto &ctg : contigs) 49 | std::cout << ctg << " : " << agc.GetCtgLen(samples.front(), ctg) << std::endl;; 50 | 51 | // *** Print part of 0th contig of 0th sample 52 | int part_len = 2000; 53 | int from = 1000000; 54 | int to = from + part_len - 1; 55 | 56 | std::string seq; 57 | 58 | int ctg_len = agc.GetCtgLen(samples.front(), contigs.front()); 59 | 60 | if(ctg_len <= to) 61 | { 62 | to = ctg_len - 1; 63 | if(ctg_len < part_len) 64 | from = 0; 65 | else 66 | from = to - (part_len - 1); 67 | } 68 | 69 | int seq_len = agc.GetCtgSeq(samples.front(), contigs.front(), from, to, seq); 70 | 71 | std::cout << from << " " << to << " " << seq_len << " " << seq << std::endl; 72 | 73 | // Query without sample name 74 | seq_len = agc.GetCtgSeq("", contigs.front(), from, to, seq); 75 | 76 | std::cout << from << " " << to << " " << seq_len << " " << seq << std::endl; 77 | 78 | agc.Close(); 79 | } 80 | 81 | void many_threads(const char *fn) 82 | { 83 | CAGCFile agc; 84 | 85 | if(!agc.Open(fn, true)) // in case of many queries it is better to open agc file in prefetching mode 86 | { 87 | std::cerr << "Cannot open " << fn << " file" << std::endl; 88 | return; 89 | } 90 | 91 | std::vector v_thr; 92 | auto n_thr = std::thread::hardware_concurrency(); 93 | 94 | std::cout << "Running " + std::to_string(n_thr) + " threads\n"; 95 | 96 | // Multithreaded reading of contigs 97 | for(size_t i = 0; i < n_thr; ++i) 98 | v_thr.emplace_back([&agc, i]{ 99 | std::vector samples, contigs; 100 | 101 | agc.ListSample(samples); 102 | int n_sample = samples.size(); 103 | 104 | std::mt19937 mt(i); 105 | int my_sample_id = mt() % n_sample; 106 | 107 | std::string sample_name = samples[my_sample_id]; 108 | 109 | agc.ListCtg(sample_name, contigs); 110 | int n_contig = contigs.size(); 111 | 112 | for(int i = 0; i < 10; ++i) 113 | { 114 | uint64_t sum_ctg = 0; 115 | 116 | std::string seq; 117 | std::string ctg_name = contigs[mt() % n_contig]; 118 | agc.GetCtgSeq(sample_name, ctg_name, -1, -1, seq); 119 | 120 | // Do anything - here we calculate sum of symbols 121 | for(auto c : seq) 122 | sum_ctg += static_cast(c); 123 | 124 | std::cout << "Thread " + std::to_string(i) + " : " + sample_name + " " + ctg_name + " " + std::to_string(sum_ctg) + "\n"; 125 | } 126 | 127 | }); 128 | 129 | for(auto &t : v_thr) 130 | t.join(); 131 | 132 | agc.Close(); 133 | } 134 | 135 | int main(int argc, char **argv) 136 | { 137 | if(argc < 2) 138 | { 139 | printf("Usage: example-agc-lib-c \n"); 140 | return 0; 141 | } 142 | 143 | single_thread(argv[1]); 144 | 145 | many_threads(argv[1]); 146 | 147 | return 0; 148 | } -------------------------------------------------------------------------------- /src/examples/makefile: -------------------------------------------------------------------------------- 1 | all: example-agc-lib-c example-agc-lib-cpp 2 | 3 | AGC_ROOT_DIR = ../.. 4 | EXAMPLE_APP_DIR = . 5 | AGC_CXX_DIR = ../lib-cxx 6 | AGC_LIBS_DIR = ../../libs 7 | LIBS_DIR = . #/usr/local/lib 8 | INCLUDE_DIR= . #/usr/local/include 9 | 10 | CXX = g++ 11 | CC = gcc 12 | CFLAGS = -Wall -O3 -m64 -std=c11 -pthread -mavx -I $(INCLUDE_DIR) -I $(AGC_CXX_DIR) 13 | CXXFLAGS = -Wall -O3 -m64 -std=c++17 -pthread -mavx -I $(INCLUDE_DIR) -I $(AGC_CXX_DIR) -fpermissive 14 | CLINK = -lm -pthread -std=c++17 15 | 16 | ifdef MSVC # Avoid the MingW/Cygwin sections 17 | uname_S := Windows 18 | else # If uname not available => 'not' 19 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') 20 | endif 21 | ifeq ($(uname_S),Linux) 22 | CLINK+=-fabi-version=6 23 | LIB_ZSTD=libzstd.a 24 | LIB_AGC=libagc.a 25 | endif 26 | 27 | ifeq ($(uname_S),Darwin) 28 | LIB_ZSTD=libzstd.mac.a 29 | LIB_AGC=libagc.a 30 | CXX=g++-11 31 | endif 32 | # default install location (binary placed in the /bin folder) 33 | prefix = /usr/local 34 | 35 | # optional install location 36 | exec_prefix = $(prefix) 37 | 38 | 39 | %.o: %.cpp 40 | $(CXX) $(CXXFLAGS) -c $< -o $@ 41 | 42 | %.o: %.c 43 | $(CC) $(CFLAGS) -c $< -o $@ 44 | 45 | example-agc-lib-c: $(EXAMPLE_APP_DIR)/example-agc-lib-c.o 46 | $(CXX) -o $(EXAMPLE_APP_DIR)/$@ \ 47 | $(EXAMPLE_APP_DIR)/example-agc-lib-c.o \ 48 | $(AGC_ROOT_DIR)/$(LIB_AGC) \ 49 | $(AGC_LIBS_DIR)/$(LIB_ZSTD) \ 50 | $(CLINK) 51 | 52 | example-agc-lib-cpp: $(EXAMPLE_APP_DIR)/example-agc-lib-cpp.o 53 | $(CXX) -o $(EXAMPLE_APP_DIR)/$@ \ 54 | $(EXAMPLE_APP_DIR)/example-agc-lib-cpp.o \ 55 | $(AGC_ROOT_DIR)/$(LIB_AGC) \ 56 | $(AGC_LIBS_DIR)/$(LIB_ZSTD) \ 57 | $(CLINK) 58 | 59 | clean: 60 | -rm $(EXAMPLE_APP_DIR)/*.o 61 | -rm example-agc-lib-c 62 | -rm example-agc-lib-cpp 63 | -------------------------------------------------------------------------------- /src/lib-cxx/agc-api.h: -------------------------------------------------------------------------------- 1 | // ******************************************************************************************* 2 | // This file is a part of AGC software distributed under MIT license. 3 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 4 | // 5 | // Copyright(C) 2021-2024, S.Deorowicz, A.Danek, H.Li 6 | // 7 | // Version: 3.2 8 | // Date : 2024-11-21 9 | // ******************************************************************************************* 10 | 11 | #ifndef AGC_API_H 12 | #define AGC_API_H 13 | 14 | #ifdef __cplusplus 15 | // ******************************************************************************************* 16 | // C++ API (available only when using C++ compiler) 17 | // ******************************************************************************************* 18 | #include 19 | #include 20 | #include 21 | 22 | // ******************************************************************************************* 23 | class CAGCFile 24 | { 25 | std::unique_ptr agc; 26 | bool is_opened; 27 | 28 | public: 29 | CAGCFile(); 30 | ~CAGCFile(); 31 | 32 | /** 33 | * @param file_name file name 34 | * @param prefetching true to preload whole file into memory (faster if you plan series of sequence queries), false otherwise 35 | * 36 | * @return false for error 37 | */ 38 | bool Open(const std::string& file_name, bool prefetching = true); 39 | 40 | /** 41 | * @return true for success and false for error 42 | */ 43 | bool Close(); 44 | 45 | /** 46 | * Get the length of a contig. Return an error if _name_ is not present, or if 47 | * _name_ is not unique but _sample_ is an empty string, 48 | * 49 | * @param sample sample name; can be an empty string 50 | * @param name contig name 51 | * 52 | * @return contig length, or <0 for errors 53 | */ 54 | int GetCtgLen(const std::string& sample, const std::string& name) const; 55 | 56 | /** 57 | * @param sample sample name; can be an empty string 58 | * @param name contig name 59 | * @param start start offset 60 | * @param end end offset 61 | * @param buf sequence to be written; user should allocate memory (returned value) 62 | * 63 | * @return contig length, or <0 for errors 64 | */ 65 | int GetCtgSeq(const std::string& sample, const std::string& name, int start, int end, std::string& buffer) const; 66 | 67 | /** 68 | * @return the number of samples 69 | */ 70 | int NSample() const; 71 | 72 | /** 73 | * @param sample sample name 74 | * 75 | * @return the number of contigs in sample 76 | */ 77 | int NCtg(const std::string& sample) const; 78 | 79 | /** 80 | * @param samples vector of strings with sample names (returned value) 81 | * 82 | * @return number of samples to be written to 83 | */ 84 | int ListSample(std::vector& samples) const; 85 | 86 | /** 87 | * @param samples vector of strings with sample names (returned value) 88 | * 89 | * @return number of samples to be written to 90 | */ 91 | int GetReferenceSample(std::string& sample) const; 92 | 93 | /** 94 | * @param sample sample name; can be an empty string 95 | * @param names vector of strings with contig names (returned value) 96 | * 97 | * @return number of contigs in the sample 98 | */ 99 | int ListCtg(const std::string& sample, std::vector& names) const; 100 | }; 101 | 102 | typedef CAGCFile agc_t; 103 | #define EXTERNC extern "C" 104 | #else 105 | typedef struct agc_t agc_t; 106 | #define EXTERNC 107 | #endif 108 | 109 | // ******************************************************************************************* 110 | // C version of the API (can be used in C or C++ code) 111 | // ******************************************************************************************* 112 | 113 | /** 114 | * @param fn file name 115 | * @param prefetching 1 to preload whole file into memory (faster if you plan series of sequence queries), 0 otherwise 116 | * 117 | * @return NULL for error 118 | */ 119 | EXTERNC agc_t* agc_open(char* fn, int prefetching); 120 | 121 | /** 122 | * @param fp agc handle 123 | * 124 | * @return 0 for success and -1 for error 125 | */ 126 | EXTERNC int agc_close(agc_t* agc); 127 | 128 | /** 129 | * Get the length of a contig. Return an error if _name_ is not present, or if 130 | * _name_ is not unique but _sample_ is NULL, 131 | * 132 | * @param agc agc handle 133 | * @param sample sample name; can be NULL 134 | * @param name contig name 135 | * 136 | * @return contig length, or <0 for errors 137 | */ 138 | EXTERNC int agc_get_ctg_len(const agc_t *agc, const char *sample, const char *name); 139 | 140 | /** 141 | * @param agc agc handle 142 | * @param sample sample name; can be NULL 143 | * @param name contig name 144 | * @param start start offset 145 | * @param end end offset 146 | * @param buf sequence to be written; user should allocate memory (returned value) 147 | * 148 | * @return contig length, or <0 for errors 149 | */ 150 | EXTERNC int agc_get_ctg_seq(const agc_t *agc, const char *sample, const char *name, int start, int end, char *buf); 151 | 152 | /** 153 | * @param agc agc handle 154 | * 155 | * @return the number of samples 156 | */ 157 | EXTERNC int agc_n_sample(const agc_t* agc); 158 | 159 | /** 160 | * @param agc agc handle 161 | * @param sample sample name 162 | * 163 | * @return the number of contigs in sample 164 | */ 165 | EXTERNC int agc_n_ctg(const agc_t *agc, const char *sample); 166 | 167 | /** 168 | * @param agc agc handle 169 | * 170 | * @return NULL-terminated string. Use agc_string_destroy() to deallocate. 171 | */ 172 | EXTERNC char* agc_reference_sample(const agc_t* agc); 173 | 174 | /** 175 | * @param agc agc handle 176 | * @param n_sample number of samples to be written to (returned value) 177 | * 178 | * @return array of NULL-terminated strings. Use agc_list_destroy() to deallocate. 179 | */ 180 | EXTERNC char **agc_list_sample(const agc_t *agc, int *n_sample); 181 | 182 | /** 183 | * @param agc agc handle 184 | * @param sample sample name; can be NULL 185 | * @param n_ctg number of contigs in the sample (returned value) 186 | * 187 | * @return array of NULL-terminated strings. Use agc_list_destroy() to deallocate. 188 | */ 189 | EXTERNC char **agc_list_ctg(const agc_t *agc, const char *sample, int *n_ctg); 190 | 191 | /** 192 | * Deallocate an array of strings returned by agc_list_samples or agc_list_ctg 193 | * 194 | * @param list array to deallocate 195 | */ 196 | EXTERNC int agc_list_destroy(char **list); 197 | 198 | /** 199 | * Deallocate string returned by agc_reference_sample 200 | * 201 | * @param sample string to deallocate 202 | */ 203 | EXTERNC int agc_string_destroy(char *sample); 204 | 205 | #endif 206 | 207 | // EOF 208 | -------------------------------------------------------------------------------- /src/lib-cxx/lib-cxx.cpp: -------------------------------------------------------------------------------- 1 | // ******************************************************************************************* 2 | // This file is a part of AGC software distributed under MIT license. 3 | // The homepage of the AGC project is https://github.com/refresh-bio/agc 4 | // 5 | // Copyright(C) 2021-2022, S.Deorowicz, A.Danek, H.Li 6 | // 7 | // Version: 3.2 8 | // Date : 2024-11-21 9 | // ******************************************************************************************* 10 | 11 | #include "../common/agc_decompressor_lib.h" 12 | #include "agc-api.h" 13 | #include 14 | 15 | // ******************************************************************************************* 16 | char** agc_internal_cnv_vec2list(vector& vec); 17 | 18 | // ******************************************************************************************* 19 | // C++ part 20 | // ******************************************************************************************* 21 | 22 | // ******************************************************************************************* 23 | CAGCFile::CAGCFile() 24 | { 25 | agc = std::make_unique(false); 26 | is_opened = false; 27 | } 28 | 29 | // ******************************************************************************************* 30 | CAGCFile::~CAGCFile() 31 | { 32 | } 33 | 34 | // ******************************************************************************************* 35 | bool CAGCFile::Open(const std::string& file_name, bool prefetching) 36 | { 37 | if (agc->IsOpened()) 38 | return false; 39 | 40 | is_opened = agc->Open(file_name, prefetching); 41 | 42 | return is_opened; 43 | } 44 | 45 | // ******************************************************************************************* 46 | bool CAGCFile::Close() 47 | { 48 | if (!is_opened) 49 | return false; 50 | 51 | return agc->Close(); 52 | } 53 | 54 | // ******************************************************************************************* 55 | int CAGCFile::GetCtgLen(const std::string& sample, const std::string& name) const 56 | { 57 | if (!is_opened) 58 | return -1; 59 | 60 | return (int) agc->GetContigLength(sample, name); 61 | } 62 | 63 | // ******************************************************************************************* 64 | int CAGCFile::GetCtgSeq(const std::string& sample, const std::string& name, int start, int end, std::string& buffer) const 65 | { 66 | if (!is_opened) 67 | return -1; 68 | 69 | return agc->GetContigString(sample, name, start, end, buffer); 70 | } 71 | 72 | // ******************************************************************************************* 73 | int CAGCFile::NSample() const 74 | { 75 | if (!is_opened) 76 | return -1; 77 | 78 | return agc->GetNoSamples(); 79 | } 80 | 81 | // ******************************************************************************************* 82 | int CAGCFile::NCtg(const std::string& sample) const 83 | { 84 | if (!is_opened) 85 | return -1; 86 | 87 | return agc->GetNoContigs(sample); 88 | } 89 | 90 | // ******************************************************************************************* 91 | int CAGCFile::GetReferenceSample(std::string& sample) const 92 | { 93 | if (!is_opened) 94 | return -1; 95 | 96 | agc->GetReferenceSample(sample); 97 | 98 | return 0; 99 | } 100 | 101 | // ******************************************************************************************* 102 | int CAGCFile::ListSample(std::vector& samples) const 103 | { 104 | if (!is_opened) 105 | return -1; 106 | 107 | agc->ListSamples(samples); 108 | 109 | return 0; 110 | } 111 | 112 | // ******************************************************************************************* 113 | int CAGCFile::ListCtg(const std::string& sample, std::vector& names) const 114 | { 115 | if (!is_opened) 116 | return -1; 117 | 118 | agc->ListContigs(sample, names); 119 | 120 | return 0; 121 | } 122 | 123 | // ******************************************************************************************* 124 | // C part 125 | // ******************************************************************************************* 126 | agc_t* agc_open(char* fn, int prefetching) 127 | { 128 | agc_t* agc = new CAGCFile(); 129 | bool r = agc->Open(fn, (bool)prefetching); 130 | 131 | if (!r) 132 | { 133 | delete agc; 134 | agc = NULL; 135 | } 136 | 137 | return agc; 138 | } 139 | 140 | // ******************************************************************************************* 141 | int agc_close(agc_t* agc) 142 | { 143 | if (!agc) 144 | return -1; 145 | 146 | return agc->Close() ? 0 : -1; 147 | } 148 | 149 | // ******************************************************************************************* 150 | int agc_n_sample(const agc_t* agc) 151 | { 152 | if (!agc) 153 | return -1; 154 | 155 | return agc->NSample(); 156 | } 157 | 158 | // ******************************************************************************************* 159 | int agc_get_ctg_seq(const agc_t* agc, const char* sample, const char* name, int start, int end, char* buf) 160 | { 161 | if (!agc) 162 | return -1; 163 | 164 | string buffer; 165 | 166 | if (agc->GetCtgSeq(sample ? sample : "", name, start, end, buffer) != 0) 167 | return -1; 168 | 169 | strcpy(buf, buffer.data()); 170 | 171 | return (int) buffer.size(); 172 | } 173 | 174 | // ******************************************************************************************* 175 | int agc_get_ctg_len(const agc_t* agc, const char* sample, const char* name) 176 | { 177 | if (!agc) 178 | return -1; 179 | 180 | return agc->GetCtgLen(sample ? sample : "", name); 181 | } 182 | 183 | // ******************************************************************************************* 184 | int agc_n_ctg(const agc_t* agc, const char* sample) 185 | { 186 | if (!agc) 187 | return -1; 188 | 189 | return agc->NCtg(sample); 190 | } 191 | 192 | // ******************************************************************************************* 193 | char* agc_reference_sample(const agc_t* agc) 194 | { 195 | if (!agc) 196 | return NULL; 197 | 198 | string sample; 199 | 200 | if (agc->GetReferenceSample(sample) < 0) 201 | return NULL; 202 | 203 | char* c_sample = (char*) malloc(sample.size() + 1); 204 | strcpy(c_sample, sample.c_str()); 205 | 206 | return c_sample; 207 | } 208 | 209 | // ******************************************************************************************* 210 | char** agc_list_sample(const agc_t* agc, int* n_sample) 211 | { 212 | if (!agc) 213 | return NULL; 214 | 215 | vector v_samples; 216 | 217 | agc->ListSample(v_samples); 218 | 219 | *n_sample = (int)v_samples.size(); 220 | 221 | return agc_internal_cnv_vec2list(v_samples); 222 | } 223 | 224 | // ******************************************************************************************* 225 | char** agc_internal_cnv_vec2list(vector& vec) 226 | { 227 | char** list = (char**)malloc(sizeof(char*) * (vec.size() + 1)); 228 | 229 | if (!list) 230 | return NULL; 231 | 232 | char** p = list; 233 | 234 | for (auto& s : vec) 235 | { 236 | *p = (char*)malloc(s.size() + 1); 237 | if (!*p) 238 | { 239 | for (auto q = list; q != p; ++q) 240 | free(*q); 241 | free(list); 242 | 243 | return NULL; 244 | } 245 | 246 | strcpy(*p, s.data()); 247 | ++p; 248 | } 249 | 250 | *p = NULL; 251 | 252 | return list; 253 | } 254 | 255 | // ******************************************************************************************* 256 | char** agc_list_ctg(const agc_t* agc, const char* sample, int* n_ctg) 257 | { 258 | if (!agc) 259 | return NULL; 260 | 261 | vector v_contigs; 262 | 263 | agc->ListCtg(sample, v_contigs); 264 | 265 | *n_ctg = (int)v_contigs.size(); 266 | 267 | return agc_internal_cnv_vec2list(v_contigs); 268 | } 269 | 270 | // ******************************************************************************************* 271 | int agc_list_destroy(char** list) 272 | { 273 | for (char** p = list; p; ++p) 274 | free(*p); 275 | 276 | free(list); 277 | 278 | return 0; 279 | } 280 | 281 | // ******************************************************************************************* 282 | int agc_list_destroy(char* sample) 283 | { 284 | free(sample); 285 | 286 | return 0; 287 | } 288 | 289 | 290 | // EOF -------------------------------------------------------------------------------- /src/lib-cxx/lib-cxx.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | Header Files 56 | 57 | 58 | Header Files 59 | 60 | 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | Source Files 82 | 83 | 84 | Source Files 85 | 86 | 87 | Source Files 88 | 89 | 90 | Source Files 91 | 92 | 93 | Source Files 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/lib-cxx/lib-cxx.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/py_agc_api/py_agc_api.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "../core/agc_decompressor.h" 6 | #include "../lib-cxx/agc-api.h" 7 | 8 | //binding STL container std::vector 9 | PYBIND11_MAKE_OPAQUE(std::vector); 10 | 11 | namespace py = pybind11; 12 | 13 | 14 | PYBIND11_MODULE(py_agc_api, m) { 15 | m.doc() = "Python wrapper for AGC_API."; // optional module docstring 16 | 17 | // StringVector can be used in Python code (binding std::vector) 18 | py::bind_vector>(m, "StringVector") 19 | .def(py::init<>()) 20 | .def("clear", &std::vector::clear) 21 | .def("pop_back", &std::vector::pop_back) 22 | .def("__len__", [](const std::vector &v) { return v.size(); }) 23 | .def("__iter__", [](std::vector &v) { 24 | return py::make_iterator(v.begin(), v.end()); 25 | }, py::keep_alive<0, 1>()); 26 | 27 | // Class that represents agc archive 28 | py::class_(m, "CAGCFile") 29 | .def(py::init<>()) //parameterless constructor 30 | 31 | //Open(file_name, prefetching = true) opens agc archive 32 | // 33 | //@return true for success and false for error 34 | .def("Open", &CAGCFile::Open) 35 | 36 | //Close() closes opened archive 37 | //@return true for success and false for error 38 | .def("Close", &CAGCFile::Close) //Close() closes opened archive 39 | 40 | //NSample() 41 | //@returns number of samples in the archive 42 | .def("NSample", &CAGCFile::NSample) 43 | 44 | //GetReferenceSample() 45 | //@returns reference sample 46 | .def("GetReferenceSample", [](CAGCFile& ptr){ std::string s; ptr.GetReferenceSample(s); return s;}) 47 | 48 | 49 | //NCtg(sample) 50 | //@returns number of contig in sample 51 | .def("NCtg", &CAGCFile::NCtg) 52 | 53 | //ListSample(samples: StringVector) 54 | //@param samples vector of strings (StringVector) with sample names (returned value) 55 | //@return number of samples to be written to 56 | .def("ListSample", &CAGCFile::ListSample) 57 | 58 | //ListCtg(sample, names: StringVector) 59 | //@param sample sample name 60 | //@param names vector of strings (StringVector) with contig names (returned value) 61 | //@return number of contigs in the sample 62 | .def("ListCtg", &CAGCFile::ListCtg) 63 | 64 | //GetCtgLen(sample, name) 65 | //Get the length of a contig. 66 | //@param sample sample name; 67 | //@param name contig name 68 | //@return contig length, or <0 for errors 69 | .def("GetCtgLen", &CAGCFile::GetCtgLen) 70 | 71 | //GetCtgSeq(sample, name, start, end) 72 | //@param sample sample name 73 | //@param name contig name 74 | //@param start start offset 75 | //@param end end offset 76 | //@return contig sequence 77 | .def("GetCtgSeq", [](CAGCFile& ptr, const std::string& sample, const std::string& name, int start, int end) { std::string s; ptr.GetCtgSeq(sample, name, start, end, s); return s;}) 78 | 79 | //GetCtgSeq(name, start, end) 80 | //@param name contig name 81 | //@param start start offset 82 | //@param end end offset 83 | //@return contig sequence (if unique name across all contigs in all samples) 84 | .def("GetCtgSeq", [](CAGCFile& ptr, const std::string& name, int start, int end) { std::string s; std::string empty; ptr.GetCtgSeq(empty, name, start, end, s); return s;}) 85 | ; 86 | 87 | } 88 | 89 | -------------------------------------------------------------------------------- /src/py_agc_api/py_agc_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | import py_agc_api as agc 4 | import textwrap 5 | 6 | 7 | # open AGC archive ("toy_ex/toy_ex.agc") 8 | agc_arch = agc.CAGCFile() 9 | if not agc_arch.Open("toy_ex/toy_ex.agc", True): 10 | print("Error: cannot open agc archive") 11 | sys.exit(1) 12 | 13 | #Get number of samples in the archive 14 | n = agc_arch.NSample(); 15 | print("No. samples: ", n) 16 | 17 | #Get reference name 18 | reference = agc_arch.GetReferenceSample() 19 | print("Reference sample: ", reference) 20 | 21 | #Get list of samples in the archive 22 | set_list = agc.StringVector() 23 | 24 | 25 | agc_arch.ListSample(set_list); 26 | print("Samples in file with no. of contigs") 27 | 28 | iterator = iter(set_list) 29 | for i in range(n): #for i in range(len(set_list)): 30 | sample = set_list[i]; 31 | no_ctg = agc_arch.NCtg(sample) #Get number of contigs for sample 32 | print(sample, ":", no_ctg) 33 | 34 | 35 | #Get contents of the sample 36 | sample=set_list[0] 37 | print("\nContents of sample:", sample) 38 | #Get number of contigs for the 0th sample 39 | no_ctg = agc_arch.NCtg(sample) 40 | #Get name of contigs of the 0th sample 41 | ctg_list = agc.StringVector() 42 | agc_arch.ListCtg(sample, ctg_list); 43 | #Print name and length of each contig of the 0th sample 44 | for i in range(no_ctg): 45 | ctg_len = agc_arch.GetCtgLen(sample, ctg_list[i]) #Get length of the of the contig 46 | print("length of contig", ctg_list[i],":",ctg_len) #print contig name and length 47 | #Print part of contig in the sample (of length 5 if possible, from position 8, if possible) 48 | start=8 #start position of contig part 49 | length=5 #part length 50 | end=start+length-1 #end position of contig part 51 | ctg_len = agc_arch.GetCtgLen(sample, ctg_list[i]) #Get length of the of the contig 52 | if end >= ctg_len: 53 | end = ctg_len - 1 54 | if length > ctg_len: 55 | start = 0 #print whole contig 56 | else: 57 | start = end - (length - 1) 58 | print("\tsubsequence start:", start, ", end:", end, ", length:", length) 59 | #Get and print part of 0th contig in the 0th sample, from start to end 60 | seq = agc_arch.GetCtgSeq(sample, ctg_list[i], start, end) 61 | print("\tsubsequence length:", len(seq)) 62 | print("\tpos:", start, "-", end, "len:", end-start+1, "seq:",seq); 63 | #Get (query without sample name) and print part of 0th contig in the 0th sample, from start to end (work only if contig name is unique among samples) 64 | seq = agc_arch.GetCtgSeq(ctg_list[i], start, end) 65 | print("\tsubsequence start:", start, ", end:", end, ", length:", length) 66 | print("\tsubsequence length:", len(seq)) 67 | print("\tpos:", start, "-", end, "len:", end-start+1, "seq:",seq); 68 | -------------------------------------------------------------------------------- /src/py_agc_api/set_path.sh: -------------------------------------------------------------------------------- 1 | SCRIPTPATH="$( cd "$(dirname "$BASH_SOURCE")" ; pwd -P )" 2 | export PYTHONPATH="${PYTHONPATH}:${SCRIPTPATH}/" 3 | -------------------------------------------------------------------------------- /toy_ex/a.fa: -------------------------------------------------------------------------------- 1 | >chr1a 2 | CTGAGCTGACTGA 3 | >chr3a 4 | AGTTTAGCT 5 | -------------------------------------------------------------------------------- /toy_ex/b.fa: -------------------------------------------------------------------------------- 1 | >chr1 2 | AAAAAAAAA 3 | >g h i 21 4 | GGGAGGG 5 | >c 6 | CCCCCCCCC 7 | >t 8 | TTTTTTT 9 | -------------------------------------------------------------------------------- /toy_ex/c.fa: -------------------------------------------------------------------------------- 1 | >1 2 | TGTGTGTGTGTG 3 | >2 4 | ACACACACA 5 | >3 6 | TTTTCCCGGGAAAAAA 7 | -------------------------------------------------------------------------------- /toy_ex/ref.fa: -------------------------------------------------------------------------------- 1 | >chr1 2 | AGCTAGCTAGCTAGCT 3 | >chr2 4 | TAAAAAAAAAAATTT 5 | >chr3 6 | TGGGGGGGGGGTTT 7 | >seq 8 | TGTGTGTGTG 9 | -------------------------------------------------------------------------------- /toy_ex/ref2.fa: -------------------------------------------------------------------------------- 1 | >chr1 2 | AGCTAGCTAGCTAGCT 3 | -------------------------------------------------------------------------------- /toy_ex/toy_ex.agc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/refresh-bio/agc/f0fef1ca444926debdb6970f33a3a985795a8df4/toy_ex/toy_ex.agc --------------------------------------------------------------------------------