-
Notifications
You must be signed in to change notification settings - Fork 112
/
example.cpp
54 lines (45 loc) · 1.84 KB
/
example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// ==========================
// example.cpp
// This is a simple example to show you how to use the SSW C++ library.
// To run this example:
// 1) g++ -Wall ssw_cpp.cpp ssw.c example.cpp
// 2) ./a.out
// Created by Wan-Ping Lee on 09/04/12.
// Last revision by Mengyao Zhao on 2023-Apr-21
// ==========================
#include <iostream>
#include <string.h>
#include "ssw_cpp.h"
using std::string;
using std::cout;
using std::endl;
static void PrintAlignment(const StripedSmithWaterman::Alignment& alignment);
int main() {
const string ref = "CAGCCTTTCTGACCCGGAAATCAAAATAGGCACAACAAA";
const string query = "CTGAGCCGGTAAATC";
int32_t maskLen = strlen(query.c_str())/2;
maskLen = maskLen < 15 ? 15 : maskLen;
// Declares a default Aligner
StripedSmithWaterman::Aligner aligner;
// Declares a default filter
StripedSmithWaterman::Filter filter;
// Declares an alignment that stores the result
StripedSmithWaterman::Alignment alignment;
// Aligns the query to the ref
aligner.Align(query.c_str(), ref.c_str(), ref.size(), filter, &alignment, maskLen);
PrintAlignment(alignment);
return 0;
}
static void PrintAlignment(const StripedSmithWaterman::Alignment& alignment){
cout << "===== SSW result =====" << endl;
cout << "Best Smith-Waterman score:\t" << alignment.sw_score << endl
<< "Next-best Smith-Waterman score:\t" << alignment.sw_score_next_best << endl
<< "Reference start:\t" << alignment.ref_begin << endl
<< "Reference end:\t" << alignment.ref_end << endl
<< "Query start:\t" << alignment.query_begin << endl
<< "Query end:\t" << alignment.query_end << endl
<< "Next-best reference end:\t" << alignment.ref_end_next_best << endl
<< "Number of mismatches:\t" << alignment.mismatches << endl
<< "Cigar: " << alignment.cigar_string << endl;
cout << "======================" << endl;
}