2014-07-17 5 views
1

파이썬을 사용하여 다음 BLAT 결과와 일치하지 않는 위치 번호를 얻을 수있는 방법이 있습니까?UCSC BLAT 출력 파이썬

00000001 taaaagatgaagtttctatcatccaaaaaatgggctacagaaacc 00000045 
<<<<<<<< ||||||||||||||||||||||||||| |||||||||||||||| <<<<<<<< 
41629392 taaaagatgaagtttctatcatccaaagtatgggctacagaaacc 41629348 

위의 출력에서 ​​두 가지 불일치가 있습니다. 파이썬을 사용하여 불일치/돌연변이의 위치 번호를 얻을 수 있습니까? 이것이 소스 코드에도 나타나는 방식입니다. 그래서 어떻게 진행해야하는지 조금 혼란 스럽습니다. 감사합니다.

+0

위 또는 아래 시퀀스에서 위치를 원합니까? 양자 모두? – sirlark

+0

하단 시퀀스에서 원합니다. – user3783999

답변

0

.find 문자열을 사용하면 불일치를 찾을 수 있습니다. 불일치는 공백 ('')으로 표시되므로 blat 출력의 가운데 줄에서 찾으십시오. 나는 개인적으로 뻔뻔 스러움을 모른다. 그래서 출력이 항상 삼중 선으로 오는 지 확신 할 수는 없지만, 다음과 같은 함수는 일치하지 않는 위치의 튜플로 표현 된 각 위치가 일치하지 않는 위치 목록을 반환한다. 상단 시퀀스 및 하단 시퀀스의 동일 시퀀스가 ​​포함됩니다. 우리는 (정상 순서에 따라 인덱스) (28, 29)을 배치하거나 (아래 순서에 따라 인덱스) 41629419 및 41629420를 배치 말하는

[(28, 41629419), (29, 41629420)] 

생산

blat_src = """00000001 taaaagatgaagtttctatcatccaaaaaatgggctacagaaacc 00000045 
<<<<<<<< ||||||||||||||||||||||||||| |||||||||||||||| <<<<<<<< 
41629392 taaaagatgaagtttctatcatccaaagtatgggctacagaaacc 41629348""" 

def find_mismatch(blat): 
    #break the blat input into lines 
    lines = blat.split("\n") 

    #give some firendly names to the different lines 
    seq_a = lines[0] 
    seq_b = lines[2] 

    #We're not interested in the '<' and '>' so we strip them out with a slice 
    matchstr = lines[1][9:-9] 

    #Get the integer values of the starts of each sequence segment 
    pos_a = int(seq_a[:8]) 
    pos_b = int(seq_b[:8]) 

    results = [] 

    #find the index of first space character, mmpos = mismatch position 
    mmpos = matchstr.find(" ") 
    #if a space exists (-1 if none found) 
    while mmpos != -1: 
     #the position of the mismatch is the start position of the 
     #sequence plus the index within the segment 
     results.append((posa+mmpos, posb+mmpos)) 
     #search the rest of the string (from mmpos+1 onwards) 
     mmpos = matchstr.find(" ", mmpos+1) 
    return results 

print find_mismatch(blat_src) 

은 일치한다.