$self is not defined?

Posted in API by Nathaniel Watson Fri May 20 2016 00:33:55 GMT+0000 (UTC)·2·Viewed 1,549 times

Hi, Please explain the use of $self in the Value field of a job input spec. I don't know when and how I can use it. For example, say the ID of my input parameter is called 'quality'. In the JavaScript expression I want to enter in the Value field, it seems I must refer to the parameter as $job.inputs.quality, but I thought I could also do $self.quality. In the documentation at http://docs.cancergenomicscloud.org/docs/dynamic-expressions-in-tool-descriptions#section-the-self-object, it says: """ In the command line bindings for the tool inputs, $self is set to the value of the input. In other words, in this context $self is just $job.inputs.<input_id>. """ According to that documentation, I should be able to use an expression such as "$self || 5" to create a default value of 5. But when doing so, I get this error when trying to run my tool: """ Error This task ran into a problem during execution and did not finish. Failed to start trimgalore. Failed to build command line. Failed to build command line. Failed evaluating expression $self || 20. org.mozilla.javascript.EcmaError: ReferenceError: "$self" is not defined. (script#1). """ So why does it say that $self is not defined?
Erik Lehnert
May 26, 2016

Hi,

The $self variable can be used in dynamic expressions to refer to the variable itself. In your example, $self and $job.inputs.quality should evaluate to the same thing. So, for example, rather than using "$self.quality," you should use "$self" in the dynamic expression for the quality input.

That said, in our current implementation, $self || 5 will not work in the case where there is no input for that input parameter. The input you are getting is because $self is not defined for a parameter if no input parameter is specified. We are going to change this in the future, but in the meantime, we recommend the following.

You can use $self whenever you want to refer to the input parameter itself and it will be defined. However, given this behavior, it will be more robust to use the more explicit "$job.input.quality." You can use this to set the default value by the following:

default = 5
if ($job.inputs.quality) {
return $job.inputs.quality
}
else {
return default
}

Hope this clarified things! Please let me know if you have any more questions.

Nathaniel Watson
May 26, 2016

Thanks for the clarification!

  
Markdown is allowed