package impl.sequence_readers;
import Sight.Agents.*;
import Sight.Agents.Signals.*;
import Sight.Structures.*;
import Sight.dds.*;
import java.io.*;
import Sight.Agents.util.*;
public class fastaReaderNCBI extends Sight.Agents.Prototypes.sightGeneratedAgent implements Serializable {
public class Request extends Sight.Request implements java.io.Serializable {
public String Id="XP_134428";
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();
map.add("url:identifier", request.Id); 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?txt=on&view=fasta&val="); map.add("url:suffix", ""); return map; };
public static Request getDefaultRequest() {
return Public.getRequest(); }
private Request getRequest() { return new Request(); };
public String getFormURL() {
return ""; }
public String getMasterURL() {
return "http://www.ncbi.nlm.nih.gov/entrez/"; }
public dStructure getRequestDds() {
return new Sight.dds.Records(false,
new dField[] {
new dField("Id","CharSequence",null,"XP_134428") }
);
}
public static class Record extends Sight.Record implements Serializable {
public CharSequence Header;
public CharSequence Sequence;
};
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 ""+r.Header+" ";
case 1: return ""+r.Header+" ";
default: return r.Header+"<br><textarea rows=\"3\" cols=\"80\">"+
r.Sequence+"</textarea>";
}
};
}
public dStructure getResultDds() {
return new Sight.dds.Records(true,
new dField[] {
new dField("Header","CharSequence",null,""),
new dField("Sequence","CharSequence",null,"") }
);
}
public Sight.Result resultFromString(String html) throws Exception {
try {
Result r = new Result();
int a = html.indexOf(">");
int b = html.indexOf("\n");
if (html.indexOf(">",b)>=0)
throw new FatalAgentException("Multiple entries not supported.");
Record R = new Record();
R.Header = html.substring(a,b).trim();
R.Sequence = getPlainSequence(html.substring(b+1));
r.a = new Record[1];
r.a[0] = R;
return r;
} catch (ArrayIndexOutOfBoundsException exc)
{ throw new FatalAgentException("Not a FASTA format."); }
};
public Class getRecordClass() { return Record.class; };
public fastaReaderNCBI() {
setDescription("Reads sequence and fasta header from NCBI database using given accession number");
};
public static fastaReaderNCBI Public = new fastaReaderNCBI();
public static Agent getAvailableAgent() { return Public; };
public static void main(String[] args) {
Sight.Agents.util.Pind.showConsoles();
try {
Request request = getDefaultRequest();
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();
};
}
;
}