Skip to content

Review RHNO1#34

Open
nvaulin wants to merge 1 commit intomainfrom
RHNO1
Open

Review RHNO1#34
nvaulin wants to merge 1 commit intomainfrom
RHNO1

Conversation

@nvaulin
Copy link
Copy Markdown
Member

@nvaulin nvaulin commented Feb 26, 2024

Review RHNO1

Copy link
Copy Markdown

@uzunmasha uzunmasha left a comment

Choose a reason for hiding this comment

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

Привет! Хороший код! Структурированный и хорошо читаемый
Есть только пара косметических комментариев

Comment thread RHNO1.py
if min(record.letter_annotations["phred_quality"]) < self.min_quality:
return False

gc_content = gc_fraction(record.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.

gc_content = GC(record.seq)
Для подсчета гц-состава можно использовать такой подход. Импортируется через from Bio.SeqUtils import GC

Comment thread RHNO1.py


class NucleicAcidSequence(BiologicalSequence):
complement_dict = {"A": "", "T": "", "G": "", "C": ""}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не очень поняла зачем здесь эта строка. Кажется, что она определяет словарь, который фактически не используется в классе NucleicAcidSequence, так как метод complement() использует словарь, определенный в дочерних классах DNASequence и RNASequence. Но лучше, конечно, чтобы в этом классе все определялось, а не в наследуемых.

Comment thread RHNO1.py
return self.sequence

def check_alphabet(self):
valid_alphabet = set("ATGC")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Вижу проверку на ДНК и на аминокислоты ниже, круто! Но не вижу на РНК, лучше ее тоже добавить

Comment thread RHNO1.py
return self.__class__(sequence)

def gc_content(self):
gc_count = sum(base in "GCgc" for base in self.sequence)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Круто, что проверяется регистр! Можно для проверки алфавита тоже такое добавить

Comment thread RHNO1.py
def __str__(self):
return self.sequence

def check_alphabet(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно еще прописать вывод ошибок, если подаются символы, отличные от ДНК/РНК/аминокислот, без них у меня работает вообще с любой последовательностью.

Comment thread RHNO1.py

def filter_fastq(self):
with open(self.output_file, "w") as output_handle:
for record in SeqIO.parse(self.input_file, "fastq"):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

тут можно было бы добавить тест на существование файла с последовательностью, который берется на вход, если его нет, то можно выводить ошибку о его отсутствии

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
for record in SeqIO.parse(self.input_file, "fastq"):
for record in SeqIO.parse(self.input_file, "fastq"):
if not self.input_file():
raise FileNotFoundError(f"Файл '{self.input_file}' не найден!")

Comment thread RHNO1.py
self.min_length = min_length
self.min_quality = min_quality
self.min_gc = min_gc
self.max_gc = max_gc
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

все логично и понятно, что приходит на вход, хорошо, что прописаны автоматические минимальные значения

Comment thread RHNO1.py


class NucleicAcidSequence(BiologicalSequence):
complement_dict = {"A": "", "T": "", "G": "", "C": ""}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

не совсем понятно для чего этот словарь, если я правильно понимаю, он дальше меняется, но вероятно, тогда стоит задать пустой словарь

Comment thread RHNO1.py

def check_alphabet(self):
valid_alphabet = set("ATGC")
return set(self.sequence) <= valid_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.

хорошая проверка, на всякий случай можно добавить в сет значения с нижним регистром, или добавить при вводе последовательности перевод все в верхний регистр

Comment thread RHNO1.py


class DNASequence(NucleicAcidSequence):
complement_dict = {"A": "T", "T": "A", "G": "C", "C": "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.

Вероятно этот комментарий супер вкусовщина. Более приятно читается словарь, когда он построчный. Но это сугубо вкусовщина

Suggested change
complement_dict = {"A": "T", "T": "A", "G": "C", "C": "G"}
complement_dict = {"A": "T",
"T": "A",
"G": "C",
"C": "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.

следующие словарики я бы также подпарвил

Comment thread RHNO1.py
complement_dict = {"A": "U", "U": "A", "G": "C", "C": "G"}

def codons(self):
return [self.sequence[i : i + 3] for i in range(0, len(self.sequence), 3)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Может оказаться так, что последовательность не кратна 3, поэтому на такой случай стоит что-то придумать, например показывать пользователю ошибку

Suggested change
return [self.sequence[i : i + 3] for i in range(0, len(self.sequence), 3)]
if len(self.sequence) % 3 != 0:
raise ValueError("Sequence length is not a multiple of 3")
else:
return [self.sequence[i : i + 3] for i in range(0, len(self.sequence), 3)]

Comment thread RHNO1.py
"V": 117.15,
"W": 204.23,
"Y": 181.19,
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

очень красивый словарик, легко читаемый

Comment thread RHNO1.py
"W": 204.23,
"Y": 181.19,
}
return sum(molecular_weights[aa] for aa in self.sequence)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это очень хорошая работа, она структурно логичная, приятно читается, нет лишних переменных и функций, что радует. Если добавить аннотации, то к работе будет самой идеальной, но она уже на высоте

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.

3 participants