plz help

3 views
Skip to first unread message

sandy smile

unread,
Apr 28, 2009, 2:23:19 AM4/28/09
to py...@googlegroups.com, python...@googlegroups.com

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 output:

 

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.

program:

 content='UACUGUUAA'
s=''
for i in range(0,(len(content))):
    s=s+content[i].replace('\n','')
print len(s)
L=[]
for k in range(0,len(s),3):
   two=s[k:k+3]
   if len(two)==3:
      L.append(two)
   #L[k].find('A')
print len(L)
print L
for i in range(len(L)):
    if L[i].find('A')>0:
         b=L[i].index('A')
         print i,'th element of A is in the position of',b



output:

9
3
['UAC', 'UGU', 'UAA']
0 th element of A is in the position of 1
2 th element of A is in the position of 1




Walker Hale IV

unread,
Apr 28, 2009, 11:58:58 PM4/28/09
to py...@googlegroups.com, sandy smile, python...@googlegroups.com
Here you go...

from pprint import pprint # only needed for some output below

seq = 'UACUGUUAA'

codons = [seq[k:k+3] for k in range(0, len(seq), 3)]
print codons

# totals[position][base] = count
totals = [
{'A': 0, 'C': 0, 'G': 0, 'U': 0},
{'A': 0, 'C': 0, 'G': 0, 'U': 0},
{'A': 0, 'C': 0, 'G': 0, 'U': 0}
]

for codon in codons:
for pos in range(3):
base = codon[pos]
totals[pos][base] += 1

pprint(totals)

for c in 'UACG':
for pos in range(3):
print 'Number of %s in position %d: %d' % (c, pos, totals[pos][c])
print

-Walker

> -~----------~----~----~----~------~----~------~--~---
>
>

--
Walker Hale <walker....@gmail.com>

Reply all
Reply to author
Forward
0 new messages