NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Macros | Functions
ssw.cpp File Reference
#include <emmintrin.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "ssw.h"

Go to the source code of this file.

Classes

struct  alignment_end
 
struct  cigar
 
struct  _profile
 

Macros

#define LIKELY(x)   (x)
 
#define UNLIKELY(x)   (x)
 
#define set_u(u, w, i, j)   { int x=(i)-(w); x=x>0?x:0; (u)=(j)-x+1; }
 
#define set_d(u, w, i, j, p)   { int x=(i)-(w); x=x>0?x:0; x=(j)-x; (u)=x*3+p; }
 
#define kroundup32(x)   (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
 
#define max16(m, vm)
 
#define max8(m, vm)
 

Functions

__m128i * qP_byte (const int8_t *read_num, const int8_t *mat, const int32_t readLen, const int32_t n, uint8_t bias)
 
alignment_endsw_sse2_byte (const int8_t *ref, int8_t ref_dir, int32_t refLen, int32_t readLen, const uint8_t weight_gapO, const uint8_t weight_gapE, __m128i *vProfile, uint8_t terminate, uint8_t bias, int32_t maskLen)
 
__m128i * qP_word (const int8_t *read_num, const int8_t *mat, const int32_t readLen, const int32_t n)
 
alignment_endsw_sse2_word (const int8_t *ref, int8_t ref_dir, int32_t refLen, int32_t readLen, const uint8_t weight_gapO, const uint8_t weight_gapE, __m128i *vProfile, uint16_t terminate, int32_t maskLen)
 
cigarbanded_sw (const int8_t *ref, const int8_t *read, int32_t refLen, int32_t readLen, int32_t score, const uint32_t weight_gapO, const uint32_t weight_gapE, int32_t band_width, const int8_t *mat, int32_t n)
 
int8_tseq_reverse (const int8_t *seq, int32_t end)
 
s_profilessw_init (const int8_t *read, const int32_t readLen, const int8_t *mat, const int32_t n, const int8_t score_size)
 
void init_destroy (s_profile *p)
 
s_alignssw_align (const s_profile *prof, const int8_t *ref, int32_t refLen, const uint8_t weight_gapO, const uint8_t weight_gapE, const uint8_t flag, const uint16_t filters, const int32_t filterd, const int32_t maskLen)
 
void align_destroy (s_align *a)
 

Macro Definition Documentation

#define kroundup32 (   x)    (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))

Round an integer to the next closest power-2 integer.

Parameters
xinteger to be rounded (in place) x will be modified.

Definition at line 64 of file ssw.cpp.

#define LIKELY (   x)    (x)

Definition at line 49 of file ssw.cpp.

#define max16 (   m,
  vm 
)
Value:
(vm) = _mm_max_epu8((vm), _mm_srli_si128((vm), 8)); \
(vm) = _mm_max_epu8((vm), _mm_srli_si128((vm), 4)); \
(vm) = _mm_max_epu8((vm), _mm_srli_si128((vm), 2)); \
(vm) = _mm_max_epu8((vm), _mm_srli_si128((vm), 1)); \
(m) = _mm_extract_epi16((vm), 0)
#define max8 (   m,
  vm 
)
Value:
(vm) = _mm_max_epi16((vm), _mm_srli_si128((vm), 8)); \
(vm) = _mm_max_epi16((vm), _mm_srli_si128((vm), 4)); \
(vm) = _mm_max_epi16((vm), _mm_srli_si128((vm), 2)); \
(m) = _mm_extract_epi16((vm), 0)
#define set_d (   u,
  w,
  i,
  j,
 
)    { int x=(i)-(w); x=x>0?x:0; x=(j)-x; (u)=x*3+p; }

Definition at line 57 of file ssw.cpp.

#define set_u (   u,
  w,
  i,
 
)    { int x=(i)-(w); x=x>0?x:0; (u)=(j)-x+1; }

Definition at line 54 of file ssw.cpp.

#define UNLIKELY (   x)    (x)

Definition at line 50 of file ssw.cpp.

Function Documentation

void align_destroy ( s_align a)

Release the memory allocated by function ssw_align.

Parameters
apointer to the alignment result structure

Definition at line 857 of file ssw.cpp.

cigar* banded_sw ( const int8_t ref,
const int8_t read,
int32_t  refLen,
int32_t  readLen,
int32_t  score,
const uint32_t  weight_gapO,
const uint32_t  weight_gapE,
int32_t  band_width,
const int8_t mat,
int32_t  n 
)

Definition at line 548 of file ssw.cpp.

void init_destroy ( s_profile p)

Release the memory allocated by function ssw_init.

Parameters
ppointer to the query profile structure

Definition at line 764 of file ssw.cpp.

__m128i* qP_byte ( const int8_t read_num,
const int8_t mat,
const int32_t  readLen,
const int32_t  n,
uint8_t  bias 
)

Definition at line 88 of file ssw.cpp.

