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

run tests on Python 3.8 #324

Merged
merged 12 commits into from
Jun 2, 2020
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ matrix:
- python: 2.7
- python: 3.6
- python: 3.7
- python: 3.8
dist: xenial
sudo: true

Expand Down
19 changes: 11 additions & 8 deletions condatest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ no_cy="pbtpy${PY_VERSION}_conda_no_cython"
if ! conda env list | grep -q $no_cy; then
log "creating environment"

# pysam not available from bioconda for py37 so remove it from
# requirements.
# conflicts with pysam in bioconda for py37 or py38 so remove it from
# conda requirements; allow to install from pip
TMPREQS=$(tempfile)
grep -v pysam requirements.txt > $TMPREQS
REQS=requirements.txt
if [[ "$PY_VERSION" == "3.7" ]]; then
grep -v pysam requirements.txt > $TMPREQS
REQS=$TMPREQS
fi

if [[ "$PY_VERSION" == "3.8" ]]; then
grep -v pysam requirements.txt > $TMPREQS
REQS=$TMPREQS
else
REQS=requirements.txt
fi

# genomepy>=0.8 not available for py27
Expand All @@ -76,7 +80,6 @@ if ! conda env list | grep -q $no_cy; then
OPTREQS=optional-requirements.txt
fi


conda create -n $no_cy -y \
--channel conda-forge \
--channel bioconda \
Expand All @@ -100,8 +103,8 @@ pip install -e .
# manipulation in test_helpers and test_issues. So run in its own separate
# pytests process.
log "Unit tests"
pytest -v --doctest-modules --ignore pybedtools/test/test_genomepy_integration.py
pytest -v pybedtools/test/test_genomepy_integration.py
pytest -v --doctest-modules
pytest -v pybedtools/test/genomepy_integration.py

# ----------------------------------------------------------------------------
# sphinx doctests
Expand Down
2 changes: 1 addition & 1 deletion pybedtools/bedtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2794,7 +2794,7 @@ def percentileofscore(a, score):
a_len = np.array(list(range(len(a)))) + 1.0

a = np.sort(a)
idx = [a == score]
idx = tuple([a == score])
pct = (np.mean(a_len[idx]) / n) * 100.0
return pct

Expand Down
6 changes: 3 additions & 3 deletions pybedtools/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .logger import logger
from .cbedtools import create_interval_from_list

BUFSIZE = 1
BUFSIZE = -1

_tags = {}

Expand Down Expand Up @@ -744,7 +744,7 @@ def get_chromsizes_from_ucsc(
d = {}
try:
p = subprocess.Popen(
cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1
cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=BUFSIZE
)
stdout, stderr = p.communicate()
if stderr:
Expand All @@ -770,7 +770,7 @@ def get_chromsizes_from_ucsc(
try:
cmds = [fetchchromsizes, genome]
p = subprocess.Popen(
cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1
cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=BUFSIZE
)
stdout, stderr = p.communicate()
if stderr:
Expand Down
38 changes: 19 additions & 19 deletions pybedtools/scripts/intron_exon_reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,31 @@ def count_reads_in_features(features):
g = pybedtools.BedTool(gff).remove_invalid().saveas()

# Set up pool of workers
pool = multiprocessing.Pool(processes=args.processes)
with multiprocessing.Pool(processes=args.processes) as pool:

# Get separate files for introns and exons in parallel
featuretypes = ["intron", "exon"]
introns, exons = pool.map(subset_featuretypes, featuretypes)
# Get separate files for introns and exons in parallel
featuretypes = ["intron", "exon"]
introns, exons = pool.map(subset_featuretypes, featuretypes)

# Since `subset_featuretypes` returns filenames, we convert to BedTool objects
# to do intersections below.
introns = pybedtools.BedTool(introns)
exons = pybedtools.BedTool(exons)
# Since `subset_featuretypes` returns filenames, we convert to BedTool objects
# to do intersections below.
introns = pybedtools.BedTool(introns)
exons = pybedtools.BedTool(exons)

# Identify unique and shared regions using bedtools commands subtract, merge,
# and intersect.
exon_only = exons.subtract(introns).merge()
intron_only = introns.subtract(exons).merge()
intron_and_exon = exons.intersect(introns).merge()
# Identify unique and shared regions using bedtools commands subtract, merge,
# and intersect.
exon_only = exons.subtract(introns).merge()
intron_only = introns.subtract(exons).merge()
intron_and_exon = exons.intersect(introns).merge()

# Do intersections with BAM file in parallel. Note that we're passing filenames
# to multiprocessing.Pool rather than BedTool objects.
features = (exon_only.fn, intron_only.fn, intron_and_exon.fn)
# Do intersections with BAM file in parallel. Note that we're passing filenames
# to multiprocessing.Pool rather than BedTool objects.
features = (exon_only.fn, intron_only.fn, intron_and_exon.fn)

# Run count_reads_in_features in parallel over features
results = pool.map(count_reads_in_features, features)
# Run count_reads_in_features in parallel over features
results = pool.map(count_reads_in_features, features)

labels = ("exon_only", "intron_only", "intron_and_exon")
labels = ("exon_only", "intron_only", "intron_and_exon")

for label, reads in zip(labels, results):
print("{0}\t{1}".format(label, reads))
2 changes: 1 addition & 1 deletion pybedtools/test/test_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_tuple_creation():
def test_tabix():
try:
a = pybedtools.example_bedtool("a.bed")
t = a.tabix()
t = a.tabix(force=True)
assert t._tabixed()
results = t.tabix_intervals("chr1:99-200")
results = str(results)
Expand Down
3 changes: 2 additions & 1 deletion pybedtools/test/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,11 @@ def test_issue_251():
def test_issue_257():
try:
import pandas
import numpy as np
except ImportError:
pytest.mark.skip("Pandas not installed; skipping")
df = pybedtools.example_bedtool("a.bed").to_dataframe()
df.iloc[-1, -3:] = pandas.np.nan
df.iloc[-1, -3:] = np.nan
b = pybedtools.BedTool.from_dataframe(df)
assert str(b) == fix(
"""
Expand Down
3 changes: 2 additions & 1 deletion pybedtools/test/test_scripts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pybedtools
import six
from textwrap import dedent
from .tfuncs import setup_module, teardown_module
from pybedtools.scripts import annotate, venn_mpl, venn_gchart
Expand Down Expand Up @@ -188,7 +189,7 @@ def test_venn_gchart_main():
sys.stderr = orig_stderr
os.unlink("gcharttmp")


@pytest.mark.skipif(six.PY2, reason="multiprocessing pool context manager does not work for py2")
def test_intron_exon_reads():
gff = pybedtools.example_filename("gdc.gff")
bam = pybedtools.example_filename("gdc.bam")
Expand Down