Bash apps are the simplest apps you can create on DNAnexus. They include a shell script which runs on a virtual machine on the cloud. The script, written by the app developer, is responsible for downloading inputs, processing, and uploading outputs.
There are two ways to download inputs: one by one, or all at once.
To download all inputs at once (recommended), use the
"dx-download-all-inputs" utility. Add
"--parallel" to allow multiple downloads in parallel.
Inputs are downloaded to a folder called "in" under the home folder. Each input is placed under its own subfolder
"~/in/name_of_input_field/", named after the input field. Files retain their original filenames as supplied by the user who launched the applet.
For example, if your applet defines a file input called "mappings" and a user runs it with a file called
"SRR001.bam", it will be downloaded into
The system defines the following helper bash variables, which you can use in your applet:
NOTE: The variable
$mappings_prefixis a bash array of filenames of every file in the file array with the extension stripped off, as well as any
.gzextension (if applicable). File extension is picked from
patternsand should specified in the dxapp.json file.
To download inputs one by one, use the following syntax:
dx download "$name_of_input_field"
This will download the file to the current working directory. It will retain the original file as supplied by the user who launched the applet. You can use the
"$xxxxxx_name" variable (as shown in the table above) to refer to that filename.
To name the local file using a different name than the original filename, use the following syntax:
dx download "$name_of_input_field" -o local_filename
To stream the local file and pipe it to another command, use the following syntax:
dx cat "$name_of_input_field" | command
You can combine these strategies. You can download or stream some inputs one by one, and the rest all at once, using the following syntax:
dx-download-all-inputs --except name_of_input_field1 --except name_of_input_field2
dx download "$name_of_input_field1"
dx cat "$name_of_input_field2" | command
There are two ways to upload outputs: one by one, or all at once.
To upload outputs one by one, use the following syntax:
id=$(dx upload /path/to/local/file --brief)
dx-jobutil-add-output name_of_output_field "$id"
If you would like the uploaded file to have a different name than the local file, add the following to the dx upload command:
If you would like the uploaded file to appear under a subfolder in the applet outputs, add the following to the dx upload command:
--path /subfolder/remote_filename --parents
If you would like the uploaded file to contain metadata, for example set a property (key/value pair), add the following to the dx upload command:
To upload all outputs at once, create a folder "out" under the home folder, and create a subfolder named after each output field. Place a file under each subfolder, and call the "dx-upload-all-outputs" utility:
mkdir -p ~/out/name_of_output_field1/ ~/out/name_of_output_field2/
mv file1 ~/out/name_of_output_field1/
mv file2 ~/out/name_of_output_field2/
If you would like any uploaded file to have a different name than the local file, rename them as you move them:
mv file1 ~/out/name_of_output_field1/renamed_file1
If you would like any uploaded file to appear under a subfolder in the applet outputs, create the subfolder like this:
mkdir -p ~/out/name_of_output_field1/subfolder/
mv file1 ~/out/name_of_output_field1/subfolder/
If you would like the uploaded files to contain metadata, for example set a property (key/value pair), make the following changes:
Install the "attr" Linux executable by specifying the "attr" Ubuntu package in your 'dxapp.json'.
For each file, and for each key/value pair you would like to attach, set the respective Linux extended file system attribute like this:
attr -s key -V value ~/out/name_of_output_field1/file1
"--xattr-properties" to the dx-upload-all-outputs invocation: