/* * Rajarshi Guha * 26/04/2006 * * Uses the ToxTree program developed by * Nina Jeliazkova, IdeaConsult Ltd. Sofia, Bulgaria * */ import toxTree.tree.*; import toxTree.core.*; import toxTree.data.*; import toxTree.exceptions.DecisionResultException; import javax.swing.*; import java.awt.*; import java.io.*; import org.openscience.cdk.smiles.SmilesParser; import org.openscience.cdk.interfaces.Molecule; import org.openscience.cdk.exception.CDKException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServlet; import javax.servlet.ServletContext; import org.apache.axis.MessageContext; import org.apache.axis.transport.http.HTTPConstants; public class toxTreeWS { public toxTreeWS() {} public String getCramerClass(String smiles) throws CDKException { MessageContext mcon = MessageContext.getCurrentContext(); ServletContext scon = ((HttpServlet)mcon.getProperty(HTTPConstants.MC_HTTP_SERVLET)).getServletContext(); String baseDir = scon.getRealPath("/") + "WEB-INF/lib"; //String baseDir = "/usr/local/share/java/tomcat/webapps/tox/WEB-INF/lib"; Introspection.addDirectory(baseDir); ToxTreeModule toxTreeModel = null; DecisionMethodsList methods = new DecisionMethodsList(); try { methods.loadAllFromPlugins(); } catch (Exception e) { e.printStackTrace(); } ToxTreeData data = new ToxTreeData(null); // set up a new molecule to test SmilesParser sp = new SmilesParser(); Molecule m = sp.parseSmiles(smiles); m.setProperty("SMILES", "XYZ"); data.newMolecule(m); // prepare to classify IDecisionMethod method = methods.getMethod(0); IDecisionResult result = method.createDecisionResult(); // classify! try { data.classify(result); } catch (DecisionResultException dre) { throw new CDKException(dre.toString()); } // parse the string form of the result return(result.getCategory().getName()+"#"+result.getCategory().getExplanation()); } public static void main(String[] args) { toxTreeWS tws = new toxTreeWS(); try { String res = tws.getCramerClass(args[0]); System.out.println(res); System.exit(0); } catch (CDKException cdke) { cdke.printStackTrace(); } } private HttpServletRequest getRequest() { MessageContext context = MessageContext.getCurrentContext(); HttpServletRequest req = (HttpServletRequest) context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); return req; } }