/**
 *  NCBI Conserved Domain Search
 *  Internet robot, CDD_ncbi, that uses form, located in page
 *  http://www.ncbi.nlm.nih.gov/Structure/cdd/wrpsb.cgi.
 *  It is your responsibility to find and cite appropriate references
 *  from this page.
 *  Generated 2002.7.14  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 CDD_ncbi extends Sight.Agents.Prototypes.tableBasedAgent implements Serializable {
 /* Data structure to pass query to this robot. */
  public class Request extends Sight.Request implements java.io.Serializable {
   /** Choices for DATALIB:
    * oasis_smart=Smart v3.4 - 638 PSSMs oasis_pfam=Pfam v7.3 - 3849 PSSMs oasis_sap=All - 4540 PSSMs default
    * , default=oasis_sap. */
   public String Datalib="oasis_sap"; // select
   public String Sequence; // required.
     /** Choices for EXPECT:
    * 0.000001= 0.000001 0.0001= 0.0001 0.01= 0.01 default 1= 1 10= 10
    * 100= 100 , default=0.01. */
   public String Expect="0.01"; // select
     /** Choices for SMODE:
    * 0=Multiple hits 1-pass default 1=Single hit 1-pass 2=2-pass , default=0. */
   public String Smode="0"; // select
     /** Choices for NHITS:
    * 10= 10 hits 25= 25 hits 50= 50 hits default 100= 100 hits 250= 250 hits
    * , default=50. */
   public String Nhits="50"; // select
     /** Choices for GRAPH:
    * 0=No Graphic Overview 1=Condensed Graphic Overview 2=Extended Graphic Overview default
    * , default=2. */
   public String Graph="2"; // select
     /** Choices for PAIR:
    * 0=Color Scheme 1 1=Color Scheme 2 2=Color Scheme 3 default , default=2. */
   public String Pair="2"; // select
     /** Choices for GW:
    * -5=5 pixels per residue -2=2 pixels per residue -1=Default Width default 1=1 residue per pixel
    * 2=2 residues per pixel 5=5 residues per pixel 10=10 residues per pixel , default=-1. */
   public String Gw="-1"; // 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://www.ncbi.nlm.nih.gov/Structure/cdd/wrpsb.cgi"); // connect
    map.add("connect:action", "POST"); // connect
    map.add("connect:master", "http://www.ncbi.nlm.nih.gov/Structure/cdd/wrpsb.cgi"); // connect
    map.add("DATALIB", request.Datalib); // select
    map.add("SEQUENCE", request.Sequence); // textarea
    map.add("EXPECT", request.Expect); // select
    map.add("FILTER", "T"); // checkbox
    map.add("SMODE", request.Smode); // select
    map.add("NHITS", request.Nhits); // select
    map.add("GRAPH", request.Graph); // select
    map.add("PAIR", request.Pair); // select
    map.add("GW", request.Gw); // select
    map.add("RID", ""); // text
    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

    /** Type definitions for Request. */
   public dStructure getRequestDds() {
    return new Sight.dds.Records(false,
     new dField[] {
        new dField("Datalib","CharSequence","Data lib","oasis_sap",new String[] {"oasis_smart","oasis_pfam","oasis_sap"},new String[] {"Smart v3.4 - 638 PSSMs","Pfam v7.3 - 3849 PSSMs","All - 4540 PSSMs default"}),
        new dField("Sequence","CharSequence","Sequence",""),
        new dField("Expect","CharSequence","Expectation value","0.01",new String[] {"0.000001","0.0001","0.01","1","10","100"},new String[] {" 0.000001"," 0.0001"," 0.01 default"," 1"," 10"," 100"}),
        new dField("Smode","CharSequence",null,"0",new String[] {"0","1","2"},new String[] {"Multiple hits 1-pass default","Single hit 1-pass","2-pass"}),
        new dField("Nhits","CharSequence",null,"50",new String[] {"10","25","50","100","250"},new String[] {" 10 hits"," 25 hits"," 50 hits default"," 100 hits"," 250 hits"}),
        new dField("Graph","CharSequence",null,"2",new String[] {"0","1","2"},new String[] {"No Graphic Overview","Condensed Graphic Overview","Extended Graphic Overview default"}),
        new dField("Pair","CharSequence",null,"2",new String[] {"0","1","2"},new String[] {"Color Scheme 1","Color Scheme 2","Color Scheme 3 default"}),
        new dField("Gw","CharSequence","Residue per pixel","-1",new String[] {"-5","-2","-1","1","2","5","10"},new String[] {"5 pixels per residue","2 pixels per residue","Default Width default","1 residue per pixel","2 residues per pixel","5 residues per pixel","10 residues per pixel"})                 }
    );
   }
 /* 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 {
        /** id */
        public CharSequence id;
        public CharSequence id_url;
        public CharSequence header;
        /** Score bits */
        public CharSequence Bits;
        /** E */
        public CharSequence E;
      };
      /** 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 ""+" <a href=\""+r.id_url+"\"> "+r.id+"</a>" +r.header+" "+r.Bits+" "+r.E+" ";
              case 1:  return ""+" <a href=\""+r.id_url+"\"> "+r.id+"</a>" +r.header+" "+r.Bits+" "+r.E+" ";
              default: return ""+" id:" +" <a href=\""+r.id_url+"\"> "+r.id+"</a> "+" :" +r.header+" "+" Score bits:" +r.Bits+" "+" E:" +r.E+" ";
            }
          };
      }

    /** Type definitions for Result. */
   public dStructure getResultDds() {
    return new Sight.dds.Records(true,
     new dField[] {
        new dField("id",null,"id",""),
        new dField("id_url","URL","id url ",""),
        new dField("header",null,null,""),
        new dField("Bits",null,"Score bits",""),
        new dField("E",null,"E","")                 }
    );
   }

  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();
        if (fields.length>=5)
         {
        r.id=noHtml(fields[1]);
        r.id_url=getURL(fields[1]);
        r.header=noHtml(fields[2]);
        r.Bits=noHtml(fields[3]);
        r.E=fields[4];
         } else
        if (fields.length==4)
         {
        r.id=noHtml(fields[0]);
        r.id_url=getURL(fields[0]);
        r.header=noHtml(fields[1]);
        r.Bits=noHtml(fields[2]);
        r.E=fields[3];
         } else
            throw new Exception("At least 4 columns required.");
        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 CDD_ncbi() { ignoreFirstLine=true;
   ignoreLastLine =false;
   table_position ="2.2";
   setDescription("NCBI Conserved Domain Search");
   setFormURL("http://www.ncbi.nlm.nih.gov/Structure/cdd/wrpsb.cgi");
   setMasterURL("http://www.ncbi.nlm.nih.gov/Structure/cdd/wrpsb.cgi");
   // define pre scan section.
   preScan = new preScan();
   preScan.zeroCases = new String[] { "No hits found" };
   };
  /** Public instance of agent for user. */
  public static CDD_ncbi Public = new CDD_ncbi();
  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();
         };
   }
;
  }