aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--r_qtl/r_qtl2.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py
index dfa84ba..dbf5a7b 100644
--- a/r_qtl/r_qtl2.py
+++ b/r_qtl/r_qtl2.py
@@ -580,3 +580,25 @@ def read_csv_file(filepath: Union[str, Path],
if line.startswith(comment_char):
continue
yield tuple(field.strip() for field in line.split(separator))
+
+
+def read_csv_file_headers(
+ filepath: Union[str, Path],
+ transposed: bool,
+ separator: str = ",",
+ comment_char: str = "#"
+) -> tuple[str, ...]:
+ """Read the 'true' headers of a CSV file."""
+ headers = tuple()
+ for line in read_text_file(filepath):
+ if line.startswith(comment_char):
+ continue
+
+ line = tuple(field.strip() for field in line.split(separator))
+ if not transposed:
+ return line
+
+ headers = headers + (line[0],)
+ continue
+
+ return headers