# Flexbar — flexible barcode and adapter removal, version 2.5
The program Flexbar is provided as pre-compiled binary for Linux 64 and Mac OSX on sourceforge (flexbar.sf.net). See installation instructions for binaries below. A version of Flexbar sources can be obtained using svn, see compilation section. Flexbar is also available via package manager on Debian systems.

## Installation
To run Flexbar binaries, the tbb library (Intel Threading Building Blocks) has to be available. Binary downloads contain the corresponding library file for runtime. Extract the downloaded archive and follow these platform specific instructions:

### Linux
Adjust lib search path to include absolute path of the extracted Flexbar directory containing lib file libtbb.so.2 for the current terminal session, or permanently in shell startup scripts:
export LD_LIBRARY_PATH=/path/FlexbarDir:$LD_LIBRARY_PATH

### Mac OSX
It applies the same as for Linux. Make the file libtbb.dylib available by setting the lib search path:
export DYLD_LIBRARY_PATH=/path/FlexbarDir:$DYLD_LIBRARY_PATH

## Compilation
Make sure that svn and cmake commands are available, as well as development and runtime files of the tbb library.

- Check out or export Flexbar to a local directory and go there:
svn export https://svn.code.sf.net/p/flexbar/code/trunk Flexbar
cd Flexbar

- Get the SeqAn library if not available on your system:
svn export -r 14262 https://github.com/seqan/seqan/trunk/core/include

- Type these commands to build Flexbar:
cmake .
make

## Program usage
Flexbar needs at least one file with sequencing reads in fasta/q or csfasta/q format as input. Additionally, the target name, quality format of reads and further options can be specified. For barcode based read seperation and adapter removal, a file in fasta format with barcode or adapter sequences should be provided.

Please refer to the help screen (flexbar -h) or manual (sf.net/p/flexbar/wiki).

SYNOPSIS
flexbar -r reads [-t target] [-b barcodes] [-a adapters] [options]

EXAMPLES
flexbar -r reads.fq -f i1.8 -t target -b brc.fa -a adap.fa
flexbar -r reads.csfastq.gz -a adap.fa -ao 5 -ae LEFT -c

In the first example, barcoded reads in illumina version 1.8 fastq format are demultiplexed by specifying a file with barcodes in fasta format. After read seperation based on barcodes, adapters given in fasta format are removed from the right side if they align at the read beginning or downstream. After removal the left side of reads is kept. Remaining reads are written to the file target.fastq in same format.

The second example, shows how to remove adapters in fasta format from left side of gzip compressed color-space (c) reads with quality scores (csfastq), if the overlap of adapter and read has at least length five. For left trim-end type the right side of reads is retained.

To run Flexbar with the test dataset, make sure flexbar is reachable via the path variable and run flexbar_validate.sh within the test folder. Although default parameters of Flexbar are optimized to deliver good results in a large number of scenarios, the adjustment of parameters might improve results, e.g. --adapter-min-overlap and --adapter-threshold.
