/**
 *  Glycosylphosphatidylinositol modification site prediction
 *  Internet robot, GPI_modification, that uses form, located in page
 *  http://mendel.imp.univie.ac.at/gpi/index_content.html.
 *  It is your responsibility to find and cite appropriate references
 *  from this page.
 *  Generated 2002.5.18  by Sight 2.0, Ulm university.
 */
package impl.protein_analysers;

import Sight.Agents.*;
import Sight.Agents.Redirectors.*;
import Sight.Structures.*;
import Sight.dds.*;
import java.io.*;
import Sight.Agents.util.*;

public class GPI_modification extends Sight.Agents.Prototypes.preformattedResponseAgent implements Serializable {
 /* Data structure to pass query to this robot. */
  public class Request extends Sight.Request implements java.io.Serializable {
   public String Sequence; // required.
       /** Submit request, compute key by SHA digesting algorithm. */
       public Sight.Agents.Request submit() { return Sight.Agents.Request.submit(Public, this, getKey()); };
       /** Submit request with the known key. */
       public Sight.Agents.Request submit(String key)
        { return Sight.Agents.Request.submit(Public, this, key); };
       };

   /** Get the AMap data structure, required by post method. */
  protected AMap getFormParameters(Object req) {
    Request request = (Request) req;
    AMap map = new AMap();
    map.add("connect:master", "http://mendel.imp.univie.ac.at/gpi/index_content.html"); // connect
    map.add("connect:url", "http://mendel.imp.univie.ac.at/gpi/cgi-bin/gpi_pred.cgi"); // connect
    map.add("connect:action", "POST"); // connect
    map.add("LSet", "metazoa"); // radio
    map.add("", ""); // radio
    map.add("Sequence", request.Sequence); // textarea
    return map; };
  /** Get default request for this robot. */
  public static Request getDefaultRequest() {
     return Public.getRequest(); }
  private Request getRequest() { return new Request(); }; // must be non static

  /** Form URL to connect. http://mendel.imp.univie.ac.at/gpi/cgi-bin/gpi_pred.cgi.*/
  public String getFormURL() {
     return "http://mendel.imp.univie.ac.at/gpi/cgi-bin/gpi_pred.cgi"; }

  /** URL to refer. http://mendel.imp.univie.ac.at/gpi/index_content.html.*/
  public String getMasterURL() {
     return "http://mendel.imp.univie.ac.at/gpi/index_content.html"; }

    /** Type definitions for Request. */
   public dStructure getRequestDds() {
    return new Sight.dds.Records(false,
     new dField[] {
        new dField("Sequence","CharSequence",null,"")                 }
    );
   }
 /* Record type, used in results for this robot. */
 /* The result of this robot is an array of records. */
  public static class Record extends Sight.Record implements Serializable {
        /** Total score for GPI-modification motif. */
        public CharSequence Score;
      };
      /** The result of this robot. */
      public static class Result extends Sight.Result implements Serializable {
         public Record[] a; // array of results.
         /** Create report for one record. */
         public CharSequence getReportForRecord(Object ro, int level)
          { Record r = (Record) ro;
           switch (level) {
              case 0:  return ""+r.Score+" ";
              case 1:  return ""+r.Score+" ";
              default: return ""+" Total score for GPI-modification motif.: "+r.Score+" ";
            }
          };
      }

    /** Type definitions for Result. */
   public dStructure getResultDds() {
    return new Sight.dds.Records(true,
     new dField[] {
        new dField("Score","CharSequence","Total score for GPI-modification motif.","")                 }
    );
   }

  public Sight.Record createRecord(String[] row) throws Exception
    { return fillRecord(row); };
  public Class getRecordClass() { return Record.class; };
   Record fillRecord(String[] fields) throws Exception {
        Record r = new Record();
        String score = noHtml(fields[0]);
        try {
          } catch (Exception exc)
             {
               double S = Double.parseDouble(score.trim());
               if (S>0.95) score = "HIGHLY PROBABLE"; else
               if (S>0.80) score = "probable"; else
               if (S<0.05) score = "for sure not"; else
               score = "";
             };
        r.Score = score;
        return r;
   };

   /** Get result from the given html content. */
  public Sight.Result resultFromString(String html) throws Exception {
     Result r = new Result();
     r.a = (Record[]) createResultArray(html);
     return r;
   };
  public GPI_modification() { signatures = new Sight.tools.xPlain.multiSignatures();
   signatures.far_start="Prediction of potential C-terminal GPI-modification sites";
   signatures.top="P-value of the best site, linear fit........................:";
   signatures.bottom="P-value of the best site, 6th degree polynomial fit";
   signatures.Columns = 1;
   setDescription("Glycosylphosphatidylinositol modification site prediction");
   // define pre scan section.
   preScan = new preScan();
   };
  /** Public instance of agent for user. */
  public static GPI_modification Public = new GPI_modification();
  public static Agent getAvailableAgent() { return Public; };
  /** main(..) method provided to check robot, launching it
   * as standalone program. */
  public static void main(String[] args) {
  Sight.Agents.util.Pind.showConsoles();
      try {
        Request request = getDefaultRequest();
        // Now modify and assign request fields in accordance with task:
        request. Sequence="MPSSGRALLDSPLDSGSLTSLDSSVFCSEGEGEPLALGDCFTVNVGGSRFVLSQQALSCFPHTRLGKLAVVVASYRRPGALAAVPSPLELCDDANPVDNEYFFDRSSQAFRYVLHYYRTGRLHVMEQLCALSFLQEIQYWGIDELSIDSCCRDRYFRRKELSETLDFKKDTEDQESQHESEQDFSQGPCPTVRQKLWNILEKPGSSTAARIFGVISIIFVVVSIINMALMSAELSWLDLQLLEILEYVCISWFTGEFVLRFLCVRDRCRFLRKVPNIIDLLAILPFYITLLVESLSGSQTTQELENVGRIVQVLRLLRALRMLKLGRHSTGLRSLGMTITQCYEEVGLLLLFLSVGISIFSTVEYFAEQSIPDTTFTSVPCAWWWATTSMTTVGYGDIRPDTTTGKIVAFMCILSGILVLALPIAIINDRFSACYFTLKLKEAAVRQREALKKLTKNIATDSYISVNLRDVYARSIMEMLRLKGRERASTRSSGGDDFWF";
        Sight.Agents.Request submission = request.submit();
        // processing now started in separate thread:
        Result response = (Result) submission.getResult();
        // print report, verbosity level 2:
        System.out.println(response.getReport(2));
      } catch (Exception exc)
         { if (exc!=null) System.out.println(exc.getMessage());
           exc.printStackTrace();
         };
   }
;
  }