1 package jalview.ws.jws2;
3 import jalview.api.AlignCalcWorkerI;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.Annotation;
6 import jalview.gui.AlignFrame;
7 import jalview.ws.jws2.jabaws2.Jws2Instance;
8 import jalview.ws.params.WsParamSetI;
10 import java.util.ArrayList;
11 import java.util.Iterator;
12 import java.util.List;
14 import java.util.TreeMap;
15 import java.util.TreeSet;
17 import compbio.data.msa.jaxws.Align;
18 import compbio.data.sequence.Range;
19 import compbio.data.sequence.Score;
20 import compbio.data.sequence.RNAStructScoreManager;
21 import compbio.data.sequence.ScoreManager;
22 import compbio.metadata.Argument;
24 public class RNAalifoldClient extends JabawsAlignCalcWorker implements
32 public RNAalifoldClient(Jws2Instance sh, AlignFrame alignFrame,
33 WsParamSetI preset, List<Argument> paramset)
35 super(sh, alignFrame, preset, paramset);
40 methodName = sh.serviceType;
45 public String getServiceActionText()
47 return "Submitting RNA alignment for Secondary Structure prediction using"
48 + "RNAalifold Service";
52 public void updateResultAnnotation(boolean immediate)
55 if (immediate || !calcMan.isWorking(this) && scoremanager != null)
60 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
61 // ourAnnots = new ArrayList<AlignmentAnnotation>();
63 // So I don't have to do any more casting
64 List<String> structs = ((RNAStructScoreManager) scoremanager).getStructs();
65 List<TreeSet<Score>> data = ((RNAStructScoreManager) scoremanager).getData();
67 // Deal with the consensus structure and (?)BasePair Probabilities
68 Annotation[] anns = new Annotation[structs.get(1).length()];
70 // check if the first Score object is populated with base pair probabilities
71 Score fscore = data.get(0).first();
72 boolean BPScores = (fscore.getScores().size() > 0
73 && fscore.getRanges() != null);
75 TreeMap<Range, Float> basePairs = null;
77 // The base pair probabilities are stored in a set in scoremanager... we want a map
78 basePairs = new TreeMap<Range, Float>();
79 for (Score score : data.get(0)) {
80 // The Score objects contain a set of size one containing the range and
81 // an ArrayList<float> of size one containing the probabilty
82 basePairs.put(score.getRanges().first(), new Float(score.getScores().get(0)));
86 // ignoring the Consensus alignemnt for now, get the Structure and make an AlignmentAnnotation
87 String struct = structs.get(1);
88 for (int i = 0; i < struct.length(); i++) {
91 // Return all the contacts associated with position i
92 List<Range> contacts = isContact(basePairs, i+1);
94 if (contacts.size() == 0) {
95 anns[i] = new Annotation(struct.substring(i, i+1), "", struct.charAt(i), 0f);
97 else if (contacts.size() == 1) {
98 // There is only one contact associated with this base
99 float prob = basePairs.get(contacts.get(i));
100 anns[i] = new Annotation(struct.substring(i, i+1), "", struct.charAt(i), prob);
102 else if (contacts.size() > 1) {
103 // For now we will simply deal with alternate contact information by mentioning its
104 // existance in the description
105 float prob = basePairs.get(contacts.get(i));
106 anns[i] = new Annotation(struct.substring(i, i+1), "This base has alternate contact(s)",
107 struct.charAt(i), prob);
111 // Same as the first if from the previous block
112 anns[i] = new Annotation(struct.substring(i, i+1), "", struct.charAt(i), 0f);
116 AlignmentAnnotation annot = new AlignmentAnnotation("Consensus Structure", "Free Energy", anns);
117 annot.setScore(data.get(1).first().getScores().get(0));
119 if (ourAnnot.size() > 0) {
120 updateOurAnnots(ourAnnot);
126 // Check whether, at position i there is a base contact and return all the
127 // contacts at this position. Should be in order of descending probability.
128 private List<Range> isContact(TreeMap<Range, Float> basePairs, int i) {
130 List<Range> contacts = new ArrayList<Range>();
132 for (Range contact : basePairs.keySet()) {
133 // finds the contacts associtated with position i ordered by the natural
134 // ordering of the Scores TreeSet in ScoreManager which is, descending probability
135 if (contact.from == i || contact.to == i) contacts.add(contact);