package impl.rna_analysers;
import Sight.Agents.*;
import Sight.Agents.Redirectors.*;
import Sight.Structures.*;
import Sight.dds.*;
import java.io.*;
import org.w3c.dom.*;
public class EST_reader extends Sight.Agents.Prototypes.xml_based_agent implements Serializable {
public class Request extends Sight.Request implements java.io.Serializable {
public String Id="22519907";
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;
AMap map = new AMap();
String Gi = request.Id.toLowerCase();
if (Gi.indexOf("|")>=0)
{
String left = "gi|";
int a = Gi.indexOf(left);
if (a<0) { Sight.io.Output.e("EST_reader: "+"Invalid gi: "+Gi); return null; }
a = a+left.length();
int b = Gi.indexOf("|",a);
if (b<0) { Sight.io.Output.e("EST_reader: "+"Invalid gi: "+Gi); return null; }
Gi = Gi.substring(a,b);
};
map.add("url:identifier", Gi); map.add("connect:master", "http://www.ncbi.nlm.nih.gov/entrez/"); map.add("connect:action", "get"); map.add("url:prefix", "http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?view=xml&txt=on&val="); map.add("url:suffix", ""); 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("Id","CharSequence",null,"22519907") }
);
}
public static class Record extends Sight.Record implements Serializable {
public CharSequence Id;
public CharSequence Header;
public CharSequence Tissue;
public CharSequence Sequence;
public CharSequence Cell;
};
public static class Result extends Sight.Result implements Serializable {
public Record[] a;
public CharSequence getReportForRecord(Object ro, int level)
{ Record r = (Record) ro;
StringBuffer b = new StringBuffer();
if (r.Id!=null)
{ b.append(r.Id);
};
if (r.Tissue!=null)
{
b.append(' ');
b.append(r.Tissue);
};
if (r.Cell!=null)
{
b.append(' ');
b.append(r.Cell);
};
if (level>=1 && r.Header!=null)
{ b.append(' ');
b.append(r.Header);
};
if (level>=2 && r.Sequence!=null)
{
b.append("<textarea>");
b.append(r.Sequence);
b.append("</textarea>");
};
return b;
};
}
public dStructure getResultDds() {
return new Sight.dds.Records(true,
new dField[] {
new dField("Id","CharSequence",null,""),
new dField("Header","CharSequence",null,""),
new dField("Tissue","CharSequence",null,""),
new dField("Sequence","CharSequence",null,""),
new dField("Cell","CharSequence",null,"") }
);
}
public Sight.Record createRecord(Node xml)
{
Record r = new Record();
r. Id = getXMLField("Id", xml);
r. Header = getXMLField("Header", xml);
r. Tissue = getXMLField("Tissue", xml);
r. Sequence = getXMLField("Sequence", xml);
r. Cell = getXMLField("Cell", xml);
return r;
};
public static void main(String[] args) {
try {
Request request = getDefaultRequest();
Sight.Agents.Request submission = request.submit();
Result response = (Result) submission.getResult();
try {
String html = EST_reader .getAvailableAgent().getReport(response, 2);
System.out.println("Report: "+html);
}
catch (java.lang.UnsupportedOperationException ui)
{ System.out.println(ui.getMessage()); };
} catch (Exception exc)
{ if (exc!=null) System.out.println(exc.getMessage());
exc.printStackTrace();
};
}
public EST_reader() {
setDescription("Reads NCBI EST records.");
setFormURL("http://www.ncbi.nlm.nih.gov/entrez/");
setMasterURL("http://www.ncbi.nlm.nih.gov/entrez/");
preScan = new preScan();
cn_maxConnectionLength = 80000000; }
public static EST_reader Public = new EST_reader();
public static Agent getAvailableAgent() { return Public; };
public Class getRecordClass() { return Record.class; };
public Sight.Result resultFromDocument(Document node) throws Exception {
Result r = new Result();
r.a = (Record[]) createResultArray(node);
return r;
};
public String getXSLT() {
return getXMLFromSelf("Sight:xml-xsl-insert-1");
};
}