-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a service get predictions from a previously built model
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |