Skip to content

Commit

Permalink
WIP: argweavers 1.0
Browse files Browse the repository at this point in the history
1. drop cmake while compile Rust
2. drop binaries wrapper for legacy C++
3. Make legacy R interface optional in Python
  • Loading branch information
tcztzy committed Feb 26, 2024
1 parent 301e696 commit a483e21
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 283 deletions.
18 changes: 8 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "argweavers"
version = "0.9.0"
version = "1.0.0"
edition = "2021"
authors = ["Tang Ziya <[email protected]>"]

Expand All @@ -12,23 +12,23 @@ crate-type = ["lib", "cdylib"]
[dependencies]
autocxx = "0.26.0"
bio = { version = "1.5.0", features = ["phylogeny"] }
clap = { version = "4.4.18", features = ["derive", "cargo"] }
clap = { version = "4.5.1", features = ["derive", "cargo"] }
csv = "1.3.0"
cxx = "1.0.115"
cxx = "1.0.117"
flate2 = "1.0.28"
libc = "0.2.153"
log = "0.4.20"
log4rs = "1.3.0"
nom = "7.1.3"
polars = { version = "0.37.0", features = ["lazy"] }
pyo3 = { version = "0.20", features = ["abi3-py38", "extension-module", "multiple-pymethods"], optional = true }
pyo3-polars = { version = "0.11.1", optional = true }
pyo3-polars = { version = "0.11.3", optional = true }
rust-htslib = { version = "0.46.0", features = ["libdeflate"] }
serde = { version = "1.0.195", features = ["derive"] }
tempfile = "3.9.0"
serde = { version = "1.0.197", features = ["derive"] }
tempfile = "3.10.0"

[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }
criterion = { version = "0.5", features = ["html_reports"] }

[[bench]]
name = "my_benchmark"
Expand All @@ -44,7 +44,5 @@ extension-module = [

[build-dependencies]
autocxx-build = "0.26.0"
cmake = "0.1"
glob = "0.3.1"
miette = { version = "5.10.0", features = ["fancy"] }
pyo3-build-config = { version = "0.20.2", features = ["abi3-py38"], optional = true }
pyo3-build-config = { version = "0.20.3", features = ["abi3-py38"], optional = true }
13 changes: 1 addition & 12 deletions argweavers/bin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Wrapper for compiled binaries."""
import pathlib
import shutil
import subprocess
import sys
Expand All @@ -17,8 +16,7 @@ def __call__(self, args: _CMD = None, **kwargs) -> subprocess.CompletedProcess:
...


_binaries = ["arg_likelihood", "arg_sample", "arg_summarize"]
__all__ = _binaries + ["require_executable"]
__all__ = ["require_executable"]

arg_likelihood: "_BinaryWrapper"
"Sampler for large ancestral recombination graphs"
Expand All @@ -27,8 +25,6 @@ def __call__(self, args: _CMD = None, **kwargs) -> subprocess.CompletedProcess:
arg_summarize: "_BinaryWrapper"
"Summarize the output of ARGweaver."

_bin_dir = pathlib.Path(__file__).parent.parent / "bin"


def _bin_wrapper(path: "Union[Path, str]", **kwargs) -> "_BinaryWrapper":
def f(args=None, **kw):
Expand All @@ -45,13 +41,6 @@ def f(args=None, **kw):
return f


for _ in _binaries:
_bin = _bin_dir / _.replace("_", "-")
if not _bin.exists():
raise RuntimeError(f"Missing binary: {_bin}")
globals()[_] = _bin_wrapper(_bin, capture_output=False, return_process=False)


def require_executable(executable: str, additional_message: str = "", **kwargs):
"""Require an executable to be available and return a wrapper for it.
Expand Down
4 changes: 4 additions & 0 deletions argweavers/r.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""R interface for argweaver."""
import importlib.util
import typing

if importlib.util.find_spec("rpy2") is None:
raise ImportError("rpy2 not installed, please install this package with `r` extra.")

import rpy2.robjects as ro
from rpy2.robjects import pandas2ri
from rpy2.robjects.packages import importr
Expand Down
2 changes: 1 addition & 1 deletion benches/my_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn ffi_read_sites() {

fn read_sites() {
let path = std::path::PathBuf::from("examples/sim1/sim1.sites");
let _sites = Sites::from_path(path).unwrap();
let _sites = Sites::from_path(&path).unwrap();
}

fn criterion_benchmark(c: &mut Criterion) {
Expand Down
207 changes: 0 additions & 207 deletions bin/allele_age

This file was deleted.

43 changes: 0 additions & 43 deletions bin/meanIterTime.sh

This file was deleted.

9 changes: 2 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
use miette::IntoDiagnostic;

fn main() -> miette::Result<()> {
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "extension-module")]
pyo3_build_config::add_extension_module_link_args();
cmake::build(".");
let path = std::path::PathBuf::from("src");
let mut b = autocxx_build::Builder::new("src/lib.rs", [&path]).build()?;
let source_files = glob::glob("src/argweaver/*.cpp")
.into_diagnostic()?
.map(|p| p.unwrap());
let source_files = glob::glob("src/argweaver/*.cpp")?.map(|x| x.unwrap());
b.flag_if_supported("-std=c++14")
.files(source_files)
.flag("-w")
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ dependencies = [
"numpy>=1.24.4",
"polars>=0.20.9",
"pyarrow>=15.0.0",
"rpy2>=3.5.15",
"pandas>=2.0.3",
"matplotlib>=3.7.5",
"biopython>=1.83",
]

[project.optional-dependencies]
r = ["rpy2>=3.5.15"]

[project.scripts]
arg-likelihood = "argweavers.bin:arg_likelihood"
arg-sample = "argweavers.bin:arg_sample"
Expand Down Expand Up @@ -64,7 +66,6 @@ htmlcov-serve = "python -m http.server --directory htmlcov"

[tool.maturin]
features = ["extension-module"]
include = ["bin/*"]

[[tool.mypy.overrides]]
module = [
Expand Down
Loading

0 comments on commit a483e21

Please sign in to comment.