Skip to content

Commit

Permalink
Merge v1a, support commented BEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
bede committed Sep 18, 2024
1 parent 432f97a commit 5f2cfc3
Show file tree
Hide file tree
Showing 76 changed files with 6,550 additions and 1,507 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.10", "3.11"]
python-version: ["3.11"]
name: Python ${{ matrix.python-version }} (${{ matrix.os }})
steps:
- uses: actions/checkout@v3
Expand All @@ -16,11 +16,9 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install pytest
python -m pip install .
git clone https://github.com/pha4ge/primer-schemes.git
python -m pip install '.[dev]'
- name: Test with pytest
env:
PRIMASCHEMA_ROOT_PATH: ${{ github.workspace }}
run: |
pytest
env:
PRIMER_SCHEMES_PATH: "${{ github.workspace }}/primer-schemes"
16 changes: 6 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
44 changes: 21 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

# Primaschema

The toolkit for validating and building tiling amplicon PCR primer scheme definitions for inclusion in the [PHA4GE primer-schemes repository](https://github.com/pha4ge/primer-schemes), using 6 or 7 column Primal Scheme-like BED files and scheme metadata contained in a YAML file.
**🚨 Migration to v1 scheme specification in progress**

A toolkit for fetching, validating and interrogating tiled amplicon PCR primer scheme definitions. Provides convenient programmatic accesss to the [PHA4GE primer-schemes repository](https://github.com/pha4ge/primer-schemes), a community repository of tiled amplicons primer schemes.


## Install (Python 3.10+)
## Install (Python 3.8+)

```
```shell
# Latest stable release
pip install primaschema

Expand All @@ -19,13 +20,14 @@ pip install ./primaschema
# Development
git clone https://github.com/pha4ge/primaschema.git
cd primaschema
pip install --editable ./
pip install --editable '.[dev]'
pre-commit install
pytest
```

Some Primaschema commands use components from the [primer-schemes](https://github.com/pha4ge/primer-schemes) repository. To show Primaschema where to find these, create the environment variable `PRIMER_SCHEMES_PATH` pointing to the location of the primer-schemes directory on your machine:

```
```shell
git clone https://github.com/pha4ge/primer-schemes.git
export PRIMER_SCHEMES_PATH="/path/to/primer-schemes"
```
Expand All @@ -35,32 +37,28 @@ export PRIMER_SCHEMES_PATH="/path/to/primer-schemes"
## Usage

```
% primaschema --help
% primaschema -h
usage: primaschema [-h] [--version]
{hash-ref,hash-bed,validate,validate-recursive,build,build-recursive,build-manifest,diff,6to7,7to6,show-non-ref-alts}
...
{validate,build,build-manifest,hash-ref,hash-bed,diff,6to7,7to6,plot,show-intervals,show-discordant-primers,subset,sync} ...
positional arguments:
{hash-ref,hash-bed,validate,validate-recursive,build,build-recursive,build-manifest,diff,6to7,7to6,show-non-ref-alts}
{validate,build,build-manifest,hash-ref,hash-bed,diff,6to7,7to6,plot,show-intervals,show-discordant-primers,subset,sync}
validate Validate one or more primer scheme definitions comprising info.yml, primer.bed and reference.fasta
build Build one or more primer scheme definitions comprising info.yml, primer.bed and reference.fasta
build-manifest Build a complete manifest of schemes contained in the specified directory
hash-ref Generate reference sequence checksum
hash-bed Generate a bed file checksum
validate Validate a primer scheme bundle containing info.yml, primer.bed and reference.fasta
validate-recursive Recursively validate primer scheme bundles in the specified directory
build Build a primer scheme bundle containing info.yml, primer.bed and reference.fasta
build-recursive Recursively build primer scheme bundles in the specified directory
build-manifest Build a complete manifest of schemes contained in the specified directory
diff Show the symmetric difference of records in two bed files
6to7 Convert a 6 column scheme.bed file to a 7 column primer.bed file using a reference sequence
7to6 Convert a 7 column primer.bed file to a 6 column scheme.bed file by droppign a column
show-non-ref-alts Show primer records with sequences not matching the reference sequence
6to7 Convert a 6 column scheme.bed file to a 7 column primer.bed file using reference backfill
7to6 Convert a 7 column primer.bed file to a 6 column scheme.bed file by removing a column
plot Plot amplicon and primer coords from 7 column primer.bed
show-intervals Show amplicon start and end coordinates given a BED file of primer coordinates
show-discordant-primers
Show primer records with sequences not matching the reference sequence
subset Extract a primer.bed and reference.fasta scheme subset for a single chromosome
sync Retrieve/update local copy of remote primer scheme repository
options:
-h, --help show this help message and exit
--version show program's version number and exit
% primaschema build test/data/primer-schemes/eden/v1
INFO: Scheme bed file has the expected number of columns (6)
INFO: Writing info.yml with checksums
INFO: Generating primer.bed from scheme.bed and reference.fasta
```
53 changes: 33 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
[build-system]
requires = [
"setuptools >= 64",
"wheel >= 0.37.1",
]
build-backend = "setuptools.build_meta"
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "primaschema"
description = "A toolkit for primer scheme defintions"
authors = [
{name = "Bede Constantinides", email="[email protected]"},
{name = "Peter van Heusden", email="[email protected]"}
]
dynamic = ["version", "description"]
readme = "README.md"
requires-python = ">=3.10"
requires-python = ">=3.8"
keywords = ["genomics"]
license = {text = "MIT License"}
classifiers = [
"Framework :: Django",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.12",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
Expand All @@ -23,21 +24,33 @@ classifiers = [
"Operating System :: MacOS",
]
dependencies = [
"biopython == 1.80",
"defopt == 6.4.0",
"pandas >= 1.5.3",
"pre-commit",
"pytest",
"altair>=5.3.0",
"biopython>=1.80",
"defopt==6.4.0",
"httpx>=0.27.0",
"jsonschema",
"pyyaml",
"linkml==1.5.2",
"linkml",
"natsort>=8.4.0",
"pandas>=1.5.3",
"platformdirs>=4.2.2",
"pydantic>=2.0.0",
"pyyaml>=6.0.2",
"vl-convert-python>=1.6.0"
]
dynamic = ["version"]

[project.scripts]
primaschema = "primaschema.cli:main"

[tool.setuptools.dynamic]
version = {attr = "primaschema.__version__"}
[project.urls]
Home = "https://github.com/pha4ge/primaschema"

[project.optional-dependencies]
dev = [
"pytest",
"pre-commit",
"flit"
]

[tool.flit.external-data]
directory = "test"

[tool.setuptools.packages.find]
where = ["src"]
64 changes: 61 additions & 3 deletions src/primaschema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,64 @@
"""Infrastructure for tiled amplicon PCR primer scheme definitions"""

import logging
import logging.config
import os

from pathlib import Path

__version__ = "0.2.0"
from platformdirs import user_data_dir


__version__ = "1.0.0a0"


SCHEMES_ARCHIVE_URL = os.environ.get(
"PRIMASCHEMA_SCHEMES_ARCHIVE_URL",
"https://github.com/pha4ge/primer-schemes/archive/refs/heads/main.tar.gz",
)
CACHE_DIR = Path(
os.environ.get("PRIMASCHEMA_CACHE_DIR") or user_data_dir("primaschema", "PHA4GE")
)

PKG_DIR = Path(
os.environ.get(
"PRIMASCHEMA_ROOT_PATH", Path(__file__).absolute().parent.parent.parent
)
)
SCHEMA_DIR = PKG_DIR / "src" / "primaschema" / "schema"
MANIFEST_SCHEMA_PATH = SCHEMA_DIR / "manifest.json"
MANIFEST_HEADER_PATH = SCHEMA_DIR / "manifest-header.yml"

logging_config = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"default": {
"format": "%(name)s %(levelname)s: %(message)s",
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "default",
"level": "INFO",
"stream": "ext://sys.stderr",
},
},
"root": {
"handlers": ["console"],
"level": "INFO",
},
"loggers": {
"primaschema": {
"handlers": ["console"],
"level": "INFO",
"propagate": False,
},
},
}

logging.config.dictConfig(logging_config)
logger = logging.getLogger("primaschema")

# pkg_dir = Path(__file__)
# data_dir = pkg_dir.parent / "data"
logger.debug(f"{PKG_DIR=} {SCHEMA_DIR=}")
Loading

0 comments on commit 5f2cfc3

Please sign in to comment.