hello everybody rebel Cody here and welcome to our first 大家好，我是叛军科迪，欢迎来到我们的第一个
lesson in bioinformatics in Python today we're gonna start working on our DNA 今天在Python中的生物信息学课程，我们将开始研究我们的DNA
toolkit we're gonna write our first two 我们要写的前两个工具包
functions and we're also going to take a look at how we can store DNA data in 功能，我们还将看一下如何将DNA数据存储在
dictionaries and lists in Python how to pass it on to a function and how to get Python中的字典和列表如何将其传递给函数以及如何获取
meaningful results out of it just to start off if you don't know how DNA 如果您不知道DNA如何，就可以从中获得有意义的结果
double helix is structured and how nucleotides bind to each other I would 双螺旋的结构以及核苷酸如何彼此结合
strongly recommend watching this amazing and beautiful video it's only six 强烈建议您观看这部精彩绝伦的视频，只有六个
minutes long but it has amazing animations and explanation of how that 分钟之久，但动画效果惊人，并说明了
stuff works especially the part at around two minutes I can leave a link in 东西起作用，尤其是大约两分钟的零件，我可以在其中留下一个链接
the description below and you should be able to see a link right now in your 下面的说明，您现在应该可以在您的链接中看到一个链接
video we're definitely going to need that knowledge to develop more complex 视频，我们肯定会需要这些知识来开发更复杂的视频
algorithms so if you don't know how DNA is structured please watch that video 算法，如果您不了解DNA的结构，请观看该视频
before you continue so now we're going to go to our project and let's see how 在继续之前，现在我们将进入我们的项目，让我们看看如何
it is structured an access to this project will also be available via a 通过结构化方式，也可以通过
github link and they're going to leave that in the description below so let's github链接，他们将在下面的描述中保留该链接，因此让我们
take a look at two files we have in our project 看看我们项目中有两个文件
Amane dot pi where we're just going to be testing our code that we write and Amane dot pi，我们将要测试我们编写的代码，
DNA toolkit that by that is going to be our main file we're gonna populate that DNA工具包将成为我们的主要文件，我们将填充
file with a lot of cool functionality and we're gonna be testing that we're 具有很多很棒功能的文件，我们将测试我们
gonna be including DNA to keep on our main dot pi and testing that 将包括DNA保留在我们的主要点pi上并进行测试
functionality before we commit and before we can actually use it so without 功能在我们提交之前和实际使用之前，因此无需
further ado let's start working in our DNA toolkit first thing we need is a 事不宜迟，让我们开始使用DNA工具包，我们需要做的第一件事是
list of four nucleotides and we're gonna define it just like that 四个核苷酸的列表，我们将像这样定义它
adenine cytosine guanine and thymine we're gonna be reusing that list in our 腺嘌呤胞嘧啶鸟嘌呤和胸腺嘧啶，我们将在我们的表中重复使用该列表
functions and the first function we're going to write is going to be a validate 函数，而我们要编写的第一个函数将是验证
sequence function let me copy and paste that from my snippets here and let's 序列功能让我从这里的片段中复制并粘贴，然后
talk about it why do you need a validate sequence function imagine you are 谈论它为什么您需要一个验证序列函数假设您是
working with a DNA data that is coming from some txt file some CSV file or an 处理来自某些txt文件，某些CSV文件或
online database you just have to make sure that it is a valid DNA string 在线数据库，您只需要确保它是有效的DNA字符串即可
meaning it does not contain any unexpected characters and only has those 表示它不包含任何意外字符，仅包含那些
four nucleotides ACGT or a combination of those four nucleotides if it is not 四个核苷酸ACGT或这四个核苷酸的组合（如果不是）
it's not a valid DNA string I'm not interested in working with it 它不是有效的DNA字符串，我对使用它不感兴趣
so our validate seek with sequence for short function accepts a string then it 因此我们的带有短函数序列的验证搜索将接受一个字符串，然后
creates a temporary string which is upper case and then we just loop through 创建一个大写的临时字符串，然后我们循环遍历
each character in that string to make sure it is one of these four characters 该字符串中的每个字符，以确保它是这四个字符之一
if it is not if it at least one character does not match break out of 如果不是，如果至少一个字符不匹配，则跳出
the loop and we can return false because we're not interested in working with a 循环，我们可以返回false，因为我们对使用
string anymore because it has it has at least one invalid character and if all 不再有字符串，因为它至少有一个无效字符，如果有的话
of characters match just fine then we're going to return an uppercase version so 的字符匹配就很好了，那么我们将返回大写版本，因此
why would we need an uppercase version of that string it is because lowercase a 为什么我们需要该字符串的大写版本，这是因为小写的a
is not equals to an uppercase a and lowercase C is not equals 2n uppercase C 不等于大写字母a，小写字母C不等于2n大写字母C
etc in ASCII table right so we just have to make sure that we're comparing all of 等等，所以我们只需要确保我们正在比较所有
the uppercase characters okay let's try testing our function we're going to 大写字符好吧，让我们尝试测试我们要使用的功能
demain that PI file we're going to be testing all of our functionality we're 保留我们将要测试的所有功能的PI文件
gonna need to include the stuff from DNA toolkit PI into our main that PI file of 需要将DNA工具包PI中的内容包括到我们主要的PI文件中
course and let's do a total include 当然，让我们总共包括
import everything star means everything now we just need to create a random DNA 导入所有星星，这意味着一切，现在我们只需要创建一个随机DNA
string so we can test our function which will validate that string so let's 字符串，以便我们可以测试将验证该字符串的函数，因此让我们
create an RD so random DNA string and now we can start calling our function 创建一个RD这样随机的DNA字符串，现在我们可以开始调用函数了
let's call our function validate sequence and we're gonna give that 让我们称之为函数验证序列，我们将给出
random string to it and of course we want to print out the result right 随机字符串，当然我们要正确打印结果
because it has a return value let's see what comes back save run okay so we get 因为它有一个返回值，让我们看一下返回的内容，然后保存运行，这样我们就得到了
back exactly the same string as we passed to it and that makes sense right 返回与传递给它的字符串完全相同的字符串，这很有意义
so we pass a string it makes it an uppercase even though it's already an 因此我们传递了一个字符串，即使它已经是
uppercase it goes through the loop make sure all of the characters match one of 大写字母通过循环，确保所有字符都与以下字符之一匹配
these characters and then they do and it just returns our temporary list upper 这些字符，然后他们做，它只是返回我们的临时列表的上位
case so let's correct let's try testing the 情况下，让我们更正确地尝试测试
false statement let's introduce a character X which is an invalid 错误的陈述让我们介绍一个无效的字符X
character it's not a TC or G let's save that and run and we're getting false 字符不是TC或G，让我们保存并运行，我们将得到错误
great our function works and we will be able to pass on correct DNA strings to 我们的功能很好，我们将能够将正确的DNA字符串传递给
our functions we write in the future one other thing we can test is make sure 我们将来编写的函数我们可以测试的另一件事是确保
that it makes the string in uppercase so let's do a mixed case string here I'm 它使字符串大写，所以我们在这里做一个混合大小写的字符串
gonna save that and run and what we should get is a string all uppercase 要保存并运行，我们应该得到的是一个全部大写的字符串
that's great so our first function is up and running and it's tested and it works 太好了，因此我们的第一个功能已启动并正在运行，并且已经过测试并且可以正常工作
now we have our first function running and we have tested with three scenarios 现在我们正在运行我们的第一个功能，并且已经在三种情况下进行了测试
and all scenarios pass as expected now let's add one more cool feature to that 现在所有场景都按预期通过了，现在让我们添加一个更酷的功能
instead of defining DNA string and every time we can make it generate a 而不是定义DNA字符串，每次我们都可以使它生成一个
random DNA string how can we do that we can use pythons 随机DNA字符串我们该怎么做才能使用python
random module let's import it first and let's generate a random string every 随机模块让我们先导入它，然后每隔一个生成一个随机字符串
time we run main that PI file and let me copy and paste one of my snippets right 时候我们运行主要的PI文件，然后让我复制并粘贴我的片段之一
here so here we have a choice method from random module and all we do is 在这里，所以这里我们有一个从随机模块中选择的方法，我们要做的就是
we're telling it here's a list of nucleotides which we have in our toolkit 我们告诉它这是我们工具包中的核苷酸列表
file that's the list so we'll give that list to that function and we tell it 这就是列表文件，所以我们将该列表提供给该函数，然后告诉它
just loop 20 times and pick a random character from our list so I'm just 只需循环20次，然后从我们的列表中选择一个随机字符，
gonna generate a random DNA string of course we have to have you change this 当然会生成一个随机的DNA字符串
here too let's try running it and see what comes out so we run it once twice 这里也让我们尝试运行它，看看结果如何，所以我们运行两次
three times four times five times so as you can see this creates a random DNA 三倍，四倍，五倍，如您所见，这将创建一个随机的DNA
string from 20 characters we can change it let's say 250 and we can see it 由20个字符组成的字符串，我们可以更改它，例如250，我们可以看到它
changes the length of our string now we have a 50 nucleotide long DNA strand 改变字符串的长度，现在我们有一条50核苷酸长的DNA链
here alright so let's go to our second function which is a count nucleotide 好了，让我们转到第二个功能，即计数核苷酸
frequency function let me copy and paste that from my snippets right here and 频率功能让我从此处的片段中复制并粘贴
that is going to be our first function that actually does something with the 这将是我们的第一个功能，实际上对
DNA okay so we're gonna call this function count new frequency and we're DNA很好，所以我们将这个函数称为新频率，
gonna pass it a string which we validated beforehand we're gonna define 要传递一个我们预先验证的字符串，然后定义
a temporary frequency dictionary here so again you will have to know how Deeksha 这里是一个临时频率词典，所以您将不得不再次了解Deeksha
Nerys work and you can go back to Corey's YouTube channel that I mentioned Nerys工作，您可以回到我提到的Corey的YouTube频道
in my introduction video and he has a very good explanation on how 在我的介绍视频中，他对如何
dictionaries work that's basically have very fast hashmap why do we define it 字典的工作基本上具有非常快的哈希图，为什么我们要定义它
like that of course we can create an empty dictionary right here and have a 当然，我们可以在此处创建一个空字典，
for loop with a lot of logic saying if it doesn't if for循环有很多逻辑说是否
Aiki does not exist create it and only then increment its value but instead Aiki不存在，只能创建它，然后增加它的值，但是
we're going to create it this way so our for loop is nice and clean so all we do 我们将以这种方式创建它，因此我们的for循环非常漂亮而且干净，因此我们所做的一切
here is we loop through the string that we passed and if it's a we're gonna use 这是我们遍历传递的字符串，如果是，我们将使用
nucleotide a and we can increase that value if it's in contact see we're gonna 核苷酸a，我们可以增加该值，如果它处于接触状态，我们将
increase this value if we're gonna come across nucleotide a in our string again 如果我们要再次遇到字符串中的核苷酸a，请增加此值
we can increase that value and it's going to be 2 so and we're going to 我们可以增加该值，它将变为2，所以我们将
return the temporary dictionary in the end let's do a test here so now we're 最后返回临时字典，让我们在这里进行测试，现在
gonna print out the result of that function it is called count so we can 要打印出该函数的结果，称为计数，因此我们可以
actually see here and we're gonna pass our random string to it as well so let's 实际看到这里，我们也将随机字符串传递给它，所以让我们
see what happens okay so our first line which is calling a validate sequence 看看会发生什么，所以我们的第一行是调用验证序列
returns the sequence of course it's correct and the second line here returns 返回正确的顺序，这里的第二行返回
this so a is 19 times C has been found seven times G has been found 11 and T 因此，a被发现是19倍C，七次是G被找到11和T
has been found 13 yeah we can I mean it's a bit too much to count but let's 已经被发现13是的，我可以说这有点儿不算数，但让我们
say C is 7 times we can see 1 2 3 4 5 6 7 and let's do the smallest one here G 说C是7倍，我们可以看到1 2 3 4 5 6 7，我们在这里做最小的G
Ang's 1 2 3 4 5 6 7 8 9 10 11 so this is correct now we have this validate Ang的1 2 3 4 5 6 7 8 9 10 11所以这是正确的，现在我们有这个验证
function we did not really use it here let's do this which is much better way 函数，我们在这里并没有真正使用它，这是更好的方法
so we're gonna call it a final DNA string or just let's say DNA STR I'm 所以我们将其称为最终的DNA字符串，或者说我是DNA STR
gonna make it equals to a validated sequence okay and then we're gonna be 使其等于经过验证的序列好吧，然后我们将
passing this in all of our functions just to make sure that all of our 在我们所有的功能中传递此信息只是为了确保我们所有的
functions like count nucleotide frequency on all the other functions are 其他功能如计数核苷酸频率
working with the correct DNA string so let's run it again just to make sure it 使用正确的DNA字符串，所以让我们再次运行它只是为了确保它
all works now we're not printing on the validated 现在所有的作品我们都不会在经过验证的作品上打印
sequence but of course we are printing out our 顺序，但是我们当然要打印出
okay so one small thing we can also do which is not really important we can 好吧，我们也可以做一件小事，这不是很重要，我们可以
take a look at our account frequency function here and we can try thinking 在这里看看我们的帐户频率函数，我们可以尝试思考
can we actually optimize it it is a small function it doesn't really need 我们可以实际优化它吗，这是一个很小的功能，实际上并不需要
any optimizations but there is a module called collections in Python and we can 任何优化，但Python中都有一个名为collections的模块，我们可以
basically make one line out of all of these four lines I gonna show you that 基本上从这四行中选出一行，我会告诉你
right now but again it's not necessary it's a bit more complicated than just 现在，但又没有必要，它比仅仅复杂一点
these four lines with a for loop but let's see how it actually works so what 这四行带有for循环，但让我们看看它的实际工作原理
we can do we can includes or import collections now collections has this 我们可以做到，我们可以包含或导入集合，现在集合具有此功能
method which is called count let's try replacing this with one line 称为count的方法，让我们尝试用一行代替
return and of course it needs to be casted to a dictionary because it 返回，当然需要将其强制转换为字典，因为
returns a an object file collections and we're gonna use our count counter and 返回一个对象文件集合，我们将使用计数计数器
we're gonna give it our sequence that we just passed sorry sequence okay so yeah 我们要给它我们的序列，我们刚刚通过了抱歉的序列，好吧，是的
we had four lines we were place it was just one line and let's see if it 我们有四行，我们只放置了一行，让我们看看是否
actually still works as expected okay yep it returns the same result I guess 实际上仍然可以按预期工作，是的，它返回的结果与我猜的相同
it's up to you if you understand how counters work or you looked at the 如果您了解计数器的工作方式或您查看了计数器，则取决于您
videos of how counters work in Python you can use that as long as you 有关如何在Python中使用计数器的视频，只要您
understand but we're gonna comment this out for now we don't actually need that 了解，但我们暂时将其注释掉，我们实际上并不需要
this is nice and clean and easy to understand which I guess is more 这很好，很干净，很容易理解，我猜还可以
important than just optimizing it but again if you want to optimize some stuff 比优化它重要，但如果要优化某些东西，这又很重要
and you have a deep understanding of what these functions do you can always 并且您对这些功能有深刻的了解
do that alright so this is it for this lesson 做到这一点，所以这是本课
today we wrote our first two functions we validated the DNA string and we 今天我们编写了我们的前两个函数，我们验证了DNA字符串，
counted nucleotides in that validated string we've also used main that pi file 在经过验证的字符串中计算核苷酸的数量，我们还使用了主要的pi文件
to test our functionality just to make sure it all works as expected 测试我们的功能只是为了确保一切正常
I will leave a gitlab link in the description 我将在说明中保留一个gitlab链接
so you can see our first lesson already committed it was valid a DNA and count 这样您就可以看到我们已经完成的第一堂课是有效的DNA和计数
nucleotides so you can always pull down the latest version of the lessons just 核苷酸，这样您就可以随时获取最新版本的课程
to take a look at them if you're not familiar with get lab or get I suggest 如果您不熟悉实验室或建议我看一下
again Corey's channel here's an amazing video on how git works so we're going to 再次，Corey的频道这里有一个很棒的视频，介绍了git的工作原理，因此我们将
be committing all of the lessons to this repository in the case if you need to go 如果需要，将所有课程都提交到此存储库
back and look at the lessons we did before thank you very much for watching 返回并查看我们之前的课程非常感谢您的观看
this video if you have any questions please leave 如果您有任何疑问，请离开此视频
them in the comment section below jordan helped to build our telegram 他们在jordan下面的评论部分帮助建立了我们的电报
bioinformatics community and for more in-depth discussions please join our 生物信息学社区，如果需要更深入的讨论，请加入我们
matrix server if you have enjoyed these lessons and they have helped you in any 矩阵服务器（如果您喜欢这些课程，并且它们在任何方面都为您提供了帮助）
way I would appreciate a thumbs up and please share these videos with anyone 非常感谢，请与任何人分享这些视频
who might find them useful too and of course any help and contributions 可能会发现它们也很有用，当然会有所帮助和贡献
through PayPal cryptocurrencies or patreon are always welcome all of the 始终欢迎通过PayPal加密货币或patreon
links are in the description below don't forget to subscribe if you're interested 下方说明中的链接如果您有兴趣，请不要忘记订阅
in the upcoming videos until next time rebel coder signing out 在即将到来的视频中，直到下一次叛军编码器退出