제한효소 커터 만든 썰 푼다

뭐 하는 코드인가

시퀀스와 제한효소 이름을 입력하면 그 제한효소가 인식하는 시퀀스와 커팅 방식을 찾아주는 코드. 그러니까 얘가 이걸 자르냐를 보는거지 이걸 자르는 효소를 무작정 찾는 게 아님. 그 기능이 필요하시다고요?

http://nc2.neb.com/NEBcutter2/

여기로 모시겠습니다 고객님~

코드

일단 깃헙에도 있는데 Jupyter file임… py파일로도 만들긴 만들어야 하는데 일단 주는 Jupyter쪽.

import pandas as pd

DB가 csv고, 파이썬에서 이거 불러서 본격적으로 만지려면 판다스가 필요합니다.

enzyme_table = pd.read_csv('/home/koreanraichu/restriction.csv') # 일단 자체적으로 구축했음... 저거 종류 개많습니다 ㅠㅠ 
enzyme_table = enzyme_table.sort_values('Enzyme')
# csv파일의 구성은 크게 효소 이름, 인식하는 시퀀스, 해당 시퀀스를 자르는 형태와 sticky or blunt 여부로 구성되어 있습니다.

참고로 현재 csv파일 형식은

효소 이름, 시퀀스, 시퀀스(절단 후), sticky or blunt

이렇게 되어 있음. 깃헙에는 안 올라와있습니다. 얘가 용량때문에 걸릴까봐 그런 것도 있고 지금 수동으로 구축중이라… (이사람) sort는 그냥 효소 이름순으로 정렬한겁니다.

enzyme=input('시퀀스를 찾을 제한효소를 입력해주세요: ')
search_sequence=input('제한효소 site를 찾을 시퀀스를 입력해주세요: ')

이건 평범하게 효소랑 시퀀스 입력 받는 란. 효소 이름의 경우 토씨 하나 안 틀리고 입력해야 한다. 아직 대소문자 보정 기능이 없다.

if enzyme_table['Enzyme'].isin([enzyme]).any() == True:
    res_find = enzyme_table.sequence[(enzyme_table['Enzyme'] == enzyme)]
    res_find = res_find.to_string(index=False)
    res_find = str(res_find)
    print(res_find)
    # 효소 이름이 데이터베이스에 있을 경우 검색할 시퀀스 데이터를 가져온다
    res_site = enzyme_table.restriction_site[(enzyme_table['Enzyme'] == enzyme)]
    res_site = res_site.to_string(index=False)
    res_site = str(res_site)
    print(res_site)
    # 효소 이름이 데이터베이스에 있을 경우 검색하고 대체할 시퀀스 데이터를 가져온다
    cut_feature = enzyme_table.cut_feature[(enzyme_table['Enzyme'] == enzyme)]
    cut_feature = cut_feature.to_string(index=False)
    cut_feature = str(cut_feature)
    print(cut_feature)
    # blunt or sticky(나중에 저장 기능 추가할 때 넣을 예정입니다)
else: 
    print("No data in Database")

일단 여기서 진행되는 처리가 크게 두 가지임.

  1. DB에 효소가 있다
  2. DB에 효소가 없다

그레서 거기에 대한 처리를 하는 겁니다. 참고로 인식하는 시퀀스나 자르는 시퀀스에 N, W, B같은 게 들어가 있는 효소는 DB에 없음. 그거는 따로 처리가 필요해서…

if enzyme_table['Enzyme'].isin([enzyme]).any() == True:
    print(search_sequence.find(str(res_find)))
else: 
    pass
# 여기는 검색결과가 존재하지 않으면 -1로 나옵니다. (윗 블럭이랑 여기는 넘어가도 되는 부분)

여기는 패스해도 되는 부분. 마지막 줄에 패스하라고 나왔는데 그게 그 패스였냐 find()는 백준 문자열 파트에서도 꽤 썼던건데, 이거는 문자열이 있으면 문자열의 위치를(여러개 있을 경우 가장 처음 위치), 없으면 -1을 출력한다.

with open ('Result.txt','w',encoding='utf-8') as f: 
    if search_sequence.find(res_find) != -1:
        search_sequence = search_sequence.replace(res_find,res_site)
        print(enzyme,",",cut_feature)
        print(search_sequence)
        f.write(enzyme)
        f.write(", ")
        f.write(res_site)
        f.write(", ")
        f.write(cut_feature)
        f.write("\n")
        f.write(search_sequence)
        f.close()
        # DB에 효소가 있고 일치하는 시퀀스가 있을 때
    elif enzyme_table['Enzyme'].isin([enzyme]).any() == True and search_sequence.find(res_find) == -1:  
        print("No restriction site in this sequence. ")
        f.write(enzyme)
        f.write(", ")
        f.write(res_site)
        f.write(", ")
        f.write(cut_feature)
        f.write("\n")
        f.write("This restricion enzyme never cut this sequence. ")
        f.close()
        # DB에 효소가 있으나 일치하는 시퀀스가 없을 때
    else:
        print("No data in database. ")
        f.write(enzyme)
        f.write("\n")
        f.write("This restriction enzyme not entried in database. ")
        f.close()
        # DB에 효소가 없을 때

결과 출력은 크게 분기가 세 개다. 그 중 하나는 위에서도 말했던 DB에 효소가 없을 때의 분기. DB에 있을 때는

  1. DB에 있고 인식 시퀀스가 있는가?
  2. DB에 있는데 인식 시퀀스가 없는가?

이걸로 나눈다. 거기에 따라 저장 형식도 다르다.

DB에 효소가 있고 입력받은 시퀀스를 자를 때
DB에 효소가 있으나 시퀀스를 자르지 않을 때
DB에 효소가 없을 때