본문 바로가기
Python

Rosalind - Computing GC Content

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

문제 설명:

GC 함량 (GC contents) 는 해당 영역의 전체 염기 중 구아닌 (G) 와 시토신 (C) 의 비율을 의미하는데

이는 높을수록 DNA 밀도가 높고 변성의 저항성이 높은 것으로 알려져 있습니다. 

해당 문제는 데이터 형태( 첫줄은 > Rosalind_0000 뒤에 서열이 이어짐) 를 고려해서

풀어야 하고 NCBI 에서 제공되는 형태랑 유사합니다.

 

출처:Efficient computation of absent words in genomic sequences

 

코드:

import re

f=open("./rosalind_gc.txt", "r")

lines = f.readlines()
name=[]
score=[]
seq=[]
temp=[]
lengthlines= len(lines)-1

for line in lines:
    if re.match(">",line):
        name.append(line.replace(">",""))
        if temp:
            seq.append("".join(temp))
            temp=[]
    else:
        if lines[lengthlines]==line:
            temp.append(line)
            seq.append("".join(temp))
        else:
            temp.append(line)
for i in range(0,len(seq)):
    length = len(seq[i]) - seq[i].count("\n")
    score.append((seq[i].count("C")+seq[i].count("G"))/length*100)

maxvalue = score.index(max(score))
print(name[maxvalue])
print(round(score[maxvalue],6))
f.close
#result
#Rosalind_9046
51.869159

 

반응형

'Python' 카테고리의 다른 글

Rosalind - Mendel's First Law  (0) 2023.09.30
Rosalind - Counting Point Mutations  (0) 2023.09.23
Rosalind - Rabbits and Recurrence Relations  (0) 2023.09.11
Rosalind - Complementing a Strand of DNA  (0) 2023.09.11
Rosalind - Transcribing DNA into RNA  (0) 2023.09.11