午夜的留言附属站
ReversalChain
任腾 发表于 2008-05-06 15:38:18
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
map<pair<string,string>,int> h;
int calc(const pair<string,string> &input){
if (input.first.compare(input.second)==0) return 0;
if (h.count(input)) return h[input];
int &res=h[input];
res=-1;
for (int i=0;i<input.first.size();i++){
if (i&&input.first[i-1]!=input.second[i-1]) break;
for (int j=input.first.size();j>i;j--){
if (j<input.first.size()&&input.second[j]!=input.first[j]) break;
pair<string,string> next(
string(input.first.begin()+i,input.first.begin()+j),
string(input.second.begin()+i,input.second.begin()+j));
reverse(next.first.begin(),next.first.end());
int tmp=calc(next);
if (tmp==-1) continue;
tmp++;
if (res==-1||tmp<res) res=tmp;
}
}
return res;
}
struct ReversalChain{
int minReversal(string x,string y){
h.clear();
return calc(make_pair(x,y));
}
};
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
map<pair<string,string>,int> h;
int calc(const pair<string,string> &input){
if (input.first.compare(input.second)==0) return 0;
if (h.count(input)) return h[input];
int &res=h[input];
res=-1;
for (int i=0;i<input.first.size();i++){
if (i&&input.first[i-1]!=input.second[i-1]) break;
for (int j=input.first.size();j>i;j--){
if (j<input.first.size()&&input.second[j]!=input.first[j]) break;
pair<string,string> next(
string(input.first.begin()+i,input.first.begin()+j),
string(input.second.begin()+i,input.second.begin()+j));
reverse(next.first.begin(),next.first.end());
int tmp=calc(next);
if (tmp==-1) continue;
tmp++;
if (res==-1||tmp<res) res=tmp;
}
}
return res;
}
struct ReversalChain{
int minReversal(string x,string y){
h.clear();
return calc(make_pair(x,y));
}
};
收藏:
QQ书签
del.icio.us
DividingIntoTeams
任腾 发表于 2008-05-06 12:35:36
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <map>
#include <set>
using namespace std;
struct DividingIntoTeams{
string findYourTeam(vector<int> af,vector<int> bf,vector<int> cf,int k){
int n=af.size();
bool flag[100]={0};
int turn=0;
while (1){
int key=-1;
if (turn==0){
for (int i=0;i<af.size();i++){
if (!flag[af[i]]){
key=af[i];
break;
}
}
}else if (turn==1){
for (int i=0;i<bf.size();i++){
if (!flag[bf[i]]){
key=bf[i];
break;
}
}
}else{
for (int i=0;i<cf.size();i++){
if (!flag[cf[i]]){
key=cf[i];
break;
}
}
}
flag[key]=true;
if (key==k){
break;
}
turn++;
if (turn==3) turn=0;
}
if (turn==0){
return "Alex";
}else if (turn==1){
return "Bob";
}else
return "Charlie";
}
};
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <map>
#include <set>
using namespace std;
struct DividingIntoTeams{
string findYourTeam(vector<int> af,vector<int> bf,vector<int> cf,int k){
int n=af.size();
bool flag[100]={0};
int turn=0;
while (1){
int key=-1;
if (turn==0){
for (int i=0;i<af.size();i++){
if (!flag[af[i]]){
key=af[i];
break;
}
}
}else if (turn==1){
for (int i=0;i<bf.size();i++){
if (!flag[bf[i]]){
key=bf[i];
break;
}
}
}else{
for (int i=0;i<cf.size();i++){
if (!flag[cf[i]]){
key=cf[i];
break;
}
}
}
flag[key]=true;
if (key==k){
break;
}
turn++;
if (turn==3) turn=0;
}
if (turn==0){
return "Alex";
}else if (turn==1){
return "Bob";
}else
return "Charlie";
}
};
收藏:
QQ书签
del.icio.us
TimeToSay
任腾 发表于 2008-05-06 12:34:24
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <map>
#include <set>
using namespace std;
struct TimeToSay{
int maximumJoy(vector<int> he,vector<int> jo){
int n=he.size();
int res=0;
for (int i=0;i<1<<n;i++){
int tmp=0;
int th=100;
for (int j=0;j<n;j++){
if ((1<<j)&i){
th-=he[j];
tmp+=jo[j];
}
}
if (th>0&&tmp>res){
res=tmp;
}
}
return res;
}
};
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <map>
#include <set>
using namespace std;
struct TimeToSay{
int maximumJoy(vector<int> he,vector<int> jo){
int n=he.size();
int res=0;
for (int i=0;i<1<<n;i++){
int tmp=0;
int th=100;
for (int j=0;j<n;j++){
if ((1<<j)&i){
th-=he[j];
tmp+=jo[j];
}
}
if (th>0&&tmp>res){
res=tmp;
}
}
return res;
}
};
收藏:
QQ书签
del.icio.us
BestResult
任腾 发表于 2008-05-05 22:41:14
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <sstream>
using namespace std;
struct BestResult{
vector<int> findBestResult(vector<string> team){
int a[15][3]={0};
int n=team.size();
for (int i=0;i<n;i++){
istringstream strin(team[i]);
for (int j=0;j<3;j++) strin>>a[i][j];
}
for (int i=1;i<n;i++){
for (int j=0;j<3;j++)
a[i][j]=a[0][j]-a[i][j];
}
int ansx,ansy,ansz,ans=-1;
for (int x=1;x<=1000;x++){
for (int y=1;y<=x;y++){
int seg[15][2]={0};
for (int i=1;i<n;i++){
if (a[i][2]==0){
if (-a[i][0]*x-a[i][1]*y<=0){
seg[i][0]=1;
seg[i][1]=y;
}else{
seg[i][0]=y+1;
seg[i][1]=0;
}
continue;
}
if (a[i][2]>0){
seg[i][1]=y;
double xp=1.0*(-a[i][0]*x-a[i][1]*y)/a[i][2];
int tp;
if (xp>0) tp=ceil(xp);
else tp=ceil(xp);
if (tp>seg[i][1]) seg[i][1]=0;
tp=max(1,min(y,tp));
seg[i][0]=tp;
continue;
}
seg[i][0]=1;
double xp=1.0*(-a[i][0]*x-a[i][1]*y)/a[i][2];
int tp;
if (xp>0) tp=floor(xp);
else tp=floor(xp);
if (tp<seg[i][0]) seg[i][0]=y+1;
tp=max(1,min(y,tp));
seg[i][1]=tp;
}
int best=0,bestz=1;
for (int i=1;i<n;i++){
if (seg[i][0]>seg[i][1]) continue;
int subbest=0,subbestz;
for (int j=1;j<n;j++){
if (seg[j][0]<=seg[i][0]&&seg[j][1]>=seg[i][0]){
subbest++;
}
}
subbestz=seg[i][0];
if (subbest>best||subbest==best&&bestz>subbestz){
best=subbest;
bestz=subbestz;
}
}
if (best>ans||best==ans&&x<ansx||best==ans&&x==ansx&&y<ansy||best==ans&&y==ansy&&bestz<ansz){
ans=best;
ansx=x;
ansy=y;
ansz=bestz;
}
}
}
cout<<ans<<endl;
vector<int> res;
res.push_back(ansx);
res.push_back(ansy);
res.push_back(ansz);
return res;
}
};
#include <string>
#include <cmath>
#include <vector>
#include <sstream>
using namespace std;
struct BestResult{
vector<int> findBestResult(vector<string> team){
int a[15][3]={0};
int n=team.size();
for (int i=0;i<n;i++){
istringstream strin(team[i]);
for (int j=0;j<3;j++) strin>>a[i][j];
}
for (int i=1;i<n;i++){
for (int j=0;j<3;j++)
a[i][j]=a[0][j]-a[i][j];
}
int ansx,ansy,ansz,ans=-1;
for (int x=1;x<=1000;x++){
for (int y=1;y<=x;y++){
int seg[15][2]={0};
for (int i=1;i<n;i++){
if (a[i][2]==0){
if (-a[i][0]*x-a[i][1]*y<=0){
seg[i][0]=1;
seg[i][1]=y;
}else{
seg[i][0]=y+1;
seg[i][1]=0;
}
continue;
}
if (a[i][2]>0){
seg[i][1]=y;
double xp=1.0*(-a[i][0]*x-a[i][1]*y)/a[i][2];
int tp;
if (xp>0) tp=ceil(xp);
else tp=ceil(xp);
if (tp>seg[i][1]) seg[i][1]=0;
tp=max(1,min(y,tp));
seg[i][0]=tp;
continue;
}
seg[i][0]=1;
double xp=1.0*(-a[i][0]*x-a[i][1]*y)/a[i][2];
int tp;
if (xp>0) tp=floor(xp);
else tp=floor(xp);
if (tp<seg[i][0]) seg[i][0]=y+1;
tp=max(1,min(y,tp));
seg[i][1]=tp;
}
int best=0,bestz=1;
for (int i=1;i<n;i++){
if (seg[i][0]>seg[i][1]) continue;
int subbest=0,subbestz;
for (int j=1;j<n;j++){
if (seg[j][0]<=seg[i][0]&&seg[j][1]>=seg[i][0]){
subbest++;
}
}
subbestz=seg[i][0];
if (subbest>best||subbest==best&&bestz>subbestz){
best=subbest;
bestz=subbestz;
}
}
if (best>ans||best==ans&&x<ansx||best==ans&&x==ansx&&y<ansy||best==ans&&y==ansy&&bestz<ansz){
ans=best;
ansx=x;
ansy=y;
ansz=bestz;
}
}
}
cout<<ans<<endl;
vector<int> res;
res.push_back(ansx);
res.push_back(ansy);
res.push_back(ansz);
return res;
}
};
收藏:
QQ书签
del.icio.us
ScoreMatrix 711.29
任腾 发表于 2007-11-29 04:45:59
/*
* 2007年11月28日完成
* 这是一个提供打分矩阵的类,打分矩阵应用BLUSUM62。
* 注释为生成矩阵过程,OriginScore为导入的原始BLUSUM62。
* 对于PAMxx矩阵,可以类似导入,目前本项目应用BLUSUM62打分矩阵
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace RTPpca
{
public class ScoreMatrix
{
/* const string order = "CSTPAGNDEQHRKMILVFYW";
int[][] OriginScore = new int[][]{
new int[] {9,-1,-1,-3,0,-3,-3,-3,-4,-3,-3,-3,-3,-1,-1,-1,-1,-2,-2,-2},
new int[] {-1,4,1,-1,1,0,1,0,0,0,-1,-1,0,-1,-2,-2,-2,-2,-2,-3},
new int[] {-1,1,4,1,-1,1,0,1,0,0,0,-1,0,-1,-2,-2,-2,-2,-2,-3},
new int[] {-3,-1,1,7,-1,-2,-1,-1,-1,-1,-2,-2,-1,-2,-3,-3,-2,-4,-3,-4},
new int[] {0,1,-1,-1,4,0,-1,-2,-1,-1,-2,-1,-1,-1,-1,-1,-2,-2,-2,-3},
new int[] {-3,0,1,-2,0,6,-2,-1,-2,-2,-2,-2,-2,-3,-4,-4,0,-3,-3,-2},
new int[] {-3,1,0,-2,-2,0,6,1,0,0,-1,0,0,-2,-3,-3,-3,-3,-2,-4},
new int[] {-3,0,1,-1,-2,-1,1,6,2,0,-1,-2,-1,-3,-3,-4,-3,-3,-3,-4},
new int[] {-4,0,0,-1,-1,-2,0,2,5,2,0,0,1,-2,-3,-3,-3,-3,-2,-3},
new int[] {-3,0,0,-1,-1,-2,0,0,2,5,0,1,1,0,-3,-2,-2,-3,-1,-2},
new int[] {-3,-1,0,-2,-2,-2,1,1,0,0,8,0,-1,-2,-3,-3,-2,-1,2,-2},
new int[] {-3,-1,-1,-2,-1,-2,0,-2,0,1,0,5,2,-1,-3,-2,-3,-3,-2,-3},
new int[] {-3,0,0,-1,-1,-2,0,-1,1,1,-1,2,5,-1,-3,-2,-3,-3,-2,-3},
new int[] {-1,-1,-1,-2,-1,-3,-2,-3,-2,0,-2,-1,-1,5,1,2,-2,0,-1,-1},
new int[] {-1,-2,-2,-3,-1,-4,-3,-3,-3,-3,-3,-3,-3,1,4,2,1,0,-1,-3},
new int[] {-1,-2,-2,-3,-1,-4,-3,-4,-3,-2,-3,-2,-2,2,2,4,3,0,-1,-2},
new int[] {-1,-2,-2,-2,0,-3,-3,-3,-2,-2,-3,-3,-2,1,3,1,4,-1,-1,-3},
new int[] {-2,-2,-2,-4,-2,-3,-3,-3,-3,-3,-1,-3,-3,0,0,0,-1,6,3,1},
new int[] {-2,-2,-2,-3,-2,-3,-2,-3,-2,-1,2,-2,-2,-1,-1,-1,-1,3,7,2},
new int[] {-2,-3,-3,-4,-3,-2,-4,-4,-3,-2,-2,-3,-3,-1,-3,-2,-3,1,2,11}
};
public int[][] Score;
public ScoreMatrix()
{
Score=new int[26][];
for (int i = 0; i < 26; i++)
{
Score[i] = new int[26];
}
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 20; j++)
{
Score[order[i] - 'A'][order[j] - 'A'] = OriginScore[i][j];
}
}
}*/
public static int[][] Score = new int[][]{
new int[]{4,0,0,-2,-1,-2,0,-2,-1,0,-1,-1,-1,-1,0,-1,-1,-1,1,-1,0,-2,-3,0,-2,0},
new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[]{0,0,9,-3,-4,-2,-3,-3,-1,0,-3,-1,-1,-3,0,-3,-3,-3,-1,-1,0,-1,-2,0,-2,0},
new int[]{-2,0,-3,6,2,-3,-1,-1,-3,0,-1,-4,-3,1,0,-1,0,-2,0,1,0,-3,-4,0,-3,0},
new int[]{-1,0,-4,2,5,-3,-2,0,-3,0,1,-3,-2,0,0,-1,2,0,0,0,0,-3,-3,0,-2,0},
new int[]{-2,0,-2,-3,-3,6,-3,-1,0,0,-3,0,0,-3,0,-4,-3,-3,-2,-2,0,-1,1,0,3,0},
new int[]{0,0,-3,-1,-2,-3,6,-2,-4,0,-2,-4,-3,-2,0,-2,-2,-2,0,1,0,0,-2,0,-3,0},
new int[]{-2,0,-3,1,0,-1,-2,8,-3,0,-1,-3,-2,1,0,-2,0,0,-1,0,0,-2,-2,0,2,0},
new int[]{-1,0,-1,-3,-3,0,-4,-3,4,0,-3,2,1,-3,0,-3,-3,-3,-2,-2,0,1,-3,0,-1,0},
new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[]{-1,0,-3,-1,1,-3,-2,-1,-3,0,5,-2,-1,0,0,-1,1,2,0,0,0,-3,-3,0,-2,0},
new int[]{-1,0,-1,-4,-3,0,-4,-3,2,0,-2,4,2,-3,0,-3,-2,-2,-2,-2,0,3,-2,0,-1,0},
new int[]{-1,0,-1,-3,-2,0,-3,-2,1,0,-1,2,5,-2,0,-2,0,-1,-1,-1,0,-2,-1,0,-1,0},
new int[]{-2,0,-3,1,0,-3,0,-1,-3,0,0,-3,-2,6,0,-2,0,0,1,0,0,-3,-4,0,-2,0},
new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[]{-1,0,-3,-1,-1,-4,-2,-2,-3,0,-1,-3,-2,-1,0,7,-1,-2,-1,1,0,-2,-4,0,-3,0},
new int[]{-1,0,-3,0,2,-3,-2,0,-3,0,1,-2,0,0,0,-1,5,1,0,0,0,-2,-2,0,-1,0},
new int[]{-1,0,-3,-2,0,-3,-2,0,-3,0,2,-2,-1,0,0,-2,1,5,-1,-1,0,-3,-3,0,-2,0},
new int[]{1,0,-1,0,0,-2,0,-1,-2,0,0,-2,-1,1,0,-1,0,-1,4,1,0,-2,-3,0,-2,0},
new int[]{-1,0,-1,1,0,-2,1,0,-2,0,0,-2,-1,0,0,1,0,-1,1,4,0,-2,-3,0,-2,0},
new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[]{0,0,-1,-3,-2,-1,-3,-3,3,0,-2,1,1,-3,0,-2,-2,-3,-2,-2,0,4,-3,0,-1,0},
new int[]{-3,0,-2,-4,-3,1,-2,-2,-3,0,-3,-2,-1,-4,0,-4,-2,-3,-3,-3,0,-3,11,0,2,0},
new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[]{-2,0,-2,-3,-2,3,-3,2,-1,0,-2,-1,-1,-2,0,-3,-1,-2,-2,-2,0,-1,2,0,7,0},
new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
}
}
收藏:
QQ书签
del.icio.us
TwoSequenceCompare 711.29
任腾 发表于 2007-11-29 04:45:57
/*
* 2007年11月29日重新实现本功能
* 本类实现了双序列比对的全局算法,应用Needleman-Wunsch算法,打分矩阵应用的是BLOSUM62矩阵。
* 通过个人测试,正常
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace RTPpca
{
public class TwoSequenceCompare
{
const int penalty = 8;
static int ScoreCalc(char ch1, char ch2)
{
return ScoreMatrix.Score[ch1 - 'A'][ch2 - 'A'];
}
public static int CalcResScore(ref ComparedSequenceType seq)
{
int res = 0;
for (int i = 0; i < seq.Sequences[0].Sequences.Length; i++)
{
if (seq.Sequences[0].Sequences[i] == '-' || seq.Sequences[1].Sequences[i] == '-')
{
res -= penalty;
continue;
}
res += ScoreMatrix.Score[seq.Sequences[0].Sequences[i] - 'A'][seq.Sequences[1].Sequences[i] - 'A'];
}
return res;
}
public static ComparedSequenceType calc(ref SequenceType[] seq)
{
int m = seq[0].Sequences.Length;
int n = seq[1].Sequences.Length;
int[,] d = new int[m + 1, n + 1];
ComparedSequenceType res = new ComparedSequenceType();
for (int i = 1; i < m + 1; i++)
{
for (int j = 1; j < n + 1; j++)
{
d[i, j] = int.MinValue;
}
}
int[, ,] path = new int[m + 1, n + 1, 2];
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
if (d[i, j] < d[i - 1, j] - penalty)
{
d[i, j] = d[i - 1, j] - penalty;
path[i, j, 0] = i - 1; ;
path[i, j, 1] = j;
}
if (d[i, j] < d[i, j - 1] - penalty)
{
d[i, j] = d[i, j - 1] - penalty;
path[i, j, 0] = i;
path[i, j, 1] = j - 1;
}
if (d[i, j] < d[i - 1, j - 1] + ScoreCalc(seq[0].Sequences[i - 1], seq[1].Sequences[j - 1]))
{
d[i, j] = d[i - 1, j - 1] + ScoreCalc(seq[0].Sequences[i - 1], seq[1].Sequences[j - 1]);
path[i, j, 0] = i - 1;
path[i, j, 1] = j - 1;
}
}
}
res.score = d[m, n];
List pathx = new List ();
List pathy = new List ();
int nowx = m;
int nowy = n;
while (nowx > 0 && nowy > 0)
{
pathx.Add(nowx);
pathy.Add(nowy);
int nx = path[nowx, nowy, 0];
int ny = path[nowx, nowy, 1];
nowx = nx;
nowy = ny;
}
pathx.Reverse();
pathy.Reverse();
res.Sequences = new SequenceType[2];
res.Sequences[0].SequenceInfo = seq[0].SequenceInfo;
res.Sequences[1].SequenceInfo = seq[1].SequenceInfo;
List res1list = new List ();
List res2list = new List ();
for (int i = 0; i < pathx.Count; i++)
{
if (i > 0 && pathx[i] == pathx[i - 1]) res1list.Add('-');
else res1list.Add(seq[0].Sequences[pathx[i]-1]);
if (i > 0 && pathy[i] == pathy[i - 1]) res2list.Add('-');
else res2list.Add(seq[1].Sequences[pathy[i]-1]);
}
res.Sequences[0].Sequences = res1list.ToArray();
res.Sequences[1].Sequences = res2list.ToArray();
return res;
}
}
}
收藏:
QQ书签
del.icio.us
Test 711.29
任腾 发表于 2007-11-29 04:45:56
/*
* 这是一个对功能进行测试的程序
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace RTPpca
{
class Test
{
static void Main(string[] args)
{
/*
SequenceType[] s = RTIO.ReadFasta(@"D:\project\ppca_0\gene.fasta.txt");
for (int i = 0; i < s.Length; i++)
{
Console.WriteLine(s[i].SequenceInfo);
Console.WriteLine(s[i].Sequences);
}
*/
/*
for (int i = 0; i < ScoreMatrix.Score.Length; i++)
{
for (int j = 0; j < ScoreMatrix.Score[i].Length; j++)
{
Console.Write(ScoreMatrix.Score[i][j] + " ");
}
Console.WriteLine();
}
*/
SequenceType[] a = new SequenceType[2];
a[0].SequenceInfo = "a";
a[1].SequenceInfo = "b";
a[0].Sequences = "AJCJNRCKCRBP".ToCharArray();
a[1].Sequences = "ABCNJRQCLCRPM".ToCharArray();
/*
a[0].Sequences = "GLT".ToCharArray();
a[1].Sequences = "GLVT".ToCharArray();
*/
ComparedSequenceType b = TwoSequenceCompare.calc(ref a);
ComparedSequenceType c = new ComparedSequenceType();
c.Sequences = new SequenceType[2];
c.Sequences[0].Sequences = "AJCJN-R-CKCRBP-".ToCharArray();
c.Sequences[1].Sequences = "ABC-NJRQCLCR-PM".ToCharArray();
Console.WriteLine(TwoSequenceCompare.CalcResScore(ref c));
Console.WriteLine(TwoSequenceCompare.CalcResScore(ref b));
RTIO.WriteComparedTwoSequence(ref b);
}
}
}
收藏:
QQ书签
del.icio.us
RTIO 711.29
任腾 发表于 2007-11-29 04:45:55
/*
* RTIO Class Libary for RT's ppca project
* 2007.10.21 done RTReadFile, for "fasta" format gene sequences
*
*/
/*
* 2007.11.29 对代码进行修正,并写入双序列比对结果的输出函数
* 通过个人测试,正常
*/
/*
* 需要将output写入到文件中,*.aln,还未实现
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;
namespace RTPpca
{
public class RTIO
{
public static SequenceType[] ReadFasta(string fileName)
{
if (!File.Exists(fileName))
{
Console.WriteLine("File don't exist!");
return new SequenceType[10];
}
List ListSequence = new List();
using (StreamReader sr = File.OpenText(fileName))
{
string s = "";
string sb = "";
SequenceType SequenceTemp=new SequenceType();
bool firstSequence = true;
while ((s = sr.ReadLine()) != null)
{
if (s[0] == '>')
{
if (firstSequence)
{
firstSequence = false;
}
else
{
SequenceTemp.Sequences = sb.ToCharArray();
ListSequence.Add(SequenceTemp);
sb = "";
}
SequenceTemp = new SequenceType(s.Substring(0,s.LastIndexOf('|')+1), "");
}
else
{
sb += s;
}
}
SequenceTemp.Sequences = sb.ToCharArray();
ListSequence.Add(SequenceTemp);
}
return ListSequence.ToArray();
}
static char ChooseChar(char ch1, char ch2)
{
if (ch1 == ch2) return '|';
if (ch1 == '-' || ch2 == '-') return ' ';
if (ScoreMatrix.Score[ch1 - 'A'][ch2 - 'A'] >= 2) return ':';
if (ScoreMatrix.Score[ch1 - 'A'][ch2 - 'A'] == 1) return '.';
return ' ';
}
public static void WriteComparedTwoSequence(ref ComparedSequenceType CS)
{
int len = CS.Sequences[0].Sequences.Length;
int line = len / 50 + 1;
char[][] sb = new char[line*4][];
Console.WriteLine("Powered By RT>~<");
Console.WriteLine();
for (int i = 0; i < sb.Length; i++)
{
sb[i] = new char[85];
}
for (int i = 0; i < line; i++)
{
for (int j = 0; j < CS.Sequences[0].SequenceInfo.Length; j++)
{
sb[i * 4][j] = CS.Sequences[0].SequenceInfo[j];
}
for (int j = 0; j < CS.Sequences[1].SequenceInfo.Length; j++)
{
sb[i * 4 + 1][j] = CS.Sequences[1].SequenceInfo[j];
}
}
for (int i = 0; i < len; i++)
{
sb[i / 50 * 4][(i % 50) + 35] = CS.Sequences[0].Sequences[i];
}
for (int i = 0; i < len; i++)
{
sb[i / 50 * 4 + 1][(i % 50) + 35] = CS.Sequences[1].Sequences[i];
}
for (int i = 0; i < len; i++)
{
sb[i / 50 * 4 + 2][(i % 50) + 35] = ChooseChar(CS.Sequences[0].Sequences[i], CS.Sequences[1].Sequences[i]);
}
for (int i = 0; i < sb.Length; i++)
{
for (int j = 0; j < sb[i].Length; j++)
{
if (sb[i][j] == 0) Console.Write(' ');
else Console.Write(sb[i][j]);
}
Console.WriteLine();
}
}
}
}
收藏:
QQ书签
del.icio.us
RTSequence 711.29
任腾 发表于 2007-11-29 04:45:54
/*
* 2007.11.28重新code。主要设计了需要比对序列的结构,还有比对好的序列的结构
* 通过个人测试,正常
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace RTPpca
{
public struct SequenceType
{
public string SequenceInfo;
public char[] Sequences;
public SequenceType(string SI, string S)
{
this.SequenceInfo = SI;
this.Sequences = S.ToCharArray();
}
}
public struct ComparedSequenceType
{
public int score;
public SequenceType[] Sequences;
}
}
收藏:
QQ书签
del.icio.us
RTIO v710.21
任腾 发表于 2007-10-22 00:25:04
/*
* RTIO Class Libary for RT's ppca project
* 2007.10.21 done RTReadFile, for "fasta" format gene sequences
*
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Collections;
using System.Text;
namespace RTIO
{
public class RTFile
{
public static char[][] RTReadFile(string FileName, ref string[] SeqsName)
{
if (!File.Exists(FileName))
{
Console.WriteLine("File doesn't exist!");
return (new char[0][]);
}
string sb = "";
using (StreamReader sr = File.OpenText(FileName))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
sb += s;
}
}
// Console.WriteLine(sb);
string[] seqs = sb.Split('>');
SeqsName = new string[seqs.Length - 1];
for (int i = 1; i < seqs.Length; i++)
{
SeqsName[i - 1] = seqs[i].Substring(0, seqs[i].LastIndexOf('|')+1);
seqs[i] = seqs[i].Remove(0, seqs[i].IndexOf(']') + 1);
}
char[][] res = new char[seqs.Length-1][];
for (int i = 1; i < seqs.Length; i++)
{
res[i-1] = seqs[i].ToCharArray();
}
return res;
}
}
}
收藏:
QQ书签
del.icio.us
