{"__v":0,"_id":"5819c88208e04c2300fdc22b","category":{"project":"55faf11ba62ba1170021a9a7","version":"55faf11ba62ba1170021a9aa","_id":"57ff5c5dc135231700aed806","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-10-13T10:05:17.381Z","from_sync":false,"order":15,"slug":"tool-wrapping-troubleshooting","title":"TOOL WRAPPING TIPS AND TRICKS"},"parentDoc":null,"project":"55faf11ba62ba1170021a9a7","user":"5767bc73bb15f40e00a28777","version":{"__v":35,"_id":"55faf11ba62ba1170021a9aa","project":"55faf11ba62ba1170021a9a7","createdAt":"2015-09-17T16:58:03.490Z","releaseDate":"2015-09-17T16:58:03.490Z","categories":["55faf11ca62ba1170021a9ab","55faf8f4d0e22017005b8272","55faf91aa62ba1170021a9b5","55faf929a8a7770d00c2c0bd","55faf932a8a7770d00c2c0bf","55faf94b17b9d00d00969f47","55faf958d0e22017005b8274","55faf95fa8a7770d00c2c0c0","55faf96917b9d00d00969f48","55faf970a8a7770d00c2c0c1","55faf98c825d5f19001fa3a6","55faf99aa62ba1170021a9b8","55faf99fa62ba1170021a9b9","55faf9aa17b9d00d00969f49","55faf9b6a8a7770d00c2c0c3","55faf9bda62ba1170021a9ba","5604570090ee490d00440551","5637e8b2fbe1c50d008cb078","5649bb624fa1460d00780add","5671974d1b6b730d008b4823","5671979d60c8e70d006c9760","568e8eef70ca1f0d0035808e","56d0a2081ecc471500f1795e","56d4a0adde40c70b00823ea3","56d96b03dd90610b00270849","56fbb83d8f21c817002af880","573c811bee2b3b2200422be1","576bc92afb62dd20001cda85","5771811e27a5c20e00030dcd","5785191af3a10c0e009b75b0","57bdf84d5d48411900cd8dc0","57ff5c5dc135231700aed806","5804caf792398f0f00e77521","58458b4fba4f1c0f009692bb","586d3c287c6b5b2300c05055"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-11-02T11:05:38.944Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"On this page, we will explain how to wrap your tool so that it takes a particular input value as a default, in the case that no other value is provided to that input port.\n\nYou may have noticed that [a field entitled **Tool Default**](doc:tool-input-ports#section-additional-information) is available for all non-file inputs on the **Inputs** tab of the Tool Editor. This field is descriptive only: it is used to provide information on what the default value is, but does not actually set the value. However, you can use dynamic expressions in the form of 'if' statements to set the default value for an input port that will be used by the tool if no value is entered to port in question at runtime. To illustrate how a default value is defined, we will use the app **GATK VariantRecalibrator** as an example. This app is available as a public tool on the CGC, and has been wrapped to include a default input value for the input port **use_annotation**.\n\nExamine the **use_annotation** port for **GATK VariantRecalibrator** in the Tool Editor:\n1. Search for **GATK VariantRecalibrator** in the **Public Apps** and copy it to one of your projects.\n2. Navigate to the **Apps** tab in the project you added the app to, and click the pencil icon <img src=\"https://files.readme.io/65a7b9e-icon-edit-transp.png\"\nheight=\"15px\" width=\"auto\" align=\"inline\" style=\"margin:1px\"/> next to the app name. This opens the Tool Editor.\n\nWhen you open **GATK VariantRecalibrator** in the Tool Editor, on the **Inputs** tab you will find an input port whose ID is **use_annotation**. This input port takes an array of strings that contains the names of the annotations that should be used for calculations. When you click the pencil icon <img src=\"https://files.readme.io/65a7b9e-icon-edit-transp.png\"\nheight=\"15px\" width=\"auto\" align=\"inline\" style=\"margin:1px\"/> to edit this input port's properties, the **Value** field contains the following expression:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  if ($job.inputs.use_annotation.length == 0){\\n    return ['QD', 'MQRankSum', 'FS', 'DP', 'ReadPosRankSum', 'HaplotypeScore']\\n  }\\n  else\\n    return $job.inputs.use_annotation\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThe expression works as follows:\n1. The `if` statement checks if there is any input value for the input port whose ID is **use_annotation**:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"if ($job.inputs.use_annotation.length == 0)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n2. If nothing has been entered to that port for the particular job being executed, the following array of strings is assigned as the value:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"return ['QD', 'MQRankSum', 'FS', 'DP', 'ReadPosRankSum', 'HaplotypeScore']\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThese strings are hard-coded as the default values for the input port.\n \n3. If values have been entered for the **use_annotation** input port, then those values are used:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"return $job.inputs.use_annotation\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nYou can adjust this dynamic expression to match the name and type of your input port by:\n* Replacing the two occurrences of **use_annotation** with the ID of your input port.\n* Replacing the array of strings on line 3 of the expression with value(s) appropriate for your input port. The entered value(s) will be used as the default if no other value is provided at runtime.","excerpt":"","slug":"set-the-default-value-for-an-input-port","type":"basic","title":"Set the default value for an input port"}

Set the default value for an input port


On this page, we will explain how to wrap your tool so that it takes a particular input value as a default, in the case that no other value is provided to that input port. You may have noticed that [a field entitled **Tool Default**](doc:tool-input-ports#section-additional-information) is available for all non-file inputs on the **Inputs** tab of the Tool Editor. This field is descriptive only: it is used to provide information on what the default value is, but does not actually set the value. However, you can use dynamic expressions in the form of 'if' statements to set the default value for an input port that will be used by the tool if no value is entered to port in question at runtime. To illustrate how a default value is defined, we will use the app **GATK VariantRecalibrator** as an example. This app is available as a public tool on the CGC, and has been wrapped to include a default input value for the input port **use_annotation**. Examine the **use_annotation** port for **GATK VariantRecalibrator** in the Tool Editor: 1. Search for **GATK VariantRecalibrator** in the **Public Apps** and copy it to one of your projects. 2. Navigate to the **Apps** tab in the project you added the app to, and click the pencil icon <img src="https://files.readme.io/65a7b9e-icon-edit-transp.png" height="15px" width="auto" align="inline" style="margin:1px"/> next to the app name. This opens the Tool Editor. When you open **GATK VariantRecalibrator** in the Tool Editor, on the **Inputs** tab you will find an input port whose ID is **use_annotation**. This input port takes an array of strings that contains the names of the annotations that should be used for calculations. When you click the pencil icon <img src="https://files.readme.io/65a7b9e-icon-edit-transp.png" height="15px" width="auto" align="inline" style="margin:1px"/> to edit this input port's properties, the **Value** field contains the following expression: [block:code] { "codes": [ { "code": "{\n if ($job.inputs.use_annotation.length == 0){\n return ['QD', 'MQRankSum', 'FS', 'DP', 'ReadPosRankSum', 'HaplotypeScore']\n }\n else\n return $job.inputs.use_annotation\n}", "language": "javascript" } ] } [/block] The expression works as follows: 1. The `if` statement checks if there is any input value for the input port whose ID is **use_annotation**: [block:code] { "codes": [ { "code": "if ($job.inputs.use_annotation.length == 0)", "language": "javascript" } ] } [/block] 2. If nothing has been entered to that port for the particular job being executed, the following array of strings is assigned as the value: [block:code] { "codes": [ { "code": "return ['QD', 'MQRankSum', 'FS', 'DP', 'ReadPosRankSum', 'HaplotypeScore']", "language": "javascript" } ] } [/block] These strings are hard-coded as the default values for the input port. 3. If values have been entered for the **use_annotation** input port, then those values are used: [block:code] { "codes": [ { "code": "return $job.inputs.use_annotation", "language": "javascript" } ] } [/block] You can adjust this dynamic expression to match the name and type of your input port by: * Replacing the two occurrences of **use_annotation** with the ID of your input port. * Replacing the array of strings on line 3 of the expression with value(s) appropriate for your input port. The entered value(s) will be used as the default if no other value is provided at runtime.