Skip to content

Commit

Permalink
Merge pull request #245 from Rungetf/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
joachimwolff committed Jun 29, 2018
2 parents ca69b7a + bce783d commit 1c66c5d
Show file tree
Hide file tree
Showing 29 changed files with 2,446 additions and 217 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ nosetests.xml
# Ignore all emacs backup files
*~
.Rproj.user

# pytest
.pytest_cache/
.cache
123 changes: 101 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,7 @@ os:
stages:
- lint
- test
jobs:
include:
- stage: lint
env:
- LINT=1
- TRAVIS_PYTHON_VERSION=2.7
before_install:
- curl https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -o miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- PATH_WITHOUT_CONDA="$PATH"
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
install:
- conda install --yes python=2.7 flake8
script:
- if [[ "$LINT" == "1" ]]; then flake8 . --exclude=.venv,.build,planemo_test_env,build --ignore=E501,F403,E402,F999,F405,E712 ; fi


# Setup anaconda
before_install:
- export HIC_TEST_DATA_DIR="`pwd`/hicexplorer/test/test_data/"
Expand All @@ -45,14 +27,111 @@ before_install:
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a

# Install packages
install:
- conda install --yes -c conda-forge -c bioconda python=$TRAVIS_PYTHON_VERSION --file requirements.txt
- conda install --yes -c conda-forge -c bioconda pytest
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then conda install --yes -c defaults -c conda-forge -c bioconda configparser ; fi
- python setup.py install

# command to run tests
script:
- py.test hicexplorer --doctest-modules
- py.test hicexplorer/test/test_pytest_collected_items.py --doctest-modules --capture=sys
- py.test hicexplorer/test/general/ --doctest-modules --capture=sys
- py.test hicexplorer --doctest-modules --ignore=hicexplorer/test/
jobs:
include:
- stage: lint
env:
- LINT=1
before_install:
- curl https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -o miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- PATH_WITHOUT_CONDA="$PATH"
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
install:
- conda install --yes python=2.7 flake8
script:
- if [[ "$LINT" == "1" ]]; then flake8 . --exclude=.venv,.build,planemo_test_env,build --ignore=E501,F403,E402,F999,F405,E712 ; fi
- stage: test
os: linux
env: TRAVIS_PYTHON_VERSION=2.7
script: py.test hicexplorer/test/long_run/test_build_matrix_trivial_runs.py
- stage: test
os: osx
env: TRAVIS_PYTHON_VERSION=2.7
script: py.test hicexplorer/test/long_run/test_build_matrix_trivial_runs.py
- stage: test
os: linux
env: TRAVIS_PYTHON_VERSION=3.6
script: py.test hicexplorer/test/long_run/test_build_matrix_trivial_runs.py
- stage: test
os: osx
env: TRAVIS_PYTHON_VERSION=3.6
script: py.test hicexplorer/test/long_run/test_build_matrix_trivial_runs.py
- stage: test
os: linux
env: TRAVIS_PYTHON_VERSION=2.7
script: py.test hicexplorer/test/long_run/test_buildMatrix.py
- stage: test
os: osx
env: TRAVIS_PYTHON_VERSION=2.7
script: py.test hicexplorer/test/long_run/test_buildMatrix.py
- stage: test
os: linux
env: TRAVIS_PYTHON_VERSION=3.6
script: py.test hicexplorer/test/long_run/test_buildMatrix.py
- stage: test
os: osx
env: TRAVIS_PYTHON_VERSION=3.6
script: py.test hicexplorer/test/long_run/test_buildMatrix.py
- stage: test
os: linux
env: TRAVIS_PYTHON_VERSION=2.7
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs.py
- stage: test
os: osx
env: TRAVIS_PYTHON_VERSION=2.7
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs.py
- stage: test
os: linux
env: TRAVIS_PYTHON_VERSION=3.6
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs.py
- stage: test
os: osx
env: TRAVIS_PYTHON_VERSION=3.6
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs.py
- stage: test
os: linux
env: TRAVIS_PYTHON_VERSION=2.7
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs_two.py
- stage: test
os: osx
env: TRAVIS_PYTHON_VERSION=2.7
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs_two.py
- stage: test
os: linux
env: TRAVIS_PYTHON_VERSION=3.6
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs_two.py
- stage: test
os: osx
env: TRAVIS_PYTHON_VERSION=3.6
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs_two.py
- stage: test
os: linux
env: TRAVIS_PYTHON_VERSION=2.7
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs_three.py
- stage: test
os: osx
env: TRAVIS_PYTHON_VERSION=2.7
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs_three.py
- stage: test
os: linux
env: TRAVIS_PYTHON_VERSION=3.6
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs_three.py
- stage: test
os: osx
env: TRAVIS_PYTHON_VERSION=3.6
script: py.test hicexplorer/test/long_run/test_hicAggregateContacts_trivial_runs_three.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# DIFF = 60


ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"
tolerance = 13 # default matplotlib pixed difference tolerance


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from matplotlib.testing.compare import compare_images


ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"


