欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用python實(shí)現(xiàn)BLAST

 更新時(shí)間:2018年02月12日 10:28:23   投稿:lijiao  
最近在自學(xué)python,又用python實(shí)現(xiàn)了一下BLAST。 這次更新了打分函數(shù)如下,空位罰分改為-5,但不區(qū)分gap open 和 gap extend。

最近在自學(xué)python,又用python實(shí)現(xiàn)了一下BLAST。

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

''''' 
@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) 

運(yùn)行結(jié)果:

無(wú)疑python對(duì)字符串的處理更加強(qiáng)大,語(yǔ)言也更加簡(jiǎn)單,優(yōu)雅。比如最后逆序輸出alignment,java我是單獨(dú)寫(xiě)了一個(gè)逆序函數(shù),而python只用一個(gè)語(yǔ)句就可以完成相同任務(wù)。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論