티스토리 뷰
In genetics, a distinction is made between two types of mutations (the replacement of one nucleotide by a different nucleotide). A transition changes a purine nucleotide (two rings) into another purine (A ↔ G), or changes a pyrimidine nucleotide (one ring) into another pyrimidine (C ↔ T). All other mutations in which a purine is substituted for a pyrimidine, or vice versa, are called transversions.

Although in theory there are only four possible transitions and eight possible transversions, in practice transitions are more likely than transversions because substituting a single ring structure for another single ring structure is more likely than substituting a double ring for a single ring. Also, transitions are less likely to result in amino acid substitutions (due to wobble base pair) and are therefore more likely to persist as silent substitutions in populations.
Assignment
In this assignment we represent DNA sequences as strings that only contains the letters A, C, G and T. These letters represent the nucleotides that make up the DNA sequence. The nucleotides can also be represented using their lowercase variants. Given two DNA sequences and that have the same length, we define their transition/transversion ratio as the ratio of the number of transitions to the number of transversions, where nucleotides at the corresponding positions between the two DNA sequences are compared with each other.
The transition/transversion ratio between homologous strands of DNA is generally about 2, but it is typically elevated in coding regions, where transversions are more likely to change the underlying amino acid and thus possibly lead to a fatal mutation in the translated protein. Point mutations that do not change this amino acid (which are thus more likely for transitions) are called silent substitutions. Your task:
Write a function transition that takes two nucleotides. The function must return a Boolean value that indicates whether or not replacing the first nucleotide by the second nucleotide leads to a transition.
Write a function transversion that takes two nucleotides. The function must return a Boolean value that indicates whether or not replacing the first nucleotide by the second nucleotide leads to a transversion.
Write a function ratio that takes two DNA sequences and . The function may assume that both sequences have the same length (the function does not need to check this explicitly). The function must return the transition/transversion ratio of the two given sequences as a floating point number. In case there are no transversions between the two sequences, by definition.
None of these function may make a distinction between uppercase and lowercase letters in the arguments passed to them.
Example
>>> transition('G', 'A')
True
>>> transition('t', 'g')
False
>>> transition('C', 'c')
False
>>> transversion('G', 'A')
False
>>> transversion('t', 'g')
True
>>> transversion('C', 'c')
False
>>> ratio('ATTAGCATTATCATC', 'AAATAGGATATATGG')
0.2222222222222222
>>> seq1 = 'GCAACGCACAACGAAAACCCTTAGGGACTGGATTATTTCGTGATCGTTGTAGTTATTGGAAGTACGGGCATCAACCCAGTT'
>>> seq2 = 'ttatctgacaaagaaagccgtcaacggctggataatttcgcgatcgtgctggttactggcggtacgagtgttcctttgggt'
>>> ratio(seq1, seq2)
1.2142857142857142
def transition(a, b):
GROUP_TOKENS = [['A', 'G'], ['C', 'T']]
for tokens in GROUP_TOKENS:
if a.lower() == tokens[0].lower():
if b.lower() == tokens[1].lower():
return True
if b.lower() == tokens[0].lower():
if a.lower() == tokens[1].lower():
return True
return False
def transversion(a, b):
GROUP_TOKENS = [['a', 'g', 'A', 'G'], ['c', 't', 'C', 'T']]
if a in GROUP_TOKENS[0]:
if b.lower() in GROUP_TOKENS[1]:
return True
if a in GROUP_TOKENS[1]:
if b in GROUP_TOKENS[0]:
return True
return False
def ratio(a, b):
count_transition = 0
count_transversion = 0
for i, char in enumerate(a):
count_transition += 1 if transition(char, b[i]) else 0
count_transversion += 1 if transversion(char, b[i]) else 0
return (count_transition / count_transversion) if count_transversion != 0 else 0.0
print(ratio(str(input()), str(input())))
'python lecture > algorism' 카테고리의 다른 글
[edu] Zigzag (0) | 2018.10.15 |
---|---|
[edu] Kaprekar series (0) | 2018.10.14 |
[edu] Word sums (0) | 2018.10.08 |
[edu] Penney Ante (0) | 2018.10.06 |
[edu] Corkscrew (0) | 2018.10.04 |
- Total
- Today
- Yesterday
- 파이썬 입문
- PuTTYGen
- Tistory
- chatbot
- 문과 코딩
- virtualenv
- 모바일 테마 적용
- 장고
- 파이썬
- django chatbot
- 면접답변
- 장고 카톡 자동응답
- gitignore
- django
- 장고 플러스친구 자동응답
- 엑셀 비교
- wsgi
- pycrypto
- Python
- 파이썬 프로그래밍
- GIT
- 문서 비교
- gitlab
- 모바일 스킨 적용
- 면접정답
- admin.py
- 플러스친구 자동응답
- 이미지 비교
- 파이썬 독학
- 파이썬 강좌
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |