Skip to content

Hw14 new#3

Open
MariaLuk wants to merge 16 commits intomainfrom
HW14_new
Open

Hw14 new#3
MariaLuk wants to merge 16 commits intomainfrom
HW14_new

Conversation

@MariaLuk
Copy link
Copy Markdown
Owner

Modified tool_for_bioinformatics by using classes

from Bio import SeqUtils


class BiologicalSequence(ABC, str):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я здесь хотел сперва написать что на самом деле наследование от строки это дискуссионный вопрос)))
но обсудил с другими преподавателями и - да, по возможности лучше избегать наследования от built-in типов: оочень сложно придумать ситуацию, где издержки подтягивания всех методов (например) строки были бы оправданы.

...но если очень захочется, то наследуйтесь от collections.UserString - там этих издержек будет несколько поменьше.

# а переделать уже не успеваю
def check_alphabet(self):
if set(self.seq) <= self.alphabet:
raise UnexpectedSymbolInSeqError
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь сравнение не в ту сторону
у вас "если set, составленный из символов self.seq, является подмножеством множества self.alphabet", выбрасывается исключение

'g', 'F', 'S', 'e', 'l', 'U', 'P', 'Q', 'K', 'Y', 'u', 'y', 'd', 'h', 'k', 'r', 't', 'G', 'o', 'E',
'p', 'T', 'C', 'a'}
masses = {'A': 71.08, 'R': 156.2, 'N': 114.1, 'D': 115.1, 'C': 103.1, 'E': 129.1, 'Q': 128.1, 'G': 57.05, 'H': 137.1,
'I': 113.2, 'L': 113.2, 'K': 128.2, 'M': 131.2, 'F': 147.2, 'P': 97.12, 'S': 87.08, 'T': 101.1,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здорово, что сделали эти таблицы классовыми


def __init__(self, seq):
super().__init__(seq)
self.seq = seq
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.seq = seq стоит убрать - это поле уже унаследовано (и инициализировано в конструкторе родительского класса), здесь происходит только переприсваивание

m = 0
for acid in str(self.seq):
m += self.masses[acid]
return m
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше сократить до

return sum(self.masses[acid] for acid in self.seq)

class NucleicAcidSequence(BiologicalSequence):
def __init__(self, seq):
super().__init__(seq)
self.check_alphabet()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

круто, что в конструкторе проверяйте алфавит сразу!

"""
n = 0
for nucl in self.seq:
if nucl == 'c' or nucl == 'g' or nucl == 'C' or nucl == 'G':
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь просится if nucl in "cgCG"

можно впринципе сократить функцию до

return 100 * sum(nucl in "cgCG" for nucl in self.seq) / len(self.seq)

"""
complementary_dna = self.seq.maketrans(self.dict_comp)
res = self.seq.translate(complementary_dna)
return NucleicAcidSequence(res)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

метод complement наследуется классами {DNA,RNA}Sequence

и этот метод должен возвращать не NucleicAcidSequence, но объект того же класса, у которого он был вызван,
т.е. должно быть так:

>>> type(DNASequence("ACGT").complement())
<class '__main__.DNASequence'>

return RNASequence(res)


class RNASequence(BiologicalSequence):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RNA- и DNASequence должны наследовать от NucleicAcidSequence - у них общий метод complement.

This function provides you the opportunity to filter the FASTQ file to select sequences
that fit requirements on 5 parameters: input and output(optional) files, length, GC composition,
and quality of the reed
:parameters
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь всё ок
но вообще более эффективно было бы проходить по ридам 1 раз (а не 3), и для каждого из ридов по очереди все фильтры

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants