Skip to content

Commit

Permalink
fix: make sniffing more robust by reading full lines
Browse files Browse the repository at this point in the history
fix #1561
  • Loading branch information
Midnighter committed May 16, 2022
1 parent c78733e commit 6a20d9f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions nf_core/pipeline-template/bin/check_samplesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ def validate_unique_samples(self):
row[self._sample_col] = f"{sample}_T{seen[sample]}"


def read_head(handle, num_lines=10):
"""Read the specified number of lines from the current position in the file."""
lines = []
for idx, line in enumerate(handle):
if idx == num_lines:
break
lines.append(line)
return "".join(lines)


def sniff_format(handle):
"""
Detect the tabular format.
Expand All @@ -144,13 +154,13 @@ def sniff_format(handle):
https://docs.python.org/3/glossary.html#term-text-file
"""
peek = handle.read(2048)
peek = read_head(handle)
handle.seek(0)
sniffer = csv.Sniffer()
if not sniffer.has_header(peek):
logger.critical(f"The given sample sheet does not appear to contain a header.")
sys.exit(1)
dialect = sniffer.sniff(peek)
handle.seek(0)
return dialect


Expand Down

0 comments on commit 6a20d9f

Please sign in to comment.