Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dagou committed Sep 12, 2024
1 parent 5c18ed0 commit 8231d06
Show file tree
Hide file tree
Showing 19 changed files with 299 additions and 1,622 deletions.
231 changes: 231 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

env:
PROJECT_NAME: kun_peng
REPO_NAME: ${{ github.repository }}
BREW_TAP: eric9n/homebrew-tap
DESC: "An ultra-fast, low-memory footprint and accurate taxonomy classifier for all"

jobs:
dist:
permissions:
contents: write
name: Dist
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build: [x86_64-linux, x86_64-macos, x86_64-windows, aarch64-macos]
include:
- build: x86_64-linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
- build: x86_64-macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
- build: x86_64-windows
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
- build: aarch64-macos
os: macos-latest
rust: stable
target: aarch64-apple-darwin

steps:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true

- name: Install ${{ matrix.rust }} toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.cross }}
command: test
args: --release --locked --target ${{ matrix.target }}

- name: Build release binary
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.cross }}
command: build
args: --release --locked --target ${{ matrix.target }}

- name: Build archive
shell: bash
run: |
mkdir dist
if [ "${{ matrix.os }}" = "windows-latest" ]; then
cp "target/${{ matrix.target }}/release/${{ env.PROJECT_NAME }}.exe" "dist/${{ env.PROJECT_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.exe"
else
cp "target/${{ matrix.target }}/release/${{ env.PROJECT_NAME }}" "dist/${{ env.PROJECT_NAME }}-${{ github.ref_name }}-${{ matrix.target }}"
fi
# Set up the GitHub CLI
- name: Install GitHub CLI (macOS)
run: |
brew install gh
if: matrix.os == 'macos-latest'

- name: Install GitHub CLI (Ubuntu)
run: |
sudo apt install -y gh
if: matrix.os == 'ubuntu-latest'

- name: Install GitHub CLI (Windows)
run: |
choco install gh
if: matrix.os == 'windows-latest'

# Log in to the GitHub CLI
- name: Login to GitHub CLI
run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token

- name: Upload Release Asset
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
ASSET_NAME="${{ env.PROJECT_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.exe"
else
ASSET_NAME="${{ env.PROJECT_NAME }}-${{ github.ref_name }}-${{ matrix.target }}"
fi
gh release upload ${{ github.ref_name }} \
"./dist/$ASSET_NAME" \
--clobber
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash

- name: Set macOS artifact name
if: matrix.os == 'macos-latest' && matrix.target == 'x86_64-apple-darwin'
run: echo "macos_artifact=${{ env.PROJECT_NAME }}-${{ github.ref_name }}-${{ matrix.target }}" >> $GITHUB_OUTPUT
id: artifact_name

- name: Build on CentOS 7
if: matrix.os == 'ubuntu-latest'
run: |
docker run --name centos7-container -v $GITHUB_WORKSPACE:/github/workspace -w /github/workspace centos:7 \
/bin/bash -c "echo '[base]' > /etc/yum.repos.d/CentOS-Base.repo; \
echo 'name=CentOS-7 - Base' >> /etc/yum.repos.d/CentOS-Base.repo; \
echo 'baseurl=http://vault.centos.org/centos/7/os/x86_64/' >> /etc/yum.repos.d/CentOS-Base.repo; \
echo 'gpgcheck=1' >> /etc/yum.repos.d/CentOS-Base.repo; \
echo 'enabled=1' >> /etc/yum.repos.d/CentOS-Base.repo; \
echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7' >> /etc/yum.repos.d/CentOS-Base.repo; \
yum update -y && yum install -y gcc make openssl openssl-devel && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && export PATH=\$HOME/.cargo/bin:\$PATH && cd /github/workspace && cargo build --release"
docker cp centos7-container:/github/workspace/target/release/${{ env.PROJECT_NAME }} ./dist/${{ env.PROJECT_NAME }}-${{ github.ref_name }}-centos7
docker rm centos7-container
- name: Upload CentOS 7 Release Asset
if: matrix.os == 'ubuntu-latest'
run: |
gh release upload ${{ github.ref_name }} \
"./dist/${{ env.PROJECT_NAME }}-${{ github.ref_name }}-centos7" \
--clobber
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

