#! /usr/bin/python #boltzmannAlignment.cgi #P. Clote - python script import os,cgi,tempfile,string,sys,os.path #Function taken from M.Lutz p.761 def splitpath(origpath): basename = os.path.split(origpath)[1] if basename==origpath: if '\\' in origpath: basename = string.split(origpath,'\\')[-1] elif '/' in origpath: basename = string.split(origpath,'/')[-1] return basename form = cgi.FieldStorage() if "unix" == form["operatingSystem"].value: eolnMarker = "\n" elif "windows" == form["operatingSystem"].value: eolnMarker = "\r\n" else: eolnMarker = "\r" if "type/paste sequences" == form["sequenceType"].value: cutPaste = 1; fileUpload = 0 else: cutPaste = 0; fileUpload = 1 if "yes" == form["printFiles"].value: PRINT=1 else: PRINT=0 gapPenalty = int(form["gapPenalty"].value) form_ok=1 if cutPaste: if not form.has_key("peptide1") or not form.has_key("peptide2"): form_ok = 0 elif form["peptide1"].value == "" or form["peptide2"].value == "": form_ok = 0 else: peptideFileName1 = "FirstPeptide" peptide1 = form["peptide1"].value peptideFileName2 = "SecondPeptide" peptide2 = form["peptide2"].value else: #file upload if not form.has_key("peptideFile1") or not form.has_key("peptideFile2"): form_ok = 0 else: peptideFileName1 = splitpath(form["peptideFile1"].filename) peptideFile1 = form["peptideFile1"].file peptideFileName2 = splitpath(form["peptideFile2"].filename) peptideFile2 = form["peptideFile2"].file print "Content-type: text/html\n" print '' if not form_ok: print "

Please RESET, then input sequences in FASTA format!

" print "" else: if fileUpload: peptideFile1 = form["peptideFile1"].file peptideFile2 = form["peptideFile2"].file filename1 = "TMPFILES/" + peptideFileName1 filename2 = "TMPFILES/" + peptideFileName2 file1 = open(filename1,"w") file2 = open(filename2,"w") line = peptideFile1.readline() #WARNING: One can read the file contents ONLY ONCE #This means that one can not first read and print if PRINT holds #then close and reopen the file contents for processing #Print (if requested) and copy file 1 to tmpfile if PRINT: print "Filename: " + peptideFileName1 print "
"
      print line.replace(eolnMarker,"")
    if line[0]=='>': line = peptideFile1.readline()
    while line:
      line = line.replace(eolnMarker,"")
      if PRINT: print line
      file1.write(line)
      line = peptideFile1.readline()
    if PRINT:  print "
" #Print (if requested) and copy file 2 to tmpfile line = peptideFile2.readline() if PRINT: print "Filename: " + peptideFileName2 print "
"
      print line.replace(eolnMarker,"")
    if line[0]=='>': line = peptideFile2.readline()
    while line:
      line = line.replace(eolnMarker,"")
      if PRINT: print line
      file2.write(line)
      line = peptideFile2.readline()
    if PRINT:  print "
" file1.close(); file2.close() cmd = "./BoltzmannAlignment/smithWatermanBoltzmann.py -f " cmd += filename1 + " " + filename2 else: if PRINT: print "First sequence: " + peptide1 print "
"; print peptide1; print "
" print "Second sequence: " + peptide2 print "
"; print peptide2; print "
" cmd = "./BoltzmannAlignment/smithWatermanBoltzmann.py -s " cmd += peptide1 + " " + peptide2 print "

Output:

" text = os.popen(cmd, "r") lines = text.readlines() print "
"
  for line in lines:
    print line[:-1]
  print "
" print ""