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.
25 import java.util.jar.*;
29 import org.exolab.castor.xml.*;
30 import jalview.binding.*;
31 import jalview.schemes.*;
32 import jalview.util.MessageManager;
33 import jalview.util.jarInputStreamProvider;
41 public class Jalview2XML_V1
43 boolean raiseGUI = true;
45 public Jalview2XML_V1()
50 public Jalview2XML_V1(boolean raiseGUI)
52 this.raiseGUI = raiseGUI;
55 jalview.schemes.UserColourScheme GetUserColourScheme(
56 JalviewModelSequence jms, String id)
58 UserColours[] uc = jms.getUserColours();
59 UserColours colours = null;
61 for (int i = 0; i < uc.length; i++)
63 if (uc[i].getId().equals(id))
71 int csize = colours.getUserColourScheme().getColourCount();
72 java.awt.Color[] newColours = new java.awt.Color[csize];
74 for (int i = 0; i < csize; i++)
76 newColours[i] = new java.awt.Color(Integer.parseInt(colours
77 .getUserColourScheme().getColour(i).getRGB(), 16));
80 return new jalview.schemes.UserColourScheme(newColours);
89 public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider)
91 final String file = jprovider.getFilename();
92 jalview.gui.AlignFrame af = null;
96 JarInputStream jin = null;
97 JarEntry jarentry = null;
102 jin = jprovider.getJarInputStream();
104 for (int i = 0; i < entryCount; i++)
106 jarentry = jin.getNextJarEntry();
109 class NoDescIDResolver implements IDResolver
111 public Object resolve(String idref)
113 System.out.println(idref + " used");
118 if (jarentry != null)
120 InputStreamReader in = new InputStreamReader(jin, "UTF-8");
121 JalviewModel object = new JalviewModel();
123 object = (JalviewModel) object.unmarshal(in);
125 af = LoadFromObject(object, file);
128 } while (jarentry != null);
129 } catch (final java.net.UnknownHostException ex)
131 ex.printStackTrace();
134 javax.swing.SwingUtilities.invokeLater(new Runnable()
139 System.err.println("Couldn't locate Jalview XML file : " + ex
141 JOptionPane.showInternalMessageDialog(Desktop.desktop,
142 MessageManager.formatMessage("label.couldnt_locate", new String[]{file}),
143 MessageManager.getString("label.url_not_found"),
144 JOptionPane.WARNING_MESSAGE);
149 } catch (Exception ex)
151 System.err.println("Exception whilst loading jalview XML file : ");
152 ex.printStackTrace();
155 javax.swing.SwingUtilities.invokeLater(new Runnable()
160 JOptionPane.showInternalMessageDialog(Desktop.desktop,
161 "Error loading " + file, "Error loading Jalview file",
162 JOptionPane.WARNING_MESSAGE);
171 AlignFrame LoadFromObject(JalviewModel object, String file)
173 Vector seqids = new Vector();
174 SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
175 Sequence[] vamsasSeq = vamsasSet.getSequence();
177 JalviewModelSequence jms = object.getJalviewModelSequence();
179 // ////////////////////////////////
181 jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];
182 JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
183 for (int i = 0; i < vamsasSeq.length; i++)
185 jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),
186 vamsasSeq[i].getSequence());
187 jseqs[i].setStart(JSEQ[i].getStart());
188 jseqs[i].setEnd(JSEQ[i].getEnd());
189 seqids.add(jseqs[i]);
192 // /SequenceFeatures are added to the DatasetSequence,
193 // so we must create the dataset before loading features
194 // ///////////////////////////////
195 jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);
197 // ///////////////////////////////
199 for (int i = 0; i < vamsasSeq.length; i++)
201 if (JSEQ[i].getFeaturesCount() > 0)
203 Features[] features = JSEQ[i].getFeatures();
204 for (int f = 0; f < features.length; f++)
206 jalview.datamodel.SequenceFeature sf = new jalview.datamodel.SequenceFeature(
207 features[f].getType(), features[f].getDescription(),
208 features[f].getStatus(), features[f].getBegin(),
209 features[f].getEnd(), null);
211 al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
214 if (JSEQ[i].getPdbidsCount() > 0)
216 Pdbids[] ids = JSEQ[i].getPdbids();
217 for (int p = 0; p < ids.length; p++)
219 jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
220 entry.setId(ids[p].getId());
221 entry.setType(ids[p].getType());
222 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
228 // ///////////////////////////////
229 // ////////////////////////////////
231 if (vamsasSet.getAnnotation() != null)
233 Annotation[] an = vamsasSet.getAnnotation();
235 for (int i = 0; i < an.length; i++)
237 AnnotationElement[] ae = an[i].getAnnotationElement();
238 jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al
241 for (int aa = 0; aa < ae.length; aa++)
243 anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(
244 ae[aa].getDisplayCharacter(), ae[aa].getDescription(),
245 ae[aa].getSecondaryStructure().charAt(0),
249 jalview.datamodel.AlignmentAnnotation jaa = null;
251 if (an[i].getGraph())
253 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
254 an[i].getDescription(), anot, 0, 0,
255 jalview.datamodel.AlignmentAnnotation.BAR_GRAPH);
259 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
260 an[i].getDescription(), anot);
263 al.addAnnotation(jaa);
267 // ///////////////////////////////
269 Viewport[] views = jms.getViewport();
270 Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER
272 AlignFrame af = new AlignFrame(al, view.getWidth(), view.getHeight());
274 af.setFileName(file, "Jalview");
276 for (int i = 0; i < JSEQ.length; i++)
278 af.viewport.setSequenceColour(af.viewport.getAlignment()
279 .getSequenceAt(i), new java.awt.Color(JSEQ[i].getColour()));
282 // af.changeColour() );
283 // ///////////////////////
285 if (jms.getJGroupCount() > 0)
287 JGroup[] groups = jms.getJGroup();
289 for (int i = 0; i < groups.length; i++)
291 ColourSchemeI cs = null;
293 if (groups[i].getColour() != null)
295 if (groups[i].getColour().startsWith("ucs"))
297 cs = GetUserColourScheme(jms, groups[i].getColour());
301 cs = ColourSchemeProperty.getColour(al, groups[i].getColour());
306 cs.setThreshold(groups[i].getPidThreshold(), true);
311 Vector seqs = new Vector();
312 int[] ids = groups[i].getSeq();
314 for (int s = 0; s < ids.length; s++)
316 seqs.addElement((jalview.datamodel.SequenceI) seqids
320 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(
321 seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(),
322 groups[i].getDisplayText(), groups[i].getColourText(),
323 groups[i].getStart(), groups[i].getEnd());
325 sg.setOutlineColour(new java.awt.Color(groups[i].getOutlineColour()));
327 if (groups[i].getConsThreshold() != 0)
329 jalview.analysis.Conservation c = new jalview.analysis.Conservation(
330 "All", ResidueProperties.propHash, 3,
331 sg.getSequences(null), 0, sg.getWidth() - 1);
333 c.verdict(false, 25);
334 sg.cs.setConservation(c);
341 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
343 af.viewport.setStartRes(view.getStartRes());
344 af.viewport.setStartSeq(view.getStartSeq());
345 af.viewport.setShowAnnotation(view.getShowAnnotation());
346 af.viewport.setAbovePIDThreshold(view.getPidSelected());
347 af.viewport.setColourText(view.getShowColourText());
348 af.viewport.setConservationSelected(view.getConservationSelected());
349 af.viewport.setShowJVSuffix(view.getShowFullId());
350 af.viewport.setFont(new java.awt.Font(view.getFontName(), view
351 .getFontStyle(), view.getFontSize()));
352 af.alignPanel.fontChanged();
354 af.viewport.setRenderGaps(view.getRenderGaps());
355 af.viewport.setWrapAlignment(view.getWrapAlignment());
356 af.alignPanel.setWrapAlignment(view.getWrapAlignment());
357 af.viewport.setShowAnnotation(view.getShowAnnotation());
358 af.alignPanel.setAnnotationVisible(view.getShowAnnotation());
359 af.viewport.setShowBoxes(view.getShowBoxes());
360 af.viewport.setShowText(view.getShowText());
362 ColourSchemeI cs = null;
364 if (view.getBgColour() != null)
366 if (view.getBgColour().startsWith("ucs"))
368 cs = GetUserColourScheme(jms, view.getBgColour());
372 cs = ColourSchemeProperty.getColour(al, view.getBgColour());
377 cs.setThreshold(view.getPidThreshold(), true);
378 cs.setConsensus(af.viewport.getSequenceConsensusHash());
382 af.viewport.setGlobalColourScheme(cs);
383 af.viewport.setColourAppliesToAllGroups(false);
385 if (view.getConservationSelected() && cs != null)
387 cs.setConservationInc(view.getConsThreshold());
390 af.viewport.setColourAppliesToAllGroups(true);
391 af.viewport.showSequenceFeatures = view.getShowSequenceFeatures();
393 if (jms.getFeatureSettings() != null)
395 af.viewport.featuresDisplayed = new Hashtable();
396 String[] renderOrder = new String[jms.getFeatureSettings()
398 for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++)
400 Setting setting = jms.getFeatureSettings().getSetting(fs);
402 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(
403 setting.getType(), new java.awt.Color(setting.getColour()));
405 renderOrder[fs] = setting.getType();
407 if (setting.getDisplay())
409 af.viewport.featuresDisplayed.put(setting.getType(), new Integer(
410 setting.getColour()));
413 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;
416 af.setMenusFromViewport(af.viewport);
418 Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
422 // /////////////////////////////////////
423 if (jms.getTreeCount() > 0)
427 for (int t = 0; t < jms.getTreeCount(); t++)
430 Tree tree = jms.getTree(t);
432 TreePanel tp = af.ShowNewickTree(
433 new jalview.io.NewickFile(tree.getNewick()),
434 tree.getTitle(), tree.getWidth(), tree.getHeight(),
435 tree.getXpos(), tree.getYpos());
437 tp.fitToWindow.setState(tree.getFitToWindow());
438 tp.fitToWindow_actionPerformed(null);
440 if (tree.getFontName() != null)
442 tp.setTreeFont(new java.awt.Font(tree.getFontName(), tree
443 .getFontStyle(), tree.getFontSize()));
447 tp.setTreeFont(new java.awt.Font(view.getFontName(), view
448 .getFontStyle(), tree.getFontSize()));
451 tp.showPlaceholders(tree.getMarkUnlinked());
452 tp.showBootstrap(tree.getShowBootstrap());
453 tp.showDistances(tree.getShowDistances());
455 tp.treeCanvas.threshold = tree.getThreshold();
457 if (tree.getCurrentTree())
459 af.viewport.setCurrentTree(tp.getTree());
463 } catch (Exception ex)
465 ex.printStackTrace();