Skip to content

Commit

Permalink
ci(semantic-release): Add semantic release.
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
aaronmussig committed Dec 12, 2023
1 parent 7b2417c commit 9717f45
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/setup-node@v4
with:
cache: npm
node-version: lts
node-version: lts/Hydrogen
- run: npm install
- run: npx semantic-release --dry-run
id: semantic_release
Expand All @@ -25,7 +25,7 @@ jobs:
with:
name: semantic-release
path: |
betula/__init__.py
gtdb_precurate/__init__.py
CHANGELOG.md
retention-days: 1
outputs:
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
- uses: actions/setup-node@v4
with:
cache: npm
node-version: lts
node-version: lts/Hydrogen
- run: npm install
- run: npx semantic-release
env:
Expand Down
4 changes: 2 additions & 2 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[
"@semantic-release/exec",
{
"verifyReleaseCmd": "sed -i \"s/.*__version__.*/__version__ = '${nextRelease.version}'/g\" betula/__init__.py && echo version=${nextRelease.version} >> $GITHUB_OUTPUT"
"verifyReleaseCmd": "sed -i \"s/.*__version__.*/__version__ = '${nextRelease.version}'/g\" gtdb_precurate/__init__.py && echo version=${nextRelease.version} >> $GITHUB_OUTPUT"
}
],
[
Expand All @@ -23,7 +23,7 @@
{
"assets": [
"CHANGELOG.md",
"betula/__init__.py"
"gtdb_precurate/__init__.py"
],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
Expand Down
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# betula
Automatic pre-curation of GTDB trees.
# GTDB Precurate

[![PyPI](https://img.shields.io/pypi/v/gtdb_precurate.svg)](https://pypi.python.org/pypi/gtdb_precurate)

`gtdb_precurate` is an internally used tool used that provides automatic pre-curation of GTDB trees.

## Installation

gtdb_precurate is available on PyPI and can be installed with pip:

```bash
pip install gtdb_precurate
```

## Usage

After a successful install, the `gtdb_precurate` command should be available.

The following positional arguments are required:

* `metadata` - This is the path to the metadata file, it should contain a header as the first line.
The only requirement is that it has the following columns: `formatted_accession` and `ncbi_wgs_formatted`.
* `red_dict` - This is the path to the RED dictionary output by PhyloRank.
* `red_decorated_tree` - This is the path to the scaled RED decorated output by PhyloRank.
* `out_directory` - This is the path to the directory where the output files will be written.

The following optional arguments are available:

* `--min-bootstrap` - This is the minimum bootstrap value to consider a node to be supported. Default: 95.0.
* `--debug` - This enables debug logging. Default: False.
1 change: 0 additions & 1 deletion betula/__init__.py

This file was deleted.

15 changes: 15 additions & 0 deletions gtdb_precurate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
__author__ = 'Aaron Mussig'
__author_email__ = '[email protected]'
__copyright__ = 'Copyright 2023'
__credits__ = ['Aaron Mussig']
__description__ = 'Automatic pre-curation of GTDB trees.'
__email__ = '[email protected]'
__license__ = 'GPL3'
__maintainer__ = 'Aaron Mussig'
__maintainer_email__ = '[email protected]'
__name__ = 'gtdb_precurate'
__python_requires__ = '>=3.8'
__status__ = 'Production'
__title__ = 'GTDB Precurate'
__url__ = 'https://github.com/Ecogenomics/gtdb_precurate'
__version__ = '1.0.0'
22 changes: 11 additions & 11 deletions betula/__main__.py → gtdb_precurate/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import typer

from betula import __version__
from betula.method.create_denovo import create_denovo_clusters
from betula.model.metadata import MetadataFile
from betula.model.ranks import RANKS
from betula.model.red_dict import RedDict
from betula.model.tree import Tree
from betula.util.logger import init_logger
from gtdb_precurate import __version__
from gtdb_precurate.method.create_denovo import create_denovo_clusters
from gtdb_precurate.model.metadata import MetadataFile
from gtdb_precurate.model.ranks import RANKS
from gtdb_precurate.model.red_dict import RedDict
from gtdb_precurate.model.tree import Tree
from gtdb_precurate.util.logger import init_logger


def main(
Expand All @@ -25,14 +25,14 @@ def main(

# Initialise the logger
log = init_logger(out_directory, debug)
log.info(f'betula v{__version__}')
log.info(f'betula {" ".join(sys.argv[1:])}')
log.info(f'gtdb_precurate v{__version__}')
log.info(f'gtdb_precurate {" ".join(sys.argv[1:])}')

# Create the output paths
if 'red_decorated' in red_decorated_tree.name:
tree_path_out = out_directory / red_decorated_tree.name.replace('red_decorated', 'betula')
tree_path_out = out_directory / red_decorated_tree.name.replace('red_decorated', 'gtdb_precurate')
else:
tree_path_out = out_directory / f'{red_decorated_tree.stem}.betula{red_decorated_tree.suffix}'
tree_path_out = out_directory / f'{red_decorated_tree.stem}.gtdb_precurate{red_decorated_tree.suffix}'
report_path_out = out_directory / f'{tree_path_out.stem}_report.tsv'

# Read the RED dictionary
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging
from collections import defaultdict

from betula.model.metadata import MetadataFile
from betula.model.node_label import NodeLabel
from betula.model.ranks import RANKS
from betula.model.red_dict import RedDict
from betula.model.tree import Tree
from gtdb_precurate.model.metadata import MetadataFile
from gtdb_precurate.model.node_label import NodeLabel
from gtdb_precurate.model.ranks import RANKS
from gtdb_precurate.model.red_dict import RedDict
from gtdb_precurate.model.tree import Tree


def get_gids_missing_ranks(tree):
Expand Down Expand Up @@ -106,7 +106,7 @@ def create_taxon(rank, meta, new_taxa, tree, gids):
def create_ranks(d_rank_to_leaf_candidates, tree, meta):
# We will now iterate from the highest to lower rank to find shared nodes
created = set()
log = logging.getLogger('betula')
log = logging.getLogger('gtdb_precurate')
for cur_rank, d_leaf_to_candidate_node in sorted(d_rank_to_leaf_candidates.items(),
key=lambda x: RANKS.index(x[0])):

Expand Down Expand Up @@ -142,7 +142,7 @@ def create_denovo_clusters(
):
"""Creates de novo clusters from the specified tree and metadata."""

log = logging.getLogger('betula')
log = logging.getLogger('gtdb_precurate')

# First, we need to find all genomes that are missing ranks
d_leaf_to_missing_ranks = get_gids_missing_ranks(tree)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from pathlib import Path

from betula.model.ranks import RANKS
from gtdb_precurate.model.ranks import RANKS


class RedDict:
Expand Down
6 changes: 3 additions & 3 deletions betula/model/tree.py → gtdb_precurate/model/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import dendropy

from betula.model.node_label import NodeLabel
from betula.model.ranks import RANKS, TaxString
from betula.util.tree import parse_node_label
from gtdb_precurate.model.node_label import NodeLabel
from gtdb_precurate.model.ranks import RANKS, TaxString
from gtdb_precurate.util.tree import parse_node_label


class Tree:
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions betula/util/logger.py → gtdb_precurate/util/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def init_logger(out_dir: Path, debug=False):
# Logger setup
logger = logging.getLogger('betula')
logger = logging.getLogger('gtdb_precurate')
if debug:
logger.setLevel(logging.DEBUG)
else:
Expand All @@ -20,7 +20,7 @@ def init_logger(out_dir: Path, debug=False):
logger.addHandler(console_handler)

# File handler
file_handler = logging.FileHandler(out_dir / 'betula.log')
file_handler = logging.FileHandler(out_dir / 'gtdb_precurate.log')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "betula",
"name": "gtdb_precurate",
"devDependencies": {
"@semantic-release/github": "^9.2.5",
"@semantic-release/changelog": "^6.0.3",
Expand Down
60 changes: 60 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import re

from setuptools import setup, find_packages


def read_meta():
"""Read each of the keys stored in __init__.py
Returns
-------
dict[str, str]
A dictionary containing each of the string key value pairs.
"""
path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'gtdb_precurate/__init__.py')
with open(path) as fh:
hits = re.findall(r'__(\w+)__ ?= ?["\'](.+)["\']\n', fh.read())
return {k: v for k, v in hits}


def readme():
with open('README.md') as f:
return f.read()


meta = read_meta()
setup(
author=meta['author'],
author_email=meta['author_email'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Scientific/Engineering :: Bio-Informatics',
],
data_files=[("", ["LICENSE"])],
description=meta['description'],
entry_points={
'console_scripts': [
'gtdb_precurate = gtdb_precurate.__main__:main'
]
},
install_requires=["dendropy>=4.1.0"],
license=meta['license'],
long_description=readme(),
long_description_content_type='text/markdown',
maintainer=meta['maintainer'],
maintainer_email=meta['maintainer_email'],
name=meta['name'],
packages=find_packages(),
python_requires=meta['python_requires'],
url=meta['url'],
version=meta['version']
)

0 comments on commit 9717f45

Please sign in to comment.