-
Notifications
You must be signed in to change notification settings - Fork 0
Review RAG2 #30
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?
Review RAG2 #30
Conversation
MariaLuk
left a comment
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.
Подсмотрела интересные идеи, особенно про continue) спасибо!
| from Bio import SeqIO | ||
| from Bio.SeqUtils import gc_fraction | ||
| from Bio.Seq import Seq | ||
|
|
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.
PEP просит две пустых строки, после import
| from Bio.SeqUtils import gc_fraction | ||
| from Bio.Seq import Seq | ||
|
|
||
| class BiologicalSequence(ABC): |
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.
По предложению Никиты мы могли здесь наследоваться от строки, но потом было сказано, что так лучше не делать). Так что, видимо ,хорошо, что тут не так.
Но при этом мы обсуждали что абстрактный класс это каркас в котором должны быть только abstact методы, а определены они будут ниже в дочерних классах.
| def gc_content(self): | ||
| gc_content = (self.sequence.count('G') + self.sequence.count('C')) / len(self.sequence) if self.sequence else 0 | ||
| return gc_content | ||
|
|
||
| class DNASequence(NucleicAcidSequence): | ||
| complement_map = {'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G'} |
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.
Словари прописаны как атрибуты классов, а не экземпляров, отлично!
Но я бы добавила в этот словарь и буквы в нижнем регистре, да ,обычно пишут заглавными, но все же g это тоже G. и соответственно в подсчет GC бы тоже добавила
| class DNASequence(NucleicAcidSequence): | ||
| complement_map = {'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G'} | ||
| def transcribe(self): | ||
| return RNASequence(self.sequence.replace('T', 'U')) |
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.
Прикольно, что сделано через replace, я так не догадалась
| return all(nucleotide in self.complement_map for nucleotide in self.sequence) | ||
|
|
||
| def complement(self): | ||
| return ''.join(self.complement_map[nucleotide] for nucleotide in self.sequence) |
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.
По условию тут должны были возвращаться объекты классов RNASequence или DNASequence
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.
Такие штуки в ревью еще здорово оформлять кодом (RNASequence), хотя в целом когда это 1-2 слова то не обязательно тратить время на такие мелочи
| sequence (str): The input protein sequence in one-letter code. | ||
|
|
||
| Returns: | ||
| str: The converted protein sequence in three-letter code. |
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.
Классно, что есть докстринга
| Returns: | ||
| str: The converted protein sequence in three-letter code. | ||
| """ | ||
| AMINO_ACIDS = {'A': 'Ala', 'C': 'Cys', 'D': 'Asp', 'E': 'Glu', 'F': 'Phe', 'G': 'Gly', 'H': 'His', 'I': 'Ile', |
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.
Так как это не глобальная переменная, то я бы назвала ее маленькими буквами
| if not (gc_bounds[0] <= gc_content <= gc_bounds[1]): | ||
| continue | ||
|
|
||
| if not (length_bounds[0] <= len(sequence) <= length_bounds[1]): | ||
| continue | ||
|
|
||
| if not check_quality(quality_scores, quality_threshold): | ||
| continue |
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.
Очень долго разбиралась, но поняла, что да , так должно работать. Если условие не выполнится, то все прейдет к следующей итерации! Не знала такого про continue, либо знала, но забыла, очень круто, хочу попробовать пользоваться. Здорово, что каждая запись последовательно отрабатывается на три фильтра
Если возвращаться к условиям задачи на основе которой мы делали из прошлого семестра, то там надо было отработать ситуации ,в которых подавалась только одна граница для интервалов фильтрования, а не две. Это, кстати, вроде, есть в функциях check ниже
|
|
||
| filtered_seqs[record.id] = (sequence, quality_scores) | ||
|
|
||
| if output_filename: |
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.
Если имя файла не прописано, то вернутся просто последовательности без записи в файл. Опять же по условиям задачи прошлого семестра, надо было тогда создавать папку с результатами и туда складывать файл с названием, как исходный
И еще такой момент, получается в запись идет только последовательность и качество, и теряется исходный формат записи fastq файла
| if not (length_bounds[0] <= len(sequence) <= length_bounds[1]): | ||
| continue | ||
|
|
||
| if not check_quality(quality_scores, quality_threshold): |
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.
Сначала думала, что функция check_quality потерялась, потом нашла ее
Мне кажется, это не очень гуманным к проверяющему оставлять почти 500 строк никак не используемого кода в формате дз четким тз))
Там, конечно ,есть классные и интересные функции, и я бы даже почитала ВСЕ) но если я буду выполнять задание "провести код ревью", то тут получится код ревью без границ просто. Опять же, check_quality где-то там потерялась)
| return '-'.join(three_letter_code) | ||
|
|
||
|
|
||
| def filter_fastq(input_path: str, output_filename: str = None, gc_bounds: tuple = (0, 100), length_bounds: tuple = (0, 2 ** 32), |
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.
Нас просили переписать, заменить функцию фильтратор. Когда их две, я могу потеряться)
Review RAG2