If you are getting Counter error : This is what worked for my Counter error: freqDict = dict(collections.Counter(tmpList)) Thanks rebelCoder for these videos ! Keep Going..
Basically, this is made to make sure we don't hit array/list out of bounds error and we also we scan every triplet (codon) in a string. As we have a third parameter '3' that will ensure we read 3 nucleotides, jump 3 positions, read another 3. I always suggest writing a simplified version of a code you are trying to understand and print() the results of every step so you can see what is happening: --- seq = "ATCGCATACA" k = 3 # With - 2 correction for pos in range(0, len(seq) - 2, k): print(seq[pos:pos + k]) Result: ATC GCA TAC # Without -2 correction: for pos in range(0, len(seq), k): print(seq[pos:pos + k]) ATC GCA TAC A ^-- this last, single nucleotide 'A' will result in a KeyError as we will try to search/match A in our DNA_Codons dictionary. And DNA_Codons only has triplets/codons. So we need to make sure we always read 3 nucleotides and any 'tail' is discarded. Try using VSCode debugger to see what is happening at every stage. Also join our Telegram/Matrix chat. It is easier to discuss code there.
@bryzsalvador86924 жыл бұрын
@@rebelScience Thank you so much. I also tried omitting that "-2" and I found that I'm having a problem with that tail. Sorry I'm really new at this. Just started learning coding this sem. What I used to get around the keyerror was a function where if the len(seq) %3 = 0 or 1 or 2 and it trimmed nucleotides at the end that but I had problems when I tried to attach my reverse complement code and translation of that complement because the sequence is now trimmed.
@talkpython3 жыл бұрын
Thanks a bunch for recommending @talkpython at the end of the video. :)
@吕萌-e3e4 жыл бұрын
Hi, I have a little question about this part. When I use function -codon_usage, "freqDict = dict(Counter(tmpList)) NameError: name 'Counter' is not defined" was happened. I don't know why.
@rebelScience4 жыл бұрын
Hi! Did you watch previous videos ? We included that module before. You can see it on a line 3 in this video at 3:00
@吕萌-e3e4 жыл бұрын
@@rebelScience I watched previous videos. Maybe I missed the key point. OK! I will check it again. Thank you!
@吕萌-e3e4 жыл бұрын
@@rebelScience oh! I found it!
@rebelScience4 жыл бұрын
Good. Basically Counter is a method from Python's collections module. It has a lot of good stuff it it. You should search for a video on that module.
@吕萌-e3e4 жыл бұрын
@@rebelScience Thanks for your advice!
@dylanneal82443 жыл бұрын
what is the "-2" for in the translate_seq function? Great video by the way!
@rebelScience3 жыл бұрын
Hey! Someone already asked this in the comments and got an answer. Make sure you look through next time :) We read triplets in this function, right? Three amino acids at a time. -2 will ensure we stop at the very end and don't ready past the last three. Don't just take my word, and try using a small string of 9 and print every step, so you can see and understand why we are doing this. Try removing -2, see what happens, experiment, break things. Make sure you don’t just copy-past code.
@f-man32742 жыл бұрын
Hi, thank you for video freqDict = dict(Counter(tmpList)) ^ SyntaxError: invalid syntax Do you know why that error can occur?
@proyectoalejandria66092 жыл бұрын
Did you try importing the Counter class from collections?
@dr.lokbahadurshrestha45073 жыл бұрын
In codon usage, I am getting "seq_type" is not defined.
@ariellewolter82962 жыл бұрын
same
@moa4f2234 жыл бұрын
I have counter is not defined and i don't know which video to watch (it's title) pls
@rebelScience4 жыл бұрын
Hey! 'counter' is a method, that is built-in to Python. Python has this cool module, called 'collections', right? We use some of that functionality. 'counter' method is one of them. You can just make sure you include that module by adding it on the very first line in your file: 'from collections import counter' or you can watch the very first video in this series here: kzbin.info/www/bejne/jZzbYZl_acpjnNU
@ethan_bodybuilder4 жыл бұрын
Hi rebelCoder if you were to try and join the amino acids together and omit the [] and '' how would you do that?
@CakeAndPi34 жыл бұрын
return "".join([DNA_Codons[seq[pos:pos+ 3 ]] for pos in range(init_pos, len(seq) - 2, 3)])