Commit 7e25a230 authored by Blaise Li's avatar Blaise Li
Browse files

Context-manage gff file opening.

parent fcfaae6c
...@@ -188,19 +188,19 @@ def id_list_gtf2bed(identifiers, gtf_filename, feature_type="transcript", id_kwd ...@@ -188,19 +188,19 @@ 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 in the feature annotations in the gtf_file. These feature IDs will be
matched against the elements in *identifiers*. matched against the elements in *identifiers*.
""" """
gtf_file = open(gtf_filename, "r") with open(gtf_filename, "r") as gtf_file:
gtf = BedTool(gtf_file) gtf = BedTool(gtf_file)
if identifiers: if identifiers:
ids = set(identifiers) ids = set(identifiers)
def feature_filter(feature): def feature_filter(feature):
return feature[2] == feature_type and feature[id_kwd] in ids return feature[2] == feature_type and feature[id_kwd] in ids
return gtf.filter(feature_filter) return gtf.filter(feature_filter)
else: else:
# https://stackoverflow.com/a/13243870/1878788 # https://stackoverflow.com/a/13243870/1878788
def empty_bed_generator(): def empty_bed_generator():
return return
yield yield
return empty_bed_generator() return empty_bed_generator()
def make_empty_bigwig(filename, chrom_sizes): def make_empty_bigwig(filename, chrom_sizes):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment