vcf-subset 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.1
2
+ Name: vcf_subset
3
+ Version: 1.0.0
4
+ Summary: Efficient VCF subsetting by genome position.
5
+ Home-page: https://github.com/GlobalPathogenAnalysisService/vcf_subset
6
+ Author: Jeremy Westhead
7
+ Author-email: jeremy.westhead@ndm.ox.ac.uk
8
+ License: MIT
9
+ Requires-Python: >=3.7
10
+ Description-Content-Type: text/markdown
11
+
12
+ Efficient VCF subsetting by genome position.
@@ -0,0 +1,23 @@
1
+ # vcf_subset
2
+ Efficient VCF subsetting by genome position. Written in C++, but provided as a python module to save ~3 minutes per TB GVCF
3
+
4
+ ## Install
5
+ ```
6
+ pip install vcf_subset
7
+ ```
8
+
9
+ ## Local (dev) install
10
+ ```
11
+ # Optional virtual environment
12
+ python -m virtualenv env
13
+ source env/bin/activate
14
+
15
+ # Install requirements
16
+ pip install build
17
+
18
+ # Build dist
19
+ python -m build --sdist --outdir dist
20
+
21
+ # Install
22
+ pip install .
23
+ ```
@@ -0,0 +1,6 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=42",
4
+ "pybind11>=2.10.0",
5
+ ]
6
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,38 @@
1
+ # Based on example https://github.com/pybind/python_example
2
+ from pybind11.setup_helpers import Pybind11Extension
3
+ from setuptools import setup
4
+ import os
5
+
6
+ __version__ = "v1.0.0"
7
+
8
+ long_description = "Efficient VCF subsetting by genome position."
9
+
10
+ files = sorted(["vcf_subset.cpp"])
11
+
12
+ ext_modules = [
13
+ Pybind11Extension(
14
+ "vcf_subset",
15
+ files,
16
+ include_dirs=[],
17
+ extra_compile_args=["-std=c++2a", "-O3"],
18
+ # Example: passing in the version to the compiled code
19
+ define_macros=[("VERSION_INFO", __version__)],
20
+ ),
21
+ ]
22
+
23
+ setup(
24
+ name="vcf_subset",
25
+ version=__version__,
26
+ author="Jeremy Westhead",
27
+ author_email="jeremy.westhead@ndm.ox.ac.uk",
28
+ url="https://github.com/GlobalPathogenAnalysisService/vcf_subset",
29
+ description="Efficient VCF subsetting by genome position.",
30
+ ext_modules=ext_modules,
31
+ zip_safe=False,
32
+ python_requires=">=3.7",
33
+ license="MIT",
34
+ long_description=long_description,
35
+ long_description_content_type='text/markdown',
36
+ include_package_data=True,
37
+ package_data={'vcf_subset': ['./**']}
38
+ )
@@ -0,0 +1,80 @@
1
+ #include<iostream>
2
+ #include<fstream>
3
+ #include<vector>
4
+ #include<algorithm>
5
+
6
+ #include <pybind11/pybind11.h>
7
+ #include <pybind11/stl.h>
8
+
9
+ #define STRINGIFY(x) #x
10
+ #define MACRO_STRINGIFY(x) STRINGIFY(x)
11
+
12
+ using namespace std;
13
+ namespace py = pybind11;
14
+
15
+
16
+ vector<string> subset_gvcf(string filename, vector<int> positions){
17
+ vector<string> header;
18
+ vector<string> output;
19
+ fstream fin(filename, fstream::in);
20
+ if(!fin.good()){
21
+ throw invalid_argument("Invalid gvcf path: " + filename);
22
+ }
23
+ char ch;
24
+ string acc;
25
+ size_t pos = 0;
26
+ while (fin >> noskipws >> ch) {
27
+ if(ch == '\n'){
28
+ if(acc[0] == '#'){
29
+ header.push_back(acc);
30
+ acc = "";
31
+ continue;
32
+ }
33
+ // Pull out the second column (which should be the position)
34
+ string line = acc;
35
+ pos = acc.find("\t");
36
+ acc.erase(0, pos + 1);
37
+ pos = acc.find("\t");
38
+ string p = acc.substr(0, pos);
39
+ int genome_pos = stoi(p);
40
+
41
+ if(binary_search(positions.begin(), positions.end(), genome_pos)){
42
+ output.push_back(line);
43
+ }
44
+
45
+ acc = "";
46
+ }
47
+ else{
48
+ acc += ch;
49
+ }
50
+ }
51
+ fin.close();
52
+ header.insert( header.end(), output.begin(), output.end() );
53
+ return header;
54
+
55
+ }
56
+
57
+ PYBIND11_MODULE(vcf_subset, m) {
58
+ m.doc() = R"pbdoc(
59
+ Efficient VCF subsetting by genome position.
60
+ Designed for subsetting a gVCF file, but should work for any VCF.
61
+ -----------------------
62
+ subset_gvcf
63
+ )pbdoc";
64
+ #ifdef VERSION_INFO
65
+ m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
66
+ #else
67
+ m.attr("__version__") = "dev";
68
+ #endif
69
+ m.def("subset_vcf", &subset_gvcf, R"pbdoc(
70
+ Subset a given VCF file to just the given positions (and the header).
71
+ -----------------------
72
+
73
+ Args:
74
+ str filename: Path to the VCF file to subset. Must not be gzipped.
75
+ list[int] positions: List of genome positions to keep
76
+
77
+ Returns:
78
+ list[str]: Lines of the VCF file that match the given positions (and the header)
79
+ )pbdoc", py::arg("filename"), py::arg("positions"));
80
+ }
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.1
2
+ Name: vcf_subset
3
+ Version: 1.0.0
4
+ Summary: Efficient VCF subsetting by genome position.
5
+ Home-page: https://github.com/GlobalPathogenAnalysisService/vcf_subset
6
+ Author: Jeremy Westhead
7
+ Author-email: jeremy.westhead@ndm.ox.ac.uk
8
+ License: MIT
9
+ Requires-Python: >=3.7
10
+ Description-Content-Type: text/markdown
11
+
12
+ Efficient VCF subsetting by genome position.
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ vcf_subset.cpp
5
+ vcf_subset.egg-info/PKG-INFO
6
+ vcf_subset.egg-info/SOURCES.txt
7
+ vcf_subset.egg-info/dependency_links.txt
8
+ vcf_subset.egg-info/not-zip-safe
9
+ vcf_subset.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ vcf_subset