Output


This document covers how outputs work on BioLib and explains how to print, save outputs, figures and reports.

Similar to Unix style command-line tools, BioLib applications return outputs in four distinct streams: stdout, stderr, exit codes and files. When users run an application, during execution, they will see the application log. Once the computation has completed, outputs that were printed (stdout) will be shown in the application window along with any non-zero exit codes. All files written to disk, are saved to a virtual filesystem. All files written to disk as well as stdout and stderr can be download by the user using the download button.

Printing outputs example

The example Python application below takes a text input and prints it to the application window:

# define imports
import argparse

# read inputs provided by user
parser = argparse.ArgumentParser()
parser.add_argument('--name')
args = parser.parse_args()

print("My name is", args.name)

The printed message (stdout) will be shown on screen when the application has finished running together with stderr if there are any errors present.

By default, the output is rendered as plain text. However, if an application outputs markdown, the enriched text can be rendered as intended, by setting the output format to markdown in the Advanced Settings section of the application editor. NB! This option only changes the way the output is rendered and not the output itself - i.e. If the output of an application is plain text, changing this to markdown will not make the output markdown.

Writing to disk example

Each application comes with a virtual file system to which the application can write files. Any new file created or edited during computation will be available for the user of the application to download once the computation has completed. In the Python example below, the application creates a file called 'my_name.txt' which can be downloaded by the user of the application.

# define imports
import argparse

# read inputs provided by user
parser = argparse.ArgumentParser()
parser.add_argument('--name')
args = parser.parse_args()

# write output into file
outfile = open('my_name.txt', 'w')
outifle.write("My name is", args.name)
outfile.close()

While the format and rendering of output printed to stdout are limited, when writing to disk one can use any file format, like FASTA, FASTQ and other formats commonly used in bioinformatics.

Figures and images

BioLib supports a number of common Python libraries like Matplotlib and Seaborn for producing figures and plots. The example below creates a simple linear plot using Matplotlib. The plot in this example is saved to the virtual file system as my_plot.png.

# define imports
import matplotlib.pyplot as plt

# generate plot
plt.plot([1,2,3,4,5,6,7,8,9,10])
plt.savefig("my_plot.png")

BioLib Output Plot

How to Show Figures in the Application Window Output (stdout)?

As explained above, the output shown in the application window is whatever is printed during execution (stdout), and this output will be rendered either as plain text or markdown. The figure my_plot.png can be shown in the application window output by using the markdown syntax as shown below.

# Generate the Markdown preview
print("![Markdown Picture Alt Text](my_plot.png)")

To render the image and not just the markdown source, set the output type to Markdown under Advanced Settings in the application editor.

BiLib Advanced Output Settings

Reports

Applications can generate markdown reports containing both descriptions, tables and visuals. If, your application prints markdown make sure to set the output type in the Advanced Settings to Markdown. An example of an application that produces a simple report is the Manhattan Plot Generator. The markdown report rendered in the application window can be saved as .pdf by the end user.

import matplotlib.pyplot as plt
from datetime import datetime
import argparse

# read inputs provided by user
parser = argparse.ArgumentParser()
parser.add_argument('--data',help="Input a string of comma separated values")
args = parser.parse_args()

# define some variables
title = 'Title'
description = 'Description'

# datetime object containing current date and time.
now = datetime. now()
date = now.strftime("%d/%m/%Y %H:%M:%S")

# load input data
array = args.data.split(",")

# generate plot
plt.plot(array)
plt.savefig("my_plot.png")

# generate full markdown report
print(f'# {title}')
print(date)
print(description)
print(f'\n{array}\n')
print('![Markdown Picture Alt Text](my_plot.png)')
Title
26/08/2020 14:27:41
Description

['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

BioLib Example Plot Image