diff options
author | Frederick Muriuki Muriithi | 2025-05-19 10:24:09 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-05-19 10:26:29 -0500 |
commit | 94fe97b01a3887209f4785a3d7bce6291ed3cf3d (patch) | |
tree | f2f927aa57fadfd727b0f79fb43c91e155dbd3bc /r_qtl/r_qtl2.py | |
parent | 2b03ca5772dd347d7fd8bd4d3a94ccca933861ec (diff) | |
download | gn-uploader-94fe97b01a3887209f4785a3d7bce6291ed3cf3d.tar.gz |
Read headers from a CSV file, whether transposed or not.
Diffstat (limited to 'r_qtl/r_qtl2.py')
-rw-r--r-- | r_qtl/r_qtl2.py | 22 |
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 |