Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Actions workflow #41

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Python Package using Conda

on: [push, pull_request]

jobs:
build-linux:
runs-on: ubuntu-20.04
strategy:
max-parallel: 5
defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.6.15
uses: actions/setup-python@v3
with:
python-version: '3.6.15'
- name: Create conda/mamba environment using micromamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml
cache-downloads: true
- name: Add micromamba to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Set EMU_DATABASE env variable
run: echo "EMU_DATABASE_DIR=./emu_database" >> $GITHUB_ENV
- name: Lint with flake8
run: |
micromamba install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
micromamba install pytest
pytest
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Emu: species-level taxonomic abundance for full-length 16S reads

[![Tests](https://github.com/treangenlab/emu/actions/workflows/python-tests.yml/badge.svg)](https://github.com/treangenlab/emu/actions/workflows/python-tests.yml)

### Description

Expand Down
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: custom-emu

channels:
- bioconda
- conda-forge
- bioconda
- nodefaults

dependencies:
- biopython
Expand Down
6 changes: 6 additions & 0 deletions tests/test_emu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def test_placeholder():
"""
Add an empty test so as not to fail the pytest process until some real
tests have been added.
"""
assert True
54 changes: 54 additions & 0 deletions tests/test_emu_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pytest
import subprocess
import os
import pandas as pd
import tempfile


@pytest.mark.parametrize(
"emu_command_tpl, abundance_filepath_tpl, expected_abundancies",
[
(
"./emu abundance --db emu_database --output-dir {tempdir_path} --keep-files example/full_length.fa",
"{tempdir_path}/full_length_rel-abundance.tsv",
{
"Sphingobacterium puteale": 0.5,
"Mycobacterium saskatchewanense": 0.25,
"Streptococcus sobrinus": 0.25,
},
),
(
"./emu abundance --db emu_database --output-dir {tempdir_path} --type sr --keep-files example/short_read_f.fq",
"{tempdir_path}/short_read_f_rel-abundance.tsv",
{
"Staphylococcus hominis": 1.0,
},
),
(
"./emu abundance --db emu_database --output-dir {tempdir_path} --type sr --keep-files example/short_read_f.fq example/short_read_r.fq",
"{tempdir_path}/short_read_f-short_read_r_rel-abundance.tsv",
{
"Staphylococcus aureus": 1.0 / 3,
"Salmonella enterica": 1.0 / 3,
"Enterococcus columbae": 1.0 / 3,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not completely sure here if it is expected that "Staphylococcus hominis" no longer shows up, and instead we get three equal parts of three other species, although the same forward strand file is used?

),
],
)
def test_cli_on_example_datasets(emu_command_tpl, abundance_filepath_tpl, expected_abundancies):
tempdir = tempfile.TemporaryDirectory()

emu_command = emu_command_tpl.format(tempdir_path=tempdir.name)
abundance_filepath = abundance_filepath_tpl.format(tempdir_path=tempdir.name)

if os.path.exists(abundance_filepath):
os.remove(abundance_filepath)

subprocess.check_output(emu_command, shell=True)

assert os.path.exists(abundance_filepath)

df = abundance_df = pd.read_csv(abundance_filepath, sep="\t")

for species, expected_abundance in expected_abundancies.items():
assert df[df["species"] == species].iloc[0]["abundance"] == expected_abundance