/**
 *  NCBI electronic PCR
 *  Internet robot, E_PCR, that uses form, located in page
 *  http://www.ncbi.nlm.nih.gov/genome/sts/epcr.cgi.
 *  It is your responsibility to find and cite appropriate references
 *  from this page.
 *  Generated 2002.5.7  by Sight 2.0, Ulm university.
 */
package impl.dna_analysers;

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

public class E_PCR 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 {
   public String Ntseq; // required.
     /** Choices for STS_SET:
    * unists=all markers non_warn=non-repetitive markers default , default=non_warn. */
   public String Sts_set="non_warn"; // select
     /** Choices for W:
    * 3=3 4=4 5=5 6=6 7=7 default 8=8 , default=7. */
   public String W="7"; // select
     /** Choices for M:
    * 0=0 10=10 default 50=50 100=100 500=500 1000=1000 5000=5000 , default=10. */
   public String M="10"; // select
     /** Choices for N:
    * 0=0 1=1 default 2=2 3=3 , default=1. */
   public String N="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:master", "http://www.ncbi.nlm.nih.gov/genome/sts/epcr.cgi"); // connect
    map.add("connect:url", "http://www.ncbi.nlm.nih.gov/genome/sts/epcr.cgi"); // connect
    map.add("connect:action", "Post"); // connect
    map.add("NTSEQ", request.Ntseq); // textarea
    map.add("STS_SET", request.Sts_set); // select
    map.add("W", request.W); // select
    map.add("M", request.M); // select
    map.add("N", request.N); // select
    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://www.ncbi.nlm.nih.gov/genome/sts/epcr.cgi.*/
  public String getFormURL() {
     return "http://www.ncbi.nlm.nih.gov/genome/sts/epcr.cgi"; }

  /** URL to refer. http://www.ncbi.nlm.nih.gov/genome/sts/epcr.cgi.*/
  public String getMasterURL() {
     return "http://www.ncbi.nlm.nih.gov/genome/sts/epcr.cgi"; }

    /** Type definitions for Request. */
   public dStructure getRequestDds() {
    return new Sight.dds.Records(false,
     new dField[] {
        new dField("Ntseq","CharSequence","DNA/RNA sequence or NCBI accession number",""),
        new dField("Sts_set","CharSequence","Return repetetive markers or not","non_warn",new String[] {"unists","non_warn"},new String[] {"all markers","non-repetitive markers default"}),
        new dField("W","CharSequence","Required match area","7",new String[] {"3","4","5","6","7","8"},new String[] {"3","4","5","6","7 default","8"}),
        new dField("M","CharSequence","An e-PCR product size to be within M bases margin of the previously reported PCR product size. ","10",new String[] {"0","10","50","100","500","1000","5000"},new String[] {"0","10 default","50","100","500","1000","5000"}),
        new dField("N","CharSequence","Allowed mismatches, but not in the word size area.","1",new String[] {"0","1","2","3"},new String[] {"0","1 default","2","3"})                 }
    );
   }
 /* 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 {
        /** region */
        public s_feature region;
        public CharSequence marker;
        public CharSequence marker_url;
        public CharSequence chromosome;
        /** organism */
        public CharSequence organism;
      };
      /** 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.marker_url+"\">"+r.marker+"</a>" +r.chromosome+" ";
              case 1:  return ""+r.region+" "+" <a href=\""+r.marker_url+"\">"+r.marker+"</a>" +r.chromosome+" ";
              default: return ""+" region:" +r.region+" "+" :" +" <a href=\""+r.marker_url+"\">"+r.marker+"</a> "+" :" +r.chromosome+" "+" organism:" +r.organism+" ";
            }
          };
      }

    /** Type definitions for Result. */
   public dStructure getResultDds() {
    return new Sight.dds.Records(true,
     new dField[] {
        new dField("region",null,"region",""),
        new dField("marker",null,null,""),
        new dField("marker url","URL","marker url ",""),
        new dField("chromosome",null,null,""),
        new dField("organism",null,"organism","")                 }
    );
   }

  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.region=new s_feature(fields[0]);
        r.marker=noHtml(fields[1]);
        r.marker_url=getURL(fields[1]);
        r.chromosome=fields[2];
        r.organism=fields[3];
        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 E_PCR() { ignoreFirstLine=true;
   ignoreLastLine =false;
   table_position ="2.3";
   setDescription("NCBI electronic PCR");
   };
  /** Public instance of agent for user. */
  public static E_PCR Public = new E_PCR();
  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. Ntseq="AC018608";
        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();
         };
   }
;
  }