Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
66 changes: 25 additions & 41 deletions pybedtools/test/test_1.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import pybedtools
import os, difflib, sys
from pybedtools import featurefuncs
import tempfile
import shutil
from pathlib import Path

from pybedtools import featurefuncs, filenames
import pytest

import threading
import warnings
from .tfuncs import test_tempdir

unwriteable = "unwriteable"


def setup_module():
if not os.path.exists(test_tempdir):
os.system("mkdir -p %s" % test_tempdir)
pybedtools.set_tempdir(test_tempdir)


def teardown_module():
if os.path.exists(test_tempdir):
os.system("rm -r %s" % test_tempdir)
pybedtools.cleanup()


Expand Down Expand Up @@ -67,7 +62,8 @@ def cleanup_unwriteable():
"""
if os.path.exists(unwriteable):
os.system("rm -rf %s" % unwriteable)
pybedtools.set_tempdir(test_tempdir)
tempfile.tempdir = None
pybedtools.set_tempdir(tempfile.gettempdir())


def test_interval_index():
Expand Down Expand Up @@ -132,37 +128,24 @@ def test_tuple_creation():
assert x[0]["ID"] == "gene1"


def test_tabix():
try:
a = pybedtools.example_bedtool("a.bed")
t = a.tabix(force=True)
assert t._tabixed()
results = t.tabix_intervals("chr1:99-200")
results = str(results)
print(results)
assert results == fix(
"""
chr1 1 100 feature1 0 +
chr1 100 200 feature2 0 +
chr1 150 500 feature3 0 -"""
)

assert str(t.tabix_intervals(a[2])) == fix(
"""
chr1 100 200 feature2 0 +
chr1 150 500 feature3 0 -"""
)

finally:
# clean up
fns = [
pybedtools.example_filename("a.bed.gz"),
pybedtools.example_filename("a.bed.gz.tbi"),
]
for fn in fns:
if os.path.exists(fn):
os.unlink(fn)
def test_tabix(tmp_path: Path) -> None:
shutil.copy(os.path.join(filenames.data_dir(), "a.bed"), tmp_path)
a = pybedtools.BedTool(tmp_path / "a.bed")
t = a.tabix(force=True)
assert t._tabixed()
results = t.tabix_intervals("chr1:99-200")
results = str(results)
print(results)
assert results == fix("""
chr1 1 100 feature1 0 +
chr1 100 200 feature2 0 +
chr1 150 500 feature3 0 -"""
)

assert str(t.tabix_intervals(a[2])) == fix("""
chr1 100 200 feature2 0 +
chr1 150 500 feature3 0 -"""
)

def test_tabix_intervals():
a = pybedtools.BedTool("chr1 25 30", from_string=True).tabix()
Expand Down Expand Up @@ -503,6 +486,7 @@ def test_sequence():
For example, the first 100 bases of a chromosome are defined as
chromStart=0, chromEnd=100, and span the bases numbered 0-99. """

test_tempdir = os.path.abspath(tempfile.gettempdir())
fi = os.path.join(test_tempdir, "test.fasta")

