Menu Desplegable

Beautifulsoup4 4.3.2...

Cómo instalar Beautifulsoup4 4.3.2

"C:\Path\To\BeautifulSoup\setup.py" install

ADMETutils.py

import urllib, sgmllib

def gdownload(urldown):    
    # Get a file-like object for the Python Web site's home page.
    f = urllib.urlopen(urldown)
    # Read from the object, storing the page's contents in 's'.
    data = f.read()
    print data
    data=data.replace("<"+chr(92),'<')
    data=data.replace(chr(92)+"'","'")
    
    data=data.replace(chr(92)+chr(110),'')
    data=data.replace(chr(92)+chr(34),'"')

    f.close()
    return data

def getcode(s):
    data_ini=s.find('

ADMET Predicted Profile --- Classification

') #print data_ini data_fin=s.find('

get-lmmd.py

import sys
from bs4 import BeautifulSoup
import urllib, sgmllib
import fileinput
from ADMETutils import *
filelist=sys.argv[1]
fileout=sys.argv[2]
file = open(filelist, 'r')
allmols={}
allproperties={}
for line in file:
	lineparams=line.split('	');
	namemol=lineparams[0]
	smile=lineparams[1] 
	smile=smile[:len(smile)-1]
	print "Getting "+namemol +"..."
	urllmmd='http://lmmd.ecust.edu.cn:8000/predict/?smiles='+urllib.quote_plus(smile)+'&action=A'	
	#print urllmmd
	admetdata={};admetprob={}
	stringhtml=gdownload(urllmmd)
	stringhtml=getcode(stringhtml)
	vechtml = stringhtml.split('')
	for elemhtml in vechtml:
		soupsubsub=BeautifulSoup(elemhtml)
		colsinrow=soupsubsub.find_all('td')	        	
		numelemrow=len(colsinrow)
		#if (numelemrow==3 and (soupsubsub.find('td',attrs={'rowspan':"1"}))):
		if numelemrow==3:
			textname=colsinrow[0].get_text()
			valuename=colsinrow[1].get_text()
			probability=colsinrow[2].get_text()
			allproperties.update({textname:1})
			#print textname,valuename,probability 			
			if admetdata.has_key(textname):
				textname=textname+' B'
				allproperties.update({textname:1})
			admetdata[textname]=valuename;admetprob[textname]=probability
			if  (soupsubsub.find('td',attrs={'rowspan':"2"})):
				nextname=textname
		elif  numelemrow==2:
			textname=nextname+"2"
			if admetdata.has_key(textname):
                                textname=textname+' B'
				allproperties.update({textname:1})
                       
			valuename=colsinrow[0].get_text()
                        probability=colsinrow[1].get_text()
			allproperties.update({textname:1})
                        #print textname,valuename,probability
			admetdata[textname]=valuename;admetprob[textname]=probability
                        
	allmols[namemol]=admetdata	
	#break
file = open(fileout, 'w')
txtrow='NAME\t'
for prop in allproperties.keys():
	txtrow=txtrow+prop+'\t'
file.write(txtrow+'\n')
for namemol in allmols.keys():
	print namemol
	thismol= allmols[namemol]
	txtrow=namemol+'\t'
	for prop in allproperties.keys():
		#print prop
        	if thismol.has_key(prop): 
			txtrow=txtrow+thismol[prop]+'\t'
		else:
			txtrow=txtrow+'----\t'
	file.write(txtrow+'\n')
	#for elemol in 
	#break

file.close()