Skip to content

Commit

Permalink
RENAME: argweavers
Browse files Browse the repository at this point in the history
1. Rename the module to resolve several issues
2. Drop the bedops sort-bed. It sort the BED file in alphabet order on iter number instead of numerical
  • Loading branch information
tcztzy committed Feb 23, 2024
1 parent cdad2f9 commit 9bfcaff
Show file tree
Hide file tree
Showing 28 changed files with 56 additions and 60 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ on:
push:
paths:
- 'docs/**'
- 'argweaver/**'
- 'argweavers/**'
pull_request:
paths:
- 'docs/**'
- 'argweaver/**'
- 'argweavers/**'
workflow_dispatch:

permissions:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ __pycache__/
/requirements-dev.lock

# maturin
/argweaver/*.so
/argweavers/*.so

# test coverage
/.coverage
Expand Down
3 changes: 1 addition & 2 deletions README+s.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
1. [rustup](https://rustup.rs/)
2. [CMake](https://cmake.org/) with any modern C++ compiler
3. [rye](https://rye-up.com) or [maturin](https://maturin.rs) for Python binding
4. [samtools](http://www.htslib.org/) and
[bedops](https://bedops.readthedocs.io/en/latest/) for `smc2bed-all`
4. [samtools](http://www.htslib.org/) for `smc2bed-all`

## Install

Expand Down
10 changes: 0 additions & 10 deletions argweaver/__init__.py

This file was deleted.

9 changes: 0 additions & 9 deletions argweavers.py

This file was deleted.

10 changes: 10 additions & 0 deletions argweavers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from importlib.metadata import version

from . import argweavers # make ruff happy
from .argweavers import * # noqa: F403

__doc__ = argweavers.__doc__
__version__ = version(__package__)

if hasattr(argweavers, "__all__"):
__all__ = argweavers.__all__
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion argweaver/io/bed.py → argweavers/io/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pandas as pd

from argweaver.utils import parse_region
from argweavers.utils import parse_region

__all__ = ["read_bed"]

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion argweaver/r.py → argweavers/r.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rpy2.robjects import pandas2ri
from rpy2.robjects.packages import importr

from argweaver.utils import parse_region
from argweavers.utils import parse_region

if typing.TYPE_CHECKING:
from os import PathLike
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from contextlib import redirect_stdout

from argweaver.s import smc2bed
from argweavers import smc2bed


def main(args=None, capture_output=False):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import argparse
import os
import sys
from io import BytesIO
from itertools import count

from argweaver.bin import require_executable
from argweaver.scripts.smc2bed import main as smc2bed
import pandas as pd

from argweavers.bin import require_executable
from argweavers.scripts.smc2bed import main as smc2bed


class MetavarFormatter(argparse.HelpFormatter):
Expand All @@ -16,7 +19,6 @@ def _get_default_metavar_for_positional(self, action):


def main(argv=None):
sort_bed = require_executable("sort-bed", "It is included in `bedops`")
bgzip = require_executable("bgzip", "It is included in `samtools`")
tabix = require_executable("tabix", "It is included in `samtools`")
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -93,14 +95,16 @@ def main(argv=None):
sys.stderr.write(f"ended at sample={num}\n")
break
sys.stderr.write(f"{num} {file}\n")
print(os.stat(file).st_size)
out += smc2bed(
["--sample", str(num), *regionarg, file],
capture_output=True,
)
print(len(out))
num += interval
out = sort_bed(["-"], input=out, capture_output=True).stdout
bed = pd.read_table(
BytesIO(out), header=None, names=["chrom", "start", "end", "iter", "tree"]
)
bed = bed.sort_values(["chrom", "start", "end", "iter"])
out = bed.to_csv(index=False, header=False, sep="\t").encode("utf-8")
with open(f"{baseout}.bed.gz", "wb") as f:
bgzip(["-"], input=out, stdout=f)
tabix(["-p", "bed", f"{baseout}.bed.gz"])
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
]

autodoc2_module_all_regexes = [
r"argweaver\..*",
r"argweavers\..*",
]
autodoc2_packages = [
"../argweaver",
"../argweavers",
]
autodoc2_render_plugin = "myst"
graphviz_output_format = "svg"
Expand Down
11 changes: 5 additions & 6 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
## Pre-requisites

1. [rustup](https://rustup.rs/)
2. (Optional) [samtools](http://www.htslib.org/) and
[bedops](https://bedops.readthedocs.io/en/latest/) for executing `smc2bed-all`
2. (Optional) [samtools](http://www.htslib.org/) for executing `smc2bed-all`
3. (Optional) R for plotting

```bash
# Install rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# If you are using macOS, you can install samtools and bedops using homebrew
brew install samtools bedops
# Otherwise, install miniconda for samtools and bedops
# If you are using macOS, you can install samtools using homebrew
brew install samtools
# Otherwise, install miniconda for samtools
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
conda install -c bioconda samtools bedops
conda install -c bioconda samtools
# Install R
sudo apt-get install r-base
# Or
Expand Down
17 changes: 10 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ dependencies = [
]

[project.scripts]
arg-likelihood = "argweaver.bin:arg_likelihood"
arg-sample = "argweaver.bin:arg_sample"
arg-summarize = "argweaver.bin:arg_summarize"
smc2bed = "argweaver.scripts.smc2bed:main"
smc2bed-all = "argweaver.scripts.smc2bed_all:main"
arg-likelihood = "argweavers.bin:arg_likelihood"
arg-sample = "argweavers.bin:arg_sample"
arg-summarize = "argweavers.bin:arg_summarize"
smc2bed = "argweavers.scripts.smc2bed:main"
smc2bed-all = "argweavers.scripts.smc2bed_all:main"

[tool.rye]
dev-dependencies = [
Expand All @@ -55,6 +55,7 @@ dev-dependencies = [
"myst-parser>=2.0.0",
"sphinx-autodoc2>=0.5.0",
"ipykernel>=6.29.2",
"cibuildwheel>=2.16.5",
]
[tool.rye.scripts]
cov-report = { chain = ["htmlcov", "htmlcov-serve"] }
Expand All @@ -63,7 +64,6 @@ htmlcov-serve = "python -m http.server --directory htmlcov"

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

[[tool.mypy.overrides]]
Expand All @@ -78,11 +78,14 @@ target-version = "py38"

[tool.pytest.ini_options]
minversion = "7.0"
addopts = ["--cov=argweaver"]
addopts = ["--cov=argweavers"]

[tool.coverage.report]
exclude_also = [
"if (typing\\.)?TYPE_CHECKING",
"if __name__ == \"__main__\"",
"class \\w+\\((argparse\\.)?HelpFormatter\\)",
]

[tool.cibuildwheel]
skip = "pp*"
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn smc2bed(args: Option<Vec<String>>) -> PyResult<()> {
#[cfg(feature = "extension-module")]
/// Ancestral recombination graph sampling method
#[pymodule]
fn s(_py: Python, m: &PyModule) -> PyResult<()> {
fn argweavers(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<sites::Sites>()?;
m.add_function(wrap_pyfunction!(sites::read_sites, m)?)?;
m.add_function(wrap_pyfunction!(smc2bed, m)?)?;
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from argweaver.scripts.smc2bed_all import main as smc2bed_all
from argweavers.scripts.smc2bed_all import main as smc2bed_all

examples_dir = pathlib.Path(__file__).parent.parent / "examples"

Expand Down
4 changes: 2 additions & 2 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import argweaver
import argweavers


def test_basic():
assert argweaver.__version__ == "0.9.0"
assert argweavers.__version__ == "0.9.0"
2 changes: 1 addition & 1 deletion tests/test_bin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from argweaver.bin import require_executable
from argweavers.bin import require_executable


def test_require_executable():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from argweaver.io import read_bed, subset_bed
from argweavers.io import read_bed, subset_bed


def test_read_bed(bedfile):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_plot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import matplotlib.pyplot as plt
from matplotlib.testing.decorators import image_comparison

from argweaver.plot import plot_tree
from argweavers.plot import plot_tree


@image_comparison(baseline_images=["test_plot_tree"], extensions=["png"])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_r.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from argweaver.r import plotTreesFromBed
from argweavers.r import plotTreesFromBed


def test_plot_trees(bedfile):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hashlib

from argweaver.scripts.smc2bed import main as smc2bed
from argweavers.scripts.smc2bed import main as smc2bed


def sha256sum(path):
Expand All @@ -18,5 +18,5 @@ def test_smc2bed(sim1_sample):


def test_smc2bed_all(bedfile):
sha256 = "577951a303869a2ab3aaf99e500ff29ce5613c27ac1a7cbef7dbfa63524136c3"
sha256 = "94012cc3ecadddaf19f823ec361a72ac9b8073fe33dc75c1f731498c789d7023"
assert sha256sum(bedfile) == sha256
2 changes: 1 addition & 1 deletion tests/test_sites.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from argweaver import read_sites
from argweavers import read_sites


def test_read_sites():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from argweaver.utils import parse_region
from argweavers.utils import parse_region


def test_parse_region():
Expand Down

0 comments on commit 9bfcaff

Please sign in to comment.