On Sunday, June 24, 2018 at 10:14:39 PM UTC-7, Kemin Zhou wrote:I have been trying to use map in he script section. Could not get any documentation for how to use it properly. I am getting null values.80 script:
81 sample2poolid = loadLookup(sampletab.toString())
82 //println "${sampleName} ${sample2poolid[${sampleName}]}"
83 poolid=sample2poolid[sampleName]
84 println "${poolid}"
I tried various combinations with curly bracket, dollar signs. So far nothing worked.
Must be some silly mistake on my part. I can print out the map sample2poolid without any problem.
Currently poolid is null.
More testings:
def allLines = sampletab.readLines()
allLines.remove(0)
def s2p = [:]
for (def ln : allLines) {
def row = ln.split("\t")
s2p[row[1]]=row[2]
}
s2p.each { entry ->
println "sample: $entry.key => poolid: $entry.value"
}
xx=s2p["NTC_20180516AW01"]
yy=s2p.NTC_20180516AW01
//def poolid=s2p[(sampleName)] // return null
//def poolid=s2p[${sampleName}] // syntax error
//def poolid=s2p["${sampleName}"] // return null
//def poolid=s2p["$sampleName"] // return null
//def poolid=s2p[$sampleName] // Unknown variable '$sampleName' -- Make sure you didn't misspell it or define somewhere in the script before use it
println "$sampleName ${poolid} $xx $yy"sample: H000362 => poolid: 22
sample: H000408 => poolid: 21
sample: P000248 => poolid: 25
sample: P000605 => poolid: 26
sample: P000606 => poolid: 27
sample: P000686 => poolid: 57
sample: P000684 => poolid: 55
sample: P000687 => poolid: 58
sample: NTC_20180516AW01 => poolid: 62
sample: Panel_1_1b => poolid: 53
sample: Panel_1_40b => poolid: 56
sample: Panel_1_400b => poolid: 59
sample: Panel_1_1000 => poolid: 60
ERROR ~ Error executing process > 'correctBarcode (1)'
Caused by:
Unknown variable '$sampleName' -- Make sure you didn't misspell it or define somewhere in the script before use itSpend two days without any progress on map.xx yy prints out expected results. Just cannot use variables for map.--
You received this message because you are subscribed to the Google Groups "Nextflow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nextflow+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/nextflow.
For more options, visit https://groups.google.com/d/optout.
More testing results:String key = new String("NTC_20180516AW01")
println s2p[key]
key = new String(sampleName)
println s2p[key]
println s2p[sampleName]
62
null
nullIf you construct key from literal java String, then the map returns proper value, any time you use a variable which has the same value, it returns null.Is it possible that I got some hidden characters in the sampleName variable?
On Sunday, June 24, 2018 at 10:14:39 PM UTC-7, Kemin Zhou wrote:I have been trying to use map in he script section. Could not get any documentation for how to use it properly. I am getting null values.80 script:
81 sample2poolid = loadLookup(sampletab.toString())
82 //println "${sampleName} ${sample2poolid[${sampleName}]}"
83 poolid=sample2poolid[sampleName]
84 println "${poolid}"
I tried various combinations with curly bracket, dollar signs. So far nothing worked.
Must be some silly mistake on my part. I can print out the map sample2poolid without any problem.
Currently poolid is null.