Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.javascript

File MouseOverStructureListener.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

28
68
10
1
315
194
27
0.4
6.8
10
2.7

Classes

Class Line # Actions
MouseOverStructureListener 73 68 27 106
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.javascript;
22   
23    import jalview.api.AlignmentViewPanel;
24    import jalview.api.FeatureRenderer;
25    import jalview.api.SequenceRenderer;
26    import jalview.appletgui.AlignFrame;
27    import jalview.bin.JalviewLite;
28    import jalview.datamodel.SequenceI;
29    import jalview.ext.jmol.JmolCommands;
30    import jalview.structure.AtomSpec;
31    import jalview.structure.StructureListener;
32    import jalview.structure.StructureMapping;
33    import jalview.structure.StructureMappingcommandSet;
34    import jalview.structure.StructureSelectionManager;
35    import jalview.util.HttpUtils;
36   
37    import java.util.ArrayList;
38    import java.util.List;
39   
40    /**
41    * Propagate events involving PDB structures associated with sequences to a
42    * javascript function. Generally, the javascript handler is called with a
43    * series of arguments like (eventname, ... ). As of Jalview 2.7, the following
44    * different types of events are supported:
45    * <ul>
46    * <li>mouseover: javascript function called with arguments
47    *
48    * <pre>
49    * ['mouseover',String(pdb file URI), String(pdb file chain ID), String(residue
50    * number moused over), String(atom index corresponding to residue)]
51    * </pre>
52    *
53    * </li>
54    * <li>colourstruct: javascript function called with arguments
55    *
56    * <pre>
57    * ['colourstruct',String(alignment view id),String(number of javascript message
58    * chunks to collect),String(length of first chunk in set of messages - or zero
59    * for null message)]
60    * </pre>
61    *
62    * <br>
63    * The message contains a series of Jmol script commands that will colour
64    * structures according to their associated sequences in the current view. Use
65    * jalview
66    * .javascript.JalviewLiteJsApi.getJsMessage('colourstruct',String(alignment
67    * view id)) to retrieve successive chunks of the message.</li>
68    * </ul>
69    *
70    * @author Jim Procter (jprocter)
71    *
72    */
 
