Creating Your First Application (Video Tutorial)


Introduction

This tutorial shows you how to build your first application on BioLib. It is designed as a video tutorial, so you should follow the steps in this video.

BioLib Video Tutorial

You do not need to write any code in this tutorial.

All the code you need will be supplied for you to copy and paste.

In total the tutorial takes 15 minutes to complete - so you will probably be able to make it in 12.

Before you start:

  1. Open the tutorial video in a separate tab - it will guide you

through each of the subsequent steps.

  1. You need to be signed in to your BioLib account to build applications. If you do not have an account yet, you can create a free account here.

The mission:

The goal in this tutorial is to turn a Python 3 script for plotting heat-maps into a user-friendly application that runs directly in the browser, requires no coding by the end-user to use, and can be used by scientist from anywhere in the world without them having to worry about dependencies.

Step 1 - Create Application using Python Template

To-do list:

  • Press Create Application (Remember, you need to be signed in!)
  • Choose the Python template

Continue to Step 2.

Step 2 - Add Code

To-do list:

  • Add your code (hint: just copy-paste the code from below) and set Module settings
  • Under advanced settings, set output to Markdown

The Code (copy and paste this)

Simply, copy-paste the code following into the __main__.py file under source files. In the Modules settings, the bl-python3: executor should already have been autoselected under the type option for the main module.

import pandas as pd
import seaborn as sns;
sns.set(color_codes=True)
import matplotlib.pyplot as plt
import argparse

# utility function to parse csv from binary on BioLib

def format_data_from_csv_buffer(infile, index=0, separator=','):
    data = pd.read_table(infile, sep=separator)
    data.rename(columns={data.columns[index]: "sample"}, inplace=True) # Change the labels column name
    labels = data.pop("sample")
    return data, labels

def generate_heatmap(data, labels, color):
    heatmap_object = sns.heatmap(data, cmap=color, yticklabels=labels, cbar_kws={'label': 'Expression level'})
    heatmap_object.figure.tight_layout()
    plt.savefig("my_heatmap.png")

# Load input parameter, or use default if none provided
# index of the labels column in the file
parser = argparse.ArgumentParser()
parser.add_argument('--in', dest='infile')
parser.add_argument('--index', dest='index')
parser.add_argument('--separator', dest='separator')
parser.add_argument('--color', dest='color', default='magma')
args = parser.parse_args()
color = args.color

# Load input data
data,labels = format_data_from_csv_buffer(args.infile, index=int(args.index), separator=args.separator)

# Generate output
generate_heatmap(data, labels, color)

# Produce Markdown
print("![Markdown Picture Alt Text](my_heatmap.png)")

Step 3 Configuring Input Arguments

Next up is configuring the input arguments. This is where you define the options that the end-user of the application will be presented with when running the application, and how their choices or inputs will be passed to your script.

The "in" input argument should be configured like this:

input file BioLib

The "index" input argument should be configured like this:

index input argument BioLib

The "separator" input argument should be configured like this:

separator input argument BioLib tutorial

The "color" input argument should be configured like this:

color scheme argument BioLib tutorial

Step 4 - Description and License

To-do list:

  • Edit the README file and add example input
  • Edit License
  • Change the name of your application under the "App Settings"
  • View the application page

Example data (copy and paste when running your application)

"Symbol","adrenalgland","brain","heart","kidney","liver","lung","lymphnode","pancreas","prostate","placenta","salivarygland","muscle","testis","thymus"
"ABCD1",76,64,473,374,355,537.5,522,463,511,622,390,478,799,512
"APC",80,57,531,622.5,410,655,580,421,478,318,724,817,678,588
"FAS",99,54,286,482.5,410,1466.5,1168,87,493,515,1099,393,499,326
"ARSB",68,71,559,1046.5,376,633.5,513,478,398,636,322,444,527,352
"ASL",56,51,247,1162.5,2536.5,735,429,638,479,304,514,205,399,305
"ASPA",72,37,236,1881,248.5,553.5,287,185,233,88,42,569,376,34
"ATM",71,72,312,561,493.5,717.5,1884,692,581,467,1255,307,633,1259
"ATP7A",47,26,178,353.5,272,495.5,388,215,394,245,382,189,248,418
"ATP7B",11,30,145,250.5,299.5,224,174,185,279,299,194,131,645,150
"AVPR2",46,55,385,393.5,161.5,490.5,506,399,323,435,306,157,333,578
"BCHE",65,63,219,169.5,2112.5,1124,112,107,252,39,101,156,224,196
"BCKDHB",74,75,897,341,835,423,648,675,183,53,1317,119,356,404
"BLM",5,22,111,125,225.5,81.5,293,10,36,354,774,121,360,122
"BRCA2",97,60,12,62,159,52,70,2,15,339,279,35,386,96
"BTK",54,36,95,168,487,964.5,1844,33,55,617,537,117,182,378
"C8B",75,44,4,35.5,1711.5,102.5,20,6,10,83,62,24,102,47
"CA2",91,24,330,1223,1352.5,870,383,763,311,569,351,1104,1114,1472
"CBS",85,94,335,521.5,1261.5,463.5,514,1529,417,864,765,289,431,612
"CD40LG",21,45,61,60,159.5,259,2792,15,95,40,1428,56,91,452
"CDK4",35,89,1049,1245.5,1277.5,1555.5,1552,1338,546,1380,1423,909,752,1012
"UROD",1207.5,826.5,616,1333.5,1829,1058.5,872,917,707,588,1016,651,728,673
"UROS",687.5,1751.5,1280,1133,1848.5,646.5,638,629,568,235,629,1798,879,589

Step 5 - Test, Publish, and Edit

  • Save your application
  • Try running your application
  • Edit, share and update your application

Congratulations, you have now built your first application on BioLib!