[Tutor] Phyton script for fasta file (seek help)

kartik sundarajan kartiksundarajan at gmail.com
Tue Apr 9 08:18:48 CEST 2013


My guess is you are using Python version >2.6 where "set" is a built-in.
You can fix this by doing the following.

1) Remove "from sets import Set"
2) And replace "alphabet = list(Set(stList))" with "alphabet =
list(set(stList))"

This should work straight away.

P.S Its "Python" not phyton

Cheers
Kartik



On Sun, Mar 24, 2013 at 12:20 PM, michelle_low <michelle_low at zoho.com>wrote:

> **
>
> Hi everyone,
>
>
> Can someone please help me with the following phyton script? I received
> the error message  DeprecationWarning: the sets module is deprecated
>   from sets import Set.
>
> After googling, I have tried the methods others suggest:  change sets to
> set or delete the from sets import Set but none of them works.
>
> Can someone suggest me how to modify the following codes so that the input
> file is read from standard input?
> I'd like to execute them with unix command
>
> script.py <  sequence.fna
>
>
> Thanks a bunch.
>
>
>
> #!/usr/local/bin/python
>
> import math
> from sets import Set
>
>
> line = file("sequence.fna", "r")
>
> for x in line:
>   if x [0] == ">" :
>
> #determine the length of sequences
>     s=line.next()
>     s=s.rstrip()
>     length = len(s)
>
> # determine the GC content
>     G = s.count('G')
>     C = s.count('C')
>     GC= 100 * (float(G + C) / length)
>
>
>     stList = list(s)
>     alphabet = list(Set(stList))
>
>     freqList = []
>     for symbol in alphabet:
>       ctr = 0
>       for sym in stList:
>         if sym == symbol:
>             ctr += 1
>     freqList.append(float(ctr)/len(stList))
>
> # Shannon entropy
>   ent = 0.0
>   for freq in freqList:
>     ent = ent + freq * math.log(freq, 2)
>   ent = -ent
>
>   print x
>   print "Length:" , length
>   print "G+C:" ,round(GC),"%"
>   print 'Shannon entropy:'
>   print ent
>   print 'Minimum number of bits required to encode each symbol:'
>   print int(math.ceil(ent))
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130409/078c371a/attachment.html>


More information about the Tutor mailing list