update-formula:
needs: dist
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Extract version
id: extract-version
run: echo "tag-name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: Set environment variables
run: |
echo "PROJECT_NAME=${{ env.PROJECT_NAME }}" >> $GITHUB_ENV
echo "REPO_NAME=${{ env.REPO_NAME }}" >> $GITHUB_ENV
- name: Verify release assets
run: |
VERSION=${{ steps.extract-version.outputs.tag-name }}
REPO=${{ env.REPO_NAME }}
PROJECT=${{ env.PROJECT_NAME }}
X86_64_URL="https://github.com/${REPO}/releases/download/${VERSION}/${PROJECT}-${VERSION}-x86_64-apple-darwin"
AARCH64_URL="https://github.com/${REPO}/releases/download/${VERSION}/${PROJECT}-${VERSION}-aarch64-apple-darwin"
if curl --output /dev/null --silent --head --fail "$X86_64_URL"; then
echo "x86_64 binary exists"
else
echo "x86_64 binary does not exist"
exit 1
fi
if curl --output /dev/null --silent --head --fail "$AARCH64_URL"; then
echo "aarch64 binary exists"
else
echo "aarch64 binary does not exist"
exit 1
fi
- name: Update Homebrew formula
env:
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
run: |
VERSION=${{ steps.extract-version.outputs.tag-name }}
REPO=${{ env.REPO_NAME }}
PROJECT=${{ env.PROJECT_NAME }}
DESC="${{ env.DESC }}"
X86_64_URL="https://github.com/${REPO}/releases/download/${VERSION}/${PROJECT}-${VERSION}-x86_64-apple-darwin"
AARCH64_URL="https://github.com/${REPO}/releases/download/${VERSION}/${PROJECT}-${VERSION}-aarch64-apple-darwin"
# 下载并更新formula
git clone https://github.com/${{ env.BREW_TAP }}.git homebrew-tap
cd homebrew-tap
cat > Formula/${PROJECT}.rb <<EOL
class $(echo $PROJECT | perl -pe 's/(^|_|-)(\w)/\U$2/g') < Formula
desc "${DESC}"
homepage "https://github.com/${REPO}"
version "${VERSION}"
on_macos do
if Hardware::CPU.intel?
url "${X86_64_URL}"
sha256 "$(curl -sL ${X86_64_URL} | shasum -a 256 | cut -d ' ' -f 1)"
else
url "${AARCH64_URL}"
sha256 "$(curl -sL ${AARCH64_URL} | shasum -a 256 | cut -d ' ' -f 1)"
end
end
def install
if Hardware::CPU.intel?
bin.install "${PROJECT}-#{version}-x86_64-apple-darwin" => "${PROJECT}"
else
bin.install "${PROJECT}-#{version}-aarch64-apple-darwin" => "${PROJECT}"
end
end
test do
system "#{bin}/${PROJECT}", "--version"
end
end
EOL
git config user.name github-actions
git config user.email github-actions@github.com
git add Formula/${PROJECT}.rb
git commit -m "Updating formula for ${PROJECT} to ${VERSION}"
git push https://${{ secrets.COMMITTER_TOKEN }}@github.com/${{ env.BREW_TAP }}.git main
12 changes: 7 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
name: "publish"

on:
create:
tags:
- '*'
# Commenting out the current trigger
# on:
# create:
# tags:
# - '*'


# This is the example from the readme.
# On each push to the `release` branch it will create or update a GitHub release, build your app, and upload the artifacts to the release.
env:
CARGO_TERM_COLOR: always
BINARIES_LIST: 'ncbi_dl kun_peng'
BINARIES_LIST: 'kun_peng'
PROJECT_PREFIX: 'Kun-peng-'

jobs:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["ncbi", "kr2r", "seqkmer"]
members = ["kr2r", "seqkmer"]
resolver = "2"

[profile.release]
Expand Down
101 changes: 60 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,56 @@ Follow these steps to install Kun-peng and run the examples.

