在三个不同的框架下阅读 [英] Reading at three different frames

查看:89
本文介绍了在三个不同的框架下阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试创建一个类,该类在三个不同的帧中读取DNA字符串-一个从位置0(或第一个碱基)开始,另一个从位置1(第二个碱基)开始,另一个从位置1开始.从位置2(第三个底端)开始读取.到目前为止,这就是我一直在玩的东西:

So I'm trying to create a class that reads a DNA string in three different frames - one that starts at position 0 (or the first base), another that starts in position 1 (the second base), and a third that starts reading at position 2 (the third base). So far, this is what I've been playing around with:

def codons(self, frame_one, frame_two, frame_three):
        start = frame_one
        while start + 3 <=len(self.seq):
            yield (self.seq[start:start+3], start)
            start += 3

        start+1 = frame_two
        while start + 3 <=len(self.seq):
            yield (self.seq[start+1:start+4], start)
            start += 3

        start+2 = frame_three
        while start + 3 <=len(self.seq):
            yield (self.seq[start+2:start+5], start)
            start += 3

在这一点上,我认为这是胡说八道,但是我尽了最大的努力.如果任何人都可以让我对在这堂课中我该从哪里开始纠正有个好主意,那就太好了.

I think it's pretty much nonsense at this point, but I tried my best. If anybody can give me an idea on where I can start to correct in this class, that would be great.

推荐答案

首先,您不能分配某些值,也无法命名变量,例如start+1start+2等.接下来,由于它与生物信息学有关,您可以将问题标记为生物信息学.另外,您要重复很多东西,这对于程序员来说实在是太糟糕了.但是,您可以尝试使用以下代码段:

First of all, you can not assign some values and name a variable like start+1, start+2 and so on. Next, as it is related to bioinformatics you can tag your question as bioinformatics. Also, you are repeating many of the stuffs three times that is too bad as a programmer. However, you can try with the following snippet:

class Codons(object):

        def __init__(self, seq):
                self.seq = seq

        def codons(self, frame_one, frame_two, frame_three):

                while frame_one <=len(self.seq):
                    yield (self.seq[frame_one:frame_one+3])
                    frame_one += 3

                while frame_two <=len(self.seq):
                    yield (self.seq[frame_two:frame_two+3])
                    frame_two += 3

                while frame_three <=len(self.seq):
                    yield (self.seq[frame_three:frame_three+3])
                    frame_three += 3


test_codons = Codons("ATCGTG-")

val = test_codons.codons(0,1,2)

print("Codons are: ")
for i in val:
        print(i)

print("")

让我们知道它是否对您有用.干杯!

And let us know if it worked for you. Cheers!!

这篇关于在三个不同的框架下阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