Skip to content

Commit

Permalink
Merge pull request #22 from gokceneraslan/gzbz2
Browse files Browse the repository at this point in the history
Add gz and bz2 support for text files.
  • Loading branch information
falexwolf authored May 14, 2018
2 parents 52fa0e9 + 8c9b121 commit ddd828d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions anndata/readwrite/read.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path
from typing import Union, Optional, Iterable, Generator, Iterator
from collections import OrderedDict
import gzip
import bz2
import numpy as np

from ..base import AnnData
Expand Down Expand Up @@ -197,8 +199,15 @@ def read_text(
Numpy data type.
"""
if isinstance(filename, (str, Path)):
with Path(filename).open() as f:
return _read_text(f, delimiter, first_column_names, dtype)
if str(filename).endswith('.gz'):
with gzip.open(str(filename), mode='rt') as f:
return _read_text(f, delimiter, first_column_names, dtype)
elif str(filename).endswith('.bz2'):
with bz2.open(str(filename), mode='rt') as f:
return _read_text(f, delimiter, first_column_names, dtype)
else:
with Path(filename).open() as f:
return _read_text(f, delimiter, first_column_names, dtype)
else:
return _read_text(filename, delimiter, first_column_names, dtype)

Expand Down

0 comments on commit ddd828d

Please sign in to comment.