这是DNA双序列比对类型中最简单的一种,要求输入的两条序列长度相同,通过运行代码给出两条序列的比对得分
Python代码如下
import numpy
## Score matrix for nucleotide alignment
NUC44=numpy.array([[5,-4,-4,-4,-2],
[-4,5,-4,-4,-2],
[-4,-4,5,-4,-2],
[-4,-4,-4,5,-2],
[-2,-2,-2,-2,-1]])
NBET='ATGCN'
seq1=input("Please input the sequence 1:")
seq2=input("Please input the sequence 2:")
## Define a function for calculating the alignment score of two sequences
def NUCScore(NUC44,NBET,seq1,seq2,gap=-7):
scr=0
seq_len=min(len(seq1),len(seq2))
for i in range(seq_len):
if (seq1[i] == '-' or seq2[i] == '-') and seq1[i] != seq2[i] :
scr+=gap
else:
nuc1=NBET.index(seq1[i].upper())
nuc2=NBET.index(seq2[i].upper())
scr+=NUC44[nuc1,nuc2]
return scr
print('The aligned sequences are:')
print(seq1)
print(seq2)
score=NUCScore(NUC44,NBET,seq1,seq2,gap=-7)
print('The alignment score for the two sequences are %d.' % score)
C语言代码如下
#include <stdio.h>
#include<string.h>
int score_array[5][5] = { {5,-4,-4,-4,-2},{-4,5,-4,-4,-2},{-4,-4,5,-4,-2},{-4,-4,-4,5,-2},{-2,-2,-2,-2,-1} };
int main()
{
int clu_score(char seq1[100], char seq2[100], char normol[5]);
char normol[] = "ATCGN";
char seq1[100], seq2[100];
printf("Please input sequence 1:");
scanf("%s", seq1);
printf("Please input sequence 2:");
scanf("%s", seq2);
int score;
score = clu_score(seq1, seq2, normol);
printf("the score is %d\t", score);
return 0;
}
int clu_score(char seq1[100], char seq2[100],char normol[5])
{
int index1, index2,score_total=0;
int i, j;
for (i = 0; i < strlen(seq1); i++)
{
for (j = 0; j < strlen(normol); j++)
{
if (seq1[i] == normol[j])
index1 = j;
if (seq2[i] == normol[j])
index2 = j;
}
score_total += score_array[index1][index2];
}
return score_total;
}
如果有问题,欢迎大家和我一起讨论!