barcode

Cutter & Finder 패치노트

Coding/Python

공통패치

Cut수 세 주는 기능이 추가되었습니다. 

Cutter

Cut수에 따른 효소 리스트 업 기능이 추가되었습니다. 살려줘... (아직 자르는 위치 안했음)
파일 이름 형식이 변경되었습니다. 그래서 이제 시퀀스 이름도 받습니다. 

 

Finder

Cut수 세 주는 기능에 따른 출력 형식 수정이 있었습니다. 


Cut수 세 주는 기능

사실상 엄청난 노가다의 결과...ㅠㅠ 

 

(생략)
        if res_find in sequence:
            site_count = 0
            while sequence.find(res_find) != -1:
                loc = sequence.find(res_find)
                site_count += 1
                sequence = sequence[loc+len(res_find):]
                print(enzyme, res_find, sequence.find(res_find))
            f.write("{0}: {1} {2},{3} times cut.\n".format(enzyme,res_find,feature,site_count))
(생략)

이 코드가 단식으로는 되는데 전체 코드에 쌩으로 도입했더니, restriction site가 없는 효소가 나오면 거기서 멈춰버린다. (여기까지가 전날 저녁에 try했던 부분)

def count_site (a,b):
    site_count = 0
    while a in b:
        loc - b.find(a)
        site_count += 1
        b = b[loc+len(a):]
        return site_count

그래서 해당 로직을 아예 함수로 빼버렸다. 

(마른세수)

 

def count_site (a,b):
    site_count = 0
    while a in b:
        loc = b.find(a)
        site_count += 1
        b = b[loc+len(a):]
        return site_count

근데 생각해보니 네번째 줄에 -가 왜 들어감? (원래 =)

실례지만 0컷이면 안 나와야 정상 아니냐. 

 

def count_func (a,b):
    site_count = 0
    while a in b:
        loc = b.find(a)
        site_count += 1
        b = b[loc+len(a):]
    return site_count
# 이거 통으로 코드에 넣었더니 if 안에 있는데도 시퀀스 없으면 끝내더라... 
print(count_site("GGCC",sequence))

답답해서 직접 해봤더니 이건 잘 되더라. 

 

def count_func (a,b):
    while a in b:
        global site_count
        loc = b.find(a)
        site_count += 1
        b = b[loc+len(a):]
    return site_count
# 이거 통으로 코드에 넣었더니 if 안에 있는데도 시퀀스 없으면 끝내더라...

함수 내에서는 그냥 전역변수 선언하고 

(생략)
        if res_find in sequence:
            site_count = 0
            count_func(res_find,sequence)
            count += 1
            f.write("{0}: {1} {2},{3} times cut.\n".format(enzyme,res_find,feature,site_count))
        else: 
            count += 0
(생략)
# 여러분 드디어 저장기능이 추가되었습니다!!!

site_count 변수를 함수 밖으로 빼버렸다. (site_count는 if문 안쪽에 있다)

 

(흐-뭇)

 

Cut수별로 나눠주는 기능

(생략)
        if res_find in sequence:
            site_count = 0
            count_func(res_find,sequence)
            count += 1
            count_nocut += 0
            cut_list.append(enzyme)
            f.write("{0}: {1} {2},{3} times cut.\n".format(enzyme,res_find,feature,site_count))
        else: 
            count += 0
            count_nocut += 1
            nocut_list.append(enzyme)
    cut_list = ', '.join(cut_list)
    nocut_list = ', '.join(nocut_list)
    f.write("Total: {0} enzymes cut input sequence, {1} enzymes never cut this sequence. \n".format(count,count_nocut))
    f.write("Enzyme cuts: {0} \nEmzyme no cuts: {1}".format(cut_list,nocut_list))
    f.close()
# 진짜 세주는거 겨우 추가했습니다...ㅠㅠ

사실 길어서 생략했는데 코드 위쪽에 0컷이랑 컷 두 개의 리스트가 있다. 

count = 0
count_nocut = 0
cut_list = []
nocut_list = []

이놈들. (count는 원래 있던 변수고 그 밑에 있는 게 새로 추가한 변수)

 

그래서 이렇게 나오는데... 이게 사람이요... 살다보면 1컷 궁금하다... 

 

count = 0
count_nocut = 0
once_cut_list = []
multi_cut_list = []
nocut_list = []
(생략)
        if res_find in sequence:
            site_count = 0
            count_func(res_find,sequence)
            count += 1
            count_nocut += 0
            if site_count == 1:
                once_cut_list.append(enzyme)
            else: 
                multi_cut_list.append(enzyme)
            f.write("{0}: {1} {2},{3} times cut.\n".format(enzyme,res_find,feature,site_count))
        else: 
            count += 0
            count_nocut += 1
            nocut_list.append(enzyme)
    once_cut_list = ', '.join(once_cut_list)
    multi_cut_list = ', '.join(multi_cut_list)
    nocut_list = ', '.join(nocut_list)
(생략)

그래서 0컷 1컷 멀티컷 나눠드렸습니다. 

가 이거. 근데... 에픽하이에도 투컷이 있고... (fly랑 one 좋아함) NEB cutter도 투컷까지는 보여줘요... 

 

count = 0
count_nocut = 0
once_cut_list = []
two_cut_list = []
multi_cut_list = []
nocut_list = []
(생략)
        if res_find in sequence:
            site_count = 0
            count_func(res_find,sequence)
            count += 1
            count_nocut += 0
            if site_count == 1:
                once_cut_list.append(enzyme)
            elif site_count == 2: 
                two_cut_list.append(enzyme)
            else: 
                multi_cut_list.append(enzyme)
            f.write("{0}: {1} {2},{3} times cut.\n".format(enzyme,res_find,feature,site_count))
        else: 
            count += 0
            count_nocut += 1
            nocut_list.append(enzyme)
(생략)

나눠드렸습니다^^ (출력은 1컷 2컷 멀티컷 빵컷 순) 빵컷하니까 빵 자르는 것 같잖아요 

 

def count_func (a,b):
    while a in b:
        global site_count
        loc = b.find(a)
        site_count += 1
        b = b[loc+len(a):]
    return site_count
# Cutter test하다가 여기에도 추가했음...

Finder에도 이 함수는 똑같이 들어간다. 

with open ('Result_{0}-{1}-{2}_{3}-{4}.txt'.format(year,month,day,enzyme,sequence_name),'w',encoding='utf-8') as f: 
    if sequence.find(res_find) != -1:
        site_count = 0
        cut_count = count_func(res_find,sequence)
        sequence = sequence.replace(res_find,res_site)
        print(enzyme,",",cut_feature)
        print(sequence,cut_count)
        f.write("{0} | {1} | {2} | {3} times cut\n".format(enzyme,res_site,cut_feature,cut_count))
        f.write('Sequence name: {0} \n {1}'.format(sequence_name,sequence))
        f.close()
        # DB에 효소가 있고 일치하는 시퀀스가 있을 때
(하략)

대신 Finder는 DB에 효소가 있고, 효소가 해당 시퀀스를 자를 때만 cut수를 세 준다. 

 

그래서 이렇게 나온다. (HaeIII이 해당 시퀀스를 자른다)

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

Finder & Cutter 패치  (0) 2022.08.21
Searcher 만들었음  (0) 2022.08.21
Cutter와 Finder에 패치가 있었습니다.  (0) 2022.08.21
제한효소 커터 2편 나왔음  (0) 2022.08.21
제한효소 커터 코드 패치했음  (0) 2022.08.21