#!/bin/bash
# idr2_test 0.0.1
# Generated by dx-app-wizard.
#
# Basic execution pattern: Your app will run on a single machine from
# beginning to end.
#
# Your job's input variables (if any) will be loaded as environment
# variables before this script runs.  Any array inputs will be loaded
# as bash arrays.
#
# Any code outside of main() (or any entry point you may add) is
# ALWAYS executed, followed by running the entry point itself.
#
# See https://wiki.dnanexus.com/Developer-Portal for tutorials on how
# to modify this file.

main() {

    echo "Value of rep1_peaks: '$rep1_peaks'"
    echo "Value of rep2_peaks: '$rep2_peaks'"
    echo "Value of pooled_peaks: '$pooled_peaks'"
    echo "Value of outfile_prefix: '$outfile_prefix'"
    echo "Value of ranking_measure: '$ranking_measure'"

    # The following line(s) use the dx command-line tool to download your file
    # inputs to the local file system using variable names for the filenames. To
    # recover the original filenames, you can use the output of "dx describe
    # "$variable" --name".

    dx download "$rep1_peaks" -o rep1_peaks
    dx download "$rep2_peaks" -o rep2_peaks
    dx download "$pooled_peaks" -o pooled_peaks

    idr --version
    idr --samples rep1_peaks rep2_peaks --plot --output-file IDR_test.narrowPeak --log-output-file IDR_test-out.txt

    log_file=$(dx upload log_file --brief)
    output_file=$(dx upload output_file --brief)
    plot_file=$(dx upload plot_file --brief)

    # The following line(s) use the utility dx-jobutil-add-output to format and
    # add output variables to your job's output as appropriate for the output
    # class.  Run "dx-jobutil-add-output -h" for more information on what it
    # does.

    dx-jobutil-add-output log_file "$log_file" --class=file
    dx-jobutil-add-output output_file "$output_file" --class=file
    dx-jobutil-add-output plot_file "$plot_file" --class=file
}
