package impl.manipulators;
import Sight.Agents.*;
import Sight.dds.*;
import java.io.*;
import java.util.*;
import Sight.Agents.util.*;
public class translator extends Sight.Agents.Prototypes.Wrapper implements Serializable {
public class Request extends Sight.Request implements java.io.Serializable {
public CharSequence rna_sequence;
public CharSequence Frame;
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); };
};
public static Request getDefaultRequest() {
return Public.getRequest(); }
private Request getRequest() { return new Request(); };
public dStructure getRequestDds() {
return new Sight.dds.Records(true,
new dField[] {
new dField("Frame","CharSequence","Frame to translate","0",
new String[] {"First","all 3 on plus strand","++"},
new String[] {"0","++","+-"}
),
new dField("rna_sequence","CharSequence","RNA sequence to translate","")
});
};
public static class Record extends Sight.Record implements Serializable {
public CharSequence protein_Sequence;
public CharSequence Frame;
};
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.protein_Sequence.length()+" aa, "+r.Frame;
default: return r.protein_Sequence.length()+" aa, "+r.Frame+
"<br><textarea>"+r.protein_Sequence+"</textarea>";
}
};
}
public dStructure getResultDds() {
return new Sight.dds.Records(false,
new dField[] {
new dField("protein_Sequence","CharSequence","Translated protein sequence",""),
new dField("Frame","CharSequence","Frame of the translated protein sequence","") }
);
}
private Record translate(String seq, String hdr)
{
Record r = new Record();
r.protein_Sequence = translator.translate(seq);
r.Frame = hdr;
return r;
};
Sight.util.Translator translator = new Sight.util.Translator();
public Object go(Object o_request) throws Exception
{
Request request = (Request) o_request;
Result result = new Result();
ArrayList list = new ArrayList();
String seq = request.rna_sequence.toString();
if (request.Frame.equals("0"))
{
list.add(translate(seq,"0"));
} else
if (request.Frame.equals("++"))
{
list.add(translate(seq,"+.0"));
list.add(translate(seq.substring(1),"+.1"));
list.add(translate(seq.substring(2),"+.2"));
} else
if (request.Frame.equals("+-"))
{
list.add(translate(seq,"+.0"));
list.add(translate(seq.substring(1),"+.1"));
list.add(translate(seq.substring(2),"+.2"));
seq = Sight.util.na.reverse_complement(seq);
list.add(translate(seq,"-.0"));
list.add(translate(seq.substring(1),"-.1"));
list.add(translate(seq.substring(2),"-.2"));
};
result.a = new Record[list.size()];
for (int i = 0; i < result.a.length; i++) {
result.a[i] = (Record) list.get(i);
}
result.setAgentSignature("Translate "+request.Frame);
return result;
};
public translator() {
setDescription("Translate rna sequence into protein, using standard (human) genetic code.");
setMasterURL("");
setWriteCache(false);
setReadCache(false);
};
public static translator Public = new translator();
public static Agent getAvailableAgent() { return Public; };
public static void main(String[] args) {
Sight.Agents.util.Pind.showConsoles();
try {
Request request = getDefaultRequest();
request.Frame = "+-";
request.rna_sequence="GGTGACAACGTTTGGAAGGGCCAGGGCGACCGGCAGTGTG";
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();
};
}
;
}