sandy smile wrote:
>
> hi,
>
> Thanks in advance.I am doing bioinformatics and plz help me
>
> Consider a sequence
>
> *S='UACUGUUAA'*
>
> I have to split three as *‘UAC’,’UGU’,’UAA’*
>
> and Consider the position within the array element
>
> *0 1 2 0 1 2 0 1 2*
>
> *U A C, U G U, U A A*
>
> And finding the frequency of occurrence of U,C,A,G in their
> respective position.so far i have identified the position .but i dont
> know to calculate the frequency.
>
>
>
> *Desired outpu*t:
>
>
>
> Total number of U at 0 th position :3
>
> Total number of U at 1th position:0
>
> Total number of U at 2nd position:1
>
>
>
> Total number of A at 0 th position :0
>
> Total number of A at 1sth position:2
>
> Total number of A at 2nd position:1
>
>
>
> Total number of C at 0 th position :0
>
> Total number of C at first position:0
>
> Total number of C at second position:1
>
>
>
> Total number of G at 0 th position :0
>
> Total number of G at first position:1
>
> Total number of G at second position:0
>
> i have wrotten program upto this.please help.
>
Here is a leg up (I hope). I'm not suggesting you use the actual
code, but maybe the structure of the dictionary 'd', will give you
an idea. You might like to read up on the builtin 'zip' function.
(Coincidentally, the first Google hit for 'python cartesian product'
is a blog post by Maciej Blizinski, who I think posted above!)
8<--------------------------------------------------------------------------------------
s = 'UACUGUUAA'
from itertools import izip, cycle
try:
from itertools import product
except ImportError:
def product(L,*lists):
if not lists:
for x in L:
yield (x,)
else:
for x in L:
for y in product(lists[0],*lists[1:]):
yield (x,)+y
S = (tuple(X) for X in product(set(s), range(3)))
d = dict(izip(S, cycle([0])))
print d
print
#The data structure d has been primed with a zero count for each
#possible option.
#Now you must add code here which finds the actual frequency
for letter, index in sorted(d.iterkeys()):
t = letter, index, d[(letter, index)]
print 'Total number of %s at position %s is %s' % t
8<--------------------------------------------------------------------------------------
Output:
Total number of A at position 0 is 0
Total number of A at position 1 is 0
Total number of A at position 2 is 0
Total number of C at position 0 is 0
Total number of C at position 1 is 0
Total number of C at position 2 is 0
Total number of G at position 0 is 0
Total number of G at position 1 is 0
Total number of G at position 2 is 0
Total number of U at position 0 is 0
Total number of U at position 1 is 0
Total number of U at position 2 is 0
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Python Ireland" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.ie/group/pythonireland?hl=en
-~----------~----~----~----~------~----~------~--~---