I have a JSON that looks like this
{
"barcodes": {
"0004F--0004R": {
"Barcode UID": "4",
"Sample ID": "10887581",
"For Barcode Name": "0004F",
"For Barcode Sequence": "GGTAGTGTGTATCAGTACATG",
"Rev Barcode Name": "0004R",
"Rev Barcode Sequence": "GGTAGTGTGTATCAGTACATG",
"Genes Sequenced": "",
"Ethnicity": "",
"laa_params": {
"--minLength": "3000",
"--ignoreEnds": "60",
"--maxReads": "2500",
"--maxPhasingReads": "500"
}
},
"0014F--0014R": {
"Barcode UID": "14",
"Sample ID": "10895675",
"For Barcode Name": "0014F",
"For Barcode Sequence": "GGTAGCGTCTATATACGTATA",
"Rev Barcode Name": "0014R",
"Rev Barcode Sequence": "GGTAGCGTCTATATACGTATA",
"Genes Sequenced": "A/B/C",
"Ethnicity": "British/Irish",
"laa_params": {
"--minLength": "3000",
"--ignoreEnds": "60",
"--maxReads": "2500",
"--maxPhasingReads": "500"
}
},
"0018F--0018R": {
"Barcode UID": "18",
"Sample ID": "10896709",
"For Barcode Name": "0018F",
"For Barcode Sequence": "GGTAGCATCACTACGCTAGAT",
"Rev Barcode Name": "0018R",
"Rev Barcode Sequence": "GGTAGCATCACTACGCTAGAT",
"Genes Sequenced": "B/C",
"Ethnicity": "British/Irish",
"laa_params": {
"--minLength": "3000",
"--ignoreEnds": "60",
"--maxReads": "2500",
"--maxPhasingReads": "500"
}
}
}
}
I use this JSON to create a fasta file, where I split the name of the barcode "0014F--0014R" into two halves. Each half is placed in a file, and then the relevant sequence below it like so:
>0014F
GGTAGCGTCTATATACGTATA
>0014R
GGTAGCGTCTATATACGTATA
I do this using Groovy, the code for this is:
// Load JSON
// cfg_file is the JSON
def analysis_config = jsonSlurper.parse(cfg_file)
// Create Keyset of "barcodes"
barcodes = Channel.from(analysis_config.barcodes.keySet())
// Create fasta:
new File('barcodes.fasta').withOutputStream { out ->
analysis_config.barcodes.each { barcode ->
def (fname, revname) = barcode.key.split('--')
out << ">$fname\n${barcode.value['For Barcode Sequence']}\n"
out << ">$revname\n${barcode.value['Rev Barcode Sequence']}\n"
}
}
I want to change this logic so that if "genes sequenced" is empty, skip that barcode.
In "0004F--0004R", there are no genes sequenced. How can I implement this logic?
In Python, you could simply do:
if not barcode['genessequenced']:
continue
... and it would skip that barcode. I'm essentially a Python programmer and am using Nextflow which uses Groovy as it's base language. Help would be greatly appreciated.
NOTE
I have a feeling like my entire logic would have to change. The flow currently is:
- Create keySet() of all barcodes
- Populate each with sequences
And the flow should now be: 1. Create keySet() of barcodes with "genes sequenced" 2. Populate each with sequences
So, barcodes = Channel.from(analysis_config.barcodes.keySet())
any idea how I could add that logic into this?
Something like:
barcodes = Channel.from(analysis_config.barcodes.[if "Genes Sequenced"].keySet())