-
Notifications
You must be signed in to change notification settings - Fork 45
Hw4 mukhametshina #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
[![Будто бы полезная ссылка, но просто попытка вставить ссылку_2]<a href="url"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/AminoAcidball_rus.svg/1280px-AminoAcidball_rus.svg.png" align="left" height="128" width="198" ></a>](https://ru.wikipedia.org/wiki/%D0%90%D0%BC%D0%B8%D0%BD%D0%BE%D0%BA%D0%B8%D1%81%D0%BB%D0%BE%D1%82%D1%8B) | ||
> *Можно было добавить что-то полезное* | ||
|
||
|
||
# HW 4. Functions 2 | ||
> *This is the repo for the fourth homework of the BI Python 2023 course* | ||
|
||
## Table of contents | ||
|
||
* [Project description](#project-description) | ||
* [Main part](#Main-part) | ||
* [Project description](#project-description) | ||
* [Examples](#examples) | ||
* [Contact](#contact) | ||
* [Educational result](#Учебный-результат) | ||
* [See also](#see-also) | ||
Comment on lines
+8
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это супер-здорово, спасибо! |
||
|
||
## Project description | ||
This project was supposed to be carried out in a team, but, unfortunately, I was unable to do only part of this project - all the code and the mini-program were written by me independently. As this HW, I refreshed my memory in working through GitHub, as well as the basic concepts of the Python language. | ||
|
||
 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😁😁😁 |
||
|
||
As a given HW, need to write your own utility for working with amino acid sequences. In addition, it is necessary to issue a file README.md as if this is the last file I wrote in my life | ||
|
||
> *Я очень постараюсь выполнить хороший ридми файл, но не обещаю, что он будет лучшим в моей жизни* | ||
|
||
## Main part | ||
Implemented the program `amino_acid_tools.py `. This program necessarily contains the `amino_acid_tools` function, as well as other functions that are described below. The `amino_acid_tools` function accepts an arbitrary number of arguments with a sequence of amino acids or several amino acid sequences (*str*), and it is also possible to introduce the word "random", which generates a random chain of amino acids, in addition, you must enter the name of the procedure to be performed (this is always the last argument, *str*, see usage example). After that, the command performs the specified action on all the transmitted sequences. If one sequence is submitted, a string with the result is returned. If several are submitted, a list of strings is returned. | ||
|
||
**Список процедур:** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Внезапно parle france |
||
- `long_amino_code (*str*) or (*list*)` — translated sequence from one-letter in three-letter code | ||
- `molecular_weight (*int*) or (*list*)` — amino acid sequence molecular weight number or list of numbers | ||
- `amino_to_rna (*str*) or (*list*)` — possible* RNA sequence | ||
- `amino_seq_charge (*str*) or (*list*)` — "positive", "negative" or "neutral" | ||
|
||
*- for more information, see the " [See also](#see-also) " section | ||
|
||
## Examples | ||
Below is an example of processing an amino acid sequence. | ||
|
||
### Using the function for translated sequence from one-letter in three-letter code | ||
|
||
```shell | ||
amino_acid_tools('PLfHnfPdD', 'YsGPFEEt', 'ogknHIPTu', 'long_amino_code') | ||
``` | ||
Input: 'PLfHnfPdD', 'YsGPFEEt', 'ogknHIPTu', 'long_amino_code' | ||
Output: '['ProLeuPheHisAsnPheProAspAsp', 'TyrSerGlyProPheGluGluThr', 'PylGlyLysAsnHisIleProThrSec']' | ||
Comment on lines
+43
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Во, да, так и надо. Чтобы можно было просто скопипастить и прогнать. Только можно наверное вставить оформление не shell, а python. И строчка и Input в целом тут лишняя, у тебя же в коде как раз input и виден:) |
||
|
||
### Using the function for molecular weight calculation | ||
|
||
```shell | ||
amino_acid_tools('fHnfPdPL','CpUPQWhmrY','random', 'CpUPQWhmrY','molecular_weight') | ||
``` | ||
|
||
Input: 'fHnfPdPL','CpUPQWhmrY','random', 'CpUPQWhmrY','molecular_weight' | ||
Input: 9 | ||
Output:[968.14, 1367.39, ('рандомная последовательнсть', 'FySiDfGym', 1124.43), 1367.39] | ||
|
||
### Using the function to convert possible RNA sequence | ||
|
||
```shell | ||
amino_acid_tools('DwhAntMcR', 'cvdrLepaW', 'VurgdOhio', 'amino_to_rna') | ||
``` | ||
|
||
Input: 'DwhAntMcR', 'cvdrLepaW', 'VurgdOhio', 'amino_to_rna' | ||
Output: Unknown amino acid code: u | ||
Unknown amino acid code: O | ||
Unknown amino acid code: o | ||
['GAUuggcauGCGaacacaAUGugcCGU', 'ugugucgaccggCUAgagccggcgUGG', 'GUUcgaggcgaucacauc'] | ||
|
||
|
||
### Using the function to estimate relative charge | ||
|
||
```shell | ||
amino_acid_tools('DwhAntMcR', 'cvdrLepaW', 'VurgdOhio', 'amino_seq_charge') | ||
``` | ||
|
||
Input: 'random', 'cvdrLepaW', 'VurgdOhio', 'amino_seq_charge' | ||
Output: [('рандомная последовательнсть', 'UgMMFsGed', 'negativ'), 'negativ', 'positiv'] | ||
|
||
**Еще один пример использования** | ||
```python | ||
Using the function for translated sequence from one-letter in three-letter code: | ||
amino_acid_tools('PLfHnfPdD','long_amino_code') # 'ProLeuPheHisAsnPheProAspAsp' | ||
amino_acid_tools('random', 'CpUPQWhmrY','molecular_weight') # [('рандомная последовательнсть', 'FySiDfGym', 1124.43), 1367.39] | ||
amino_acid_tools('cvdrLepaW', 'amino_to_rna') # 'ugugucgaccggCUAgagccggcgUGG' | ||
amino_acid_tools('cvdrLepaW', 'VurgdOhio', 'amino_seq_charge') # ['negativ', 'positiv'] | ||
``` | ||
|
||
|
||
### **Учебный результат** | ||
|
||
This task ~~позволило понять, что командная работа сокращает очень много времени и позволяет получить больше баллов за сданный вовремя проект~~ helped to better understand the Git system in practice, also to practice writing your own bioinformatic functions, as well as to better understand such things as "ответственность" "team" | ||
|
||
## Смотрите также | ||
[](https://fb.ru/article/314147/vyirojdennost-geneticheskogo-koda-obschie-svedeniya?ysclid=lnm3d0r35691821607) | ||
|
||
> *Можно нажать на картинку для получения дополнительной информации* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍 |
||
|
||
## Contact | ||
- [Mukhametshina Regina] [email protected] | ||
|
||
|
||
 | ||
|
||
> *Поставьте пожалуйста доп балл за будто бы скриншот с командой* | ||
|
||
Спасибо! ✨✨ |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,241 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_acid = 'ARNDCEQGHILKMFPSTWYVUOarndceqghilkmfpstwyvuo' | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Но в целом правильно сделала, просто пару советов по доработке |
||||||||||||||||||||||||||||||||||||||||||||||||
short_code = list(amino_acid) | ||||||||||||||||||||||||||||||||||||||||||||||||
long_code = ['Ala', 'Arg', 'Asn', 'Asp', 'Cys', 'Glu', 'Gln', 'Gly', 'His', 'Ile', 'Leu', 'Lys', 'Met', 'Phe', 'Pro', | ||||||||||||||||||||||||||||||||||||||||||||||||
'Ser', 'Thr', 'Trp', 'Tyr', 'Val', 'Sec', 'Pyl', | ||||||||||||||||||||||||||||||||||||||||||||||||
'Ala', 'Arg', 'Asn', 'Asp', 'Cys', 'Glu', 'Gln', 'Gly', 'His', 'Ile', 'Leu', 'Lys', 'Met', 'Phe', 'Pro', | ||||||||||||||||||||||||||||||||||||||||||||||||
'Ser', 'Thr', 'Trp', 'Tyr', 'Val', 'Sec', 'Pyl'] | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+2
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Хм. Кажется это было бы здорово оформить в качестве словаря AA_CODES = {'A': 'Ala', ... } Такого вида |
||||||||||||||||||||||||||||||||||||||||||||||||
codon_table = { | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Опять же, капсом. Я бы еще как нибудь типа |
||||||||||||||||||||||||||||||||||||||||||||||||
'A': ['GCU', 'GCC', 'GCA', 'GCG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'R': ['CGU', 'CGC', 'CGA', 'CGG', 'AGA', 'AGG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'N': ['AAU', 'AAC'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'D': ['GAU', 'GAC'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'C': ['UGU', 'UGC'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'Q': ['CAA', 'CAG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'E': ['GAA', 'GAG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'G': ['GGU', 'GGC', 'GGA', 'GGG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'H': ['CAU', 'CAC'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'I': ['AUU', 'AUC', 'AUA'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'L': ['UUA', 'UUG', 'CUU', 'CUC', 'CUA', 'CUG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'K': ['AAA', 'AAG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'M': ['AUG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'F': ['UUU', 'UUC'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'P': ['CCU', 'CCC', 'CCA', 'CCG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'S': ['UCU', 'UCC', 'UCA', 'UCG', 'AGU', 'AGC'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'T': ['ACU', 'ACC', 'ACA', 'ACG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'W': ['UGG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'Y': ['UAU', 'UAC'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'V': ['GUU', 'GUC', 'GUA', 'GUG'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'STOP': ['UAA', 'UAG', 'UGA'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'f': ['uuu', 'uuc'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'l': ['uua', 'uug', 'cuu', 'cuc', 'cua', 'cug'], | ||||||||||||||||||||||||||||||||||||||||||||||||
's': ['ucu', 'ucc', 'uca', 'ucg', 'agu', 'agc'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'y': ['uau', 'uac'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'c': ['ugu', 'ugc'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'w': ['ugg'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'p': ['ccu', 'ccc', 'cca', 'ccg'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'h': ['cau', 'cac'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'q': ['caa', 'cag'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'r': ['cgu', 'cgc', 'cga', 'cgg', 'aga', 'agg'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'i': ['auu', 'auc', 'aua'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'm': ['aug'], | ||||||||||||||||||||||||||||||||||||||||||||||||
't': ['acu', 'acc', 'aca', 'acg'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'n': ['aau', 'aac'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'k': ['aaa', 'aag'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'v': ['guu', 'guc', 'gua', 'gug'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'a': ['gcu', 'gcc', 'gca', 'gcg'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'd': ['gau', 'gac'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'e': ['gaa', 'gag'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'g': ['ggu', 'ggc', 'gga', 'ggg'], | ||||||||||||||||||||||||||||||||||||||||||||||||
'stop': ['uaa', 'uag', 'uga'] | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
weight_amino = [71.08, 156.2, 114.1, 115.1, 103.1, 129.1, 128.1, 57.05, 137.1, 113.2, 113.2, 128.2, 131.2, 147.2, 97.12, 87.08, | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||||||||||||||
101.1, 186.2, 163.2, 99.13, 168.05, 255.3, | ||||||||||||||||||||||||||||||||||||||||||||||||
71.08, 156.2, 114.1, 115.1, 103.1, 129.1, 128.1, 57.05, 137.1, 113.2, 113.2, 128.2, 131.2, 147.2, 97.12, 87.08, | ||||||||||||||||||||||||||||||||||||||||||||||||
101.1, 186.2, 163.2, 99.13, 168.05, 255.3] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
import random | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Импорты в самом в самом начале, до констант |
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
def long_amino_code(sequence): | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. названия функций должны быть глаголами |
||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
Function translates a given sequence of one-letter amino acids | ||||||||||||||||||||||||||||||||||||||||||||||||
into a more understandable sequence of amino acids consisting of three letters | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
Parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||
sequence (str): each letter refers to one-letter coded proteinogenic amino acids or "random" | ||||||||||||||||||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||
(str) translated in three-letter code | ||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
if sequence != 'random': | ||||||||||||||||||||||||||||||||||||||||||||||||
d_names = dict(zip(short_code, long_code)) | ||||||||||||||||||||||||||||||||||||||||||||||||
recording = sequence.maketrans(d_names) | ||||||||||||||||||||||||||||||||||||||||||||||||
return sequence.translate(recording) | ||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||
len = int(input("введите желаемую длину: ")) | ||||||||||||||||||||||||||||||||||||||||||||||||
bases = list(amino_acid) | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_sequencqe = ''.join(random.choice(bases) for i in range(len)) | ||||||||||||||||||||||||||||||||||||||||||||||||
d_names = dict(zip(short_code, long_code)) | ||||||||||||||||||||||||||||||||||||||||||||||||
recording = amino_sequencqe.maketrans(d_names) | ||||||||||||||||||||||||||||||||||||||||||||||||
return "рандомная последовательнсть", amino_sequencqe, amino_sequencqe.translate(recording) | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+68
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #1) Не надо было делать взаимодействие с пользователем через input. Но ладно, тут у тебя дизайн такой, пусть будет.
Suggested change
Красота же! Еще кажется у тебя там опечатки типа |
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
def molecular_weight(sequence): | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Глагол. Но можно сокращения, если они понятные и общепринятые |
||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
Function calculates molecular weight of the amino acid chain | ||||||||||||||||||||||||||||||||||||||||||||||||
Parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||
sequence (str): each letter refers to one-letter coded proteinogenic amino acids or "random" | ||||||||||||||||||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||
weight (float) Molecular weight of tge given amino acid chain in Da | ||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
if sequence != 'random': | ||||||||||||||||||||||||||||||||||||||||||||||||
molecular_weights = dict(zip(short_code, weight_amino)) | ||||||||||||||||||||||||||||||||||||||||||||||||
weight = sum(molecular_weights.get(aa, 0) for aa in sequence) | ||||||||||||||||||||||||||||||||||||||||||||||||
return weight | ||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||
len = int(input("введите желаемую длину: ")) | ||||||||||||||||||||||||||||||||||||||||||||||||
bases = list(amino_acid) | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_sequencqe = ''.join(random.choice(bases) for i in range(len)) | ||||||||||||||||||||||||||||||||||||||||||||||||
molecular_weights = dict(zip(short_code, weight_amino)) | ||||||||||||||||||||||||||||||||||||||||||||||||
weight = sum(molecular_weights.get(aa, 0) for aa in amino_sequencqe) | ||||||||||||||||||||||||||||||||||||||||||||||||
return "рандомная последовательнсть", amino_sequencqe, weight | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+88
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вот тут аналогично. Ты повторяешь код, и тогда можно блыо бы его оформить как в моем комменте выше. Но вообще у тебя получается прям этот блок с рандомом повторяется в разных функциях.
Я бы этот блок (как в моем прошлом комменте) вынес в главную функцию
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
def amino_to_rna(amino_sequence): | ||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
Function translates an amino acid sequence into a possible RNA sequence | ||||||||||||||||||||||||||||||||||||||||||||||||
Parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_sequence (str) or "random" | ||||||||||||||||||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||
(str) possible RNA sequence | ||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
if amino_sequence != 'random': | ||||||||||||||||||||||||||||||||||||||||||||||||
rna_sequence = "" | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+108
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут аналогично |
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
for aminoacid in amino_sequence: | ||||||||||||||||||||||||||||||||||||||||||||||||
if aminoacid in codon_table: | ||||||||||||||||||||||||||||||||||||||||||||||||
codons = codon_table[aminoacid] | ||||||||||||||||||||||||||||||||||||||||||||||||
# Selecting one random codon | ||||||||||||||||||||||||||||||||||||||||||||||||
codon = random.choice(codons) | ||||||||||||||||||||||||||||||||||||||||||||||||
rna_sequence += codon | ||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||
print("Unknown amino acid code: ", aminoacid) | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Наверное в таком случае было бы лучше упасть с ошибкой
Suggested change
Только наверное проверка воода это опять же работа не этих функций, а лучше было бы сделать где то в самом начале в главной функции |
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
return rna_sequence | ||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||
len = int(input("введите желаемую длину: ")) | ||||||||||||||||||||||||||||||||||||||||||||||||
bases = list(amino_acid) | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_sequencqe = ''.join(random.choice(bases) for i in range(len)) | ||||||||||||||||||||||||||||||||||||||||||||||||
rna_sequence = "" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
for aminoacid in amino_sequencqe: | ||||||||||||||||||||||||||||||||||||||||||||||||
if aminoacid in codon_table: | ||||||||||||||||||||||||||||||||||||||||||||||||
codons = codon_table[aminoacid] | ||||||||||||||||||||||||||||||||||||||||||||||||
# Selecting one random codon | ||||||||||||||||||||||||||||||||||||||||||||||||
codon = random.choice(codons) | ||||||||||||||||||||||||||||||||||||||||||||||||
rna_sequence += codon | ||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||
print("Unknown amino acid code: ", aminoacid) | ||||||||||||||||||||||||||||||||||||||||||||||||
return "рандомная последовательнсть", amino_sequencqe, rna_sequence | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ну и если по-русски, то все таки "случайная" :) |
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
def amino_seq_charge(amino_sequence): | ||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
Function evaluates the overall charge of the aminoacid chain in neutral aqueous solution (pH = 7) | ||||||||||||||||||||||||||||||||||||||||||||||||
Parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_sequence (str): amino acid sequence of proteinogenic amino acids or "random" | ||||||||||||||||||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||
(str): "positive", "negative" or "neutral" | ||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
if amino_sequence != 'random': | ||||||||||||||||||||||||||||||||||||||||||||||||
aminoacid_charge = {'R': 1, 'D': -1, 'E': -1, 'K': 1, 'O': 1} | ||||||||||||||||||||||||||||||||||||||||||||||||
charge = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
for aminoacid in amino_sequence.upper(): | ||||||||||||||||||||||||||||||||||||||||||||||||
if aminoacid in 'RDEKO': | ||||||||||||||||||||||||||||||||||||||||||||||||
charge += aminoacid_charge[aminoacid] | ||||||||||||||||||||||||||||||||||||||||||||||||
if charge > 0: | ||||||||||||||||||||||||||||||||||||||||||||||||
return 'positiv' | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
)) А вообще было бы здорово прямо заряд сам и вернуть наверное |
||||||||||||||||||||||||||||||||||||||||||||||||
elif charge < 0: | ||||||||||||||||||||||||||||||||||||||||||||||||
return 'negativ' | ||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||
return 'neutral' | ||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||
len = int(input("введите желаемую длину: ")) | ||||||||||||||||||||||||||||||||||||||||||||||||
bases = list(amino_acid) | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_sequencqe = ''.join(random.choice(bases) for i in range(len)) | ||||||||||||||||||||||||||||||||||||||||||||||||
aminoacid_charge = {'R': 1, 'D': -1, 'E': -1, 'K': 1, 'O': 1} | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. но то что у тебя эта штука дважды создается - не очень хорошо так как копипаст, можно было бы в начале функции или вообще в качестве константы |
||||||||||||||||||||||||||||||||||||||||||||||||
charge = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
for aminoacid in amino_sequencqe.upper(): | ||||||||||||||||||||||||||||||||||||||||||||||||
if aminoacid in 'RDEKO': | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. это будет как раз проверка на наличие в ключах |
||||||||||||||||||||||||||||||||||||||||||||||||
charge += aminoacid_charge[aminoacid] | ||||||||||||||||||||||||||||||||||||||||||||||||
if charge > 0: | ||||||||||||||||||||||||||||||||||||||||||||||||
return "рандомная последовательнсть", amino_sequencqe, 'positiv' | ||||||||||||||||||||||||||||||||||||||||||||||||
elif charge < 0: | ||||||||||||||||||||||||||||||||||||||||||||||||
return "рандомная последовательнсть", amino_sequencqe, 'negativ' | ||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||
return "рандомная последовательнсть", amino_sequencqe, 'neutral' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
def amino_seqs(amino_sequence): | ||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
Leaves only the amino acid sequences from the fed into the function. | ||||||||||||||||||||||||||||||||||||||||||||||||
Parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_sequence (list): amino acid sequence list or "random" | ||||||||||||||||||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_seqs (list): amino acid sequence list without non amino acid sequence | ||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
if amino_sequence != 'random': | ||||||||||||||||||||||||||||||||||||||||||||||||
aminoac_seqs = [] | ||||||||||||||||||||||||||||||||||||||||||||||||
for seq in amino_sequence: | ||||||||||||||||||||||||||||||||||||||||||||||||
unique_chars = set(seq) | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_acids = set(amino_acid) | ||||||||||||||||||||||||||||||||||||||||||||||||
if unique_chars <= amino_acids: | ||||||||||||||||||||||||||||||||||||||||||||||||
aminoac_seqs.append(seq) | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+184
to
+188
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. то есть если пользователь добавил что-то неправильное, то он об этом даже и не узнает? |
||||||||||||||||||||||||||||||||||||||||||||||||
return aminoac_seqs | ||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||
len = int(input("введите желаемую длину: ")) | ||||||||||||||||||||||||||||||||||||||||||||||||
bases = list(amino_acid) | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_sequencqe = ''.join(random.choice(bases) for i in range(len)) | ||||||||||||||||||||||||||||||||||||||||||||||||
aminoac_seqs = list(amino_sequencqe) | ||||||||||||||||||||||||||||||||||||||||||||||||
return "рандомная последовательнсть", amino_sequencqe, aminoac_seqs | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
def amino_acid_tools(*args: str): | ||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
Performs functions for working with amino acid sequences. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
Parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||
The function should accept an unlimited number of protein sequences (str) as input, | ||||||||||||||||||||||||||||||||||||||||||||||||
the last variable should be the function (str) that you want to execute. | ||||||||||||||||||||||||||||||||||||||||||||||||
The amino acid sequence can consist of both uppercase and lowercase letters. | ||||||||||||||||||||||||||||||||||||||||||||||||
Input example: | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_acid_tools('LVElkPL','CpUPQWhmrY','McgMmLcTTG','molecular_weight') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
or | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
amino_acid_tools('LVElkPL','CpUPQWhmrY','random','molecular_weight') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
Function: | ||||||||||||||||||||||||||||||||||||||||||||||||
molecular weight: calculates the molecular weight of an amino acid chain | ||||||||||||||||||||||||||||||||||||||||||||||||
long_amino_code: converts translations from one letter to translations | ||||||||||||||||||||||||||||||||||||||||||||||||
from three letters | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_to_rna translates a sequence of amino acids into a possible sequence of nucleic acids | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_seq_charge: estimates the total charge of the amino acid chain in a neutral aqueous solution (pH = 7) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||
If one sequence is supplied, a string with the result is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||
If several are submitted, a list of strings is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||
Depending on the function performed, the following returns will occur: | ||||||||||||||||||||||||||||||||||||||||||||||||
long_amino_code (str) or (list): translated sequence from one-letter in three-letter code | ||||||||||||||||||||||||||||||||||||||||||||||||
molecular_weight (int) or (list): amino acid sequence molecular weight number or list of numbers | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_to_rna (str) or (list): possible RNA sequence | ||||||||||||||||||||||||||||||||||||||||||||||||
amino_seq_charge (str) or (list): "positive", "negative" or "neutral" | ||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
*seqs, function = args | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это было актуально в домашке по ДНК/РНК чтобы вы потреннировались с аргументами. Вообще это не очень хорошо, так как по факту сиквенсы и название функции - это разные сущности. А мы их мешаем в одну дырку. Это не хорошо. Есть есть разные штуки - то и принимать их стоит в разные аргументы. def function(seqs, func): |
||||||||||||||||||||||||||||||||||||||||||||||||
d_of_functions = {'long_amino_code' : long_amino_code, | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
'molecular_weight': molecular_weight, | ||||||||||||||||||||||||||||||||||||||||||||||||
'amino_to_rna' : amino_to_rna, | ||||||||||||||||||||||||||||||||||||||||||||||||
'amino_seq_charge' : amino_seq_charge} | ||||||||||||||||||||||||||||||||||||||||||||||||
answer = [] | ||||||||||||||||||||||||||||||||||||||||||||||||
aminoacid_seqs = amino_seqs(seqs) | ||||||||||||||||||||||||||||||||||||||||||||||||
for sequence in aminoacid_seqs: | ||||||||||||||||||||||||||||||||||||||||||||||||
answer.append(d_of_functions[function](sequence)) | ||||||||||||||||||||||||||||||||||||||||||||||||
if len(answer) == 1: | ||||||||||||||||||||||||||||||||||||||||||||||||
return answer[0] | ||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||
return answer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Хех, правильно! Потом если когда в жизни будешь вставлять ссылки, сможешь прям отсюда и копировать