/**
 *  Scans a sequence against PROSITE (allows mismatches); at PBIL
 *  Internet robot, ProSite, that uses form, located in page
 *  http://npsa-pbil.ibcp.fr/cgi-bin/npsa_automat.pl?page=npsa_prosite.html.
 *  It is your responsibility to find and cite appropriate references
 *  from this page.
 *  Generated 2002.5.13  by Sight 2.0, Ulm university.
 */
package impl.protein_analysers;

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

public class ProSite extends Sight.Agents.Prototypes.signatureBasedAgent implements Serializable {
 /* Data structure to pass query to this robot. */
  public class Request extends Sight.Request implements java.io.Serializable {
   public String Sequence; // required.
     /** Choices for simlevel:
    * m=2=2 Mismatches m=1=1 Mismatch i=No mismatch = 100% similarity default s=95=95% similarity
    * s=90=90% similarity s=85=85% similarity s=80=80% similarity s=75=75% similarity s=70=70% similarity
    * s=65=65% similarity s=60=60% similarity s=55=55% similarity s=50=50% similarity , default=i. */
   public String simlevel="i"; // select
       /** 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:url", "http://npsa-pbil.ibcp.fr/cgi-bin/pattern_prosite.pl"); // connect
    map.add("connect:action", "post"); // connect
    map.add("connect:master", "http://npsa-pbil.ibcp.fr/cgi-bin/npsa_automat.pl?page=npsa_prosite.html"); // connect
    map.add("title", ""); // text
    map.add("notice", request.Sequence); // textarea
    map.add("simlevel", request.simlevel); // select
    map.add("withdoc", "F"); // checkbox
    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://npsa-pbil.ibcp.fr/cgi-bin/pattern_prosite.pl.*/
  public String getFormURL() {
     return "http://npsa-pbil.ibcp.fr/cgi-bin/pattern_prosite.pl"; }

  /** URL to refer. http://npsa-pbil.ibcp.fr/cgi-bin/npsa_automat.pl?page=npsa_prosite.html.*/
  public String getMasterURL() {
     return "http://npsa-pbil.ibcp.fr/cgi-bin/npsa_automat.pl?page=npsa_prosite.html"; }

    /** Type definitions for Request. */
   public dStructure getRequestDds() {
    return new Sight.dds.Records(false,
     new dField[] {
        new dField("Sequence","CharSequence",null,""),
        new dField("simlevel","CharSequence","Similarity level","i",new String[] {"m=2","m=1","i","s=95","s=90","s=85","s=80","s=75","s=70","s=65","s=60","s=55","s=50"},new String[] {"2 Mismatches","1 Mismatch","No mismatch = 100% similarity default","95% similarity","90% similarity","85% similarity","80% similarity","75% similarity","70% similarity","65% similarity","60% similarity","55% similarity","50% similarity"})                 }
    );
   }
 /* 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 {
        /** Header */
        public CharSequence Header;
        public String Url;
        public CharSequence Id;
        public CharSequence Documentation_url;
        /** documentation id */
        public CharSequence Documentation_id;
      };
      /** 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.Header+" "+r.Id+" ";
              case 1:  return ""+r.Header+" "+r.Url+" "+r.Id+" "+r.Documentation_id+" ";
              default: return ""+" Header: "+r.Header+" "+" : "+r.Url+" "+" : "+r.Id+" "+" : "+r.Documentation_url+" "+" documentation id: "+r.Documentation_id+" ";
            }
          };
      }

    /** Type definitions for Result. */
   public dStructure getResultDds() {
    return new Sight.dds.Records(true,
     new dField[] {
        new dField("Header","CharSequence","Header",""),
        new dField("Url","String",null,""),
        new dField("Id","CharSequence",null,""),
        new dField("Documentation_url","CharSequence",null,""),
        new dField("Documentation_id","CharSequence","documentation id","")                 }
    );
   }

  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();
        r.Header=fields[0];
        r.Url=getURL(fields[1]);
        r.Id=fields[2];
        r.Documentation_url=fields[3];
        r.Documentation_id=fields[4];
        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 ProSite() { signatures = new multiSignatures();

   signatures.zeroCases = new String[] { "NO PATTERN FOUND" };

   signatures.far_start=null;
   signatures.top=null;
   signatures.bottom=null;
   signatures.signatures =
   new Signature[] {
   new Signature("\n--------------------------------------------------------------------------------\n","\nProsite access number: <A HREF=\""),
   new Signature("\nProsite access number: <A HREF=\"","\">"),
   new Signature("\">","</A>\nProsite documentation access number: <A HREF=\""),
   new Signature("</A>\nProsite documentation access number: <A HREF=\"","\">"),
   new Signature("\">","</A>\n")
   };
   setDescription("Scans a sequence against PROSITE (allows mismatches); at PBIL");
   // define pre scan section.
   preScan = new preScan();
   };
  /** Public instance of agent for user. */
  public static ProSite Public = new ProSite();
  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();
         };
   }
;
  }