Sequence Alignment
来源:互联网 发布:linux cp 一个文件夹 编辑:程序博客网 时间:2024/06/01 07:34
</pre><p class="p1"><pre name="code" class="cpp">#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;// Edit penalty:// gap penalty: theta// mismatch penalty: alphaint optimalAlignment(string s1, string s2, int theta, int alpha, vector<string> &align){ int m = s1.length(); int n = s2.length(); vector<vector<int>> M(m + 1, vector<int>(n + 1, 0)); for (int i = 0; i <= m; ++i) M[i][0] = i * theta; for (int j = 0; j <= n; ++j) M[0][j] = j * theta; for (int i = 1; i <= m; ++i) { for (int j = 1; j <= n; ++j) { int cost = 0; int kind = 1; if (s1[i - 1] == s2[j - 1]) cost = M[i - 1][j - 1]; else cost = M[i - 1][j - 1] + alpha; cost = min(cost, theta + M[i - 1][j]); cost = min(cost, theta + M[i][j - 1]); M[i][j] = cost; } } int i = m, j = n; // backtracking to get the solution while (i >= 1 || j >= 1) { if ((i > 0 && M[i][j] == theta + M[i - 1][j]) || j == 0) { align[0].push_back(s1[i - 1]); align[1].push_back('-'); --i; } else if ((j > 0 && M[i][j] == theta + M[i][j - 1]) || i == 0) { align[0].push_back('-'); align[1].push_back(s2[j - 1]); --j; } else if (M[i][j] == M[i - 1][j - 1] + alpha || M[i][j] == M[i - 1][j - 1] ) { align[0].push_back(s1[i - 1]); align[1].push_back(s2[j - 1]); --i, --j; } } reverse(align[0].begin(), align[0].end()); reverse(align[1].begin(), align[1].end()); return M[m][n];}// x y cost// ------------// A T 1// A A 0// C - 2// A A 0// G G 0// T G 1// T T 0// A - 2// C C 0// C A 1// ---// 7int main(){ string x = ""; string y = "TAAGGTCA"; string x1 = "CTACCG"; string y1 = "TACATG"; vector<string> ret; ret.resize(2); cout << "s1: " << x << endl; cout << "s2: " << y << endl; cout << "The minimum cost of alignment: " << optimalAlignment(x, y, 2, 1, ret) << endl; cout << ret[0] << endl; cout << ret[1] << endl; ret.clear(); ret.resize(2); cout << "s1: " << x1 << endl; cout << "s2: " << y1 << endl; cout << "The minimum cost of alignment: " << optimalAlignment(x1, y1, 2, 1, ret) << endl; cout << ret[0] << endl; cout << ret[1] << endl; return 0;}
Reference:
http://www.cs.princeton.edu/courses/archive/fall14/cos126/assignments/sequence.html
0 0
- Sequence Alignment
- Sequence Alignment
- Sequence alignment
- sequence alignment
- Linear Space Sequence Alignment
- List of sequence alignment software
- poj 1080 dp(sequence alignment)
- POJ 2520 DNA Sequence Alignment 笔记
- alignment
- Alignment
- Alignment
- memory alignment
- Data Alignment
- Byte Alignment
- Memory Alignment
- XScale alignment
- Byte alignment
- 1836--Alignment
- Android 把jsonarray传递到下个页面
- (转载)企业级加密文件系统 eCryptfs 详解
- log4j2设置日志文件输出到web目录下,亲测可用
- ALL00 跟着小甲鱼学汇编00——背景,铺垫,前奏
- Intel S2600JF主板蓝屏问题的处理
- Sequence Alignment
- Android传感器概述(六)
- 蚂蚁感冒
- 闪屏页支持点击进入主页面
- MySQL使用可重复读作为默认隔离级别的原因之一
- iOS NSURLSession 实现网络请求-文件下载-上传-后台下载
- AOPR软件提供几种语言
- 接口的基本语法笔记及应用Mars
- 提交项目到AppStore签名授权问题“You are not allowed to perform this operation”