If you prefer not to build from source, you can download the pre-built binaries for your platform from the GitHub [releases page](https://github.com/eric9n/Kun-peng/releases).

For Linux users (CentOS 7 compatible):

```bash
mkdir kun_peng_v0.6.15
tar -xvf Kun-peng-v0.6.15-centos7.tar.gz -C kun_peng_v0.6.15
# Add environment variable
echo 'export PATH=$PATH:~/biosoft/kun_peng_v0.6.15' >> ~/.bashrc
# Replace X.Y.Z with the latest version number
VERSION=vX.Y.Z
mkdir kun_peng_$VERSION
wget https://github.com/eric9n/Kun-peng/releases/download/$VERSION/kun_peng-$VERSION-centos7
mv kun_peng-$VERSION-centos7 kun_peng_$VERSION/kun_peng
chmod +x kun_peng_$VERSION/kun_peng
# Add to PATH
echo "export PATH=\$PATH:$PWD/kun_peng_$VERSION" >> ~/.bashrc
source ~/.bashrc
```

For macOS users:

```bash
# Replace X.Y.Z with the latest version number
VERSION=vX.Y.Z
mkdir kun_peng_$VERSION
# For Intel Macs
wget https://github.com/eric9n/Kun-peng/releases/download/$VERSION/kun_peng-$VERSION-x86_64-apple-darwin
mv kun_peng-$VERSION-x86_64-apple-darwin kun_peng_$VERSION/kun_peng
# For Apple Silicon Macs
# wget https://github.com/eric9n/Kun-peng/releases/download/$VERSION/kun_peng-$VERSION-aarch64-apple-darwin
# mv kun_peng-$VERSION-aarch64-apple-darwin kun_peng_$VERSION/kun_peng
chmod +x kun_peng_$VERSION/kun_peng
# Add to PATH
echo "export PATH=\$PATH:$PWD/kun_peng_$VERSION" >> ~/.zshrc # or ~/.bash_profile for Bash
source ~/.zshrc # or source ~/.bash_profile for Bash
```

For Windows users:

```powershell
# Replace X.Y.Z with the latest version number
$VERSION = "vX.Y.Z"
New-Item -ItemType Directory -Force -Path kun_peng_$VERSION
Invoke-WebRequest -Uri "https://github.com/eric9n/Kun-peng/releases/download/$VERSION/kun_peng-$VERSION-x86_64-pc-windows-msvc.exe" -OutFile "kun_peng_$VERSION\kun_peng.exe"
# Add to PATH
$env:Path += ";$PWD\kun_peng_$VERSION"
[Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::User)
```

After installation, you can verify the installation by running:

```bash
kun_peng --version
```

#### Run the `kun_peng` example

We will use a very small virus database on the GitHub homepage as an example:
Expand Down Expand Up @@ -148,54 +190,31 @@ This output confirms that the `kun_peng` commands were executed successfully and

## ncbi_dl tool

For detailed information and usage instructions for the ncbi_dl tool, please refer to the [ncbi_dl repository](https://github.com/eric9n/ncbi_dl.git).

#### Run the `ncbi` Example

Run the example script in the ncbi project to download the necessary files. Execute the following command from the root of the workspace:
The ncbi_dl tool is used to download resources from the NCBI website, including taxonomy files and genome data. It provides a convenient way to obtain the necessary data for building Kun-peng databases.

``` sh
cargo run --release --example run_download --package ncbi_dl
```

This will run the run_download.rs example located in the ncbi project's examples directory. The script will:

1. Ensure the necessary directories exist.
2. Download the required files using the ncbi binary with the following commands:
### Downloading Genome Databases

- ./target/release/ncbi_dl -d downloads gen -g archaea
- ./target/release/ncbi_dl -d downloads tax
To download genome databases using ncbi_dl, you can use the `genomes` (or `gen`) command. Here's a basic example:

Example Output You should see output similar to the following:

``` txt
Executing command: /path/to/workspace/target/release/ncbi_dl -d /path/to/workspace/downloads gen -g archaea
NCBI binary output: [download output here]
Executing command: /path/to/workspace/target/release/ncbi_dl -d /path/to/workspace/downloads tax
NCBI binary output: [download output here]
```sh
ncbi_dl -d /path/to/download/directory gen -g bacteria
```

The ncbi_dl binary is used to download resources from the NCBI website. Here is the help manual for the ncbi_dl binary:
This command will download bacterial genomes to the specified directory. You can replace `bacteria` with other genome groups like `archaea`, `fungi`, `protozoa`, or `viral` depending on your needs.

``` sh
./target/release/ncbi_dl -h
ncbi_dl download resource
Some key options for the `genomes` command include:

Usage: ncbi_dl [OPTIONS] <COMMAND>
- `-g, --groups <GROUPS>`: Specify which genome groups to download (e.g., bacteria, archaea, viral)
- `-f, --file-types <FILE_TYPES>`: Choose which file types to download (default is genomic.fna.gz)
- `-l, --assembly-level <ASSEMBLY_LEVEL>`: Set the assembly level (e.g., complete, chromosome, scaffold, contig)

Commands:
taxonomy Download taxonomy files from NCBI (alias: tax)
genomes Download genomes data from NCBI (alias: gen)
help Print this message or the help of the given subcommand(s)
For a full list of options and more detailed usage instructions, please refer to the ncbi_dl repository documentation.

Options:
-d, --download-dir <DOWNLOAD_DIR> Directory to store downloaded files [default: lib]
-n, --num-threads <NUM_THREADS> Number of threads to use for downloading [default: 20]
-h, --help Print help (see more with '--help')
-V, --version Print version
```
For installation, additional usage examples, and more detailed documentation, please visit the ncbi_dl repository linked above.

## kun_peng tool
## kun_peng

``` sh
Usage: kun_peng <COMMAND>
Expand Down
Loading

0 comments on commit 8231d06

Please sign in to comment.