73    public class MouseOverStructureListener extends JSFunctionExec
74    implements JsCallBack, StructureListener
75    {
76   
77    String _listenerfn;
78   
79    String[] modelSet;
80   
 
81  0 toggle public MouseOverStructureListener(JalviewLite jalviewLite,
82    String listener, String[] modelList)
83    {
84  0 super(jalviewLite);
85  0 _listenerfn = listener;
86  0 modelSet = modelList;
87  0 if (modelSet != null)
88    {
89  0 for (int i = 0; i < modelSet.length; i++)
90    {
91  0 modelSet[i] = resolveModelFile(modelSet[i]);
92    }
93    }
94    }
95   
96    /**
97    * Returns the first out of: file, file prefixed by document base, or file
98    * prefixed by codebase which can be resolved to a valid URL. If none can,
99    * returns the input parameter value.
100    *
101    * @param file
102    */
 
103  0 toggle public String resolveModelFile(String file)
104    {
105    // TODO reuse JalviewLite.LoadingThread.addProtocol instead
106  0 if (HttpUtils.isValidUrl(file))
107    {
108  0 return file;
109    }
110   
111  0 String db = jvlite.getDocumentBase().toString();
112  0 db = db.substring(0, db.lastIndexOf("/"));
113  0 String docBaseFile = db + "/" + file;
114  0 if (HttpUtils.isValidUrl(docBaseFile))
115    {
116  0 return docBaseFile;
117    }
118   
119  0 String cb = jvlite.getCodeBase() + file;
120  0 if (HttpUtils.isValidUrl(cb))
121    {
122  0 return cb;
123    }
124   
125  0 return file;
126    }
127   
 
128  0 toggle @Override
129    public String[] getStructureFiles()
130    {
131  0 return modelSet;
132    }
133   
 
134  0 toggle public void mouseOverStructure(int atomIndex, String strInfo)
135    {
136   
137    // StructureSelectionManager.getStructureSelectionManager().mouseOverStructure(atomIndex,
138    // chain, pdbfile)
139    // TODO Auto-generated method stub
140   
141    }
142   
 
143  0 toggle @Override
144    public void highlightAtoms(List<AtomSpec> atoms)
145    {
146  0 for (AtomSpec atom : atoms)
147    {
148  0 try
149    {
150    // TODO is this right? StructureSelectionManager passes pdbFile as the
151    // field that is interpreted (in 2.8.2) as pdbId?
152    // JBPComment: yep - this is right! the Javascript harness uses the
153    // absolute pdbFile URI to locate the PDB file in the external viewer
154  0 executeJavascriptFunction(_listenerfn,
155    new String[]
156    { "mouseover", "" + atom.getPdbFile(), "" + atom.getChain(),
157    "" + (atom.getPdbResNum()), "" + atom.getAtomIndex() });
158    } catch (Exception ex)
159    {
160  0 System.err.println("Couldn't execute callback with " + _listenerfn
161    + " for atomSpec: " + atom);
162  0 ex.printStackTrace();
163    }
164    }
165    }
166   
 
167  0 toggle @Override
168    public synchronized void updateColours(Object srce)
169    {
170  0 final Object source = srce;
171  0 StructureSelectionManager ssm = StructureSelectionManager
172    .getStructureSelectionManager(jvlite);
173   
174  0 if (JalviewLite.debug)
175    {
176  0 System.err.println(
177    this.getClass().getName() + " modelSet[0]: " + modelSet[0]);
178  0 ssm.reportMapping();
179    }
180   
181  0 if (source instanceof jalview.api.AlignmentViewPanel)
182    {
183  0 SequenceI[][] sequence = new SequenceI[modelSet.length][];
184  0 for (int m = 0; m < modelSet.length; m++)
185    {
186  0 StructureMapping[] sm = ssm.getMapping(modelSet[m]);
187  0 if (sm != null && sm.length > 0)
188    {
189  0 sequence[m] = new SequenceI[sm.length];
190  0 for (int i = 0; i < sm.length; i++)
191    {
192  0 sequence[m][i] = sm[i].getSequence();
193    }
194    }
195    else
196    {
197  0 sequence[m] = new SequenceI[0];
198    }
199    // if (jvlite.debug)
200    // {
201    // System.err.println("Mapped '" + modelSet[m] + "' to "
202    // + sequence[m].length + " sequences.");
203    // }
204    }
205   
206  0 SequenceRenderer sr = ((jalview.appletgui.AlignmentPanel) source)
207    .getSequenceRenderer();
208  0 FeatureRenderer fr = ((jalview.appletgui.AlignmentPanel) source).av
209    .isShowSequenceFeatures()
210    ? new jalview.appletgui.FeatureRenderer(
211    ((jalview.appletgui.AlignmentPanel) source).av)
212    : null;
213  0 if (fr != null)
214    {
215  0 ((jalview.appletgui.FeatureRenderer) fr).transferSettings(
216    ((jalview.appletgui.AlignmentPanel) source)
217    .getFeatureRenderer());
218    }
219  0 ;
220   
221    // Form a colour command from the given alignment panel for each distinct
222    // structure
223  0 ArrayList<String[]> ccomands = new ArrayList<String[]>();
224  0 ArrayList<String> pdbfn = new ArrayList<String>();
225  0 StructureMappingcommandSet[] colcommands = JmolCommands
226    .getColourBySequenceCommand(ssm, modelSet, sequence, sr,
227    (AlignmentViewPanel) source);
228  0 if (colcommands == null)
229    {
230  0 return;
231    }
232  0 int sz = 0;
233  0 for (jalview.structure.StructureMappingcommandSet ccset : colcommands)
234    {
235  0 sz += ccset.commands.length;
236  0 ccomands.add(ccset.commands);
237  0 pdbfn.add(ccset.mapping);
238    }
239   
240  0 String mclass, mhandle;
241  0 String ccomandset[] = new String[sz];
242  0 sz = 0;
243  0 for (String[] ccset : ccomands)
244    {
245  0 System.arraycopy(ccset, 0, ccomandset, sz, ccset.length);
246  0 sz += ccset.length;
247    }
248  0 if (jvlite.isJsMessageSetChanged(mclass = "colourstruct",
249    mhandle = ((jalview.appletgui.AlignmentPanel) source).av
250    .getViewId(),
251    ccomandset))
252    {
253  0 jvlite.setJsMessageSet(mclass, mhandle, ccomandset);
254    // and notify javascript handler
255  0 String st[] = new String[] { "colourstruct",
256    "" + ((jalview.appletgui.AlignmentPanel) source).av.getViewId(),
257    "" + ccomandset.length, jvlite.arrayToSeparatorList(
258    pdbfn.toArray(new String[pdbfn.size()])) };
259  0 try
260    {
261  0 executeJavascriptFunction(true, _listenerfn, st);
262    } catch (Exception ex)
263    {
264  0 System.err.println("Couldn't execute callback with " + _listenerfn
265    + " using args { " + st[0] + ", " + st[1] + ", " + st[2]
266    + "," + st[3] + "}"); // + ","+st[4]+"\n");
267  0 ex.printStackTrace();
268   
269    }
270    }
271    /*
272    * new Thread(new Runnable() { public void run() { // and send to
273    * javascript handler String st[] = new String[0]; int i = 0; for (String
274    * colcommand : colcommands) { // do sync execution for each chunk try {
275    * executeJavascriptFunction( false, _listenerfn, st = new String[] {
276    * "colourstruct", "" + ((jalview.appletgui.AlignmentPanel) source).av
277    * .getViewId(), handle, "" }); } catch (Exception ex) {
278    * System.err.println("Couldn't execute callback with " + _listenerfn +
279    * " using args { " + st[0] + ", " + st[1] + ", " + st[2] + "," + st[3] +
280    * "\n"); ex.printStackTrace();
281    *
282    * } } } }).start();
283    */
284    }
285   
286    }
287   
 
288  0 toggle @Override
289    public AlignFrame getAlignFrame()
290    {
291    // associated with all alignframes, always.
292  0 return null;
293    }
294   
 
295  0 toggle @Override
296    public String getListenerFunction()
297    {
298  0 return _listenerfn;
299    }
300   
 
301  0 toggle @Override
302    public void releaseReferences(Object svl)
303    {
304   
305    // TODO Auto-generated method stub
306   
307    }
308   
 
309  0 toggle @Override
310    public boolean isListeningFor(SequenceI seq)
311    {
312  0 return true;
313    }
314   
315    }