2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.analysis.Conservation;
24 import jalview.binding.Annotation;
25 import jalview.binding.AnnotationElement;
26 import jalview.binding.Features;
27 import jalview.binding.JGroup;
28 import jalview.binding.JSeq;
29 import jalview.binding.JalviewModel;
30 import jalview.binding.JalviewModelSequence;
31 import jalview.binding.Pdbids;
32 import jalview.binding.Sequence;
33 import jalview.binding.SequenceSet;
34 import jalview.binding.Setting;
35 import jalview.binding.Tree;
36 import jalview.binding.UserColours;
37 import jalview.binding.Viewport;
38 import jalview.datamodel.PDBEntry;
39 import jalview.schemes.ColourSchemeI;
40 import jalview.schemes.ColourSchemeProperty;
41 import jalview.structure.StructureSelectionManager;
42 import jalview.util.MessageManager;
43 import jalview.util.jarInputStreamProvider;
44 import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
46 import java.io.InputStreamReader;
47 import java.io.Reader;
48 import java.net.UnknownHostException;
49 import java.util.Hashtable;
50 import java.util.Vector;
51 import java.util.jar.JarEntry;
52 import java.util.jar.JarInputStream;
54 import javax.swing.JOptionPane;
62 public class Jalview2XML_V1
64 boolean raiseGUI = true;
66 public Jalview2XML_V1()
71 public Jalview2XML_V1(boolean raiseGUI)
73 this.raiseGUI = raiseGUI;
76 jalview.schemes.UserColourScheme GetUserColourScheme(
77 JalviewModelSequence jms, String id)
79 UserColours[] uc = jms.getUserColours();
80 UserColours colours = null;
82 for (int i = 0; i < uc.length; i++)
84 if (uc[i].getId().equals(id))
92 int csize = colours.getUserColourScheme().getColourCount();
93 java.awt.Color[] newColours = new java.awt.Color[csize];
95 for (int i = 0; i < csize; i++)
97 newColours[i] = new java.awt.Color(Integer.parseInt(colours
98 .getUserColourScheme().getColour(i).getRGB(), 16));
101 return new jalview.schemes.UserColourScheme(newColours);
110 public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider)
112 final String file = jprovider.getFilename();
113 jalview.gui.AlignFrame af = null;
117 JarInputStream jin = null;
118 JarEntry jarentry = null;
123 jin = jprovider.getJarInputStream();
125 for (int i = 0; i < entryCount; i++)
127 jarentry = jin.getNextJarEntry();
130 if (jarentry != null)
133 if (jarentry.getName().endsWith(".xml"))
135 Reader in = new InputStreamReader(jin, "UTF-8");
136 JalviewModel object = new JalviewModel();
138 object = object.unmarshal(in);
140 af = LoadFromObject(object, file);
144 } while (jarentry != null);
145 } catch (final UnknownHostException ex)
147 ex.printStackTrace();
150 javax.swing.SwingUtilities.invokeLater(new Runnable()
156 System.err.println("Couldn't locate Jalview XML file : " + ex
158 JOptionPane.showInternalMessageDialog(Desktop.desktop,
159 MessageManager.formatMessage("label.couldnt_locate",
160 new String[] { file }), MessageManager
161 .getString("label.url_not_found"),
162 JOptionPane.WARNING_MESSAGE);
167 } catch (Exception ex)
169 System.err.println("Exception whilst loading jalview XML file : ");
170 ex.printStackTrace();
173 javax.swing.SwingUtilities.invokeLater(new Runnable()
179 JOptionPane.showInternalMessageDialog(Desktop.desktop,
180 MessageManager.formatMessage(
181 "label.error_loading_file_params", new String[]
182 { file }), MessageManager
183 .getString("label.error_loading_jalview_file"),
184 JOptionPane.WARNING_MESSAGE);
193 AlignFrame LoadFromObject(JalviewModel object, String file)
195 Vector seqids = new Vector();
196 SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
197 Sequence[] vamsasSeq = vamsasSet.getSequence();
199 JalviewModelSequence jms = object.getJalviewModelSequence();
201 // ////////////////////////////////
203 jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];
204 JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
205 for (int i = 0; i < vamsasSeq.length; i++)
207 jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),
208 vamsasSeq[i].getSequence());
209 jseqs[i].setStart(JSEQ[i].getStart());
210 jseqs[i].setEnd(JSEQ[i].getEnd());
211 seqids.add(jseqs[i]);
214 // /SequenceFeatures are added to the DatasetSequence,
215 // so we must create the dataset before loading features
216 // ///////////////////////////////
217 jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);
219 // ///////////////////////////////
221 for (int i = 0; i < vamsasSeq.length; i++)
223 if (JSEQ[i].getFeaturesCount() > 0)
225 Features[] features = JSEQ[i].getFeatures();
226 for (int f = 0; f < features.length; f++)
228 jalview.datamodel.SequenceFeature sf = new jalview.datamodel.SequenceFeature(
229 features[f].getType(), features[f].getDescription(),
230 features[f].getStatus(), features[f].getBegin(),
231 features[f].getEnd(), null);
233 al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
236 if (JSEQ[i].getPdbidsCount() > 0)
238 Pdbids[] ids = JSEQ[i].getPdbids();
239 for (int p = 0; p < ids.length; p++)
241 jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
242 entry.setId(ids[p].getId());
243 if (ids[p].getType() != null)
245 if (ids[p].getType().equalsIgnoreCase("PDB"))
247 entry.setType(PDBEntry.Type.PDB);
251 entry.setType(PDBEntry.Type.FILE);
254 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
255 StructureSelectionManager.getStructureSelectionManager(
256 Desktop.instance).registerPDBEntry(entry);
262 // ///////////////////////////////
263 // ////////////////////////////////
265 if (vamsasSet.getAnnotation() != null)
267 Annotation[] an = vamsasSet.getAnnotation();
269 for (int i = 0; i < an.length; i++)
271 AnnotationElement[] ae = an[i].getAnnotationElement();
272 jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al
275 for (int aa = 0; aa < ae.length; aa++)
277 anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(
278 ae[aa].getDisplayCharacter(), ae[aa].getDescription(),
279 ae[aa].getSecondaryStructure().charAt(0),
283 jalview.datamodel.AlignmentAnnotation jaa = null;
285 if (an[i].getGraph())
287 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
288 an[i].getDescription(), anot, 0, 0,
289 jalview.datamodel.AlignmentAnnotation.BAR_GRAPH);
293 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
294 an[i].getDescription(), anot);
297 al.addAnnotation(jaa);
301 // ///////////////////////////////
303 Viewport[] views = jms.getViewport();
304 Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER
306 AlignFrame af = new AlignFrame(al, view.getWidth(), view.getHeight());
308 af.setFileName(file, "Jalview");
310 for (int i = 0; i < JSEQ.length; i++)
312 af.viewport.setSequenceColour(af.viewport.getAlignment()
313 .getSequenceAt(i), new java.awt.Color(JSEQ[i].getColour()));
316 // af.changeColour() );
317 // ///////////////////////
319 if (jms.getJGroupCount() > 0)
321 JGroup[] groups = jms.getJGroup();
323 for (int i = 0; i < groups.length; i++)
325 ColourSchemeI cs = null;
327 if (groups[i].getColour() != null)
329 if (groups[i].getColour().startsWith("ucs"))
331 cs = GetUserColourScheme(jms, groups[i].getColour());
335 cs = ColourSchemeProperty.getColour(al, groups[i].getColour());
340 cs.setThreshold(groups[i].getPidThreshold(), true);
345 Vector seqs = new Vector();
346 int[] ids = groups[i].getSeq();
348 for (int s = 0; s < ids.length; s++)
350 seqs.addElement(seqids.elementAt(ids[s]));
353 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(
354 seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(),
355 groups[i].getDisplayText(), groups[i].getColourText(),
356 groups[i].getStart(), groups[i].getEnd());
358 sg.setOutlineColour(new java.awt.Color(groups[i].getOutlineColour()));
360 if (groups[i].getConsThreshold() != 0)
362 Conservation c = new Conservation("All", 3,
363 sg.getSequences(null), 0, sg.getWidth() - 1);
365 c.verdict(false, 25);
366 sg.cs.setConservation(c);
373 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
375 af.viewport.setStartRes(view.getStartRes());
376 af.viewport.setStartSeq(view.getStartSeq());
377 af.viewport.setShowAnnotation(view.getShowAnnotation());
378 af.viewport.setAbovePIDThreshold(view.getPidSelected());
379 af.viewport.setColourText(view.getShowColourText());
380 af.viewport.setConservationSelected(view.getConservationSelected());
381 af.viewport.setShowJVSuffix(view.getShowFullId());
383 new java.awt.Font(view.getFontName(), view.getFontStyle(), view
384 .getFontSize()), true);
386 af.viewport.setRenderGaps(view.getRenderGaps());
387 af.viewport.setWrapAlignment(view.getWrapAlignment());
389 af.viewport.setShowAnnotation(view.isShowAnnotation());
390 af.viewport.setShowBoxes(view.getShowBoxes());
391 af.viewport.setShowText(view.getShowText());
393 ColourSchemeI cs = null;
395 if (view.getBgColour() != null)
397 if (view.getBgColour().startsWith("ucs"))
399 cs = GetUserColourScheme(jms, view.getBgColour());
403 cs = ColourSchemeProperty.getColour(al, view.getBgColour());
408 cs.setThreshold(view.getPidThreshold(), true);
409 cs.setConsensus(af.viewport.getSequenceConsensusHash());
413 af.viewport.setGlobalColourScheme(cs);
414 af.viewport.setColourAppliesToAllGroups(false);
415 af.alignPanel.updateLayout();
417 if (view.getConservationSelected() && cs != null)
419 cs.setConservationInc(view.getConsThreshold());
422 af.viewport.setColourAppliesToAllGroups(true);
423 af.viewport.setShowSequenceFeatures(view.getShowSequenceFeatures());
425 if (jms.getFeatureSettings() != null)
427 Hashtable featuresDisplayed = new Hashtable();
428 Hashtable featureColours = new Hashtable();
429 String[] renderOrder = new String[jms.getFeatureSettings()
431 for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++)
433 Setting setting = jms.getFeatureSettings().getSetting(fs);
435 featureColours.put(setting.getType(),
436 new java.awt.Color(setting.getColour()));
438 renderOrder[fs] = setting.getType();
440 if (setting.getDisplay())
442 featuresDisplayed.put(setting.getType(),
443 new Integer(setting.getColour()));
446 FeatureRendererSettings frs = new FeatureRendererSettings(
447 renderOrder, new Hashtable(), featureColours, 1.0f, null);
448 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
449 .transferSettings(frs);
452 af.setMenusFromViewport(af.viewport);
454 Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
458 // /////////////////////////////////////
459 if (jms.getTreeCount() > 0)
463 for (int t = 0; t < jms.getTreeCount(); t++)
466 Tree tree = jms.getTree(t);
468 TreePanel tp = af.ShowNewickTree(
469 new jalview.io.NewickFile(tree.getNewick()),
470 tree.getTitle(), tree.getWidth(), tree.getHeight(),
471 tree.getXpos(), tree.getYpos());
473 tp.fitToWindow.setState(tree.getFitToWindow());
474 tp.fitToWindow_actionPerformed(null);
476 if (tree.getFontName() != null)
478 tp.setTreeFont(new java.awt.Font(tree.getFontName(), tree
479 .getFontStyle(), tree.getFontSize()));
483 tp.setTreeFont(new java.awt.Font(view.getFontName(), view
484 .getFontStyle(), tree.getFontSize()));
487 tp.showPlaceholders(tree.getMarkUnlinked());
488 tp.showBootstrap(tree.getShowBootstrap());
489 tp.showDistances(tree.getShowDistances());
491 tp.treeCanvas.threshold = tree.getThreshold();
493 if (tree.getCurrentTree())
495 af.viewport.setCurrentTree(tp.getTree());
499 } catch (Exception ex)
501 ex.printStackTrace();