Skip to content

Commit

Permalink
Merge pull request #41 from samuell/add-github-actions-workflow
Browse files Browse the repository at this point in the history
Add GitHub Actions workflow
  • Loading branch information
kdc10 authored Jan 22, 2025
2 parents 7b66f6a + b5555b8 commit 0734a77
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
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,
},
),
],
)
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

0 comments on commit 0734a77

Please sign in to comment.