barcode

Finder & Cutter 패치

Coding/Python

1. 공통: 이제 어디 자르는지도 나옵니다. 살려줘... 
2. Cutter: 제한효소 누락되던 거 수정했습니다. 근데 된건지 모르겠음. 


def count_func (a,b):
    while a in b:
        global site_count
        global res_loc 
        global res_loc_list
        loc = b.find(a)
        site_count += 1
        b = b[loc+len(a):]
        res_loc = loc + 1
        res_loc_list.append(res_loc)
    return site_count, res_loc
# 이거 통으로 코드에 넣었더니 if 안에 있는데도 시퀀스 없으면 끝내더라... 
# 위치 출력은 되는 것 같은데, 이거 더해야 하는데...

이렇게 하면 위치가 출력되긴 한데 문제가 하나 있다. 저 로직이 해당 시퀀스에서 제한효소 인식 site가 있으면 그 부분 다음 글자부터 slicing을 한다. 그래서 

AfaI [167, 150, 167, 53, 70] [830, 677, 507, 451, 378]
# restriction site 위치와 b(시퀀스에서 restriction site가 끝나는 부분부터 슬라이싱한 결과)의 길이

이렇게 나온다... (왼쪽이 find 결과) 오른쪽은 슬라이싱하고 남은 자리. 

 

def cut_func (a,b):
    while a in b:
        global res_loc
        global res_loc_list
        global length_seq
        global length_list
        loc = b.find(a)
        b = b[loc+len(a):]
        res_loc = loc + 1
        res_loc_list.append(res_loc)
        length_seq = len(b)
        length_list.append(length_seq)
    return res_loc_list,length_list
# 여기가 위치 관련 함수입니다.
# len(a): 인식 시퀀스 길이, len(b): 슬라이싱 하고 남은 시퀀스 길이

일단 복잡하니까 함수 밖으로 빼고 

AanI [80] [15]
# 결과(AanI의 시퀀스는 TTATAA로 6bp)
# 슬라이싱하고 남은 텍스트의 길이가 15bp이다.

저게 왜 저렇게 나오냐면 

1. AanI이 인식하는 시퀀스(TTATAA)는 6bp이다. (len(AanI)=6)
2. AanI이 인식하는 시퀀스 다음 위치부터 슬라이싱하면 15bp가 남는다. (왼쪽은 find에 +1한 값이다)

 

length_list.append(seq_length - (length_seq + len(a))) # slicing 후의 길이 목록

그래서 전체 길이-(슬라이싱+인식 시퀀스)+1하면 위치가 같게 나온다. (위 코드의 값에 1을 더하면 된다) 저렇게 하면 AanI의 경우 100-(15+6)+1이 되므로 80. 

 

def cut_func (a,b):
    while a in b:
        global res_loc # find로 나오는 값
        global res_loc_list
        seq_length = len(sequence)
        loc = b.find(a)
        b = b[loc+len(a):]
        res_loc = len(sequence) - (len(b) + len(a)) + 1
        res_loc_list.append(str(res_loc)) # find로 나오는 위치 목록(slicing에 따른 보정 필요)
    return res_loc_list,length_list
# 여기가 위치 관련 함수입니다.
res_loc_list = ', '.join(res_loc_list)
            f.write("{0}: {1} {2},{3} times cut. Where(bp): {4} \n".format(enzyme,res_find,feature,site_count,res_loc_list))

정리하고 출력 코드 바꾸면 된다. 

 

테스트 시퀀스(cutter, 100bp)
테스트 시퀀스(cutter, 1.5kb)
테스트 시퀀스(finder, 100bp)
테스트 시퀀스(finder, 1kb)

 

'Coding > Python' 카테고리의 다른 글

cutter, finder, searcher에 앞으로 추가할 기능  (0) 2022.08.21
For vs While  (0) 2022.08.21
Searcher 만들었음  (0) 2022.08.21
Cutter & Finder 패치노트  (0) 2022.08.21
Cutter와 Finder에 패치가 있었습니다.  (0) 2022.08.21