README.md

SSW Library

An SIMD Smith-Waterman C/C++/Python/Java Library for Use in Genomic Applications

License: MIT

Copyright (c) 2012-2015 Boston College

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Overview

SSW is a fast implementation of the Smith-Waterman algorithm, which uses the Single-Instruction Multiple-Data (SIMD) instructions to parallelize the algorithm at the instruction level. SSW library provides an API that can be flexibly used by programs written in C, C++ and other languages. We also provide a software that can do protein and genome alignment directly. Current version of our implementation is ~50 times faster than an ordinary Smith-Waterman. It can return the Smith-Waterman score, alignment location and traceback path (cigar) of the optimal alignment accurately; and return the sub-optimal alignment score and location heuristically.

C/C++ interface

How to use the API

The API files include ssw.h and ssw.c, which can be directly used by any C or C++ program. For the C++ users who are more comfortable to use a C++ style interface, an additional C++ wrapper is provided with the file ssw_cpp.cpp and ssw_cpp.h.

To use the C style API, please:

Download ssw.h and ssw.c, and put them in the same folder of your own program files.

Write #include "ssw.h" into your file that will call the API functions.

The API files are ready to be compiled together with your own C/C++ files.

The API function descriptions are in the file ssw.h. One simple example of the API usage is example.c. The Smith-Waterman penalties need to be integers. Small penalty numbers such as: match: 2, mismatch: -1, gap open (the total penalty when one gap is opened): -3, gap extension: -1 are recommended, which will lead to shorter running time.

To use the C++ style API, please:

Download ssw.h, ssw.c, ssw_cpp.cpp and ssw_cpp.h, put them in the same folder of your own program files.

Write #include "ssw_cpp.h" into your file that will call the API functions.

The API files are ready to be compiled together with your own C/C++ files.

The API function descriptions are in the file ssw_cpp.h. A simple example of using the C++ API is example.cpp.

Install the software

Run the software

Usage: ssw_test [options] ... <target.fasta> <query.fasta>(or <query.fastq>)
Options:
-m N N is a positive integer for weight match in genome sequence alignment. [default: 2]
-x N N is a positive integer. -N will be used as weight mismatch in genome sequence alignment. [default: 2]
-o N N is a positive integer. -N will be used as the weight for the gap opening. [default: 3]
-e N N is a positive integer. -N will be used as the weight for the gap extension. [default: 1]
-p Do protein sequence alignment. Without this option, the ssw_test will do genome sequence alignment.
-a FILE FILE is either the Blosum or Pam weight matrix. [default: Blosum50]
-c Return the alignment path.
-f N N is a positive integer. Only output the alignments with the Smith-Waterman score >= N.
-r The best alignment will be picked between the original read alignment and the reverse complement read alignment.
-s Output in SAM format. [default: no header]
-h If -s is used, include header in SAM output.

Software input

The input files can be in FASTA or FASTQ format. Both target and query files can contain multiple sequences. Each sequence in the query file will be aligned with all sequences in the target file. If your target file has N sequences and your query file has M sequences, the results will have M*N alignments.

The additional optional field "ZS" indicates the suboptimal alignment score. For example, the 1st record in the upper example means the optimal alignment score of the given sequence is 37; the suboptimal alignment score is 28; the mismatch and INDEL base count within the aligned fragment of the read is 11.

pyssw output

Speed and memory usage of pyssw

Java interface

The Java wrapper is a thin JNI (Java Native Interface) wrapper around the native C implementation.

Building

Only the C, C++, and C shared libraries are generated from the default make goal, and as such, the Java interface must be built explicitly.

Ensure javac and jar are in PATH.

Ensure JAVA_HOME is set to an installed JRE or JDK, or the JNI include directory is included in the C system library search path.

make java from the src directory.

libsswjni.so and ssw.jar should be built.

How to use the Java wrapper

The Java wrapper consist of the following components:

libsswjni.so: native C library exposing the JNI entry points

ssw.jar is a Java library containing the Java interface to the native C library. This small wrapper library is composed of:

ssw.Aligner Java class: a thread-safe static class that exposes two align() methods. The first exposes the SSW C library directly. No error checking is performed on arguments passed to this method and misuse is highly likely to crash the JVM. The second align() method is a more user-friendly entry point that exposes a simpler API and performs some basic error checking.

ssw.Alignment Java class: this class stores alignment results. Each each field has a direct correspondence and identical meaning to the C s_align struct.

ssw.Example Java class: Java version of the example_c sample code. Run java -jar ssw.jar to execute the sample.

To use the library, either reference the ssw.jar or including the Aligner and Alignment classes directly. As for any JNI library, the native library must be loaded (using System.loadLibrary("sswjni") or similar) before invokation of native methods. For the JVM to find the library, ensure that either the library is included in the LD_LIBRARY_PATH environment variable, or -Djava.library.path=<directory containing libsswjni.so> is set on the Java command line.