开发者

File management

I am working on python and biopython right now. I have a file upload form and whatever file is uploaded s开发者_如何学Pythonuppose(abc.fasta) then i want to pass same name in execute (abc.fasta) function parameter and display function parameter (abc.aln). Right now i am changing file name manually, but i want to have it automatically.

Workflow goes like this.

----If submit is not true then display only header and form part

--- if submit is true then call execute() and get file name from form input

--- Then displaying result file name is same as executed file name but only change in extension

My raw code is here -- http://pastebin.com/FPUgZSSe

Any suggestions, changes and algorithm is appreciated

Thanks


You need to read the uploaded file out of the cgi.FieldStorage() and save it onto the server. Ususally a temp directory (/tmp on Linux) is used for this. You should remove these files after processing or on some schedule to clean up the drive.

def main():
  import cgi
  import cgitb; cgitb.enable()
  f1 = cgi.FieldStorage()
  if "dfile" in f1:
    fileitem = f1["dfile"]
    pathtoTmpFile = os.path.join("path/to/temp/directory", fileitem.filename)
    fout = file(pathtoTmpFile, 'wb')
    while 1:
        chunk = fileitem.file.read(100000)
        if not chunk: break
        fout.write (chunk)
    fout.close()
    execute(pathtoTmpFile)
    os.remove(pathtoTmpFile)
  else:
    header()
    form()

This modified the execute to take the path to the newly saved file.

cline = ClustalwCommandline("clustalw", infile=pathToFile)

For the result file, you could also stream it back so the user gets a "Save as..." dialog. That might be a little more usable than displaying it in HTML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