s = """
Expand Down
9 changes: 0 additions & 9 deletions pybedtools/test/test_cbedtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@
from pybedtools import Interval, IntervalFile
import pybedtools
import pytest
from .tfuncs import test_tempdir

def setup_module():
if not os.path.exists(test_tempdir):
os.system("mkdir -p %s" % test_tempdir)
pybedtools.set_tempdir(test_tempdir)


def teardown_module():
if os.path.exists(test_tempdir):
os.system("rm -r %s" % test_tempdir)
pybedtools.cleanup()

PATH = os.path.dirname(__file__)
Expand Down
2 changes: 1 addition & 1 deletion pybedtools/test/test_contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pybedtools import Interval

# from pybedtools.contrib import Classifier
from .tfuncs import setup_module, teardown_module, testdir, test_tempdir, unwriteable
from .tfuncs import teardown_module

# model for gdc.
# chr2L, starts at 1 and spacing is 10bp.
Expand Down
8 changes: 0 additions & 8 deletions pybedtools/test/test_gzip_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@

import pybedtools
import gzip
from .tfuncs import test_tempdir


def setup_module():
if not os.path.exists(test_tempdir):
os.system("mkdir -p %s" % test_tempdir)
pybedtools.set_tempdir(test_tempdir)

def teardown_module():
if os.path.exists(test_tempdir):
os.system("rm -r %s" % test_tempdir)
pybedtools.cleanup()

def _make_temporary_gzip(bed_filename):
Expand Down
4 changes: 3 additions & 1 deletion pybedtools/test/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pybedtools
import sys
import os
from .tfuncs import testdir, test_tempdir
import tempfile
from .tfuncs import testdir
import pytest
from pathlib import Path

Expand Down Expand Up @@ -41,6 +42,7 @@ def test_cleanup():

# make a fake tempfile, not created during this pybedtools session
pybedtools.cleanup()
test_tempdir = os.path.abspath(tempfile.gettempdir())
testfn = Path(test_tempdir) / "pybedtools.TESTING.tmp"
testfn.parent.mkdir(parents=True, exist_ok=True)
testfn.touch()
Expand Down
35 changes: 16 additions & 19 deletions pybedtools/test/test_issues.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import pybedtools
import gzip
import os
import shutil
import subprocess
import sys
from textwrap import dedent
from pathlib import Path
import pytest
import psutil

from pybedtools import filenames

testdir = os.path.dirname(__file__)
tempdir = os.path.join(os.path.abspath(testdir), "tmp")
unwriteable = "unwriteable"


def setup_module():
if not os.path.exists(tempdir):
os.system("mkdir -p %s" % tempdir)
pybedtools.set_tempdir(tempdir)


def teardown_module():
if os.path.exists(tempdir):
os.system("rm -r %s" % tempdir)
pybedtools.cleanup()


Expand Down Expand Up @@ -415,17 +408,19 @@ def test_issue_164():
assert str(y) == expected


def test_issue_168():
def test_issue_168(tmp_path: Path) -> None:
# Regression test:
# this would previously segfault in at least pysam 0.8.4
#
x = pybedtools.example_bedtool("1000genomes-example.vcf")
shutil.copy(os.path.join(filenames.data_dir(), "1000genomes-example.vcf"), tmp_path)
x = pybedtools.BedTool(tmp_path / "1000genomes-example.vcf")
fn = x.bgzip(is_sorted=True, force=True)
y = pybedtools.BedTool(fn)


def test_issue_169():
x = pybedtools.example_bedtool("1000genomes-example.vcf")
def test_issue_169(tmp_path: Path) -> None:
shutil.copy(os.path.join(filenames.data_dir(), "1000genomes-example.vcf"), tmp_path)
x = pybedtools.BedTool(tmp_path / "1000genomes-example.vcf")
fn = x.bgzip(is_sorted=False, force=True)
line = gzip.open(fn, "rt").readline()
assert str(line).startswith("#"), line
Expand Down Expand Up @@ -486,14 +481,16 @@ def test_issue_178():
pass


def test_issue_180():
a = pybedtools.example_bedtool("a.bed")
def test_issue_180(tmp_path: Path) -> None:
shutil.copy(os.path.join(filenames.data_dir(), "a.bed"), tmp_path)
a = pybedtools.BedTool(tmp_path / "a.bed")
a = a.tabix(force=True)
assert a.tabix_contigs() == ["chr1"]


def test_issue_181():
a = pybedtools.example_bedtool("a.bed")
def test_issue_181(tmp_path: Path) -> None:
shutil.copy(os.path.join(filenames.data_dir(), "a.bed"), tmp_path)
a = pybedtools.BedTool(tmp_path / "a.bed")
a = a.tabix(force=True)
a.tabix_intervals("none:1-5")
with pytest.raises(ValueError):
Expand Down Expand Up @@ -812,10 +809,10 @@ def test_issue_291():
assert a == b == c == d == e


def test_issue_319():
def test_issue_319(tmp_path: Path) -> None:
vrn_file = os.path.join(testdir, "data", "issue319.vcf.gz")
spliceslop = os.path.join(testdir, "data", "issue319.bed")
output_bed = os.path.join(testdir, "data", "issue319.out.bed")
output_bed = tmp_path / "issue319.out.bed"
bt = pybedtools.BedTool(vrn_file).intersect(spliceslop, wa=True, header=True, v=True).saveas(output_bed)


Expand Down
9 changes: 0 additions & 9 deletions pybedtools/test/test_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@
import os
import gzip
import pybedtools
from .tfuncs import test_tempdir

def setup_module():
if not os.path.exists(test_tempdir):
os.system("mkdir -p %s" % test_tempdir)
pybedtools.set_tempdir(test_tempdir)


def teardown_module():
if os.path.exists(test_tempdir):
os.system("rm -r %s" % test_tempdir)
pybedtools.cleanup()

yamltestdesc = ["test_cases.yaml"]
Expand Down
10 changes: 0 additions & 10 deletions pybedtools/test/tfuncs.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import pytest
import pybedtools
import os

testdir = os.path.dirname(__file__)
test_tempdir = os.path.join(os.path.abspath(testdir), "tmp")
unwriteable = os.path.join(os.path.abspath(testdir), "unwriteable")


def setup_module():
if not os.path.exists(test_tempdir):
os.system("mkdir -p %s" % test_tempdir)
pybedtools.set_tempdir(test_tempdir)


def teardown_module():
if os.path.exists(test_tempdir):
os.system("rm -r %s" % test_tempdir)
pybedtools.cleanup()
Loading