



  

barcode 1.0.3 documentation

 [barcode](#) 

 stable

 

Contents:

* [Introduction](index.html#document-introduction)

* [Installation](index.html#document-installation)

	+ [From source](index.html#from-source)

* [Usage](index.html#document-usage)

* [Command Line Interface](index.html#document-cli)

	+ [Positional Arguments](index.html#positional-arguments)

	+ [Named Arguments](index.html#named-arguments)

	+ [Sub-commands](index.html#Sub-commands)

* [Library](index.html#document-library)

* [API documentation](index.html#document-api)

	+ [`all\_barcodes()`](index.html#barcode.barcode.all_barcodes)

	+ [`filter\_distance()`](index.html#barcode.barcode.filter_distance)

	+ [`filter\_stretches()`](index.html#barcode.barcode.filter_stretches)

* [Contributors](index.html#document-credits)

[barcode](#)

* [Docs](#) »

* barcode 1.0.3 documentation

* [Edit on GitHub](https://github.com/jfjlaros/barcode/blob/ce0af7eea9cfb7d6590a948097520dfb89be95bc/docs/index.rst)

---

Barcode: Design and validate NGS barcodes[¶](#barcode-design-and-validate-ngs-barcodes "Permalink to this heading")

===================================================================================================================

[![https://img.shields.io/github/last-commit/jfjlaros/barcode.svg](https://img.shields.io/github/last-commit/jfjlaros/barcode.svg)](https://github.com/jfjlaros/barcode/graphs/commit-activity)

[![https://github.com/jfjlaros/barcode/actions/workflows/python-package.yml/badge.svg](https://github.com/jfjlaros/barcode/actions/workflows/python-package.yml/badge.svg)](https://github.com/jfjlaros/barcode/actions/workflows/python-package.yml)

[![https://readthedocs.org/projects/barcode/badge/?version=latest](https://readthedocs.org/projects/barcode/badge/?version=latest)](https://barcode.readthedocs.io/en/latest)

[![https://img.shields.io/github/release-date/jfjlaros/barcode.svg](https://img.shields.io/github/release-date/jfjlaros/barcode.svg)](https://github.com/jfjlaros/barcode/releases)

[![https://img.shields.io/github/release/jfjlaros/barcode.svg](https://img.shields.io/github/release/jfjlaros/barcode.svg)](https://github.com/jfjlaros/barcode/releases)

[![https://img.shields.io/pypi/v/barcode.svg](https://img.shields.io/pypi/v/barcode.svg)](https://pypi.org/project/barcode/)

[![https://img.shields.io/github/languages/code-size/jfjlaros/barcode.svg](https://img.shields.io/github/languages/code-size/jfjlaros/barcode.svg)](https://github.com/jfjlaros/barcode)

[![https://img.shields.io/github/languages/count/jfjlaros/barcode.svg](https://img.shields.io/github/languages/count/jfjlaros/barcode.svg)](https://github.com/jfjlaros/barcode)

[![https://img.shields.io/github/languages/top/jfjlaros/barcode.svg](https://img.shields.io/github/languages/top/jfjlaros/barcode.svg)](https://github.com/jfjlaros/barcode)

[![https://img.shields.io/github/license/jfjlaros/barcode.svg](https://img.shields.io/github/license/jfjlaros/barcode.svg)](https://raw.githubusercontent.com/jfjlaros/barcode/master/LICENSE.md)

---

Barcode is a program for the design and validation of sets of sequencing

barcodes.

Please see [ReadTheDocs](https://barcode.readthedocs.io/en/latest/index.html) for the latest documentation.

Introduction[¶](#introduction "Permalink to this heading")

----------------------------------------------------------

Barcodes are used in NGS to tag samples before pooling. After

sequencing, these barcodes are used to *demultiplex* the data, thereby

assigning the reads to the originating sample.

The key aspect of a good set of barcodes is robustness against read

errors. One read error should not be able to transform one barcode into

another. This requirement can be met by selecting barcodes in such a way

that the *edit distance* between any pair of barcodes is larger than

one. An additional desired property is the ability to *correct* read

errors. This can be done by increasing the minimal edit distance between

barcodes to at least three. If one read error occurs, the sequenced

barcode will have a distance of one to the original barcode and a

minimum distance of two to any of the other barcodes. If the read error

is high, the minimum edit distance should be increased to a higher (odd)

number.

For some sequencers it is important that mononucleotide stretches in

barcodes are below a minimum length. An additional filter can be used to

remove these barcodes.

Installation[¶](#installation "Permalink to this heading")

----------------------------------------------------------

The software is distributed via [PyPI](https://pypi.python.org/pypi/barcode), it can be installed with `pip`:

```

pip install barcode

```

### From source[¶](#from-source "Permalink to this heading")

The source is hosted on [GitHub](https://github.com/jfjlaros/barcode.git), to install the latest development version, use

the following commands.

```

git clone https://github.com/jfjlaros/barcode.git

cd barcode

pip install .

```

Usage[¶](#usage "Permalink to this heading")

--------------------------------------------

The `barcode` program has two subcommands; one for the creation of a

set of barcodes and one for the validation of an existing set of

barcodes.

To make a set of barcodes and write this set to a file named

`barcodes.txt`, use the following command:

```

barcode make barcodes.txt

```

`barcodes.txt` will now contain a list of barcodes that all have

length 8, and no barcode will contain a mononucleotide stretch longer

than 2.

The length of the barcodes can be controlled with the `-l` parameter,

the minimum edit distance is controlled with the `-d` option and the

maximum mononucleotide stretch length can be set with the `-s` option.

So if we want to make a list of barcodes of length 10, a minimum edit

distance of 5 (allowing for the correction of 2 read errors) and a

maximum mononucleotide stretch of 1, we use the following command:

```

barcode make -d 5 -l 10 -s 1 barcodes.txt

```

To verify a list of existing barcodes, use the command:

```

barcode test barcode.txt

```

This will check the distance between any pair of barcodes and will tell

you how many barcodes violate the distance constraint. Again, the

minimum edit distance can be set with the `-d` parameter.

Additionally, a good set of barcodes can be extracted by providing an

output file via the `-o` option:

```

barcode test -o good\_barcodes.txt barcodes.txt

```

Command Line Interface[¶](#command-line-interface "Permalink to this heading")

------------------------------------------------------------------------------

Design and test NGS barcodes.

```

usage: barcode [-h] [-v] {make,test} ...

```

### Positional Arguments[¶](#positional-arguments "Permalink to this heading")

`subcommand`

Possible choices: make, test

### Named Arguments[¶](#named-arguments "Permalink to this heading")

`-v`

show program’s version number and exit

### Sub-commands[¶](#Sub-commands "Permalink to this heading")

#### make[¶](#make "Permalink to this heading")

Make a set of barcodes, filter them for mononucleotide stretches and fordistances with other barcodes.

```

barcode make [-h] [-d DISTANCE] [-H] [-l LENGTH] [-s STRETCH] OUTPUT

```

##### Positional Arguments[¶](#positional-arguments_repeat1 "Permalink to this heading")

`OUTPUT`

output file

##### Named Arguments[¶](#named-arguments_repeat1 "Permalink to this heading")

`-d`

minimum distance between the barcodes (int default=3)

Default: 3

`-H`

use Hamming distance

Default: False

`-l`

lenght of the barcodes (int default=8)

Default: 8

`-s`

maximum mononucleotide stretch length (int default=2)

Default: 2

#### test[¶](#test "Permalink to this heading")

Test a set of barcodes.

```

barcode test [-h] [-d DISTANCE] [-H] [-o OUTPUT] INPUT

```

##### Positional Arguments[¶](#positional-arguments_repeat2 "Permalink to this heading")

`INPUT`

input file

##### Named Arguments[¶](#named-arguments_repeat2 "Permalink to this heading")

`-d`

minimum distance between the barcodes (int default=3)

Default: 3

`-H`

use Hamming distance

Default: False

`-o`

list of good barcodes

Copyright (c) Jeroen F.J. Laros <[J.F.J.Laros@lumc.nl](mailto:J.F.J.Laros%40lumc.nl)>

Library[¶](#library "Permalink to this heading")

------------------------------------------------

Barcode design via the library is done in three steps. First obtain the

full set of permutations with the `all\_barcodes` function:

```

>>> from barcode import all\_barcodes, filter\_distance, filter\_stretches

>>>

>>> # Generate all barcodes of length 2.

>>> all\_barcodes(2)

['AA', 'AC', 'AG', 'AT', 'CA', 'CC', 'CG', 'CT', 'GA', 'GC', 'GG', 'GT', 'TA',

'TC', 'TG', 'TT']

```

The resulting list can be filtered with the `filter\_distance` and

`filter\_stretches` functions:

```

>>> # Filter all barcodes of length 3 for a minimal edit distance of 3.

>>> filter\_distance(all\_barcodes(3), 3)

['AAA', 'CCC', 'GGG', 'TTT']

>>>

>>> # Filter all barcodes of lenght 2 for mononucleotide stretches of length

>>> # longer than 1.

>>> filter\_stretches(all\_barcodes(2), 1)

['AC', 'AG', 'AT', 'CA', 'CG', 'CT', 'GA', 'GC', 'GT', 'TA', 'TC', 'TG']

```

For the best result, apply the `filter\_stretches` function before

applying the `filter\_distance` function:

```

>>> # Make a set of barcodes of length 3, having no mononucleotide stretches

>>> # and a minimum edit distance of 3.

>>> filter\_distance(filter\_stretches(all\_barcodes(3), 1), 3)

['ACA', 'CGC', 'GAG']

```

API documentation[¶](#module-barcode.barcode "Permalink to this heading")

-------------------------------------------------------------------------

barcode.barcode.all\_barcodes(*length*)[¶](#barcode.barcode.all_barcodes "Permalink to this definition")

Generate all possible barcodes of a certain length.

Parameters

**length** (*int*) – Lenth of the barcodes.

Returns list

List of barcodes.

barcode.barcode.filter\_distance(*barcodes*, *min\_dist*, *distance=<function distance>*)[¶](#barcode.barcode.filter_distance "Permalink to this definition")

Filter a list of barcodes for distance to other barcodes.

Parameters

* **barcodes** (*list*) – List of barcodes.

* **min\_dist** (*int*) – Minimum distance between the barcodes.

* **distance** (*function*) – Distance function.

Returns list

List of barcodes filtered for distance to other

barcodes.

barcode.barcode.filter\_stretches(*barcodes*, *max\_stretch*)[¶](#barcode.barcode.filter_stretches "Permalink to this definition")

Filter a list of barcodes for mononucleotide stretches.

Parameters

* **barcodes** (*list*) – List of barcodes.

* **max\_stretch** (*int*) – Maximum mononucleotide stretch length.

Returns list

List of barcodes filtered for mononucleotide stretches.

Contributors[¶](#contributors "Permalink to this heading")

----------------------------------------------------------

* Jeroen F.J. Laros <[J.F.J.Laros@lumc.nl](mailto:J.F.J.Laros%40lumc.nl)> (Original author, maintainer)

Find out who contributed:

```

git shortlog -s -e

```

