Skip to content

Commit

Permalink
9 set up unit testing workflow (#10)
Browse files Browse the repository at this point in the history
Set up basic unit tests for copy number variant detection
  • Loading branch information
jonperdomo authored Jul 31, 2023
1 parent 4b7f3c4 commit 7456f53
Show file tree
Hide file tree
Showing 26 changed files with 409 additions and 5,833 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: build tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up conda environment
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: contextsv
environment-file: environment.yml
python-version: 3.9
auto-activate-base: false

- name: Install samtools and bcftools using sudo apt-get
run: |
sudo apt-get update
sudo apt-get install -y samtools bcftools
- name: Build C++ code
shell: bash --login {0} # --login enables PATH variable access
run: |
make
- name: Run unit tests
shell: bash --login {0}
run: |
mkdir -p tests/output
python -m pytest
37 changes: 0 additions & 37 deletions .github/workflows/cmake.yml

This file was deleted.

7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
*.o
*.obj

# SWIG files
src/swig_wrapper.cpp
lib/contextsv.py

# Pycache
__pycache__/

# Precompiled Headers
*.gch
*.pch
Expand Down
66 changes: 0 additions & 66 deletions CMakeLists.txt

This file was deleted.

11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
INCL_DIR := $(CURDIR)/include
SRC_DIR := $(CURDIR)/src
LIB_DIR := $(CURDIR)/lib


all:
# Generate the SWIG wrapper (C++ -> Python)
swig -c++ -python -I$(INCL_DIR) -o $(SRC_DIR)/swig_wrapper.cpp -outdir $(LIB_DIR) $(SRC_DIR)/swig_wrapper.i

# Compile the SWIG wrapper using setuptools
python setup.py build_ext --build-lib $(LIB_DIR)
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# ContextSV
An alignment-based, generalized structural variant caller for long-read sequencing/mapping data
An alignment-based, generalized structural variant caller for long-read
sequencing/mapping data

[![build tests](https://github.com/WGLab/ContextSV/actions/workflows/build-tests.yml/badge.svg)](https://github.com/WGLab/ContextSV/actions/workflows/build-tests.yml)
57 changes: 57 additions & 0 deletions __main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
__main__.py: Run the program.
"""

import os
import argparse
from lib import contextsv

def main():

# Grab the command line arguments using argparse.
parser = argparse.ArgumentParser(
description="ContextSV: A tool for integrative structural variant detection."
)
parser.add_argument(
"-b", "--bam",
help="The path to the BAM file.",
required=True
)
parser.add_argument(
"-s", "--snps",
help="The path to the SNPs file.",
required=True
)
parser.add_argument(
"-o", "--output",
help="The path to the output file.",
required=True
)
parser.add_argument(
"-r", "--region",
help="The region to analyze.",
required=True
)

# Get the command line arguments.
args = parser.parse_args()

# Run the program.
print("Running contextsv with the following arguments:")
print("BAM: {}".format(args.bam))
print("SNPs: {}".format(args.snps))
print("Output: {}".format(args.output))
print("Region: {}".format(args.region))

contextsv.run(
args.bam,
args.snps,
args.output,
args.region
)


if __name__ == '__main__':

# Run the program.
main()
12 changes: 12 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: contextsv
channels:
- bioconda
- anaconda
- conda-forge
- defaults
dependencies:
- python
- numpy
- htslib
- swig
- pytest
26 changes: 1 addition & 25 deletions include/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,8 @@

#include "common.h"

#include <htslib/sam.h>
#include <string>

class CLI {
private:
Common common;

public:
// Parse input arguments
int parse(int argc, char** argv);

// Run the CLI
int run();

// Get the command argument input
static std::string getCmdOption(char ** begin, char ** end, const std::string & option);

// Check if the input argument is provided
static bool cmdOptionExists(char** begin, char** end, const std::string& option);

// Check if the filepath exists
static bool fileExists(const std::string &name);

static void printHelpText();

};

int run(std::string bam, std::string snps, std::string outdir, std::string region);

#endif //CONTEXTSV_CLI_H
1 change: 1 addition & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include <map>

class Common {
public:
std::string get_bam_filepath();
Expand Down
15 changes: 15 additions & 0 deletions include/contextsv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// contextsv.h
// Main header file for the contextsv library.
//

#ifndef CONTEXTSV_H
#define CONTEXTSV_H

#include "khmm.h"
#include "common.h"

#include <string>
#include <vector>

#endif // CONTEXTSV_H
Empty file added lib/__init__.py
Empty file.
66 changes: 66 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""
setup.py:
This file is used to install the package.
"""

print("Running setup.py...")

import os
import glob
from setuptools import setup, find_packages, Extension


# Set the project metadata
name = "contextsv"
version = "0.0.1"
author = "WGLab"
description = "ContextSV: A tool for integrative structural variant detection."

# Get the conda environment's include path
conda_prefix = os.environ.get("CONDA_PREFIX")
if conda_prefix is None:
raise Exception("CONDA_PREFIX is not set.")
conda_include_dir = os.path.join(conda_prefix, "include")

print("CONDA_PREFIX: {}".format(conda_prefix)) # DEBUG
print("include_dir: {}".format(conda_include_dir)) # DEBUG

# Get the conda environment's lib path
conda_lib_dir = os.path.join(conda_prefix, "lib")

print("lib_dir: {}".format(conda_lib_dir)) # DEBUG

# Set the project dependencies
src_dir = "src"
src_files = glob.glob(os.path.join(src_dir, "*.cpp"))
include_dir = "include"
include_files = glob.glob(os.path.join(include_dir, "*.h"))

# Set up the extension
ext = Extension(
name="_" + name,
sources=src_files,
include_dirs=[include_dir, conda_include_dir],
extra_compile_args=["-std=c++11"],
language="c++",
libraries=["hts"],
library_dirs=[conda_lib_dir]
)

# Set up the module
setup(
name=name,
version=version,
author=author,
description=description,
ext_modules=[ext],
py_modules=[name],
packages=find_packages(),
test_suite="tests",
entry_points={
"console_scripts": [
"contextsv = contextsv:main"
]
}
)

Loading

0 comments on commit 7456f53

Please sign in to comment.