2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import jalview.binding.Annotation;
24 import jalview.binding.AnnotationElement;
25 import jalview.binding.Features;
26 import jalview.binding.JGroup;
27 import jalview.binding.JSeq;
28 import jalview.binding.JalviewModel;
29 import jalview.binding.JalviewModelSequence;
30 import jalview.binding.Pdbids;
31 import jalview.binding.Sequence;
32 import jalview.binding.SequenceSet;
33 import jalview.binding.Setting;
34 import jalview.binding.Tree;
35 import jalview.binding.UserColours;
36 import jalview.binding.Viewport;
37 import jalview.schemes.ColourSchemeI;
38 import jalview.schemes.ColourSchemeProperty;
39 import jalview.schemes.ResidueProperties;
40 import jalview.structure.StructureSelectionManager;
41 import jalview.util.MessageManager;
42 import jalview.util.jarInputStreamProvider;
44 import java.io.InputStreamReader;
45 import java.util.Hashtable;
46 import java.util.Vector;
47 import java.util.jar.JarEntry;
48 import java.util.jar.JarInputStream;
50 import javax.swing.JOptionPane;
52 import org.exolab.castor.xml.IDResolver;
60 public class Jalview2XML_V1
62 boolean raiseGUI = true;
64 public Jalview2XML_V1()
69 public Jalview2XML_V1(boolean raiseGUI)
71 this.raiseGUI = raiseGUI;
74 jalview.schemes.UserColourScheme GetUserColourScheme(
75 JalviewModelSequence jms, String id)
77 UserColours[] uc = jms.getUserColours();
78 UserColours colours = null;
80 for (int i = 0; i < uc.length; i++)
82 if (uc[i].getId().equals(id))
90 int csize = colours.getUserColourScheme().getColourCount();
91 java.awt.Color[] newColours = new java.awt.Color[csize];
93 for (int i = 0; i < csize; i++)
95 newColours[i] = new java.awt.Color(Integer.parseInt(colours
96 .getUserColourScheme().getColour(i).getRGB(), 16));
99 return new jalview.schemes.UserColourScheme(newColours);
108 public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider)
110 final String file = jprovider.getFilename();
111 jalview.gui.AlignFrame af = null;
115 JarInputStream jin = null;
116 JarEntry jarentry = null;
121 jin = jprovider.getJarInputStream();
123 for (int i = 0; i < entryCount; i++)
125 jarentry = jin.getNextJarEntry();
128 class NoDescIDResolver implements IDResolver
130 public Object resolve(String idref)
132 System.out.println(idref + " used");
137 if (jarentry != null)
139 InputStreamReader in = new InputStreamReader(jin, "UTF-8");
140 JalviewModel object = new JalviewModel();
142 object = object.unmarshal(in);
144 af = LoadFromObject(object, file);
147 } while (jarentry != null);
148 } catch (final java.net.UnknownHostException ex)
150 ex.printStackTrace();
153 javax.swing.SwingUtilities.invokeLater(new Runnable()
158 System.err.println("Couldn't locate Jalview XML file : " + ex
160 JOptionPane.showInternalMessageDialog(Desktop.desktop,
161 MessageManager.formatMessage("label.couldnt_locate",
163 { file }), MessageManager
164 .getString("label.url_not_found"),
165 JOptionPane.WARNING_MESSAGE);
170 } catch (Exception ex)
172 System.err.println("Exception whilst loading jalview XML file : ");
173 ex.printStackTrace();
176 javax.swing.SwingUtilities.invokeLater(new Runnable()
181 JOptionPane.showInternalMessageDialog(Desktop.desktop,
182 MessageManager.formatMessage("label.error_loading_file_params", new String[]{file}), MessageManager.getString("label.error_loading_jalview_file"),
183 JOptionPane.WARNING_MESSAGE);
192 AlignFrame LoadFromObject(JalviewModel object, String file)
194 Vector seqids = new Vector();
195 SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
196 Sequence[] vamsasSeq = vamsasSet.getSequence();
198 JalviewModelSequence jms = object.getJalviewModelSequence();
200 // ////////////////////////////////
202 jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];
203 JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
204 for (int i = 0; i < vamsasSeq.length; i++)
206 jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),
207 vamsasSeq[i].getSequence());
208 jseqs[i].setStart(JSEQ[i].getStart());
209 jseqs[i].setEnd(JSEQ[i].getEnd());
210 seqids.add(jseqs[i]);
213 // /SequenceFeatures are added to the DatasetSequence,
214 // so we must create the dataset before loading features
215 // ///////////////////////////////
216 jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);
218 // ///////////////////////////////
220 for (int i = 0; i < vamsasSeq.length; i++)
222 if (JSEQ[i].getFeaturesCount() > 0)
224 Features[] features = JSEQ[i].getFeatures();
225 for (int f = 0; f < features.length; f++)
227 jalview.datamodel.SequenceFeature sf = new jalview.datamodel.SequenceFeature(
228 features[f].getType(), features[f].getDescription(),
229 features[f].getStatus(), features[f].getBegin(),
230 features[f].getEnd(), null);
232 al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
235 if (JSEQ[i].getPdbidsCount() > 0)
237 Pdbids[] ids = JSEQ[i].getPdbids();
238 for (int p = 0; p < ids.length; p++)
240 jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
241 entry.setId(ids[p].getId());
242 entry.setType(ids[p].getType());
243 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
244 StructureSelectionManager.getStructureSelectionManager(
245 Desktop.instance).registerPDBEntry(entry);
251 // ///////////////////////////////
252 // ////////////////////////////////
254 if (vamsasSet.getAnnotation() != null)
256 Annotation[] an = vamsasSet.getAnnotation();
258 for (int i = 0; i < an.length; i++)
260 AnnotationElement[] ae = an[i].getAnnotationElement();
261 jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al
264 for (int aa = 0; aa < ae.length; aa++)
266 anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(
267 ae[aa].getDisplayCharacter(), ae[aa].getDescription(),
268 ae[aa].getSecondaryStructure().charAt(0),
272 jalview.datamodel.AlignmentAnnotation jaa = null;
274 if (an[i].getGraph())
276 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
277 an[i].getDescription(), anot, 0, 0,
278 jalview.datamodel.AlignmentAnnotation.BAR_GRAPH);
282 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
283 an[i].getDescription(), anot);
286 al.addAnnotation(jaa);
290 // ///////////////////////////////
292 Viewport[] views = jms.getViewport();
293 Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER
295 AlignFrame af = new AlignFrame(al, view.getWidth(), view.getHeight());
297 af.setFileName(file, "Jalview");
299 for (int i = 0; i < JSEQ.length; i++)
301 af.viewport.setSequenceColour(af.viewport.getAlignment()
302 .getSequenceAt(i), new java.awt.Color(JSEQ[i].getColour()));
305 // af.changeColour() );
306 // ///////////////////////
308 if (jms.getJGroupCount() > 0)
310 JGroup[] groups = jms.getJGroup();
312 for (int i = 0; i < groups.length; i++)
314 ColourSchemeI cs = null;
316 if (groups[i].getColour() != null)
318 if (groups[i].getColour().startsWith("ucs"))
320 cs = GetUserColourScheme(jms, groups[i].getColour());
324 cs = ColourSchemeProperty.getColour(al, groups[i].getColour());
329 cs.setThreshold(groups[i].getPidThreshold(), true);
334 Vector seqs = new Vector();
335 int[] ids = groups[i].getSeq();
337 for (int s = 0; s < ids.length; s++)
339 seqs.addElement(seqids
343 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(
344 seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(),
345 groups[i].getDisplayText(), groups[i].getColourText(),
346 groups[i].getStart(), groups[i].getEnd());
348 sg.setOutlineColour(new java.awt.Color(groups[i].getOutlineColour()));
350 if (groups[i].getConsThreshold() != 0)
352 jalview.analysis.Conservation c = new jalview.analysis.Conservation(
353 "All", ResidueProperties.propHash, 3,
354 sg.getSequences(null), 0, sg.getWidth() - 1);
356 c.verdict(false, 25);
357 sg.cs.setConservation(c);
364 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
366 af.viewport.setStartRes(view.getStartRes());
367 af.viewport.setStartSeq(view.getStartSeq());
368 af.viewport.setShowAnnotation(view.getShowAnnotation());
369 af.viewport.setAbovePIDThreshold(view.getPidSelected());
370 af.viewport.setColourText(view.getShowColourText());
371 af.viewport.setConservationSelected(view.getConservationSelected());
372 af.viewport.setShowJVSuffix(view.getShowFullId());
373 af.viewport.setFont(new java.awt.Font(view.getFontName(), view
374 .getFontStyle(), view.getFontSize()));
375 af.alignPanel.fontChanged();
377 af.viewport.setRenderGaps(view.getRenderGaps());
378 af.viewport.setWrapAlignment(view.getWrapAlignment());
379 af.alignPanel.setWrapAlignment(view.getWrapAlignment());
380 af.viewport.setShowAnnotation(view.getShowAnnotation());
381 af.alignPanel.setAnnotationVisible(view.getShowAnnotation());
382 af.viewport.setShowBoxes(view.getShowBoxes());
383 af.viewport.setShowText(view.getShowText());
385 ColourSchemeI cs = null;
387 if (view.getBgColour() != null)
389 if (view.getBgColour().startsWith("ucs"))
391 cs = GetUserColourScheme(jms, view.getBgColour());
395 cs = ColourSchemeProperty.getColour(al, view.getBgColour());
400 cs.setThreshold(view.getPidThreshold(), true);
401 cs.setConsensus(af.viewport.getSequenceConsensusHash());
405 af.viewport.setGlobalColourScheme(cs);
406 af.viewport.setColourAppliesToAllGroups(false);
408 if (view.getConservationSelected() && cs != null)
410 cs.setConservationInc(view.getConsThreshold());
413 af.viewport.setColourAppliesToAllGroups(true);
414 af.viewport.showSequenceFeatures = view.getShowSequenceFeatures();
416 if (jms.getFeatureSettings() != null)
418 af.viewport.featuresDisplayed = new Hashtable();
419 String[] renderOrder = new String[jms.getFeatureSettings()
421 for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++)
423 Setting setting = jms.getFeatureSettings().getSetting(fs);
425 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(
426 setting.getType(), new java.awt.Color(setting.getColour()));
428 renderOrder[fs] = setting.getType();
430 if (setting.getDisplay())
432 af.viewport.featuresDisplayed.put(setting.getType(), new Integer(
433 setting.getColour()));
436 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;
439 af.setMenusFromViewport(af.viewport);
441 Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
445 // /////////////////////////////////////
446 if (jms.getTreeCount() > 0)
450 for (int t = 0; t < jms.getTreeCount(); t++)
453 Tree tree = jms.getTree(t);
455 TreePanel tp = af.ShowNewickTree(
456 new jalview.io.NewickFile(tree.getNewick()),
457 tree.getTitle(), tree.getWidth(), tree.getHeight(),
458 tree.getXpos(), tree.getYpos());
460 tp.fitToWindow.setState(tree.getFitToWindow());
461 tp.fitToWindow_actionPerformed(null);
463 if (tree.getFontName() != null)
465 tp.setTreeFont(new java.awt.Font(tree.getFontName(), tree
466 .getFontStyle(), tree.getFontSize()));
470 tp.setTreeFont(new java.awt.Font(view.getFontName(), view
471 .getFontStyle(), tree.getFontSize()));
474 tp.showPlaceholders(tree.getMarkUnlinked());
475 tp.showBootstrap(tree.getShowBootstrap());
476 tp.showDistances(tree.getShowDistances());
478 tp.treeCanvas.threshold = tree.getThreshold();
480 if (tree.getCurrentTree())
482 af.viewport.setCurrentTree(tp.getTree());
486 } catch (Exception ex)
488 ex.printStackTrace();