HW4 Sivtsev#21
Conversation
Merge Zoea1 fork with fork HW4_Sivtsev. Added 3 new functions: count_aa_length, count_nucl_length, protein_tools.
Update README.md
Edit READ.md add coursive
| aminoacid_alphabet_1to3 = {'A': 'Ala', 'R': 'Arg', 'N': 'Asn', 'D': 'Asp', 'C': 'Cys', | ||
| 'Q': 'Gln', 'E': 'Glu', 'G': 'Gly', 'H': 'His', 'I': 'Ile', | ||
| 'L': 'Leu', 'K': 'Lys', 'M': 'Met', 'F': 'Phe', 'P': 'Pro', | ||
| 'S': 'Ser', 'T': 'Thr', 'W': 'Trp', 'Y': 'Tyr', 'V': 'Val'} | ||
|
|
||
| molecular_mass = {'A': 89.094, 'R': 174.203, 'N': 132.119, 'D': 133.104, 'C': 121.154, |
There was a problem hiding this comment.
Поскольку эти переменные являются константами, то их стоит назвать заглавными буквами
| bool if sequence is correct | ||
| ValueError('Please check proteins sequences') if there were wrong symbols | ||
| """ | ||
| aas = {'A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y'} |
| prot = prot.upper() | ||
| uniq_aas = set(prot) |
There was a problem hiding this comment.
Можжно в одну строку, чтобы память не забивать prot-ом
| aa_test = (uniq_aas <= aas) | ||
| if aa_test == 0: | ||
| raise ValueError('Please check proteins sequences') | ||
| return True |
There was a problem hiding this comment.
Лучше использовать функционал множеств, и результат операции не записывать в отдельную переменную
| aa_test = (uniq_aas <= aas) | |
| if aa_test == 0: | |
| raise ValueError('Please check proteins sequences') | |
| return True | |
| aa_test = (uniq_aas <= aas) | |
| if uniq_aas.issubset(aas): | |
| return True | |
| else: | |
| raise ValueError('Please check proteins sequences') |
| if len(prot) > 0: | ||
| for i in prot: | ||
| if i in aminoacid_alphabet_1to3: | ||
| output += aminoacid_alphabet_1to3[i] | ||
| else: | ||
| raise ValueError('Input format: aminoacids in uppercase 1-letter symbols') | ||
| return output |
There was a problem hiding this comment.
Очень много уровней вложенности
У вас же есть проверка на то, является ли послед-ть белком, зачем внутри писать другую проверку, тем более итерируясь по каждой а\к отдельно? Довольно неоптимально
Тем более в главной фукнции вы эту проверку is_prot используете, у вас нет шанса при вызове этой функции выйти в ошибку, а строк вложенных написано много
| else: | ||
| for i in prot_seq: | ||
| output += prot.count(i) * molecular_mass[i] | ||
| output -= 18.0153*(len(prot)-1) |
There was a problem hiding this comment.
PEP8 грустит
| output -= 18.0153*(len(prot)-1) | |
| output -= 18.0153 * (len(prot) - 1) |
| Return: | ||
| -int - the result of the count | ||
| """ | ||
| return len(prot)*3 |
There was a problem hiding this comment.
PEP8 грустит
| return len(prot)*3 | |
| return len(prot) * 3 |
| Return: aa_content (dict) - dict of aminoacids and their quantity in protein | ||
| """ | ||
|
|
||
| aas = 'ACDEFGHIKLMNPQRSTVWY' |
There was a problem hiding this comment.
по идее должна быть как константа, более того, лучше уж сетом
| """ | ||
|
|
||
| aas = 'ACDEFGHIKLMNPQRSTVWY' | ||
| prot = prot.upper() |
There was a problem hiding this comment.
надо бы это делать в главной функции, а то в маленьких функциях то есть, то нет, и в целом это лучше в основной сделать до вызова нужной операции
| for i in range(len(prot)): | ||
| n = aas.index(prot[i]) | ||
| aa_counter[n] += 1 |
| Return: e (int) - result of counts: extinction coefficient at 280 nm | ||
|
|
||
| """ | ||
| aa_cont_dict = count_aa_content(prot) |
There was a problem hiding this comment.
Здорово, что переиспользовали имеющуюся функцию!)
| W_number = aa_cont_dict.get('W') | ||
| Y_number = aa_cont_dict.get('Y') | ||
| C_number = aa_cont_dict.get('C') |
There was a problem hiding this comment.
С заглавной буквы переменные не надо называть
| if C_number == 0: | ||
| e = 5500 * W_number + 1490 * Y_number | ||
| else: | ||
| e = 5500 * W_number + 1490 * Y_number + 125*(C_number//2) |
There was a problem hiding this comment.
Но ведь это буквально одно и то же....
| return e | ||
|
|
||
|
|
||
| def protein_tools (function : str, *prots : str) -> (int, list, str): |
There was a problem hiding this comment.
Эх, а можно было бы операцию в конце указать, так было бы интереснее функцию писать....(
|
Неплохая работа!
|
Homework №4.