| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 425 人关注过本帖
标题:高手 ,改个程序
只看楼主 加入收藏
lgdenanzi
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2008-4-2
收藏
 问题点数:0 回复次数:3 
高手 ,改个程序
这是用JAVASCRIPT写的代码
有能帮改成C语言的 编码 的高手吗:
谢谢
<script>
function pairaln(seq1, seq2){
    // scoring scheme
    
    var MATCH    =  1; // +1 for letters that match
    var MISMATCH = -1; // -1 for letters that mismatch
    var GAP      = -1; // -1 for any gap
    // initialization
    
    var score=[][];
    var pointer=[[]];
    score[0][0]   = 0;
    pointer[0][0] = 0;
    var l1=seq1.length
    var l2=seq2.length
    
    for(var j = 1; j <= l1; j++) {
        
            score[0][j]   = GAP * j;
            pointer[0][j] = 2;
    }
    for (var i = 1; i <= l2; i++) {
        
        score[i]=[];
        pointer[i]=[];
            score[i][0]   = GAP * i;
            pointer[i][0] = 3;
    }
    // fill
    
    for(var i = 1; i <= l2; i++) {
        var letter2 = seq2.charAt(i-1);
 
            for(var j = 1; j <= l1; j++) {
                
                var diagonal_score, left_score, up_score;
                // calculate match score
                
                var letter1 = seq1.charAt(j-1);                        
                
                if (letter1 == letter2) {
                    
                        diagonal_score = score[i-1][j-1] + MATCH;
                }
                
                else {
                        diagonal_score = score[i-1][j-1] + MISMATCH;
                }
                // calculate gap scores
                
                up_score   = score[i-1][j] + GAP;
                left_score = score[i][j-1] + GAP;
                // choose best score
                
                if (diagonal_score >= up_score) {
                        
                        if (diagonal_score >= left_score) {
                            
                            score[i][j]   = diagonal_score;
                            pointer[i][j] = 1;
                        }
                    
                    else {
                            score[i][j]   = left_score;
                            pointer[i][j] = 2;
                        }
                
                } else {
                        
                        if (up_score >= left_score) {
                            
                            score[i][j]   = up_score;
                            pointer[i][j] = 3;
                        }
                        
                        else {
                            score[i][j]   = left_score;
                            pointer[i][j] = 2;
                        }
                }
            }
    }
    // trace-back
    
    var align1 = [];
    var align2 = [];
    // start at last cell of matrix
    var j = l1;
    var i = l2;
    while (1) {
   
            if(pointer[i][j] == 0)break // ends at first cell of matrix
            if (pointer[i][j] == 1) {
        
                align1[align1.length] = seq1.charAt(j-1);
                align2[align2.length] = seq2.charAt(i-1);
                i--;
                j--;
            }
            
            if (pointer[i][j] == 2) {
        
                align1[align1.length] = seq1.charAt(j-1);
                align2[align2.length] = "-";
                j--;
            }
            
            if (pointer[i][j] == 3) {
        
                align1[align1.length] = "-";
                align2[align2.length] = seq2.charAt(i-1);
                i--;
            }   
    }
    align1 = align1.reverse();
    align2 = align2.reverse();
return "序列:<p>"+seq1+"<br>"+seq2+"<p>比对结果:<table><tr><td>"+align1.join("</td><td>")+"</td></tr><tr><td>"+align2.join("</td><td>")+"</tr></table>"
}
document.write(pairaln('CTGGGCTGACTGA', 'GACTAGCTAGACTGA'))

</script>
2008-04-02 14:41
lgdenanzi
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2008-4-2
收藏
得分:0 
这是动态规划在序列比对中的算法程序
现在不会用C语言编写啊
2008-04-02 16:58
lgdenanzi
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2008-4-2
收藏
得分:0 
顶上去 谢谢大家
2008-04-02 18:25
试图改变
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-4-2
收藏
得分:0 
这个也可以改的吗?我好象还不知道啊
2008-04-02 18:27
快速回复:高手 ,改个程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017016 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved