/**
 *  Proteomes and Genomes Fasta
 *  Internet robot, Ebi_fasta, that uses form, located in page
 *  http://www.ebi.ac.uk/fasta33/genomes.html.
 *  It is your responsibility to find and cite appropriate references
 *  from this page.
 *  Generated 2002.7.21  by Sight 2.0, Ulm university.
 */
package impl.Blast;

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 Ebi_fasta 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 {
   /** Choices for dbtype:
    * Protein=Proteomes default DNA=Genomes , default=Protein. */
   public String Dbtype="Protein"; // select
     /** Choices for database:
    * 3702-p=Arabidopsis thaliana 6239-p=Caenorhabditis elegans 7227-p=Drosophila melanogaster
    * 6035-p=Encephalitozoon cuniculi 55529-p=Guillardia theta 9606-p=Homo sapiens spens-p=Homo Sapiens (SpTr+Ensembl)
    * 10090-p=Mus musculus (Mouse) 10090.SPEns-p=Mus musculus (SpTr+Ensembl) 4932-p=Saccharomyces cerevisiae
    * 4896-p=Schizosaccharomyces pombe 181661-p=Agrobacterium tumefaciens (strain C58 / ATCC 33970 (Cereon))
    * 180835-p=Agrobacterium tumefaciens (strain C58 / ATCC 33970 (Washington University))
    * 103690-p=Anabaena sp. (strain PCC 7120) 63363-p=Aquifex aeolicus 86665-p=Bacillus halodurans
    * 1423-p=Bacillus subtilis 139-p=Borrelia burgdorferi 29459-p=Brucella melitensis 118099-p=Buchnera aphidicola (subsp. Acyrthosiphon pisum)
    * 197-p=Campylobacter jejuni 155892-p=Caulobacter crescentus 83560-p=Chlamydia muridarum
    * 115711-p=Chlamydia pneumoniae strain AR39 115713-p=Chlamydia pneumoniae strain CWL029
    * 138677-p=Chlamydia pneumoniae strain J138 813-p=Chlamydia trachomatis 1488-p=Clostridium acetobutylicum
    * 1502-p=Clostridium perfringens 196627-p=Corynebacterium glutamicum ATCC 13032 1299-p=Deinococcus radiodurans
    * 83333-p=Escherichia coli K-12 155864-p=Escherichia coli O157:H7 strain EDL933 83334-p=Escherichia coli O157:H7 substrain RIMD 0509952
    * 76856-p=Fusobacterium nucleatum (subsp. nucleatum) 727-p=Haemophilus influenzae 85962-p=Helicobacter pylori strain 26695
    * 85963-p=Helicobacter pylori strain J99 1360-p=Lactococcus lactis (subsp. lactis)
    * 1642-p=Listeria innocua 1639-p=Listeria monocytogenes 1769-p=Mycobacterium leprae
    * 83332-p=Mycobacterium tuberculosis 83331-p=Mycobacterium tuberculosis CDC1551 2097-p=Mycoplasma genitalium
    * 2104-p=Mycoplasma pneumoniae 2107-p=Mycoplasma pulmonis 65699-p=Neisseria meningitidis (serogroup A)
    * 491-p=Neisseria meningitidis (serogroup B) 747-p=Pasteurella multocida 287-p=Pseudomonas aeruginosa
    * 305-p=Ralstonia solanacearum (Pseudomonas solanacearum) 381-p=Rhizobium loti 382-p=Rhizobium meliloti (Sinorhizobium meliloti)
    * 781-p=Rickettsia conorii 782-p=Rickettsia prowazekii 601-p=Salmonella typhi 602-p=Salmonella typhimurium LT2
    * 158878-p=Staphylococcus aureus (strain Mu50 / ATCC 700699) 158879-p=Staphylococcus aureus (strain N315)
    * 196620-p=Staphylococcus aureus MW2 171101-p=Streptococcus pneumoniae R6 170187-p=Streptococcus pneumoniae TIGR4
    * 1314-p=Streptococcus pyogenes 186103-p=Streptococcus pyogenes (serotype M18) 1902-p=Streptomyces coelicolor
    * 1148-p=Synechocystis sp. (strain PCC 6803) 119072-p=Thermoanaerobacter tengcongensis
    * 2336-p=Thermotoga maritima 160-p=Treponema pallidum 134821-p=Ureaplasma parvum 666-p=Vibrio cholerae
    * 92829-p=Xanthomonas axonopodis (pv. citri) 340-p=Xanthomonas campestris (pv. campestris)
    * 2371-p=Xylella fastidiosa 632-p=Yersinia pestis 56636-p=Aeropyrum pernix 2234-p=Archaeoglobus fulgidus
    * 64091-p=Halobacterium sp. (strain NRC-1) 145262-p=Methanobacterium thermoautotrophicum
    * 2190-p=Methanococcus jannaschii 2320-p=Methanopyrus kandleri 2214-p=Methanosarcina acetivorans
    * 192952-p=Methanosarcina mazei Goe1 13773-p=Pyrobaculum aerophilum 29292-p=Pyrococcus abyssi
    * 2261-p=Pyrococcus furiosus 53953-p=Pyrococcus horikoshii 2287-p=Sulfolobus solfataricus
    * 111955-p=Sulfolobus tokodaii 2303-p=Thermoplasma acidophilum 50339-p=Thermoplasma volcanium
    * , default=spens-p. */
   public String Database="spens-p"; // select
   /** default= */
   public String Email=""; // text
     /** Choices for program:
    * fasta3=fasta3 default fastx3=fastx3 fasty3=fasty3 fastf3=fastf3 fasts3=fasts3 , default=fasta3. */
   public String Program="fasta3"; // select
     /** Choices for gapopen:
    * -12=-12 default -18=-18 -16=-16 -14=-14 -10=-10 -8=-8 -6=-6 -4=-4 -2=-2 0=0 , default=-12. */
   public String Gapopen="-12"; // select
     /** Choices for gapext:
    * -2=-2 default 0=0 -4=-4 -6=-6 -8=-8 , default=-2. */
   public String Gapext="-2"; // select
     /** Choices for scores:
    * 10=10 20=20 30=30 40=40 50=50 default 60=60 70=70 80=80 90=90 100=100 , default=50. */
   public String Scores="50"; // select
     /** Choices for alignments:
    * 10=10 20=20 30=30 40=40 50=50 default 60=60 70=70 80=80 90=90 100=100 , default=50. */
   public String Alignments="50"; // select
     /** Choices for ktup:
    * 2=2 default 1=1 , default=2. */
   public String Ktup="2"; // select
     /** Choices for hist:
    * no=no default yes=yes , default=no. */
   public String Hist="no"; // select
     /** Choices for strand:
    * none=none default none=none , default=none. */
   public String Strand="none"; // select
     /** Choices for matrix:
    * BL50=BLOSUM50 default BL62=BLOSUM62 BL80=BLOSUM80 P120=PAM120 P250=PAM250 M10=MDM10
    * M20=MDM20 M40=MDM40 , default=BL50. */
   public String Matrix="BL50"; // select
     /** Choices for expupperlim:
    * 1e-600=1e-600 1e-300=1e-300 1e-100=1e-100 1e-50=1e-50 1e-10=1e-10 1e-5=1e-5 0.001=0.001
    * 0.1=0.1 1.0=1.0 2.0=2.0 5.0=5.0 10.0=10.0 default 20.0=20.0 50=50 , default=10.0. */
   public String Expupperlim="10.0"; // select
     /** Choices for explowlim:
    * default=default default 1e-600=1e-600 1e-300=1e-300 1e-100=1e-100 1e-50=1e-50 1e-10=1e-10
    * 1e-5=1e-5 0.001=0.001 0.1=0.1 1.0=1.0 2.0=2.0 5.0=5.0 10.0=10.0 20.0=20.0 50=50 , default=default. */
   public String Explowlim="default"; // select
   /** default=START-END */
   public String Seqrange="START-END"; // text
   /** default=START-END */
   public String Dbrange="START-END"; // text
   /** default=PROTEIN */
   public String Stype="PROTEIN"; // text
   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:url", "http://www.ebi.ac.uk/cgi-bin/fasta/genomes.pl"); // connect
    map.add("connect:action", "POST"); // connect
    map.add("connect:master", "http://www.ebi.ac.uk/fasta33/genomes.html"); // connect
    map.add("dbtype", request.Dbtype); // select
    map.add("database", request.Database); // select
    map.add("email", request.Email); // text
    map.add("title", ""); // text
    map.add("srchtype", "interactive"); // select
    map.add("program", request.Program); // select
    map.add("gapopen", request.Gapopen); // select
    map.add("gapext", request.Gapext); // select
    map.add("scores", request.Scores); // select
    map.add("alignments", request.Alignments); // select
    map.add("ktup", request.Ktup); // select
    map.add("hist", request.Hist); // select
    map.add("strand", request.Strand); // select
    map.add("matrix", request.Matrix); // select
    map.add("expupperlim", request.Expupperlim); // select
    map.add("explowlim", request.Explowlim); // select
    map.add("seqrange", request.Seqrange); // text
    map.add("dbrange", request.Dbrange); // text
    map.add("moltype", "default"); // select
    map.add("stype", request.Stype); // text
    map.add("sequence", request.Sequence); // textarea
    map.add("jobid", ""); // hidden
    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("Dbtype","CharSequence",null,"Protein",new String[] {"Protein","DNA"},new String[] {"Proteomes default","Genomes"}),
        new dField("Database","CharSequence","Organism","spens-p",new String[] {"3702-p","6239-p","7227-p","6035-p","55529-p","9606-p","spens-p","10090-p","10090.SPEns-p","4932-p","4896-p","181661-p","180835-p","103690-p","63363-p","86665-p","1423-p","139-p","29459-p","118099-p","197-p","155892-p","83560-p","115711-p","115713-p","138677-p","813-p","1488-p","1502-p","196627-p","1299-p","83333-p","155864-p","83334-p","76856-p","727-p","85962-p","85963-p","1360-p","1642-p","1639-p","1769-p","83332-p","83331-p","2097-p","2104-p","2107-p","65699-p","491-p","747-p","287-p","305-p","381-p","382-p","781-p","782-p","601-p","602-p","158878-p","158879-p","196620-p","171101-p","170187-p","1314-p","186103-p","1902-p","1148-p","119072-p","2336-p","160-p","134821-p","666-p","92829-p","340-p","2371-p","632-p","56636-p","2234-p","64091-p","145262-p","2190-p","2320-p","2214-p","192952-p","13773-p","29292-p","2261-p","53953-p","2287-p","111955-p","2303-p","50339-p"},new String[] {"Arabidopsis thaliana","Caenorhabditis elegans","Drosophila melanogaster","Encephalitozoon cuniculi","Guillardia theta","Homo sapiens","Homo Sapiens (SpTr+Ensembl)","Mus musculus (Mouse)","Mus musculus (SpTr+Ensembl)","Saccharomyces cerevisiae","Schizosaccharomyces pombe","Agrobacterium tumefaciens (strain C58 / ATCC 33970 (Cereon))","Agrobacterium tumefaciens (strain C58 / ATCC 33970 (Washington University))","Anabaena sp. (strain PCC 7120)","Aquifex aeolicus","Bacillus halodurans","Bacillus subtilis","Borrelia burgdorferi","Brucella melitensis","Buchnera aphidicola (subsp. Acyrthosiphon pisum)","Campylobacter jejuni","Caulobacter crescentus","Chlamydia muridarum","Chlamydia pneumoniae strain AR39","Chlamydia pneumoniae strain CWL029","Chlamydia pneumoniae strain J138","Chlamydia trachomatis","Clostridium acetobutylicum","Clostridium perfringens","Corynebacterium glutamicum ATCC 13032","Deinococcus radiodurans","Escherichia coli K-12","Escherichia coli O157:H7 strain EDL933","Escherichia coli O157:H7 substrain RIMD 0509952","Fusobacterium nucleatum (subsp. nucleatum)","Haemophilus influenzae","Helicobacter pylori strain 26695","Helicobacter pylori strain J99","Lactococcus lactis (subsp. lactis)","Listeria innocua","Listeria monocytogenes","Mycobacterium leprae","Mycobacterium tuberculosis","Mycobacterium tuberculosis CDC1551","Mycoplasma genitalium","Mycoplasma pneumoniae","Mycoplasma pulmonis","Neisseria meningitidis (serogroup A)","Neisseria meningitidis (serogroup B)","Pasteurella multocida","Pseudomonas aeruginosa","Ralstonia solanacearum (Pseudomonas solanacearum)","Rhizobium loti","Rhizobium meliloti (Sinorhizobium meliloti)","Rickettsia conorii","Rickettsia prowazekii","Salmonella typhi","Salmonella typhimurium LT2","Staphylococcus aureus (strain Mu50 / ATCC 700699)","Staphylococcus aureus (strain N315)","Staphylococcus aureus MW2","Streptococcus pneumoniae R6","Streptococcus pneumoniae TIGR4","Streptococcus pyogenes","Streptococcus pyogenes (serotype M18)","Streptomyces coelicolor","Synechocystis sp. (strain PCC 6803)","Thermoanaerobacter tengcongensis","Thermotoga maritima","Treponema pallidum","Ureaplasma parvum","Vibrio cholerae","Xanthomonas axonopodis (pv. citri)","Xanthomonas campestris (pv. campestris)","Xylella fastidiosa","Yersinia pestis","Aeropyrum pernix","Archaeoglobus fulgidus","Halobacterium sp. (strain NRC-1)","Methanobacterium thermoautotrophicum","Methanococcus jannaschii","Methanopyrus kandleri","Methanosarcina acetivorans","Methanosarcina mazei Goe1","Pyrobaculum aerophilum","Pyrococcus abyssi","Pyrococcus furiosus","Pyrococcus horikoshii","Sulfolobus solfataricus","Sulfolobus tokodaii","Thermoplasma acidophilum","Thermoplasma volcanium"}),
        new dField("Email","CharSequence",null,""),
        new dField("Program","CharSequence",null,"fasta3",new String[] {"fasta3","fastx3","fasty3","fastf3","fasts3"},new String[] {"fasta3 default","fastx3","fasty3","fastf3","fasts3"}),
        new dField("Gapopen","CharSequence",null,"-12",new String[] {"-12","-18","-16","-14","-10","-8","-6","-4","-2","0"},new String[] {"-12 default","-18","-16","-14","-10","-8","-6","-4","-2","0"}),
        new dField("Gapext","CharSequence",null,"-2",new String[] {"-2","0","-4","-6","-8"},new String[] {"-2 default","0","-4","-6","-8"}),
        new dField("Scores","CharSequence",null,"50",new String[] {"10","20","30","40","50","60","70","80","90","100"},new String[] {"10","20","30","40","50 default","60","70","80","90","100"}),
        new dField("Alignments","CharSequence",null,"50",new String[] {"10","20","30","40","50","60","70","80","90","100"},new String[] {"10","20","30","40","50 default","60","70","80","90","100"}),
        new dField("Ktup","CharSequence",null,"2",new String[] {"2","1"},new String[] {"2 default","1"}),
        new dField("Hist","CharSequence",null,"no",new String[] {"no","yes"},new String[] {"no default","yes"}),
        new dField("Strand","CharSequence",null,"none",new String[] {"none","none"},new String[] {"none default","none"}),
        new dField("Matrix","CharSequence",null,"BL50",new String[] {"BL50","BL62","BL80","P120","P250","M10","M20","M40"},new String[] {"BLOSUM50 default","BLOSUM62","BLOSUM80","PAM120","PAM250","MDM10","MDM20","MDM40"}),
        new dField("Expupperlim","CharSequence",null,"10.0",new String[] {"1e-600","1e-300","1e-100","1e-50","1e-10","1e-5","0.001","0.1","1.0","2.0","5.0","10.0","20.0","50"},new String[] {"1e-600","1e-300","1e-100","1e-50","1e-10","1e-5","0.001","0.1","1.0","2.0","5.0","10.0 default","20.0","50"}),
        new dField("Explowlim","CharSequence",null,"default",new String[] {"default","1e-600","1e-300","1e-100","1e-50","1e-10","1e-5","0.001","0.1","1.0","2.0","5.0","10.0","20.0","50"},new String[] {"default default","1e-600","1e-300","1e-100","1e-50","1e-10","1e-5","0.001","0.1","1.0","2.0","5.0","10.0","20.0","50"}),
        new dField("Seqrange","CharSequence",null,"START-END"),
        new dField("Dbrange","CharSequence",null,"START-END"),
        new dField("Stype","CharSequence",null,"PROTEIN"),
        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 {
        /** Link */
        public String url;
        public CharSequence header;
        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 r.header;
              default: return "<tr><td>"+r.header+"</td><td><a href=\""+r.url+"\">"+r.E+"</a></td></tr>";
            }
          };

      /** Get BLAST report. Use generalizer for the first level. */
      public String getReport(Object[] x, int verbosityLevel)
       {
         boolean singleLine = x.length<=1;
         StringBuffer b = new StringBuffer();
         if (verbosityLevel>=1)
          { b.append(getAgentSignature());
            b.append(": ");
          };

         if (verbosityLevel==0)
          {
           Sight.util.Generalizer g = new Sight.util.Generalizer();
           g.setIgnore("aa");
           Record r;
           for (int i = 0; i < x.length; i++) {
             r = (Record) x[i];
             try {
              g.add(r.header.toString(), Double.parseDouble(r.E.toString().trim()));
             } catch (Exception exc)
               {
                g.add(r.header.toString(), -1);
               };
           }
           return g.toString();
          }
          else
          {
           b.append(Sight.Agents.Variants.sBlaster.defaultTableHeader);
           b.append("<tr><td>Header</td><td>E</td></tr>");
           for (int i = 0; i < x.length; i++) {
             b.append(getReportForRecord(x[i], verbosityLevel));
             if ( (i>=5 && verbosityLevel==1) || i>=21)
              {
                b.append("<tr><td colspan=\"2\">(truncated, "+x.length+" hits in total)<td></tr>");
                break;
              };
           }
           b.append("</table>");
          };
         return  b.toString();
       };
      }

    /** Type definitions for Result. */
   public dStructure getResultDds() {
    return new Sight.dds.Records(true,
     new dField[] {
        new dField("url","String","Link",""),
        new dField("header","CharSequence",null,""),
        new dField("E","CharSequence",null,"")                 }
    );
   }

  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.url=getURL(fields[0]);
        r.header=noHtml(fields[1]);
        r.E=fields[2];
        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 Ebi_fasta() { signatures = new multiSignatures();
   signatures.far_start=null;
   signatures.top=null;
   signatures.bottom=null;
   signatures.signatures =
   new Signature[] {
   new Signature(">>SWALL:<a href=","</a"),
   new Signature(">","\n"),
   new Signature("E():","Smith")
   };
   setDescription("Proteomes and Genomes Fasta");
   setFormURL("http://www.ebi.ac.uk/cgi-bin/fasta/genomes.pl");
   setMasterURL("http://www.ebi.ac.uk/fasta33/genomes.html");
   // define pre scan section.
   preScan = new preScan();
   preScan.zeroCases = new String[] { "!! No library sequences" };
   };
  /** Public instance of agent for user. */
  public static Ebi_fasta Public = new Ebi_fasta();
  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();
         };
   }
;
  }