def test_correct_matrix():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from matplotlib.testing.compare import compare_images


ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"


def test_correlate():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import numpy.testing as nt

ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/hicExport/"
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/hicExport/"

NPZ_MATRIX = ROOT + "matrix.npz"
COOL_MATRIX = ROOT + "matrix.cool"
Expand Down
67 changes: 67 additions & 0 deletions hicexplorer/test/general/test_hicFindEnrichedContacts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
""" Testsuite for hicFindEnrichedContacts """
from hicexplorer import hicFindEnrichedContacts as hicfec
from hicexplorer import HiCMatrix as hm
import os
import numpy as np
import numpy.testing as nt
from scipy.sparse import csr_matrix

# ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
# original_matrix = ROOT + "small_test_matrix_50kb_res"

ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"
sam_R1 = ROOT + "small_test_R1_unsorted.bam"
sam_R2 = ROOT + "small_test_R2_unsorted.bam"
dpnii_file = ROOT + "DpnII.bed"

from psutil import virtual_memory
mem = virtual_memory()
memory = mem.total / 2**30


# memory in GB the test computer needs to have to run the test case
LOW_MEMORY = 2
MID_MEMORY = 7
HIGH_MEMORY = 200


def test_getPearson():
cut_intervals = [('a', 0, 10, 1), ('a', 10, 20, 1),
('a', 20, 30, 1), ('a', 30, 40, 1), ('b', 40, 50, 1)]
hic = hm.hiCMatrix()
hic.nan_bins = []
matrix = np.array([[1, 8, 5, 3, 0],
[0, 4, 15, 5, 1],
[0, 0, 0, 0, 2],
[0, 0, 0, 0, 1],
[0, 0, 0, 0, 0]])

hic.matrix = csr_matrix(matrix)
hic.setMatrix(hic.matrix, cut_intervals)

pearson = hicfec.getPearson(hic.matrix)

nt.assert_equal(pearson.shape, (5, 5))
for row in pearson:
for value in row:
assert -1 <= value.all() <= 1

hic = hm.hiCMatrix()
hic.nan_bins = []
matrix = np.array([[2, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[1, 2, 2, 4, 5],
[1, 2, 3, 2, 5],
[1, 2, 3, 4, 2]
])

hic.matrix = csr_matrix(matrix)
hic.setMatrix(hic.matrix, cut_intervals)

pearson = hicfec.getPearson(hic.matrix)

nt.assert_equal(pearson.shape, (5, 5))
nt.assert_equal(pearson, np.zeros(shape=pearson.shape))
for row in pearson:
for value in row:
assert -1 <= value.all() <= 1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy.testing as nt


ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"


def are_files_equal(file1, file2, pDifference=10):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy.testing as nt


ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"


def test_correct_matrix():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy.testing as nt
import numpy as np
import pyBigWig
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"

import logging
log = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os.path


ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"


def test_plot():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
mem = virtual_memory()
memory = mem.total / 2 ** 30
import hicexplorer.hicPlotMatrix
tolerance = 20 # default matplotlib pixed difference tolerance
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
tolerance = 60 # default matplotlib pixed difference tolerance
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"

# memory in GB the test computer needs to have to run the test case
LOW_MEMORY = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import sys

ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"

h5_browser_track = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os.path


ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"


def are_files_equal(file1, file2):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from os.path import basename, dirname


ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data/"
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../test_data/"
original_matrix = ROOT + "small_test_matrix_50kb_res.h5"


Expand Down

0 comments on commit 1c66c5d

Please sign in to comment.