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 blast_human_ensembl extends Sight.Agents.Prototypes.preformattedResponseAgent implements Serializable {
public class Request extends Sight.Request implements java.io.Serializable {
public String Sequence;
public String Database="'Homo_sapiens.latestgp.fa'";
public String Blast_type="wutblastn";
public String Repeatmasker="T";
public String Filtering="T";
public String Matrix="BLOSUM62";
public String Expect="10";
public String Descriptions="100";
public String Sort="-sort_by_pvalue";
public String Filtertype="seg";
public String Gencode="1";
public String Altoptions="";
public Sight.Agents.Request submit() { return Sight.Agents.Request.submit(Public, this, getKey()); };
public Sight.Agents.Request submit(String key)
{ return Sight.Agents.Request.submit(Public, this, key); };
};
protected AMap getFormParameters(Object req) {
Request request = (Request) req;
if ( (request.Matrix.startsWith("BLOSUM") || request.Matrix.startsWith("PAM"))
&& request.Blast_type.equals("wutblastn"))
request.Matrix = "DNA_MAT";
AMap map = new AMap();
map.add("connect:url", "http://www.ensembl.org/Homo_sapiens/blastview"); map.add("connect:action", "POST"); map.add("connect:master", "http://www.ensembl.org/Homo_sapiens/blastview"); map.add("sequence", request.Sequence); map.add("type", "blast"); map.add("format", "karyo_format"); map.add("database", request.Database); map.add("blast_type", request.Blast_type); map.add("align", request.Descriptions); map.add("repeatmasker", request.Repeatmasker); map.add("filtering", request.Filtering); map.add("histogram", "F"); map.add("matrix", request.Matrix); map.add("expect", request.Expect); map.add("descriptions", request.Descriptions); map.add("statistics", "-sump"); map.add("sort", request.Sort); map.add("filtertype", request.Filtertype); map.add("gencode", request.Gencode); map.add("altoptions", request.Altoptions); return map; };
public static Request getDefaultRequest() {
return Public.getRequest(); }
private Request getRequest() { return new Request(); };
public dStructure getRequestDds() {
return new Sight.dds.Records(false,
new dField[] {
new dField("Sequence","CharSequence","Sequence to search",""),
new dField("Database","CharSequence","Database","\'Homo_sapiens.latestgp.fa\'",new String[] {"\'Homo_sapiens.cdna.genscan.fa\'","\'Homo_sapiens.cdna.fa\'","\'Homo_sapiens.cdna.known.fa\'","\'Homo_sapiens.cdna.novel.fa\'","\'Homo_sapiens.latestgp.fa\'","\'Homo_sapiens.latestgp.masked.fa\'","\'Homo_sapiens.pep.genscan.fa\'","\'Homo_sapiens.pep.fa\'","\'Homo_sapiens.pep.known.fa\'","\'Homo_sapiens.pep.novel.fa\'"},new String[] {"Homo sapiens, cDNA (genscan)","Homo sapiens, cDNA (known + novel)","Homo sapiens, cDNA (known only)","Homo sapiens, cDNA (novel only)","Homo sapiens, genomic sequence default","Homo sapiens, genomic sequence (masked)","Homo sapiens, peptides (genscan)","Homo sapiens, peptides (known + novel)","Homo sapiens, peptides (known only)","Homo sapiens, peptides (novel only)"}),
new dField("Blast_type","CharSequence","blast type","wutblastn",new String[] {"wublastn","wutblastn","wutblastx"},new String[] {"BLASTN (DNA vs.DNA)","TBLASTN (protein vs. transl. DNA) default","TBLASTX (transl. DNA vs. transl DNA)"}),
new dField("Align","CharSequence",null,"0"),
new dField("Repeatmasker","CharSequence","Mask repeats","T"),
new dField("Filtering","CharSequence","Filter","T"),
new dField("Matrix","CharSequence","Matrix","DNA_MAT",new String[] {"BLOSUM30","BLOSUM40","BLOSUM50","BLOSUM60","BLOSUM62","BLOSUM70","BLOSUM80","BLOSUM90","BLOSUM100","DAYHOFF","DNA_MAT","GONNET","IDENTITY","PAM30","PAM60","PAM90","PAM120","PAM150","PAM180","PAM210","PAM240"},new String[] {"blosum30","blosum40","blosum50","blosum60","blosum62 default","blosum70","blosum80","blosum90","blosum100","dayhoff","dna_mat","gonnet","identity","pam30","pam60","pam90","pam120","pam150","pam180","pam210","pam240"}),
new dField("Expect","CharSequence","E value","10",new String[] {"0.0001","0.01","1","10","100","1000"},new String[] {"0.0001","0.01","1","10 default","100","1000"}),
new dField("Descriptions","CharSequence","Descriptions","100",new String[] {"10","50","100","250","500"},new String[] {"10","50","100 default","250","500"}),
new dField("Sort","CharSequence",null,"-sort_by_pvalue",new String[] {"-sort_by_pvalue","-sort_by_count","-sort_by_highscore","-sort_by_totalscore"},new String[] {"pvalue default","count","highscore","totalscore"}),
new dField("Filtertype","CharSequence","Filter type","seg",new String[] {"seg","xnu","seg+xnu"},new String[] {"seg default","xnu","seg+xnu"}),
new dField("Gencode","CharSequence","Genetic code (blastx only)","1",new String[] {"1","2","3","4","5","6","9","11","12","13","14"},new String[] {"Standard default","Vertebrate Mitochondrial","Yeast Mitochondrial","Mold Mitochondrial","Invertebrate Mitochondrial","Ciliate Nuclear","Echinoderm Mitochondrial","Eubacterial","Alternative Yeast Nuclear","Ascidian Mitochondrial","Flatworm Mitochondrial"}),
new dField("Altoptions","CharSequence","Advanced options","") }
);
}
public static class Record extends Sight.Record implements Serializable {
public CharSequence chromosome;
public CharSequence accession;
public CharSequence accession_long;
public CharSequence length;
public CharSequence E;
public CharSequence N;
};
public static class Result extends Sight.Result implements Serializable {
public Record[] a;
public CharSequence getReportForRecord(Object ro, int level)
{ Record r = (Record) ro;
switch (level) {
case 0: return " chr"+r.chromosome+" "+r.accession+" ("+r.E+") ";
default: return "<tr><td>"+r.chromosome+"</td><td>"+r.accession_long+"</td><td>"+r.E+"</td></tr>";
}
};
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)
{
Record r;
for (int i = 0; i < x.length; i++) {
b.append(getReportForRecord(x[i], 0));
b.append(", ");
if (i>12)
{
b.append(" ... ("+x.length+" hits)");
break;
};
};
}
else
{
b.append(Sight.Agents.Variants.sBlaster.defaultTableHeader);
b.append("<tr><td>Chr</td><td>accession</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=\"3\">(truncated, "+x.length+" hits in total)<td></tr>");
break;
};
}
b.append("</table>");
};
return b.toString();
};
}
public dStructure getResultDds() {
return new Sight.dds.Records(true,
new dField[] {
new dField("chromosome","CharSequence",null,""),
new dField("accession","CharSequence","NCBI compatible accession",""),
new dField("accession_long","CharSequence","accession number like NCBI but with longer suffix",""),
new dField("length","CharSequence",null,""),
new dField("E","CharSequence",null,""),
new dField("N","CharSequence","N","number of hits?") }
);
}
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.chromosome=fields[0];
r.accession_long=noHtml(fields[2]);
String ac = r.accession_long.toString();
int a = ac.indexOf('.');
if (a>=0) r.accession = ac.substring(0,a);
else r.accession = ac;
r.length=fields[3];
r.E=fields[4];
r.N=fields[5];
return r;
};
public Sight.Result resultFromString(String html) throws Exception {
Result r = new Result();
r.a = (Record[]) createResultArray(html);
return r;
};
multiSignatures bQsignatures;
public blast_human_ensembl() {
signatures = new Sight.tools.xPlain.multiSignatures();
signatures.far_start=null;
signatures.top="Sequences producing significant alignments: Score P(N) N";
signatures.bottom=" </center> </pre>";
signatures.Columns = 6;
bQsignatures = new multiSignatures();
bQsignatures.far_start=null;
bQsignatures.top="BLAST RETRIEVAL ID";
bQsignatures.bottom="</table>";
bQsignatures.signatures =
new Signature[] {
new Signature(" <td align=\"center\"><a href=\"","\"")
};
setDescription("Ensebl human blast");
setFormURL("http://www.ensembl.org/Homo_sapiens/blastview");
setMasterURL("http://www.ensembl.org/Homo_sapiens/blastview");
preScan = new preScan();
addRedirector(new Ensembl_BLAST_Redirector());
};
public static blast_human_ensembl Public = new blast_human_ensembl();
public static Agent getAvailableAgent() { return Public; };
public static void main(String[] args) {
Sight.Agents.util.Pind.showConsoles();
try {
Request request = getDefaultRequest();
request. Sequence="GTTATTGCAATACATACAAAAAAGTTAAAGATTTTATGTATCACTAACATTAGAAGTTTTTTGCACCACTAATTTTTTAAAAATGGAAGGTAAACTGCATAGCCCAGAGAAAGATAAGTAAATATTTAAGAACATATTGAACAACTTTGCTATTTAAAGATATTATCCAAGTACATAAATTACTCCGTTCTCTATCAGTTAAAGCTATTGAATATAATACTTAGCTTTACAAGAGAAAACCCATATTTGATGGGCAGAGATTATATCCCTATCTTCTTTTTCATGTAAACCACTGGTCACAAATGAACTGATCTCTGTATCCCATTATTACTATAAGAGGTGGGAATCCCAAAACTGCTTAGATTGCAGTACATGAGTTTACACAAAGACTTCAACAATTGCACATCTTCATTCTCCCAACTGAGTGTAGTATGTGGAGCATAAAACAGCATATTCTTAGTATTTCATGAATATCAGATGGTCTTTAAATGTCTCTTTATGGATGTATTGTTCACATTATGGCTTTAAAATAATGAATATGTAAAAGTGAGGTAGTGAACATCCTAAATTTCTACACTGGAATTACTAAATAATCTTATTTCATAAAATGGGAAATATATGTTAAATGACATCACTGGATGAACTTGAAGATCTTTTACTTGTTAACAAAAAAATACTATGGACAGCTTTCTGATTGTTGGGGTAAATAG";
Sight.Agents.Request submission = request.submit();
Result response = (Result) submission.getResult();
System.out.println(response.getReport(2));
} catch (Exception exc)
{ if (exc!=null) System.out.println(exc.getMessage());
exc.printStackTrace();
};
};
public class Ensembl_BLAST_Redirector extends preScan implements RedirectionProvider, Cloneable
{
String rid = null;
int rtoe = 10;
public Redirection getRedirection(String text) throws SpecialStateException
{
if (text.indexOf("query has been added to the queue")>=0)
{ try {
String [][] ids = bQsignatures.getIds(text);
if (ids!=null)
if (ids.length!=0)
rid = ids[0][0];
if (rid!=null)
{ p("Rid "+rid+" expected time "+rtoe);
return new Redirection(
rid, rtoe, "Initiation"+rid);
};
} catch (Exception exc)
{
exc.printStackTrace();
};
} else
if (text.indexOf("RESULTS NOT READY")>=0)
{ if (rid==null)
{ p("Rid lost!!!!");
return null;
} else
{ rtoe = rtoe + 20; return new Redirection(
rid, rtoe, "still not ready "+rid);
}
};
rid = null; rtoe = 120;
return null;
};
protected void finalize() throws java.lang.Throwable {
if (rid!=null)
{ super.finalize();
};
}
public RedirectionProvider getCopy()
{ try {
return (RedirectionProvider) (this.clone());
} catch (CloneNotSupportedException exc)
{
throw new Error("This should never happen.");
}
}
}
}