[BioPython] Passing DNA sequence to CGI script

Sebastian Bassi sbassi at asalup.org
Fri Nov 7 09:31:03 EST 2003


Omid Khalouei wrote:

> Hello,
> I've had this problem for 2 weeks now and have tried everything that I 
> could come up with, I would really appreciate your feedback. This is 

I don't see any obvious mistake, but here is the a working code of a 
program I did using cgi and Python (its a web gui for EMBOSS abiview:)
Maybe you could use it as an example. It also took me a lot of time to 
make it works, so I post it here because it could help you.


#! /usr/bin/python
from HTMLgen import *
from HTMLcolors import *
import os
import cgi
import time

os.chdir('/var/www/html/abiimg')

#borro los pngs de la corrida anterior.
lospng=os.listdir(str(os.getcwd()))
for gdos in lospng:
     if gdos[-3:]=="png":
         # HACER LAS COSAS
         os.remove(gdos)
     else:
         pass


formu=cgi.FieldStorage()
doc= SimpleDocument(title="AbiView OUTPUT", bgcolor=WHITE, cgi=1)

try:
     dname=formu["dname"].value
except:
     dname = "defaultname.ab1"

try:
     ffrom=formu["ffrom"].value
except:
     ffrom = None

try:
     fend=formu["tomax"].value
except:
     fend= None

try:
     fwsize=formu["wsize"].value
     fdisseq=formu["disseq"].value
     fdisaxis=formu["disyaxis"].value
except:
     fwsize=40
     fdisseq="Yes"
     fdisaxis="No"

#EL DE ARRIBA TEMPORARIAMENTE SACADO
cudir="/var/www/html/"

if formu["upfile"].value<>"":
	#arch=open(cudir+"filenuevo.ab1","w")
	#arch=open("filenuevo.ab1","w")
	arch=open(dname,"w")
	arch.write(formu["upfile"].value)
	arch.close()
	if fend=="end":
	#pass
		#os.system('abiview -fname filenuevo.ab1 -outseq fileout.txt -graph 
png -yticks '+fdisaxis+' -window '+fwsize+' -startbase '+ffrom)
		#doc.append(os.system('pwd'))
		os.system('/BioServer/EMBOSS-2.5.0/emboss/.libs/abiview -auto -fname 
'+dname+' -outseq fileout.txt -graph png -yticks '+fdisaxis+' -window 
'+fwsize+' -startbase '+ffrom+' >malo.txt')
		#os.system('abiview -fname filenuevo.ab1 -outseq fileout.txt -graph png')
		#doc.append("ENTRA al END")
		#el problema es que no estan saliendo los graficos!!!!!
	else:
	#pass
		os.system('/BioServer/EMBOSS-2.5.0/emboss/.libs/abiview -auto -fname 
'+dname+' -outseq fileout.txt -graph png -yticks '+fdisaxis+' -window 
'+fwsize+' -startbase '+ffrom+' -endbase '+fend+' >malo.txt')
		#la dif es que este si tiene un FIN

	#Escribir la secuencia
	time.sleep(3)
	doc.append(Paragraph("La secuencia es:"))

	archtext=open("fileout.txt","r")
	# VER COMO SACAR LA SECUENCIA DE ACA!!!!
	lineas=archtext.read()
	#seq=lineas[1][:-1]
	seq=lineas
	archtext.close()
	doc.append('<pre>')
	doc.append(Paragraph(seq))
	doc.append('</pre>')
	# AHORA VIENEN LOS GRAFICOS
	doc.append(Paragraph(os.curdir))
	lospng=os.listdir(os.curdir)
	for g in lospng:
		if g[-3:]=="png":
			# HACER LAS COSAS
			#doc.append(Image(os.curdir+"/"+g))
			doc.append(Image('abiimg/'+g))
			doc.append(HR())
		else:
			pass

else:
	doc.append(Heading(2),"You must UPLOAD a file")

print doc
os.remove(dname)


-- 
Best regards,

//=\ Sebastian Bassi - Diplomado en Ciencia y Tecnologia, UNQ   //=\
\=// IT Manager Advanta Seeds - Balcarce Research Center -      \=//
//=\ Pro secretario ASALUP - www.asalup.org - PGP key available //=\
\=// E-mail: sbassi at genesdigitales.com - ICQ UIN: 3356556 -     \=//

                 http://Bioinformatica.info




More information about the BioPython mailing list