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.
@@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.
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.
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.
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: ruclips.net/video/Wkx0fI4e0fs/видео.html
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..
thanks a lot
saved my life thanks!!!
You are amazing! Thank you for this
return [DNA_Codons[seq[pos:pos...... len(seq) -2, 3)]
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.
@@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.
Thanks a bunch for recommending @talkpython at the end of the video. :)
In codon usage, I am getting "seq_type" is not defined.
same
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.
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
@@rebelScience I watched previous videos. Maybe I missed the key point. OK! I will check it again. Thank you!
@@rebelScience oh! I found it!
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.
@@rebelScience Thanks for your advice!
what is the "-2" for in the translate_seq function? Great video by the way!
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.
Hi, thank you for video
freqDict = dict(Counter(tmpList))
^
SyntaxError: invalid syntax
Do you know why that error can occur?
Did you try importing the Counter class from collections?
Hi rebelCoder if you were to try and join the amino acids together and omit the [] and '' how would you do that?
return "".join([DNA_Codons[seq[pos:pos+ 3 ]] for pos in range(init_pos, len(seq) - 2, 3)])
I have counter is not defined and i don't know which video to watch (it's title) pls
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: ruclips.net/video/Wkx0fI4e0fs/видео.html