From d6be631af735a9286d50a46988b883e08ce22f1b Mon Sep 17 00:00:00 2001 From: Haibao Tang Date: Sun, 4 Aug 2024 16:43:49 -0700 Subject: [PATCH] Allow bed format to contain browser/track headers (#698) --- jcvi/formats/bed.py | 7 ++++--- tests/formats/data/custom.bed | 10 ++++++++++ tests/formats/test_bed.py | 10 ++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/formats/data/custom.bed create mode 100644 tests/formats/test_bed.py diff --git a/jcvi/formats/bed.py b/jcvi/formats/bed.py index eb6886f5..05ca8ddb 100755 --- a/jcvi/formats/bed.py +++ b/jcvi/formats/bed.py @@ -155,9 +155,10 @@ def __init__(self, filename=None, key=None, sorted=True, juncs=False, include=No for line in must_open(filename): if ( - line[0] == "#" - or (juncs and line.startswith("track name")) - or line.strip() == "" + line.strip() == "" + or line[0] == "#" + or line.startswith("browser ") + or line.startswith("track name") ): continue b = BedLine(line) diff --git a/tests/formats/data/custom.bed b/tests/formats/data/custom.bed new file mode 100644 index 00000000..6ae23420 --- /dev/null +++ b/tests/formats/data/custom.bed @@ -0,0 +1,10 @@ +browser position chr7:4499924-4500043 +track name="Covered" description="Agilent SureSelect DNA - Custom Exome_1 - Genomic regions expected to be sequenced" color=0,128,0 visibility=dense db=hg38 +chr7 4499923 4500043 7P22.1 +chr7 4500475 4501075 7P22.1 +chr7 4501706 4501844 7P22.1 +chr7 4503679 4503919 7P22.1 +chr7 4504362 4505023 7P22.1 +chr7 4505688 4505990 7P22.1 +chr7 4506376 4506496 7P22.1 +chr7 4506928 4507768 7P22.1 diff --git a/tests/formats/test_bed.py b/tests/formats/test_bed.py new file mode 100644 index 00000000..dc742f62 --- /dev/null +++ b/tests/formats/test_bed.py @@ -0,0 +1,10 @@ +import os +import os.path as op + +from jcvi.formats.bed import summary + +def test_summary(): + cwd = os.getcwd() + os.chdir(op.join(op.dirname(__file__), "data")) + summary(["custom.bed"]) + os.chdir(cwd)