<div dir="ltr"><div><div><div><div>My guess is you are using Python version >2.6 where "set" is a built-in. You can fix this by doing the following.<br><br></div>1) Remove "from sets import Set"<br></div>
2) And replace "alphabet = list(Set(stList))" with "alphabet = list(set(stList))" <br><br></div>This should work straight away.<br><br></div>P.S Its "Python" not phyton<br><div><br></div><div>
Cheers<br></div><div>Kartik<br></div><div><br><div><div><div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Mar 24, 2013 at 12:20 PM, michelle_low <span dir="ltr"><<a href="mailto:michelle_low@zoho.com" target="_blank">michelle_low@zoho.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u><div><div style="font-size:10pt;font-family:Verdana,Arial,Helvetica,sans-serif"><div><br></div>
<div>Hi everyone,</div><div><br></div><div><br></div><div>Can someone please help me with the following phyton script? I received the error message <span style="font-size:10pt"> DeprecationWarning: the sets module is deprecated</span></div>
<div> from sets import Set.</div><div><br></div><div>After googling, I have tried the methods others suggest: change sets to set or delete the <span style="font-size:10pt">from sets import Set but none of them works. </span></div>
<div><span style="font-size:10pt"><br></span></div><div>Can someone suggest me how to modify the following codes so that the input file is read from standard input?</div><div>I'd like to execute them with unix command </div>
<div><br></div><div>script.py < sequence.fna</div><div><span style="font-size:10pt"><br></span></div><div><br></div><div>Thanks a bunch.</div><div><br></div><div><br></div><br><div>#!/usr/local/bin/python</div><div><br>
</div><div>import math</div><div>from sets import Set</div><div><br></div><div><br></div><div>line = file("sequence.fna", "r")</div><div><br></div><div>for x in line:</div><div> if x [0] == ">" :</div>
<div><br></div><div>#determine the length of sequences</div><div> s=line.next()</div><div> s=s.rstrip()</div><div> length = len(s)</div><div><br></div><div># determine the GC content</div><div> G = s.count('G')</div>
<div> C = s.count('C')</div><div> GC= 100 * (float(G + C) / length)</div><div><div> </div><div><br></div><div> stList = list(s)</div><div> alphabet = list(Set(stList))</div><div><br></div><div> freqList = []</div>
<div> for symbol in alphabet:</div><div> ctr = 0</div><div> for sym in stList:</div><div> if sym == symbol:</div><div> ctr += 1</div></div><div><div> freqList.append(float(ctr)/len(stList))</div>
<div><br></div><div># Shannon entropy</div><div> ent = 0.0</div><div> for freq in freqList:</div><div> ent = ent + freq * math.log(freq, 2)</div><div> ent = -ent</div><div><br></div><div> print x</div><div> print "Length:" , length</div>
</div><div><div> print "G+C:" ,round(GC),"%"</div><div> print 'Shannon entropy:'</div><div> print ent</div><div> print 'Minimum number of bits required to encode each symbol:'</div>
<div> print int(math.ceil(ent))</div></div></div></div><br>_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></div><br></div></div></div></div></div></div></div></div>