12.2 Modifying the App:

The app produced by the wizard is very minimal, it doesn’t actually DO anything.

ls ./ex/findNi/
## dxapp.json
## findNi_original
## Readme.developer.md
## Readme.md
## resources
## src
## test
ls ./ex/findNi/src
## findNi.sh

The main files that you will need to modify are the dxapp.json file:

cat ./ex/findNi/dxapp.json
## {
##   "name": "findNi",
##   "title": "Find Ni",
##   "summary": "Finds words that begin with ni",
##   "dxapi": "1.0.0",
##   "version": "0.0.1",
##   "inputSpec": [
##     {
##       "name": "wordsFile",
##       "label": "File of all words",
##       "class": "file",
##       "optional": false,
##       "patterns": [
##         "*"
##       ],
##       "help": ""
##     }
##   ],
##   "outputSpec": [
##     {
##       "name": "outfile",
##       "label": "Output file of words",
##       "class": "file",
##       "patterns": [
##         "*"
##       ],
##       "help": ""
##     }
##   ],
##   "runSpec": {
##     "timeoutPolicy": {
##       "*": {
##         "hours": 48
##       }
##     },
##     "interpreter": "bash",
##     "release": "16.04",
##     "distribution": "Ubuntu",
##     "file": "src/findNi.sh",
##     "execDepends": [
##         {"name": "openjdk-8-jre-headless",
##          "package_manager": "apt"},
## 
##         {"name": "tabix",
##          "package_manager": "apt"}
##     ]
##   },
##   "regionalOptions": {
##     "aws:us-east-1": {
##       "systemRequirements": {
##         "*": {
##           "instanceType": "mem1_ssd1_x4"
##         }
##       }
##     }
##   }
## }

and also the bash script in the src directory:

cat ./ex/findNi/src/findNi.sh
## #!/bin/bash
## # helloWorldTestApp 0.0.2
## 
## main() {
## 
##     #First, let's print out the input file, to make sure the inputs 
##     # got set properly:
##     echo "Value of wordsFile: '$wordsFile'"
##     echo "Value of wordsFile_name: $wordsFile_name"
##     
##     #Next let's download the words file from the cloud and into
##     # our virtual machine.
##     dx download "$wordsFile" -o $wordsFile_name
## 
##     #This part is the program itself. It takes the input and grabs 
##     # all the words that begin with Ni
##     cat $wordsFile_name | grep "^ni" > words.that.begin.with.ni.txt
## 
##     #This part uploads the resultant file to the cloud
##     # If you don't do this, then all the files you made will be 
##     # deleted when the virtual machine gets shut down.
##     #Note: dx upload --brief returns a file code that 
##     # the next tool needs in order to register the output.
##     outfile_dx_code=$(dx upload words.that.begin.with.ni.txt --brief)
## 
##     #Finally: this part registers the output and connects it to this job
##     # That way the output will be accessable from the job screen.
##     dx-jobutil-add-output outfile "$outfile_dx_code" --class=file
## 
## 
## }

I have already generated new versions of these files.

For the json file, I just added some dependencies just to show how one would do that. In this case I told the VM to install tabix and openJDK. Note: I don’t actually need them in this example.

cp ../examples/files/dxapp.v2.json ./ex/findNi/dxapp.json
cat ./ex/findNi/dxapp.json
## {
##   "name": "findNi",
##   "title": "Find Ni",
##   "summary": "Finds words that begin with ni",
##   "dxapi": "1.0.0",
##   "version": "0.0.1",
##   "inputSpec": [
##     {
##       "name": "wordsFile",
##       "label": "File of all words",
##       "class": "file",
##       "optional": false,
##       "patterns": [
##         "*"
##       ],
##       "help": ""
##     }
##   ],
##   "outputSpec": [
##     {
##       "name": "outfile",
##       "label": "Output file of words",
##       "class": "file",
##       "patterns": [
##         "*"
##       ],
##       "help": ""
##     }
##   ],
##   "runSpec": {
##     "timeoutPolicy": {
##       "*": {
##         "hours": 48
##       }
##     },
##     "interpreter": "bash",
##     "release": "16.04",
##     "distribution": "Ubuntu",
##     "file": "src/findNi.sh",
##     "execDepends": [
##         {"name": "openjdk-8-jre-headless",
##          "package_manager": "apt"},
## 
##         {"name": "tabix",
##          "package_manager": "apt"}
##     ]
##   },
##   "regionalOptions": {
##     "aws:us-east-1": {
##       "systemRequirements": {
##         "*": {
##           "instanceType": "mem1_ssd1_x4"
##         }
##       }
##     }
##   }
## }

Next we write the script itself. The main function gets executed once the virtual machine is spun up and everything is installed and prepped. Note that it sets a bunch of environment variables that link to the input files.

The program below runs through the provided words file and returns a file containing all the words that begin with “ni”.

cp ../examples/files/findNi.v2.bash ./ex/findNi/src/findNi.sh
cat ./ex/findNi/src/findNi.sh
## #!/bin/bash
## # helloWorldTestApp 0.0.2
## 
## main() {
## 
##     #First, let's print out the input file, to make sure the inputs 
##     # got set properly:
##     echo "Value of wordsFile: '$wordsFile'"
##     echo "Value of wordsFile_name: $wordsFile_name"
##     
##     #Next let's download the words file from the cloud and into
##     # our virtual machine.
##     dx download "$wordsFile" -o $wordsFile_name
## 
##     #This part is the program itself. It takes the input and grabs 
##     # all the words that begin with Ni
##     cat $wordsFile_name | grep "^ni" > words.that.begin.with.ni.txt
## 
##     #This part uploads the resultant file to the cloud
##     # If you don't do this, then all the files you made will be 
##     # deleted when the virtual machine gets shut down.
##     #Note: dx upload --brief returns a file code that 
##     # the next tool needs in order to register the output.
##     outfile_dx_code=$(dx upload words.that.begin.with.ni.txt --brief)
## 
##     #Finally: this part registers the output and connects it to this job
##     # That way the output will be accessable from the job screen.
##     dx-jobutil-add-output outfile "$outfile_dx_code" --class=file
## 
## 
## }