"The only thing that you absolutely have to know, is the location of the library." - Albert Einstein
There are common snippets of code used across diverse workflows in the LatchBio SDK. This community-led encyclopedia aims to catalog common code snippets and save developer time. Please feel free to contribute!
Become an SDK contributor! To join the Slack community, send Kenny Workman a direct message.
- Installing Miniconda
- Anaconda is an extremely useful open source package and environment management system
- To install it from a
Dockerfile
, paste the instruction in theinstalling_conda.txt
file inside yourDockerfile
- The commands in the text execute the following tasks:
- download and install
miniconda
in the indicated folder - add the conda binary to the
$PATH
- download and install
- Conda can now be used normally (e.g
conda install samtools
) - snippet | [example code](Coming soon)
- Snippet by: Matteo Bolner
- Installing from PyPi using a requirements.txt file
- Popular software used by bioinformaticians are distributed via PyPi and can easily be incorporated into LatchBio workflows.
- To do so, create a
requirements.txt
that details the packages to download in the same directory as yourDockerfile
. Next, addCOPY requirements.txt requirements.txt; RUN pip install -r requirements.txt
to yourDockerfile
. - snippet | example code
- Snippet by: Jacob L. Steenwyk
- Installing from PyPi without using a requirements.txt file
- Import the necessary subpackages (e.g. matplotlib, pylab, Bio) using the
Dockerfile
of in your workflow - To do so, specifically add
RUN python3 -m pip install matplotlib pylab biopython
to yourDockerfile
. - Snippet and example code coming soon!
- snippet | [example code coming soon!]
- Snippet by: Pedro Lovatt Garcia
- Import the necessary subpackages (e.g. matplotlib, pylab, Bio) using the
- Download and compile software
- Software can be distributed in tar gzipped directories. The source code often needs to be compiled into binaries, which is often done by executing the command
make install
. - To handle these types of software in a
Dockerfile
for use in a Latch workflow, a series of commands can be strung together to automatically download and compile the workflow. The general steps are the same as when working in the terminal wherein the software is downloaded using something likecurl
, unzipped, andmake
commands are executed. - snippet | example code
- Snippet by: Jacob L. Steenwyk
- Software can be distributed in tar gzipped directories. The source code often needs to be compiled into binaries, which is often done by executing the command
- Installing R
R
has proven to be a statistical workhorse for bioinformaticians. The following snippet details how to download and installR
in yourDockerfile
.- snippet
- Snippet by: Jacob L. Steenwyk
- Original author: Akshay Suhuag in the LatchBio SDK Slack channel.
- Installing Java
- Numerous bioinformatic software is written in
Java
. Latch workflows that useJava
require download and installation instructions forJava
to be specified in theDockerfile
. Use this code snippet for downloading and installingJava
. - snippet
- Snippet by: Jacob L. Steenwyk
- Original author: Kenny Workman in the LatchBio SDK Slack channel.
- Numerous bioinformatic software is written in
- capturing stdout
- bioinformaticians are frequently captured the stdout using the
>
character from one software to feed into another. Use this code snippet for writing the stdout to a file and returning the output. - snippet | example code
- Snippet by: Jacob L. Steenwyk
- bioinformaticians are frequently captured the stdout using the
- handling multiple output files
- numerous software will generate multiple output files that have the same prefix
- the best way to deal with this is by writing them all to a directory and then returning the resulting directory
- snippet | example code
- Snippet by: Jacob L. Steenwyk
- Piping stdout to a different command
- Lots of command line tools only take input from the standard input stream, so pipes ("|") are necessary when composing lots of these tools together. Use this snippet for piping the output of one process to the input of another.
- snippet
- Snippet by: Ayush Kamat
- Returning one or a few files
- SDK developers may want to return only one or a few files out of many. In these cases, the shutil.move() or os.rename() functions may be useful. In this example, a specific output file is moved to a preferred directory.
- snippet | Example code
- Snippet by: Geodette
- Explanation edited by: Jacob L. Steenwyk