aboutsummaryrefslogtreecommitdiff
path: root/r_qtl/r_qtl2.py
diff options
context:
space:
mode:
Diffstat (limited to 'r_qtl/r_qtl2.py')
-rw-r--r--r_qtl/r_qtl2.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py
index dfa84ba..06175ce 100644
--- a/r_qtl/r_qtl2.py
+++ b/r_qtl/r_qtl2.py
@@ -16,7 +16,7 @@ from r_qtl.exceptions import InvalidFormat, MissingFileException
FILE_TYPES = (
"geno", "founder_geno", "pheno", "covar", "phenocovar", "gmap", "pmap",
- "phenose")
+ "phenose", "phenonum")
__CONTROL_FILE_ERROR_MESSAGE__ = (
"The zipped bundle that was provided does not contain a valid control file "
@@ -575,8 +575,30 @@ def read_text_file(filepath: Union[str, Path]) -> Iterator[str]:
def read_csv_file(filepath: Union[str, Path],
separator: str = ",",
comment_char: str = "#") -> Iterator[tuple[str, ...]]:
- """Read a file as a csv file."""
+ """Read a file as a csv file. This does not process the N/A values."""
for line in read_text_file(filepath):
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