国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

使用python實現BLAST

2020-01-04 15:51:08
字體:
來源:轉載
供稿:網友

最近在自學python,又用python實現了一下BLAST。

這次更新了打分函數如下,空位罰分改為-5,但不區分gap open 和 gap extend。

python,BLAST

''''' @author: JiuYu '''  def score(a,b):#scoring function   score=0   lst=['AC','GT','CA','TG']   if a==b:     score +=2   elif a+b in lst:     score += -5   else:     score += -7   return score  def BLAST(seq1,seq2):#Basic Local Alignment Search Tool   l1 = len(seq1)   l2 = len(seq2)   GAP =-5   #-5 for any gap   scores =[]   point =[]      for j in range(l2+1):     if j == 0:       line1=[0]       line2=[0]       for i in range(1,l1+1):         line1.append(GAP*i)         line2.append(2)     else:       line1=[]       line2=[]       line1.append(GAP*j)       line2.append(3)     scores.append(line1)     point.append(line2)      #fill the blank of scores and point   for j in range(1,l2+1):     letter2 = seq2[j-1]     for i in range(1,l1+1):       letter1 = seq1[i-1]       diagonal_score = score(letter1, letter2) + scores[j-1][i-1]       left_score = GAP + scores[j][i-1]       up_score = GAP + scores[j-1][i]       max_score = max(diagonal_score, left_score, up_score)       scores[j].append(max_score)              if scores[j][i] == diagonal_score:         point[j].append(1)       elif scores[j][i] == left_score:         point[j].append(2)       else:         point[j].append(3)            #trace back   alignment1=''   alignment2=''   i = l2   j = l1   print 'scores =',scores[i][j]   while True:     if point[i][j] == 0:       break     elif point[i][j] == 1:       alignment1 += seq1[j-1]       alignment2 += seq2[i-1]       i -= 1       j -= 1     elif point[i][j] == 2:       alignment1 += seq1[j-1]       alignment2 += '-'       j -= 1     else:       alignment1 += '-'       alignment2 += seq2[i-1]       i -= 1          #reverse alignment   alignment1 = alignment1[::-1]   alignment2 = alignment2[::-1]   print 'The best alignment:'   print alignment1   print alignment2  seq1=raw_input('Please input your first sequences:/n') seq2=raw_input('input second sequences:/n') BLAST(seq1, seq2) 

運行結果:

python,BLAST

無疑python對字符串的處理更加強大,語言也更加簡單,優雅。比如最后逆序輸出alignment,java我是單獨寫了一個逆序函數,而python只用一個語句就可以完成相同任務。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到python教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 横山县| 田阳县| 凤城市| 涞水县| 清丰县| 石景山区| 宣武区| 上饶县| 汝阳县| 漠河县| 白水县| 玛纳斯县| 合江县| 景宁| 铅山县| 永登县| 建平县| 灵山县| 永平县| 家居| 平定县| 塔城市| 五台县| 如东县| 宁海县| 瓦房店市| 石林| 隆德县| 宁陕县| 庆元县| 阿拉尔市| 武汉市| 沂南县| 江城| 藁城市| 大冶市| 乌兰县| 遂川县| 翁源县| 大理市| 闻喜县|