Skip to content

Commit

Permalink
support gz and bz2 file extensions (see #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
aryarm committed Apr 9, 2022
1 parent dc7cad0 commit f71b853
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion haptools/data/covariates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
from csv import reader
from pathlib import Path
from fileinput import hook_compressed

import numpy as np

Expand Down Expand Up @@ -71,7 +72,8 @@ def read(self, samples: list[str] = None):
"""
super().read()
# load all info into memory
with open(self.fname) as covars:
# use hook_compressed to automatically handle gz files
with hook_compressed(self.fname, mode='rt') as covars:
covar_text = reader(covars, delimiter="\t")
header = next(covar_text)
# there should at least two columns
Expand Down
4 changes: 3 additions & 1 deletion haptools/data/phenotypes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
from csv import reader
from pathlib import Path
from fileinput import hook_compressed

import numpy as np

Expand Down Expand Up @@ -71,7 +72,8 @@ def read(self, samples: list[str] = None):
"""
super().read()
# load all info into memory
with open(self.fname) as phens:
# use hook_compressed to automatically handle gz files
with hook_compressed(self.fname, mode='rt') as phens:
phen_text = reader(phens, delimiter="\t")
# convert to list and subset samples if need be
if samples:
Expand Down

0 comments on commit f71b853

Please sign in to comment.