본문 바로가기
Python

Rosalind - Consensus and Profile

by 코딩하는 미토콘드리아 bioinformatics 2023. 10. 15.
반응형

 

문제 설명:

consensus sequence,공통서열 이란

DNA, RNA 및 단백질의 일차 구조 상에서

특정 기능에 연관된 영역에 공통적으로 존재하는 염기나 아미노산 서열을 의미합니다.

DNA와 RNA 의 경우에는

프로모터나 각종 잔사 조절 인자와 같은 특정 단백질의 결합 부위를 의미 하기에

공통서열을 파악하는 것이 중요합니다. 

 

출처 : https://www.youtube.com/watch?app=desktop&v=4HYJILahPw4

 

문제 해결:

1. 주어진 서열 간에 염기 빈도를 파악합니다.

2. 최빈값을 가진, 염기서열 간 같은 위치에서 최빈값을 가진 염기를 선별합니다. 

코드:

### Consensus and Profile

f = open('rosalind_cons.txt', 'r')
strings = []
for DNA in f.readlines():
    strings.append(DNA.rstrip())
f.close()

DNAlength = len(strings[1])
profileA = []
profileC = []
profileG = []
profileT = []

for x in range(0, DNAlength):
    profileA.append(0)
    profileC.append(0)
    profileG.append(0)
    profileT.append(0)

n =1
while n <= len(strings):
    string = strings[n]
    letters = list(string)
    c = 0
    while c < len(string):
        char = letters[c]
        if char == 'A':
            profileA[c] = profileA[c] + 1
        if char == 'C':
            profileC[c] = profileC[c] + 1
        if char == 'G':
            profileG[c] = profileG[c] + 1
        if char == 'T':
            profileT[c] = profileT[c] + 1
        c = c + 1 
    n = n + 2

consensus = []

for char in range(0, len(profileA)):
	d = {profileA[char]:'A', profileC[char]:'C', profileG[char]:'G', profileT[char]:'T'}
	maximum = max(k for k, v in d.items())
	consensus.append(d[maximum])

print (''.join(consensus))

strA = 'A: ' + ''.join(str(e) for e in profileA)
strC = 'C: ' + ''.join(str(e) for e in profileC)
strG = 'G: ' + ''.join(str(e) for e in profileG)
strT = 'T: ' + ''.join(str(e) for e in profileT)

print(strA.strip() + '\n' + strC.strip() + '\n' +strG.strip() + '\n'+ strT.strip())
#result
#TGCCCGGCTATTTGATGACATACCACCGGGTAGAGAACTAAGTCCTGTTACGGAGAAGCG
#A: 122220201625182123251818182427181830202521252619302018172115172612241922262217232517201722161914192415202125182722201818
#C: 212326262917242621242519202023242625272116242729182230171722212119191718132915161721172422211617192024171724232121212421
#G: 202822191926251918201721232417212915242424231721231916252525211528212419191222211624162020212621192122242214241721252221
#T: 371722252622232428213032292223271720192029182021191916211718211821162021221726202218271916221928231519192017151516141620
반응형