Skip to content

Commit 435bd9b

Browse files
committed
feat: update read_header to skip comments and empty lines
1 parent 7efec59 commit 435bd9b

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

fgpyo/util/metric.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,27 @@ def fast_concat(*inputs: Path, output: Path) -> None:
329329
)
330330

331331
@staticmethod
332-
def read_header(reader: io.Reader) -> List[str]:
332+
def read_header(
333+
reader: io.Reader,
334+
comment: str = "#",
335+
) -> List[str]:
333336
"""
334337
Read the header from an open file.
338+
339+
Comment and empty lines will be ignored.
340+
341+
Args:
342+
reader: An open, readable file
343+
comment: The character which indicates the start of a comment line.
344+
345+
Returns:
346+
A list of field names found in the header line.
335347
"""
336-
return reader.readline().rstrip("\r\n").split("\t")
348+
349+
for line in reader:
350+
if not line.startswith(comment) and not line.strip() == "":
351+
break
352+
else:
353+
raise ValueError("No header found")
354+
355+
return line.rstrip("\r\n").split("\t")

0 commit comments

Comments
 (0)