Skip to content

generate_samplesheet.py emits malformed CSV when FASTQ paths contain commas #1296

Open

Description

@agammann

Summary

At commit 95bdacc803aa5cfdb10f35e5b9fb2d4b11100133, generate_samplesheet.py reports success but writes an invalid RNA-seq CSV when a FASTQ path contains a comma.

Steps to reproduce

  1. Place a valid paired FASTQ set at reads,run/sample_R1_001.fastq.gz and reads,run/sample_R2_001.fastq.gz (the directory name contains a comma).
  2. From the repository root, run:
python bio-research/skills/nextflow-development/scripts/generate_samplesheet.py "reads,run" rnaseq -o samplesheet.csv --no-interactive
python bio-research/skills/nextflow-development/scripts/generate_samplesheet.py --validate samplesheet.csv rnaseq

Observed behavior

The generation command exits 0 and reports one samplesheet row. The CSV header has four fields (sample,fastq_1,fastq_2,strandedness), but the data row parses as six fields because both FASTQ paths contain a comma. The validation command exits 1, reporting missing FASTQ paths and an invalid strandedness value.

Expected behavior

Each FASTQ path remains one quoted CSV field. The data row has four fields and the generated samplesheet passes --validate.

Cause and verification

_write_samplesheet writes rows with ','.join(values) instead of a CSV writer. I reproduced this on Windows with Python 3.14.8 and valid gzip FASTQ records. Using the same input, the unmodified script produced 4 header fields / 6 data fields and failed its own validator. A local change using csv.writer produced 4 / 4 fields, passed validation, and passed a focused regression test.

Activity

  1. CryptGodSon commented on Oct 10, 2026

    @CryptGodSon

    I have a fix for this on my fork: CryptGodSon@88fa205

    _write_samplesheet now writes rows with csv.writer instead of ','.join, keeping \n line endings, so output for ordinary paths is unchanged. Tested with the repro above: the comma path now gives 4 header fields and 4 data fields and passes --validate, and a plain path gives the same file as before.

    External PRs to this repo are auto-closed, so I'm linking it here in case a maintainer wants to pick it up.

  2. CryptGodSon commented on Oct 11, 2026

    @CryptGodSon

    I looked into this and the cause is in _write_samplesheet: rows are built with ','.join(...), so any field containing a comma is split into extra columns and the file then fails the script's own --validate.

    A minimal fix is to write the header and rows with csv.writer, keeping \n line endings so output for ordinary paths stays byte-for-byte the same:

    import csv  # moved to module level
    
    with open(output_path, 'w', newline='') as f:
        writer = csv.writer(f, lineterminator='\n')
        writer.writerow(active_columns)
        for row in rows:
            writer.writerow([str(row.get(col, '')) for col in active_columns])

    I opened #1305 with this change before realizing the repo only accepts contributions from Anthropic team members, so it was auto-closed. The full commit is here in case it's useful: CryptGodSon@88fa205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions