SAMtools count
View full source code on GitHub
This applet performs a basic samtools view -c {bam} command, referred to as "SAMtools count", on the DNAnexus Platform.
Download BAM Files
For bash scripts, inputs to a job execution become environment variables. The inputs from the dxapp.json file are formatted as shown below:
{
"inputSpec": [
{
"name": "mappings_bam",
"label": "Mapping",
"class": "file",
"patterns": ["*.bam"],
"help": "BAM format file."
}
]
}The object mappings_bam, a DNAnexus link containing the file ID of that file, is available as an environmental variable in the applet's execution. Use the command dx download to download the BAM file. By default, downloading a file preserves the filename of the object on the platform.
dx download "${mappings_bam}"SAMtools Count
Use the bash helper variable mappings_bam_name for file inputs. For these inputs, the DNAnexus Platform creates a bash variable [VARIABLE]_name that holds the platform filename. Because the file was downloaded with default parameters, the worker filename matches the platform filename. The helper variable [VARIABLE]_prefix contains the filename minus any suffixes specified in the input field patterns (for example, the platform removes the trailing .bam to create [VARIABLE]_prefix).
readcount=$(samtools view -c "${mappings_bam_name}")
echo "Total reads: ${readcount}" > "${mappings_bam_prefix}.txt"Upload Result
Use dx upload command to upload data to the platform. This uploads the file into the job container, a temporary project that holds onto files associated with the job. When running the command dx upload with the flag --brief, the command returns only the file ID.
counts_txt_id=$(dx upload "${mappings_bam_prefix}.txt" --brief)Job containers are an integral part of the execution process. To learn more see Containers for Execution.
Associate With Output
The output of an applet must be declared before the applet is even built. Looking back to the dxapp.json file, you see the following:
{
"name": "counts_txt",
"class": "file",
"label": "Read count file",
"patterns": [
"*.txt"
],
"help": "Output file with Total reads as the first line."
}The applet declares a file type output named counts_txt. In the applet script, specify which file should be associated with the output counts_txt. On job completion, this file is copied from the temporary job container to the project that launched the job.
dx-jobutil-add-output counts_txt "${counts_txt_id}" --class=fileLast updated
Was this helpful?