Command Line Client/Example Scripts

Upload local reads files

The following script prompts the user to log in interactively and select a project for which she has at least CONTRIBUTE permission. The script will then sequentially upload each of the files given as arguments and print out the DNAnexus file-id associated with each uploaded file.

#!/usr/bin/env bash

# Log in
dx login

for file in $@
do
    echo "Uploading $file..."
    fileid=$(dx upload $file --brief --wait)
    echo "Uploaded file $file.  File-id is $fileid"
done
Note: In practice, you will probably want to replace the above script with an invocation of the Upload Agent, giving it as arguments a list of your local files.

Map reads, call variants, and export to a VCF file

The following script prompts the user to log in interactively and select a destination project for which she has at least CONTRIBUTE permission. It expects as arguments either object IDs or paths to the reference genome, a pre-computed index of the reference genome for BWA-MEM, and the reads that will be analyzed. The script will run the necessary jobs to map the reads and call variants on the resulting mappings using Freebayes.

Once the VCF file is ready, it will then be downloaded from the DNAnexus platform to the user's local filesystem.

#!/usr/bin/env bash

if [ $# -lt 3 ]
then
    echo "Usage: $0 reference_path BWA_indexed_reference_path fwd_reads_path rev_reads_path" >&2
    exit 1
fi

# Log in
dx login

reference=$1
bwa_indexed_reference=$2
reads=$3
if [ -n "$4" ]
then
  paired_reads=-ireads2_fastqgz=$4
else
  paired_reads=" "
fi

# Run the apps serially using job-based object references
bwa_job=$(dx run bwa_mem_fastq_read_mapper -igenomeindex_targz="$bwa_indexed_reference" -ireads_fastqgz="$reads" $paired_reads -y --brief)
echo "Running BWA: $bwa_job"
freebayes_job=$(dx run freebayes -igenome_fastagz="$reference" -isorted_bams=$bwa_job:sorted_bam -y --brief)
echo "Running freebayes: $freebayes_job"

# Wait for the last job to finish
dx wait $freebayes_job

# Download the resulting VCF file
dx download $freebayes_job:variants_vcfgz

Last edited by godotgildor, 2014-10-29 22:23:38

 Feedback