2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import jalview.schemes.*;
\r
23 import jalview.gui.*;
\r
31 import java.util.jar.*;
\r
33 import javax.swing.*;
\r
35 import org.exolab.castor.xml.*;
\r
37 import jalview.binding.*;
\r
46 * @version $Revision$
\r
48 public class Jalview2XML_V1
\r
50 jalview.schemes.UserColourScheme GetUserColourScheme(
\r
51 JalviewModelSequence jms, String id)
\r
53 UserColours[] uc = jms.getUserColours();
\r
54 UserColours colours = null;
\r
56 for (int i = 0; i < uc.length; i++)
\r
58 if (uc[i].getId().equals(id))
\r
66 int csize = colours.getUserColourScheme().getColourCount();
\r
67 java.awt.Color[] newColours = new java.awt.Color[csize];
\r
69 for (int i = 0; i < csize; i++)
\r
71 newColours[i] = new java.awt.Color(Integer.parseInt(
\r
72 colours.getUserColourScheme().getColour(i).getRGB(), 16));
\r
75 return new jalview.schemes.UserColourScheme(newColours);
\r
81 * @param file DOCUMENT ME!
\r
83 public AlignFrame LoadJalviewAlign(String file)
\r
86 jalview.gui.AlignFrame af = null;
\r
90 //UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING
\r
93 if (file.startsWith("http://"))
\r
95 url = new URL(file);
\r
98 JarInputStream jin = null;
\r
99 JarEntry jarentry = null;
\r
100 int entryCount = 1;
\r
106 jin = new JarInputStream(url.openStream());
\r
110 jin = new JarInputStream(new FileInputStream(file));
\r
113 for (int i = 0; i < entryCount; i++)
\r
115 jarentry = jin.getNextJarEntry();
\r
118 class NoDescIDResolver implements IDResolver
\r
120 public Object resolve(String idref)
\r
122 System.out.println(idref+" used");
\r
128 if (jarentry != null)
\r
130 InputStreamReader in = new InputStreamReader(jin, "UTF-8");
\r
131 JalviewModel object = new JalviewModel();
\r
133 object = (JalviewModel) object.unmarshal(in);
\r
135 af = LoadFromObject(object);
\r
139 while (jarentry != null);
\r
141 catch(java.net.UnknownHostException ex)
\r
143 ex.printStackTrace();
\r
144 System.err.println("Couldn't locate Jalview XML file : " +
\r
146 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
147 "Couldn't locate " + file,
\r
149 JOptionPane.WARNING_MESSAGE);
\r
152 catch (Exception ex)
\r
154 ex.printStackTrace();
\r
155 System.err.println("Exception whilst loading jalview XML file : " +
\r
157 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
158 "Error loading " + file,
\r
159 "Error loading Jalview file",
\r
160 JOptionPane.WARNING_MESSAGE);
\r
167 AlignFrame LoadFromObject(JalviewModel object)
\r
169 Vector seqids = new Vector();
\r
170 SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
\r
171 Sequence[] vamsasSeq = vamsasSet.getSequence();
\r
173 JalviewModelSequence jms = object.getJalviewModelSequence();
\r
175 //////////////////////////////////
\r
177 jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];
\r
178 JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
\r
179 for (int i = 0; i < vamsasSeq.length; i++)
\r
181 jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),
\r
182 vamsasSeq[i].getSequence());
\r
183 jseqs[i].setStart(JSEQ[i].getStart());
\r
184 jseqs[i].setEnd(JSEQ[i].getEnd());
\r
185 jseqs[i].setColor(new java.awt.Color(JSEQ[i].getColour()));
\r
186 seqids.add(jseqs[i]);
\r
189 ///SequenceFeatures are added to the DatasetSequence,
\r
190 // so we must create the dataset before loading features
\r
191 /////////////////////////////////
\r
192 jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);
\r
193 al.setDataset(null);
\r
194 /////////////////////////////////
\r
196 for (int i = 0; i < vamsasSeq.length; i++)
\r
198 if (JSEQ[i].getFeaturesCount() > 0)
\r
200 Features[] features = JSEQ[i].getFeatures();
\r
201 for (int f = 0; f < features.length; f++)
\r
203 jalview.datamodel.SequenceFeature sf
\r
204 = new jalview.datamodel.SequenceFeature(features[f].getType(),
\r
205 features[f].getDescription(), features[f].getStatus(),
\r
206 features[f].getBegin(), features[f].getEnd(),
\r
209 al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
\r
212 if (JSEQ[i].getPdbidsCount() > 0)
\r
214 Pdbids[] ids = JSEQ[i].getPdbids();
\r
215 for (int p = 0; p < ids.length; p++)
\r
217 jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
\r
218 entry.setId(ids[p].getId());
\r
219 entry.setType(ids[p].getType());
\r
220 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
\r
226 /////////////////////////////////
\r
227 //////////////////////////////////
\r
229 if (vamsasSet.getAnnotation() != null)
\r
231 Annotation[] an = vamsasSet.getAnnotation();
\r
233 for (int i = 0; i < an.length; i++)
\r
235 AnnotationElement[] ae = an[i].getAnnotationElement();
\r
236 jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al.getWidth()];
\r
238 for (int aa = 0; aa < ae.length; aa++)
\r
240 anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(ae[aa].getDisplayCharacter(),
\r
241 ae[aa].getDescription(),
\r
242 ae[aa].getSecondaryStructure().charAt(0),
\r
243 ae[aa].getValue());
\r
246 jalview.datamodel.AlignmentAnnotation jaa = null;
\r
248 if (an[i].getGraph())
\r
250 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
\r
251 an[i].getDescription(), anot, 0, 0,
\r
252 jalview.datamodel.AlignmentAnnotation.BAR_GRAPH);
\r
256 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
\r
257 an[i].getDescription(), anot);
\r
260 al.addAnnotation(jaa);
\r
265 /////////////////////////////////
\r
267 Viewport[] views = jms.getViewport();
\r
268 Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER
\r
270 AlignFrame af = new AlignFrame(al, view.getWidth(), view.getHeight());
\r
273 // af.changeColour() );
\r
274 /////////////////////////
\r
276 if (jms.getJGroupCount() > 0)
\r
278 JGroup[] groups = jms.getJGroup();
\r
280 for (int i = 0; i < groups.length; i++)
\r
282 ColourSchemeI cs = null;
\r
284 if (groups[i].getColour() != null)
\r
286 if (groups[i].getColour().startsWith("ucs"))
\r
288 cs = GetUserColourScheme(jms, groups[i].getColour());
\r
292 cs = ColourSchemeProperty.getColour(al,
\r
293 groups[i].getColour());
\r
297 cs.setThreshold(groups[i].getPidThreshold(), true);
\r
301 Vector seqs = new Vector();
\r
302 int[] ids = groups[i].getSeq();
\r
304 for (int s = 0; s < ids.length; s++)
\r
306 seqs.addElement((jalview.datamodel.SequenceI) seqids.elementAt(
\r
310 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(seqs,
\r
311 groups[i].getName(), cs, groups[i].getDisplayBoxes(),
\r
312 groups[i].getDisplayText(), groups[i].getColourText(),
\r
313 groups[i].getStart(), groups[i].getEnd());
\r
315 sg.setOutlineColour(new java.awt.Color(
\r
316 groups[i].getOutlineColour()));
\r
318 if (groups[i].getConsThreshold() != 0)
\r
320 jalview.analysis.Conservation c = new jalview.analysis.Conservation("All",
\r
321 ResidueProperties.propHash, 3, sg.getSequences(false), 0,
\r
322 sg.getWidth() - 1);
\r
324 c.verdict(false, 25);
\r
325 sg.cs.setConservation(c);
\r
334 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
\r
336 af.viewport.setStartRes(view.getStartRes());
\r
337 af.viewport.setStartSeq(view.getStartSeq());
\r
338 af.viewport.setShowAnnotation(view.getShowAnnotation());
\r
339 af.viewport.setAbovePIDThreshold(view.getPidSelected());
\r
340 af.abovePIDThreshold.setSelected(view.getPidSelected());
\r
341 af.viewport.setColourText(view.getShowColourText());
\r
342 af.colourTextMenuItem.setSelected(view.getShowColourText());
\r
343 af.viewport.setConservationSelected(view.getConservationSelected());
\r
344 af.conservationMenuItem.setSelected(view.getConservationSelected());
\r
346 af.viewport.setShowJVSuffix(view.getShowFullId());
\r
347 af.seqLimits.setSelected(view.getShowFullId());
\r
349 af.viewport.setFont(new java.awt.Font(view.getFontName(),
\r
350 view.getFontStyle(), view.getFontSize()));
\r
351 af.alignPanel.fontChanged();
\r
353 af.viewport.setRenderGaps(view.getRenderGaps());
\r
354 af.renderGapsMenuItem.setSelected(view.getRenderGaps());
\r
356 af.viewport.setWrapAlignment(view.getWrapAlignment());
\r
357 af.wrapMenuItem.setSelected(view.getWrapAlignment());
\r
360 af.alignPanel.setWrapAlignment(view.getWrapAlignment());
\r
362 af.annotationPanelMenuItem.setState(view.getShowAnnotation());
\r
363 af.viewport.setShowAnnotation(view.getShowAnnotation());
\r
364 af.alignPanel.setAnnotationVisible(view.getShowAnnotation());
\r
367 af.viewport.setShowBoxes(view.getShowBoxes());
\r
368 af.viewBoxesMenuItem.setSelected(view.getShowBoxes());
\r
369 af.viewport.setShowText(view.getShowText());
\r
370 af.viewTextMenuItem.setSelected(view.getShowText());
\r
372 ColourSchemeI cs = null;
\r
374 if (view.getBgColour() != null)
\r
376 if (view.getBgColour().startsWith("ucs"))
\r
378 cs = GetUserColourScheme(jms, view.getBgColour());
\r
382 cs = ColourSchemeProperty.getColour(al, view.getBgColour());
\r
387 cs.setThreshold(view.getPidThreshold(), true);
\r
388 cs.setConsensus(af.viewport.hconsensus);
\r
392 af.setColourSelected(view.getBgColour());
\r
393 af.viewport.setGlobalColourScheme(cs);
\r
394 af.viewport.setColourAppliesToAllGroups(false);
\r
395 af.changeColour(cs);
\r
396 if (view.getConservationSelected() && cs!=null)
\r
398 cs.setConservationInc(view.getConsThreshold());
\r
401 af.viewport.setColourAppliesToAllGroups(true);
\r
403 if (view.getShowSequenceFeatures())
\r
405 af.viewport.showSequenceFeatures = true;
\r
406 af.showSeqFeatures.setSelected(true);
\r
409 if(jms.getFeatureSettings()!=null)
\r
411 af.viewport.featuresDisplayed = new Hashtable();
\r
412 String [] renderOrder = new String[jms.getFeatureSettings().getSettingCount()];
\r
413 for(int fs=0; fs<jms.getFeatureSettings().getSettingCount(); fs++)
\r
415 Setting setting = jms.getFeatureSettings().getSetting(fs);
\r
417 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(setting.getType(),
\r
418 new java.awt.Color(setting.getColour()));
\r
420 renderOrder[fs] = setting.getType();
\r
422 if(setting.getDisplay())
\r
423 af.viewport.featuresDisplayed.put(
\r
424 setting.getType(), new Integer(setting.getColour()));
\r
426 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;
\r
430 Desktop.addInternalFrame(af, view.getTitle(),
\r
431 view.getWidth(), view.getHeight());
\r
434 ///////////////////////////////////////
\r
435 if (jms.getTreeCount() > 0)
\r
439 for (int t = 0; t < jms.getTreeCount(); t++)
\r
442 Tree tree = jms.getTree(t);
\r
444 TreePanel tp = af.ShowNewickTree(new jalview.io.NewickFile(
\r
445 tree.getNewick()), tree.getTitle(),
\r
446 tree.getWidth(), tree.getHeight(),
\r
447 tree.getXpos(), tree.getYpos());
\r
449 tp.fitToWindow.setState(tree.getFitToWindow());
\r
450 tp.fitToWindow_actionPerformed(null);
\r
452 if(tree.getFontName()!=null)
\r
453 tp.setTreeFont(new java.awt.Font(tree.getFontName(),
\r
454 tree.getFontStyle(),
\r
455 tree.getFontSize()));
\r
457 tp.setTreeFont(new java.awt.Font(view.getFontName(),
\r
458 view.getFontStyle(),
\r
459 tree.getFontSize()));
\r
461 tp.showPlaceholders(tree.getMarkUnlinked());
\r
462 tp.showBootstrap(tree.getShowBootstrap());
\r
463 tp.showDistances(tree.getShowDistances());
\r
465 tp.treeCanvas.threshold = tree.getThreshold();
\r
467 if (tree.getCurrentTree())
\r
468 af.viewport.setCurrentTree(tp.getTree());
\r
472 catch (Exception ex)
\r
474 ex.printStackTrace();
\r