extensions/net.sf.basedb.genepattern/trunk/src/net/sf/basedb/genepattern/servlet/Test.java

Code
Comments
Other
Rev Date Author Line
1107 03 Jun 09 nicklas 1 /*
1107 03 Jun 09 nicklas 2   $Id$
1107 03 Jun 09 nicklas 3
1107 03 Jun 09 nicklas 4   Copyright (C) 2007 Nicklas Nordborg
1107 03 Jun 09 nicklas 5
1107 03 Jun 09 nicklas 6   This file is part of BASE - BioArray Software Environment.
1107 03 Jun 09 nicklas 7   Available at http://base.thep.lu.se/
1107 03 Jun 09 nicklas 8
1107 03 Jun 09 nicklas 9   BASE is free software; you can redistribute it and/or
1107 03 Jun 09 nicklas 10   modify it under the terms of the GNU General Public License
1107 03 Jun 09 nicklas 11   as published by the Free Software Foundation; either version 2
1107 03 Jun 09 nicklas 12   of the License, or (at your option) any later version.
1107 03 Jun 09 nicklas 13
1107 03 Jun 09 nicklas 14   BASE is distributed in the hope that it will be useful,
1107 03 Jun 09 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
1107 03 Jun 09 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1107 03 Jun 09 nicklas 17   GNU General Public License for more details.
1107 03 Jun 09 nicklas 18
1107 03 Jun 09 nicklas 19   You should have received a copy of the GNU General Public License
1107 03 Jun 09 nicklas 20   along with this program; if not, write to the Free Software
1107 03 Jun 09 nicklas 21   Foundation, Inc., 59 Temple Place - Suite 330,
1107 03 Jun 09 nicklas 22   Boston, MA  02111-1307, USA.
1107 03 Jun 09 nicklas 23 */
1107 03 Jun 09 nicklas 24 package net.sf.basedb.genepattern.servlet;
1107 03 Jun 09 nicklas 25
1107 03 Jun 09 nicklas 26 import javax.servlet.ServletException;
1107 03 Jun 09 nicklas 27 import javax.servlet.http.HttpServlet;
1107 03 Jun 09 nicklas 28 import javax.servlet.http.HttpServletRequest;
1107 03 Jun 09 nicklas 29 import javax.servlet.http.HttpServletResponse;
1107 03 Jun 09 nicklas 30
1107 03 Jun 09 nicklas 31 import org.genepattern.webservice.Parameter;
1118 10 Jun 09 nicklas 32 import org.genepattern.webservice.TaskInfoAttributes;
1107 03 Jun 09 nicklas 33
1107 03 Jun 09 nicklas 34 import net.sf.basedb.clients.web.Base;
1107 03 Jun 09 nicklas 35 import net.sf.basedb.core.DbControl;
1107 03 Jun 09 nicklas 36 import net.sf.basedb.core.File;
1107 03 Jun 09 nicklas 37 import net.sf.basedb.core.Path;
1107 03 Jun 09 nicklas 38 import net.sf.basedb.core.SessionControl;
1107 03 Jun 09 nicklas 39 import net.sf.basedb.genepattern.file.BaseFileProxy;
1107 03 Jun 09 nicklas 40 import net.sf.basedb.genepattern.file.FileTransferGateway;
1118 10 Jun 09 nicklas 41 import net.sf.basedb.genepattern.wrapper.GPClient;
1118 10 Jun 09 nicklas 42 import net.sf.basedb.genepattern.wrapper.JobResult;
1118 10 Jun 09 nicklas 43 import net.sf.basedb.genepattern.wrapper.ParameterInfo;
1118 10 Jun 09 nicklas 44 import net.sf.basedb.genepattern.wrapper.TaskInfo;
1107 03 Jun 09 nicklas 45
1107 03 Jun 09 nicklas 46 import java.io.IOException;
1107 03 Jun 09 nicklas 47 import java.io.PrintWriter;
1107 03 Jun 09 nicklas 48 import java.net.URL;
1107 03 Jun 09 nicklas 49
1107 03 Jun 09 nicklas 50 /**
1107 03 Jun 09 nicklas 51   A test servlet that is very hardcoded for my personal setup. It will be removed
1107 03 Jun 09 nicklas 52   before release. 
1107 03 Jun 09 nicklas 53
1107 03 Jun 09 nicklas 54   @author Nicklas
1107 03 Jun 09 nicklas 55   @version 1.0
1107 03 Jun 09 nicklas 56   @base.modified $Date$
1107 03 Jun 09 nicklas 57 */
1107 03 Jun 09 nicklas 58 public final class Test
1107 03 Jun 09 nicklas 59   extends HttpServlet
1107 03 Jun 09 nicklas 60 {
1107 03 Jun 09 nicklas 61
1128 15 Jun 09 nicklas 62   public static final String DOWNLOAD_SERVLET = "http://auster.thep.lu.se:8080/trunk/extensions/servlet/gp-integration.jar/Download";
1107 03 Jun 09 nicklas 63   public static final String GP_HOME = "http://kundera.thep.lu.se:8088";
1107 03 Jun 09 nicklas 64   public static final String GP_LOGIN = "nicklas@thep.lu.se";
1107 03 Jun 09 nicklas 65   public static final String GP_PWD = "test";
1107 03 Jun 09 nicklas 66   public static final String GCT_FILE = "/GenePattern/all_aml_test.res";
1107 03 Jun 09 nicklas 67   public static final String CLS_FILE = "/GenePattern/all_aml_test.cls";
1107 03 Jun 09 nicklas 68   
1107 03 Jun 09 nicklas 69   public Test()
1107 03 Jun 09 nicklas 70   {}
1107 03 Jun 09 nicklas 71
1107 03 Jun 09 nicklas 72   @Override
1107 03 Jun 09 nicklas 73   public void doGet(HttpServletRequest request, HttpServletResponse response)
1107 03 Jun 09 nicklas 74     throws IOException, ServletException
1107 03 Jun 09 nicklas 75   {
1107 03 Jun 09 nicklas 76     
1107 03 Jun 09 nicklas 77     final SessionControl sc = Base.getExistingSessionControl(request, true);
1107 03 Jun 09 nicklas 78     final String ID = sc.getId();
1107 03 Jun 09 nicklas 79     DbControl dc = sc.newDbControl();
1128 15 Jun 09 nicklas 80     FileTransferGateway gw = new FileTransferGateway(DOWNLOAD_SERVLET);
1107 03 Jun 09 nicklas 81     try
1107 03 Jun 09 nicklas 82     {
1128 15 Jun 09 nicklas 83       /*
1107 03 Jun 09 nicklas 84       File gctFile = File.getByPath(dc, new Path(GCT_FILE, Path.Type.FILE), false);
1107 03 Jun 09 nicklas 85       File clsFile = File.getByPath(dc, new Path(CLS_FILE, Path.Type.FILE), false);
1107 03 Jun 09 nicklas 86       
1107 03 Jun 09 nicklas 87       Parameter gctParameter = gw.addFile("input.file", new BaseFileProxy(gctFile));
1107 03 Jun 09 nicklas 88       Parameter clsParameter = gw.addFile("cls.file", new BaseFileProxy(clsFile));
1128 15 Jun 09 nicklas 89     */
1107 03 Jun 09 nicklas 90       dc.close();
1128 15 Jun 09 nicklas 91     
1107 03 Jun 09 nicklas 92       GPClient gp = new GPClient(GP_HOME, GP_LOGIN, GP_PWD);
1118 10 Jun 09 nicklas 93       
1118 10 Jun 09 nicklas 94       TaskInfo[] tasks = gp.getModules(null);
1118 10 Jun 09 nicklas 95       PrintWriter out = response.getWriter();
1118 10 Jun 09 nicklas 96       out.println("<b>Tasks</b><br>");
1118 10 Jun 09 nicklas 97       for (TaskInfo ti : tasks)
1118 10 Jun 09 nicklas 98       {
1118 10 Jun 09 nicklas 99         org.genepattern.webservice.TaskInfo gpTi = ti.getGPTaskInfo();
1118 10 Jun 09 nicklas 100         TaskInfoAttributes tia = gpTi.getTaskInfoAttributes();
1118 10 Jun 09 nicklas 101         out.println("name="+ti.getName()+"<br>");
1118 10 Jun 09 nicklas 102         out.println("access_id="+gpTi.getAccessId()+"<br>");
1118 10 Jun 09 nicklas 103         out.println("descr="+ti.getDescription()+"<br>");
1118 10 Jun 09 nicklas 104         out.println("ID="+gpTi.getID()+"<br>");
1118 10 Jun 09 nicklas 105         out.println("lsid="+ti.getLsid()+"<br>");
1118 10 Jun 09 nicklas 106         out.println("shortname="+gpTi.getShortName()+"<br>");
1118 10 Jun 09 nicklas 107         out.println("userid="+gpTi.getUserId()+"<br>");
1118 10 Jun 09 nicklas 108         out.println("containsinputfileparam="+gpTi.containsInputFileParam()+"<br>");
1118 10 Jun 09 nicklas 109         out.println("pipeline="+ti.isPipeline()+"<br>");
1118 10 Jun 09 nicklas 110         out.println("attr="+gpTi.getAttributes()+"<br>");
1118 10 Jun 09 nicklas 111         out.println("tiattr="+tia+"<br>");
1118 10 Jun 09 nicklas 112         out.println("toString=" + ti.toString());
1118 10 Jun 09 nicklas 113         out.println("<hr>");
1118 10 Jun 09 nicklas 114       }
1118 10 Jun 09 nicklas 115       out.flush();
1118 10 Jun 09 nicklas 116
1118 10 Jun 09 nicklas 117       
1128 15 Jun 09 nicklas 118       ParameterInfo[] info = gp.getParameters("ImputeMissingValuesKNN", null);
1118 10 Jun 09 nicklas 119       //PrintWriter out = response.getWriter();
1118 10 Jun 09 nicklas 120       out.println("<b>Parameters</b><br>");
1118 10 Jun 09 nicklas 121       for (ParameterInfo pi : info)
1118 10 Jun 09 nicklas 122       {
1118 10 Jun 09 nicklas 123         org.genepattern.webservice.ParameterInfo gpPi = pi.getGPParameterInfo();
1118 10 Jun 09 nicklas 124         out.println("name="+pi.getName()+"<br>");
1118 10 Jun 09 nicklas 125         out.println("label="+pi.getLabel()+"<br>");
1118 10 Jun 09 nicklas 126         out.println("descr="+pi.getDescription()+"<br>");
1118 10 Jun 09 nicklas 127         out.println("default="+pi.getDefaultValue()+"<br>");
1118 10 Jun 09 nicklas 128         out.println("choices="+pi.getChoices()+"<br>");
1118 10 Jun 09 nicklas 129         out.println("attr="+gpPi.getAttributes()+"<br>");
1118 10 Jun 09 nicklas 130         out.println("optional="+pi.isOptional()+"<br>");
1118 10 Jun 09 nicklas 131         out.println("inputfile="+pi.isInputFile()+"<br>");
1118 10 Jun 09 nicklas 132         out.println("outputfile="+gpPi.isOutputFile()+"<br>");
1118 10 Jun 09 nicklas 133         out.println("password="+gpPi.isPassword()+"<br>");
1118 10 Jun 09 nicklas 134         out.println("toString=" + pi.toString());
1118 10 Jun 09 nicklas 135         out.println("<hr>");
1118 10 Jun 09 nicklas 136       }
1118 10 Jun 09 nicklas 137       out.flush();
1128 15 Jun 09 nicklas 138       /*
1118 10 Jun 09 nicklas 139       int jobId = gp.runAnalysisNoWait(
1107 03 Jun 09 nicklas 140         "urn:lsid:broad.mit.edu:cancer.software.genepattern.module.analysis:00044:5", 
1107 03 Jun 09 nicklas 141         new Parameter[]{
1107 03 Jun 09 nicklas 142           gctParameter,
1107 03 Jun 09 nicklas 143           clsParameter,
1107 03 Jun 09 nicklas 144           new Parameter("confounding.variable.cls.file", ""), 
1107 03 Jun 09 nicklas 145           new Parameter("test.direction", "2"), 
1107 03 Jun 09 nicklas 146           new Parameter("test.statistic", "0"), 
1107 03 Jun 09 nicklas 147           new Parameter("min.std", ""), 
1107 03 Jun 09 nicklas 148           new Parameter("number.of.permutations", "1000"),
1107 03 Jun 09 nicklas 149           new Parameter("complete", "false"), 
1107 03 Jun 09 nicklas 150           new Parameter("balanced", "false"), 
1107 03 Jun 09 nicklas 151           new Parameter("random.seed", "779948241"), 
1107 03 Jun 09 nicklas 152           new Parameter("smooth.p.values", "true"), 
1107 03 Jun 09 nicklas 153           new Parameter("phenotype.test", "one versus all"), 
1107 03 Jun 09 nicklas 154           new Parameter("output.filename", "<input.file_basename>.comp.marker.odf")
1107 03 Jun 09 nicklas 155         });
1118 10 Jun 09 nicklas 156       JobResult result = gp.waitFor(jobId, 5000);
1118 10 Jun 09 nicklas 157       org.genepattern.webservice.JobResult gpJr = result.getGPJobResult();
1107 03 Jun 09 nicklas 158       String[] files = result.getOutputFileNames();
1118 10 Jun 09 nicklas 159       out.println("<p><b>Result files:</b><br>");
1107 03 Jun 09 nicklas 160       for (String f : files)
1107 03 Jun 09 nicklas 161       {
1118 10 Jun 09 nicklas 162         URL url = gpJr.getURL(f);
1118 10 Jun 09 nicklas 163         out.println("<a href=\"" + url + "\" target=\"_new\">" + f + ": " + url + "</a><br>");
1107 03 Jun 09 nicklas 164       }
1128 15 Jun 09 nicklas 165       */
1107 03 Jun 09 nicklas 166
1107 03 Jun 09 nicklas 167     }
1118 10 Jun 09 nicklas 168     catch (Exception ex)
1107 03 Jun 09 nicklas 169     {
1107 03 Jun 09 nicklas 170       throw new ServletException(ex);
1107 03 Jun 09 nicklas 171     }
1107 03 Jun 09 nicklas 172     finally
1107 03 Jun 09 nicklas 173     {
1107 03 Jun 09 nicklas 174       gw.cleanUp();
1107 03 Jun 09 nicklas 175       if (dc != null) dc.close();
1107 03 Jun 09 nicklas 176     }
1107 03 Jun 09 nicklas 177     
1107 03 Jun 09 nicklas 178   }
1107 03 Jun 09 nicklas 179
1107 03 Jun 09 nicklas 180   @Override
1107 03 Jun 09 nicklas 181   public void doPost(HttpServletRequest request, HttpServletResponse response)
1107 03 Jun 09 nicklas 182     throws IOException, ServletException
1107 03 Jun 09 nicklas 183   {
1107 03 Jun 09 nicklas 184     doGet(request, response);
1107 03 Jun 09 nicklas 185   }
1107 03 Jun 09 nicklas 186 }