Skip to content

Commit

Permalink
refactor(IPVC-2276): pull out open_file into module
Browse files Browse the repository at this point in the history
  • Loading branch information
sptaylor committed Apr 4, 2024
1 parent 50ff903 commit 0e15485
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
13 changes: 1 addition & 12 deletions sbin/ncbi_parse_genomic_gff.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,16 @@
"""

import argparse
import gzip
import logging.config
import sys
from collections import defaultdict
from contextlib import contextmanager
from dataclasses import dataclass
from typing import List, Optional

import pkg_resources

from uta.formats.exonset import ExonSet, ExonSetWriter


@contextmanager
def open_file(filename):
if filename.endswith(".gz"):
with gzip.open(filename, "rt") as f:
yield f
else:
with open(filename) as f:
yield f
from uta.tools.file_utils import open_file


@dataclass
Expand Down
12 changes: 12 additions & 0 deletions src/uta/tools/file_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import gzip
from contextlib import contextmanager


@contextmanager
def open_file(filename):
if filename.endswith(".gz"):
with gzip.open(filename, "rt") as f:
yield f
else:
with open(filename) as f:
yield f

0 comments on commit 0e15485

Please sign in to comment.