Re: help on using map in the script section

20 views
Skip to first unread message
Message has been deleted
Message has been deleted

Paolo Di Tommaso

unread,
Jun 25, 2018, 1:20:33 PM6/25/18
to nextflow

The error reports `Unknown variable '$sampleName'` because that variable is defined nowhere in your code. 


p


On Mon, Jun 25, 2018 at 9:57 AM, Kemin Zhou <kem...@gmail.com> wrote:


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 it

Spend 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.

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Paolo Di Tommaso

unread,
Jun 25, 2018, 2:55:36 PM6/25/18
to nextflow
Have you taken in consideration that a discussion group is not a chat? and people receiving notifications may be annoyed by all these messages providing no constructive discussion. 

As moderator of this group I'm considering to ban your messages that does not provide a self-contained question or error report, that is:
  1. a complete example that anybody can copy, paste and execute 
  2. the complete program output  
  3. the expected behaviour
  4. the actual behaviour


Regards 
Paolo






On Mon, Jun 25, 2018 at 11:33 AM, Kemin Zhou <kem...@gmail.com> wrote:
More testing results:

  
 String key = new String("NTC_20180516AW01")
   println s2p
[key]
   key
= new String(sampleName)
   println s2p
[key]
   println s2p
[sampleName]


62
null
null
If 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.





Reply all
Reply to author
Forward
Message has been deleted
0 new messages