Skip to content

Commit

Permalink
Added a service get predictions from a previously built model
Browse files Browse the repository at this point in the history
  • Loading branch information
rajarshi committed Jan 12, 2009
1 parent 48f10f8 commit 5e47679
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions predict/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SetHandler mod_python
PythonHandler predictors
PythonDebug On
<Files ~ "\.(gif|html|jpg|png|css)$">
SetHandler default-handler
</Files>
44 changes: 44 additions & 0 deletions predict/predictors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from mod_python import apache
import SOAPpy, sys, string, StringIO, base64, urllib
import elementtree.ElementTree as ET
from elementtree.ElementTree import XML


baseUrl = 'http://rguha.ath.cx/~rguha/cicc/rest/desc/descriptors/org.openscience.cdk.qsar.descriptors.molecular.'
descs = {'ATSm1' : 'AutocorrelationDescriptorMass',
'C1SP2' : 'CarbonTypesDescriptor',
'AMR' : 'ALOGPDescriptor' }

def handler(req):
uriParts = req.uri.split('/')
smiles = uriParts[-1]

descriptors = {}

## get descriptors
for key in descs.keys():
descClass = descs[key]
url = baseUrl + descClass + "/" + smiles
doc = ''.join(urllib.urlopen(url).readlines())
root = XML(doc)
values = root.findall("Descriptor")
for value in values:
if value.attrib['name'] == key: descriptors[key] = float(value.attrib['value'])

## load the model and get a prediction
from rpy import *

makeDF = r("""
function( ..., names)
{
df <- data.frame(...)
names(df) <- names
df
}
""")

df = makeDF(1,2,3, names= ['a','b','c'])
# r("""load('test-model.R')""")

req.write(str(descriptors))
return apache.OK

0 comments on commit 5e47679

Please sign in to comment.