# Developer Quickstart

{% hint style="info" %}
This tutorial provides a quick intro to the DNAnexus developer experience, and progresses to building a fully functional, useful app on the Platform. For a more in-depth discussion of the Platform, see [Intro to Building Apps](https://documentation.dnanexus.com/developer/apps/intro-to-building-apps).
{% endhint %}

The steps below require the [DNAnexus SDK](https://documentation.dnanexus.com/downloads). You must download and install it if you have not done so already.

Besides this Quickstart, there are Developer Tutorials located in the sidebar that go over helpful tips for new users as well. A few of them include:

* [Distributed by Chr (sh)](https://documentation.dnanexus.com/getting-started/developer-tutorials/bash/distributed-by-chr-sh)
* [Parallel by Chr (py)](https://documentation.dnanexus.com/getting-started/developer-tutorials/python/parallel-by-chr-py)
* [R Shiny Example Web App](https://documentation.dnanexus.com/getting-started/developer-tutorials/bash/r-shiny-example-web-app)

## Step 1. Build an App

Every DNAnexus app starts with 2 files:

* [`dxapp.json`](https://documentation.dnanexus.com/developer/apps/app-metadata): a file containing the app's metadata: its inputs and outputs, how the app is run, and execution requirements
* a **script** that is executed in the cloud when the app is run

Start by creating a file called `dxapp.json` with the following text:

{% code title="dxapp.json" %}

```json
{ "name": "coolapp",
  "runSpec": {
    "distribution": "Ubuntu",
    "release": "24.04",
    "version": "0",
    "interpreter": "python3",
    "file": "code.py"
  }
}
```

{% endcode %}

The example specifies the app name (`coolapp`), the interpreter (`python3`) to run the script, and the path (`code.py`) to the script created next. (`"version":"0"`) refers to the Ubuntu 24.04 application execution environment version that supports the `python3` interpreter.

Next, create the script in a file called `code.py` with the following text:

{% code title="code.py" %}

```python
import dxpy

@dxpy.entry_point('main')
def main(**kwargs):
    print("Hello, DNAnexus!")
    return {}
```

{% endcode %}

That's all you need. To build the app, first log in to DNAnexus and start a project with `dx login`. In the directory with the two files above, run:

```shell
dx login
dx build -a
```

Next, run the app and watch the output:

```shell
dx run coolapp --watch
```

That's it! You have made and run your first DNAnexus applet. Applets are lightweight apps that live in your project, and are not visible in the [App Library](https://platform.dnanexus.com/apps). When you typed `dx run`, the app ran on its own Linux instance in the cloud. You have exclusive, secure access to the CPU, storage, and memory on the instance. The [DNAnexus API](https://documentation.dnanexus.com/developer/api) lets your app read and write data on the Platform, as well as launch other apps.

The app is available in the DNAnexus web interface, as part of the project that you started. It can be configured and run in the Workflow Builder, or shared with other users by sharing the project.

## Step 2. Run BLAST

Next, make the app do something a bit more interesting: take in two files with [FASTA](https://en.wikipedia.org/wiki/FASTA_format)-formatted DNA, run the [BLAST](https://blast.ncbi.nlm.nih.gov/Blast.cgi) tool to compare them, and output the result.

In the cloud, your app runs on [Ubuntu Linux](https://ubuntu.com/) [24.04](https://releases.ubuntu.com/24.04/), where BLAST is available as an APT package, `ncbi-blast+`. You can request that the DNAnexus [execution environment](https://documentation.dnanexus.com/developer/apps/execution-environment) install it before your script is run by listing `ncbi-blast+` in the `execDepends` field of your `dxapp.json` like this:

{% code title="dxapp.json" %}

```json
{ "name": "coolapp",
  "runSpec": {
    "distribution": "Ubuntu",
    "release": "24.04",
    "version": "0",
    "interpreter": "python3",
    "file": "code.py",
    "execDepends": [ {"name": "ncbi-blast+"} ]
  }
}
```

{% endcode %}

Next, update `code.py` to run BLAST:

{% code title="code.py" %}

```python
import dxpy, subprocess

@dxpy.entry_point('main')
def main(seq1, seq2):
    dxpy.download_dxfile(seq1, "seq1.fasta")
    dxpy.download_dxfile(seq2, "seq2.fasta")

    subprocess.call("blastn -query seq1.fasta -subject seq2.fasta > report.txt", shell=True)

    report = dxpy.upload_local_file("report.txt")
    return {"blast_result": report}
```

{% endcode %}

Rebuild the app and test it on some real data. You can use demo inputs available in the [Demo Data](https://platform.dnanexus.com/panx/projects/BQbJpBj0bvygyQxgQ1800Jkk/data) project, or you can upload your own data with `dx upload` or via the website. If you use the Demo Data inputs, make sure the project you are running your app in is the same region as the Demo Data project.

Rebuild the app with `dx build -a`, and run it like this:

```shell
dx run coolapp \
  -i seq1="Demo Data:/Developer Quickstart/NC_000868.fasta" \
  -i seq2="Demo Data:/Developer Quickstart/NC_001422.fasta" \
  --watch
```

Once the job is done, you can examine the output with `dx head report.txt`, download it with `dx download`, or view it on the website.

## Step 3. Provide an Input/Output Spec

[Workflows](https://documentation.dnanexus.com/developer/workflows) are a powerful way to visually connect, configure, and run multiple apps in pipelines. To add the app to a workflow and connect its inputs and outputs to other apps, specify both [input and output specifications](https://documentation.dnanexus.com/developer/api/running-analyses/io-and-run-specifications). Update the `dxapp.json` as follows:

{% code title="dxapp.json" %}

```json
{
  "name": "coolapp",
  "runSpec": {
    "distribution": "Ubuntu",
    "release": "24.04",
    "version": "0",
    "interpreter": "python3",
    "file": "code.py",
    "execDepends": [ {"name": "ncbi-blast+"} ]
  },
  "inputSpec": [
    {"name": "seq1", "class": "file"},
    {"name": "seq2", "class": "file"}
  ],
  "outputSpec": [
    {"name": "blast_result", "class": "file"}
  ]
}
```

{% endcode %}

Rebuild the app with `dx build -a`. Run it as before, and add the applet to a workflow by clicking "New Workflow" while viewing your project on the website, then click `coolapp` once to add it to the workflow. Inputs and outputs appear on the workflow stage and can be connected to other stages.

If you run `dx run coolapp` with no input arguments from the command line, the command prompts for the input values for `seq1` and `seq2`.

## Step 4. Configure App Settings

Besides specifying input files, the I/O specification can also configure settings the app uses. For example, configure the **E-value** setting and other BLAST settings with this code and `dxapp.json`:

{% code title="code.py" %}

```python
import dxpy, subprocess

@dxpy.entry_point('main')
def main(seq1, seq2, evalue, blast_args):
    dxpy.download_dxfile(seq1, "seq1.fasta")
    dxpy.download_dxfile(seq2, "seq2.fasta")

    command = "blastn -query seq1.fasta -subject seq2.fasta -evalue {e} {args} > report.txt".format(e=evalue, args=blast_args)
    subprocess.call(command, shell=True)

    report = dxpy.upload_local_file("report.txt")
    return {"blast_result": report}
```

{% endcode %}

{% code title="dxapp.json" %}

```json
{
  "name": "coolapp",
  "runSpec": {
    "distribution": "Ubuntu",
    "release": "24.04",
    "version": "0",
    "interpreter": "python3",
    "file": "code.py",
    "execDepends": [ {"name": "ncbi-blast+"} ]
  },
  "inputSpec": [
    {"name": "seq1", "class": "file"},
    {"name": "seq2", "class": "file"},
    {"name": "evalue", "class": "float", "default": 0.01},
    {"name": "blast_args", "class": "string", "default": ""}
  ],
  "outputSpec": [
    {"name": "blast_result", "class": "file"}
  ]
}
```

{% endcode %}

Rebuild the app again and add it in the workflow builder. You should see the `evalue` and `blast_args` settings available when you click the gear button on the stage. After building and configuring a workflow, you can run the workflow itself with `dx run workflowname`.

## Step 5. Use SDK Tools

One of the utilities provided in the SDK is `dx-app-wizard`. This tool prompts you with a series of questions with which it creates the basic files needed for a new app. It also gives you the option of writing your app as a bash shell script instead of Python. Run `dx-app-wizard` to try it out.

## Learn More

For additional information and examples of how to run jobs using the CLI, see [Working with files using `dx run`](https://laderast.github.io/bash_for_dnanexus/04-doing-work-with-dx-run.html) may be useful. This material is not a part of the official DNAnexus documentation and is for reference only.
