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

Peter Otten __peter__ at web.de
Sun Mar 24 09:14:11 CET 2013


michelle_low wrote:

> Can someone please help me with the following phyton script? I received

Python; write it on the blackboard one hundred times ;)

> 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.

Remove the line

from  sets import Set

completely and replace Set with set everywhere in your code.

> 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

Replace the line

> line = file("sequence.fna", "r")

with

import sys
line = sys.stdin

If you want to go fancy you can accept either a file name or read from stdin 
with

import sys
if sys.argv > 1:
    # filename was passed as an argument to the script
    line = open(sys.argv[1])
else:
    # no filename was passed, default to stdin
    line = sys.stdin




More information about the Tutor mailing list