From 1843ade546071552aa5fff11eabfabbadfb43d29 Mon Sep 17 00:00:00 2001
From: Blaise Li <blaise.li__git@nsup.org>
Date: Tue, 16 Jul 2019 18:25:14 +0200
Subject: [PATCH] Fix empty BedTool: need to pass file name, not fh.

---
 libhts/libhts.py | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/libhts/libhts.py b/libhts/libhts.py
index 6631039..b4bfc47 100644
--- a/libhts/libhts.py
+++ b/libhts/libhts.py
@@ -189,19 +189,18 @@ def id_list_gtf2bed(identifiers, gtf_filename, feature_type="transcript", id_kwd
     in the feature annotations in the gtf_file. These feature IDs will be
     matched against the elements in *identifiers*.
     """
-    with open(gtf_filename, "r") as gtf_file:
-        gtf = BedTool(gtf_file)
-        if identifiers:
-            ids = set(identifiers)
-            def feature_filter(feature):
-                return feature[2] == feature_type and feature[id_kwd] in ids
-            return gtf.filter(feature_filter)
-        else:
-            # https://stackoverflow.com/a/13243870/1878788
-            def empty_bed_generator():
-                return
-                yield
-            return empty_bed_generator()
+    if identifiers:
+        ids = set(identifiers)
+        def feature_filter(feature):
+            return feature[2] == feature_type and feature[id_kwd] in ids
+        gtf = BedTool(gtf_filename)
+        return gtf.filter(feature_filter)
+    else:
+        # https://stackoverflow.com/a/13243870/1878788
+        def empty_bed_generator():
+            return
+            yield
+        return empty_bed_generator()
 
 
 def make_empty_bigwig(filename, chrom_sizes):
-- 
GitLab