Hi! Samplesheet issues here :slightly_smiling_face...
# help
s
Hi! Samplesheet issues here 🙂 1. Is there good documentation on how to build and parse a samplesheet for a custom pipeline? We couldn't find it. 2. Here is a sample from my samplesheet
Copy code
sample,gff,fasta
Pb3A,Pb3A_genomic.gff,Pb3A_genomic.fna
PbeH,PbeH_genomic.gff,PbeH_genomic.fna
and here what we would like to do : run GFFread for each sample, knowing that it as to take the gff and fasta from the same row in the sheet (and do it for each row).
Copy code
GFFREAD (gff,fasta)
If someone could suggest the appropriate code, that would be great Thanks!
m
n
Thanks for the shout out Mahesh. @Solenne Correard feel free to ask any questions about nf-schema in the #C056RQB10LU channel 🙂
s
Too many terms and too many channels : are schema and samplesheet the same thing? I may just use parameters like it was done back in the days 😂
m
No, a schema defines what should be in the samplesheet. The code then validates the samplesheet follows that schema, and then can emit an object ( tuple with meta map ) as you want it structured.
party this 1
n
this bytesize might help you understand the difference a bit better: https://nf-co.re/events/2025/bytesize_json_schema
p
Importantly - once you have a schema you can use the function in the second line that Mahesh posted to parse it and load it into objects to use super easily.
You'll probably want to use a meta map, see https://nf-co.re/docs/contributing/components/meta_map
The Nextflow code ends up being very simple then:
Copy code
include { samplesheetToList } from 'plugin/nf-schema'

workflow {
    ch_input = Channel.fromList(samplesheetToList(params.input, "assets/schema_input.json"))

    ch_input.view()
}
and you get validation that the sample sheets that folks provide are correctly strucutred, and the data that they contain is valid (eg. you can check file extensions)
@mashehu is building a new schema-builder tool to help with writing the JSON for these, I'm not sure how usable it is yet though: https://github.com/nextflow-io/schema-builder
n
Plus you inherently have support for samplesheets in CSV, TSV, JSON and YAML format 🙂
🚀 1
p
@Nicolas Vannieuwkerke maybe we (you) should do a bytesize just on creating and using sample sheets..? 👀 😉
n
that's what this one is about 😉 https://nf-co.re/events/2025/bytesize_json_schema
this 1
p
yeah just realised that
🎉 1
we should change the title
it doesn't mention sample sheets, I assumed it was for params
n
Ah yeah maybe
samplesheet_json_schema
would make more sense
p
ok I pinned the talk to the #C01BB6T15NF channel 🙂
🎉 1
s
I love the enthusiasm, but I think it is overcomplicated. This is for a short nextflow/nf-core training that I did yesterday to beginners. They ran nf-core and nextflow pipelines easily in the morning, in the afternoon, they wanted to do their custom pipeline. We use nf-core pipeline create, nf-core install modules, etc. They got all of it (how to add modules, how to set specific parameters, etc) but the samplesheet. Maybe you could do a
nf-core pipeline samplesheet
function that would guide the user through the creation of their samplesheet, the json schema and would write the parsing code?
p
That's exactly what this is 👍🏻
You even guessed the nf-core CLI command that we're intending to use, I think 😅
👍🏻 1
We're building it as white-label so that others can use / embed in other places, but it'll get imported back into the nf-core CLI for us
s
Awesome! Let me know when it's ready to test if you want user feedback
👍🏻 1
thanks 1
m
I wonder if this is something Seqera's AI might be good for. Give it an example of the samplesheet, and ask it to write a schema to use. That should be quite low barrier for students
Prompt:
Write me an nf-schema for
sample,gff,fasta
Pb3A,Pb3A_genomic.gff,Pb3A_genomic.fna
PbeH,PbeH_genomic.gff,PbeH_genomic.fna
Output:
I'll create an nf-schema for your samplesheet. This schema will validate the CSV format with columns for sample, gff, and fasta files.
Created 'nextflow_schema.json' with 35 lines.
{ "$schema": "http://json-schema.org/draft-07/schema", "$id": "https://raw.githubusercontent.com/your-pipeline/master/nextflow_schema.json", "title": "Pipeline schema", "description": "Schema for validating pipeline samplesheet", "type": "object", "definitions": { "in...
Created 'assets/schema_input.json' with 34 lines.
{ "$schema": "http://json-schema.org/draft-07/schema", "$id": "https://raw.githubusercontent.com/your-pipeline/master/assets/schema_input.json", "title": "Pipeline input schema", "description": "Schema for the file provided with params.input", "type": "array", "items": { ...
Perfect! I've created an nf-schema for your samplesheet with the following structure:
Files Created:
1. nextflow_schema.json - Main pipeline schema
• Defines the
input
parameter that points to your CSV samplesheet
• References the samplesheet schema in
assets/schema_input.json
2. assets/schema_input.json - Samplesheet validation schema
Validates each row in your CSV with:
• sample: Required, no spaces allowed
• gff: Required, must end with
.gff
extension and file must exist
• fasta: Required, must end with
.fasta
,
.fa
, or
.fna
extension and file must exist
How to Use:
1. In your
nextflow.config
, add:
plugins {
id 'nf-schema@2.0.0'
}
1. In your
<http://main.nf|main.nf>
, validate the input:
include { validateParameters; paramsSummaryLog; samplesheetToList } from 'plugin/nf-schema'
// Validate input parameters
*validateParameters*()
// Create channel from samplesheet
ch_input = Channel.*fromList*(*samplesheetToList*(params.input, "assets/schema_input.json"))
.map { meta, gff, fasta ->
[ meta, *file*(gff), *file*(fasta) ]
}
The schema will automatically validate that your CSV has the correct format and that all referenced files exist!
(There are
expand
buttons on the schema's to give the full schema.)