aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--r_qtl/r_qtl2.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py
index ad9271c..5b926d1 100644
--- a/r_qtl/r_qtl2.py
+++ b/r_qtl/r_qtl2.py
@@ -554,3 +554,21 @@ def load_samples(zipfilepath: Union[str, Path],
pass
return tuple(samples)
+
+
+
+def read_text_file(filepath: Union[str, Path]) -> Iterator[str]:
+ """Read the raw text from a text file."""
+ with open(filepath, "r", encoding="utf8") as _file:
+ for line in _file:
+ yield line
+
+
+def read_csv_file(filepath: Union[str, Path],
+ separator: str = ",",
+ comment_char: str = "#") -> Iterator[str]:
+ """Read a file as a csv file."""
+ for line in read_text_file(filepath):
+ if line.startswith(comment_char):
+ continue
+ yield tuple(field.strip() for field in line.split(separator))