[Tutor] List of Lists for three Frames

Peter Otten __peter__ at web.de
Sat May 17 10:46:22 CEST 2014


ani wrote:

> So I thought it would be cool to read a sequence at three different
> frames, which I have pasted below. However, I've come across a conundrum:
> how to make a list of lists. See, I'd like a final output that displays
> data of the type of frame with a + or a - to signify the direction of the
> read (+1,+2, +3, -1, -2, -3), the numerical position of each start codon
> along with its stop codon, and the length between the start and stop
> codons. (I am only looking for the longest ORFs) An example of the output
> would look like this:
> 
>  +1 57166..61908  4743.
> The reason why I'd like a list of lists is so that I can take all the
> Starts I found in the code below, store it, then be able to place it in to
> the output somehow. I thought that maybe a list of lists would be the best
> way of getting this information from three different frames. However, I'm
> not sure how to go about this... could someone give me a way to start? The
> while loops work fine, last time I checked. Thanks.
> 
> 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
> 
> val = seq.codons(0,1,2)
> 
> for i in val:
>     return(i)
> 
> self.startlist.append[[frame_one], [frame_two], [frame_three]]

While making a list of lists is easy, just append the inner lists to the 
outer,

>>> items = []
>>> items.append([1, 2, 3])
>>> items.append([4, 5, 6])
>>> items
[[1, 2, 3], [4, 5, 6]]

I'd say it is far too early for you to write any "real" code. Go through a 
tutorial to get familiar with Python's syntax first.

Then write a detailed description in plain English of what you are trying to 
do. We can help you with Python, but most of us lack the domain knowledge to 
even decipher what you are up to from the exposition you give above. More 
importantly, a detailed plan will help you writing the corresponding script.

Now for the best part: once you have written working code you will usually 
throw it away and switch to a library like biopython. See 
<http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec360>




More information about the Tutor mailing list