nextflow-io / nextflow-io/nf-schema

Use `patternProperties` to match columns with a certain `prefix`

Open
#176 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Groovy
Stars
57
Forks
31
Avg merge
3d 17h
Merged PRs (30d)
1

Description

In my samplesheet.csv I wish to include other columns, such as CONTRAST_ or VARIABLE_ that will be used downstream in post-analysis.

In my R package, I use something similar as follows, that does perform pattern matching. Unfortunately, this is not supported and the samplesheetToList ignores all patternProperties despite when additionalProperties is set to true.

"patternProperties": {
          "^CONTRAST_": {
            "anyOf": [
                { "type": "string", "pattern": "^(\\S*)$" },
                { "type": "number" }
              ]
            },
          "^VARIABLE_": {
            "anyOf": [
              { "type": "string", "pattern": "^(\\S*)$" },
              { "type": "number" }
            ]
          }
        },

At the moment I made my own samplesheetToMetadata function that simply takes everything and returns it as a list. Of course, this is not the ideal approach..

def samplesheetToMetadata(input) {
    def rows = []
    input.withReader { reader ->
        def headers = reader.readLine().split(',').collect { it.trim() }
        reader.eachLine { line ->
            def values = line.split(',').collect { it.trim() }
            def row = [:]
            headers.eachWithIndex { h, i -> row[h] = values[i] }
            rows << row
        }
    }

    def isNumeric = { str ->
        str ==~ /^-?\d+(\.\d+)?$/
    }

    // Check types for each column
    def columnTypes = [:]
    if (rows) {
        def headers = rows[0].keySet()
        headers.each { col ->
            def values = rows.collect { it[col] }
            def allNumeric = values.every { v -> isNumeric(v) }
            def allString = values.every { v -> v instanceof String && !isNumeric(v) }
            columnTypes[col] = allNumeric ? 'numeric' : (allString ? 'string' : 'mixed')
        }
    }

    return [rows]
}

I didn't bother looking into samplesheetToList because I needed a quick fix to move on, but I might look into this myself soon if you nobody else is looking into it.

Also, on another note, I noticed that when I want to use the same schema_input.json in R.. it doesn't follow the correct json syntax according to json validator

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the samplesheetToList entry point and inspect how additionalProperties is handled. Add coverage for CONTRAST_ and VARIABLE_ columns containing string and numeric values, then run the relevant tests and verify that the schema_input.json syntax remains valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.