__m128i* qP_word ( const int8_t read_num,
const int8_t mat,
const int32_t  readLen,
const int32_t  n 
)

Definition at line 346 of file ssw.cpp.

int8_t* seq_reverse ( const int8_t seq,
int32_t  end 
)

Definition at line 728 of file ssw.cpp.

s_align* ssw_align ( const s_profile prof,
const int8_t ref,
int32_t  refLen,
const uint8_t  weight_gapO,
const uint8_t  weight_gapE,
const uint8_t  flag,
const uint16_t  filters,
const int32_t  filterd,
const int32_t  maskLen 
)

Do Striped Smith-Waterman alignment.

Parameters
profpointer to the query profile structure
refpointer to the target sequence; the target sequence needs to be numbers and corresponding to the mat parameter of function ssw_init
refLenlength of the target sequence
weight_gapOthe absolute value of gap open penalty
weight_gapEthe absolute value of gap extension penalty
flagbitwise FLAG; (from high to low) bit 5: when setted as 1, function ssw_align will return the best alignment beginning position; bit 6: when setted as 1, if (ref_end1 - ref_begin1 < filterd && read_end1 - read_begin1 < filterd), (whatever bit 5 is setted) the function will return the best alignment beginning position and cigar; bit 7: when setted as 1, if the best alignment score >= filters, (whatever bit 5 is setted) the function will return the best alignment beginning position and cigar; bit 8: when setted as 1, (whatever bit 5, 6 or 7 is setted) the function will always return the best alignment beginning position and cigar. When flag == 0, only the optimal and sub-optimal scores and the optimal alignment ending position will be returned.
filtersscore filter: when bit 7 of flag is setted as 1 and bit 8 is setted as 0, filters will be used (Please check the decription of the flag parameter for detailed usage.)
filterddistance filter: when bit 6 of flag is setted as 1 and bit 8 is setted as 0, filterd will be used (Please check the decription of the flag parameter for detailed usage.)
maskLenThe distance between the optimal and suboptimal alignment ending position >= maskLen. We suggest to use readLen/2, if you don't have special concerns. Note: maskLen has to be >= 15, otherwise this function will NOT return the suboptimal alignment information. Detailed description of maskLen: After locating the optimal alignment ending position, the suboptimal alignment score can be heuristically found by checking the second largest score in the array that contains the maximal score of each column of the SW matrix. In order to avoid picking the scores that belong to the alignments sharing the partial best alignment, SSW C library masks the reference loci nearby (mask length = maskLen) the best alignment ending position and locates the second largest score from the unmasked elements.
Returns
pointer to the alignment result structure
Note
Whatever the parameter flag is setted, this function will at least return the optimal and sub-optimal alignment score, and the optimal alignment ending positions on target and query sequences. If both bit 6 and 7 of the flag are setted while bit 8 is not, the function will return cigar only when both criteria are fulfilled. All returned positions are 0-based coordinate.

Definition at line 770 of file ssw.cpp.

s_profile* ssw_init ( const int8_t read,
const int32_t  readLen,
const int8_t mat,
const int32_t  n,
const int8_t  score_size 
)
    @function       Create the query profile using the query sequence.
Parameters
readpointer to the query sequence; the query sequence needs to be numbers
readLenlength of the query sequence
matpointer to the substitution matrix; mat needs to be corresponding to the read sequence
nthe square root of the number of elements in mat (mat has n*n elements)
score_sizeestimated Smith-Waterman score; if your estimated best alignment score is surely < 255 please set 0; if your estimated best alignment score >= 255, please set 1; if you don't know, please set 2
Returns
pointer to the query profile structure
Note
example for parameter read and mat: If the query sequence is: ACGTATC, the sequence that read points to can be: 1234142 Then if the penalty for match is 2 and for mismatch is -2, the substitution matrix of parameter mat will be: A C G T 2 -2 -2 -2 //A -2 2 -2 -2 //C -2 -2 2 -2 //G -2 -2 -2 2 //T mat is the pointer to the array {2, -2, -2, -2, -2, 2, -2, -2, -2, -2, 2, -2, -2, -2, -2, 2}

Definition at line 741 of file ssw.cpp.

alignment_end* sw_sse2_byte ( const int8_t ref,
int8_t  ref_dir,
int32_t  refLen,
int32_t  readLen,
const uint8_t  weight_gapO,
const uint8_t  weight_gapE,
__m128i *  vProfile,
uint8_t  terminate,
uint8_t  bias,
int32_t  maskLen 
)

Definition at line 122 of file ssw.cpp.

alignment_end* sw_sse2_word ( const int8_t ref,
int8_t  ref_dir,
int32_t  refLen,
int32_t  readLen,
const uint8_t  weight_gapO,
const uint8_t  weight_gapE,
__m128i *  vProfile,
uint16_t  terminate,
int32_t  maskLen 
)

Definition at line 370 of file ssw.cpp.