2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 import java.util.jar.*;
27 import org.exolab.castor.xml.*;
28 import jalview.binding.*;
29 import jalview.schemes.*;
30 import jalview.util.jarInputStreamProvider;
38 public class Jalview2XML_V1
40 boolean raiseGUI = true;
42 public Jalview2XML_V1()
47 public Jalview2XML_V1(boolean raiseGUI)
49 this.raiseGUI = raiseGUI;
52 jalview.schemes.UserColourScheme GetUserColourScheme(
53 JalviewModelSequence jms, String id)
55 UserColours[] uc = jms.getUserColours();
56 UserColours colours = null;
58 for (int i = 0; i < uc.length; i++)
60 if (uc[i].getId().equals(id))
68 int csize = colours.getUserColourScheme().getColourCount();
69 java.awt.Color[] newColours = new java.awt.Color[csize];
71 for (int i = 0; i < csize; i++)
73 newColours[i] = new java.awt.Color(Integer.parseInt(colours
74 .getUserColourScheme().getColour(i).getRGB(), 16));
77 return new jalview.schemes.UserColourScheme(newColours);
86 public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider)
88 final String file = jprovider.getFilename();
89 jalview.gui.AlignFrame af = null;
93 JarInputStream jin = null;
94 JarEntry jarentry = null;
99 jin = jprovider.getJarInputStream();
101 for (int i = 0; i < entryCount; i++)
103 jarentry = jin.getNextJarEntry();
106 class NoDescIDResolver implements IDResolver
108 public Object resolve(String idref)
110 System.out.println(idref + " used");
115 if (jarentry != null)
117 InputStreamReader in = new InputStreamReader(jin, "UTF-8");
118 JalviewModel object = new JalviewModel();
120 object = (JalviewModel) object.unmarshal(in);
122 af = LoadFromObject(object, file);
125 } while (jarentry != null);
126 } catch (final java.net.UnknownHostException ex)
128 ex.printStackTrace();
131 javax.swing.SwingUtilities.invokeLater(new Runnable()
136 System.err.println("Couldn't locate Jalview XML file : " + ex
138 JOptionPane.showInternalMessageDialog(Desktop.desktop,
139 "Couldn't locate " + file, "URL not found",
140 JOptionPane.WARNING_MESSAGE);
145 } catch (Exception ex)
147 System.err.println("Exception whilst loading jalview XML file : ");
148 ex.printStackTrace();
151 javax.swing.SwingUtilities.invokeLater(new Runnable()
156 JOptionPane.showInternalMessageDialog(Desktop.desktop,
157 "Error loading " + file, "Error loading Jalview file",
158 JOptionPane.WARNING_MESSAGE);
167 AlignFrame LoadFromObject(JalviewModel object, String file)
169 Vector seqids = new Vector();
170 SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
171 Sequence[] vamsasSeq = vamsasSet.getSequence();
173 JalviewModelSequence jms = object.getJalviewModelSequence();
175 // ////////////////////////////////
177 jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];
178 JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
179 for (int i = 0; i < vamsasSeq.length; i++)
181 jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),
182 vamsasSeq[i].getSequence());
183 jseqs[i].setStart(JSEQ[i].getStart());
184 jseqs[i].setEnd(JSEQ[i].getEnd());
185 seqids.add(jseqs[i]);
188 // /SequenceFeatures are added to the DatasetSequence,
189 // so we must create the dataset before loading features
190 // ///////////////////////////////
191 jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);
193 // ///////////////////////////////
195 for (int i = 0; i < vamsasSeq.length; i++)
197 if (JSEQ[i].getFeaturesCount() > 0)
199 Features[] features = JSEQ[i].getFeatures();
200 for (int f = 0; f < features.length; f++)
202 jalview.datamodel.SequenceFeature sf = new jalview.datamodel.SequenceFeature(
203 features[f].getType(), features[f].getDescription(),
204 features[f].getStatus(), features[f].getBegin(),
205 features[f].getEnd(), null);
207 al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
210 if (JSEQ[i].getPdbidsCount() > 0)
212 Pdbids[] ids = JSEQ[i].getPdbids();
213 for (int p = 0; p < ids.length; p++)
215 jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
216 entry.setId(ids[p].getId());
217 entry.setType(ids[p].getType());
218 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
224 // ///////////////////////////////
225 // ////////////////////////////////
227 if (vamsasSet.getAnnotation() != null)
229 Annotation[] an = vamsasSet.getAnnotation();
231 for (int i = 0; i < an.length; i++)
233 AnnotationElement[] ae = an[i].getAnnotationElement();
234 jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al
237 for (int aa = 0; aa < ae.length; aa++)
239 anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(
240 ae[aa].getDisplayCharacter(), ae[aa].getDescription(),
241 ae[aa].getSecondaryStructure().charAt(0),
245 jalview.datamodel.AlignmentAnnotation jaa = null;
247 if (an[i].getGraph())
249 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
250 an[i].getDescription(), anot, 0, 0,
251 jalview.datamodel.AlignmentAnnotation.BAR_GRAPH);
255 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
256 an[i].getDescription(), anot);
259 al.addAnnotation(jaa);
263 // ///////////////////////////////
265 Viewport[] views = jms.getViewport();
266 Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER
268 AlignFrame af = new AlignFrame(al, view.getWidth(), view.getHeight());
270 af.setFileName(file, "Jalview");
272 for (int i = 0; i < JSEQ.length; i++)
274 af.viewport.setSequenceColour(af.viewport.getAlignment()
275 .getSequenceAt(i), new java.awt.Color(JSEQ[i].getColour()));
278 // af.changeColour() );
279 // ///////////////////////
281 if (jms.getJGroupCount() > 0)
283 JGroup[] groups = jms.getJGroup();
285 for (int i = 0; i < groups.length; i++)
287 ColourSchemeI cs = null;
289 if (groups[i].getColour() != null)
291 if (groups[i].getColour().startsWith("ucs"))
293 cs = GetUserColourScheme(jms, groups[i].getColour());
297 cs = ColourSchemeProperty.getColour(al, groups[i].getColour());
302 cs.setThreshold(groups[i].getPidThreshold(), true);
307 Vector seqs = new Vector();
308 int[] ids = groups[i].getSeq();
310 for (int s = 0; s < ids.length; s++)
312 seqs.addElement((jalview.datamodel.SequenceI) seqids
316 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(
317 seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(),
318 groups[i].getDisplayText(), groups[i].getColourText(),
319 groups[i].getStart(), groups[i].getEnd());
321 sg.setOutlineColour(new java.awt.Color(groups[i].getOutlineColour()));
323 if (groups[i].getConsThreshold() != 0)
325 jalview.analysis.Conservation c = new jalview.analysis.Conservation(
326 "All", ResidueProperties.propHash, 3,
327 sg.getSequences(null), 0, sg.getWidth() - 1);
329 c.verdict(false, 25);
330 sg.cs.setConservation(c);
337 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
339 af.viewport.setStartRes(view.getStartRes());
340 af.viewport.setStartSeq(view.getStartSeq());
341 af.viewport.setShowAnnotation(view.getShowAnnotation());
342 af.viewport.setAbovePIDThreshold(view.getPidSelected());
343 af.viewport.setColourText(view.getShowColourText());
344 af.viewport.setConservationSelected(view.getConservationSelected());
345 af.viewport.setShowJVSuffix(view.getShowFullId());
346 af.viewport.setFont(new java.awt.Font(view.getFontName(), view
347 .getFontStyle(), view.getFontSize()));
348 af.alignPanel.fontChanged();
350 af.viewport.setRenderGaps(view.getRenderGaps());
351 af.viewport.setWrapAlignment(view.getWrapAlignment());
352 af.alignPanel.setWrapAlignment(view.getWrapAlignment());
353 af.viewport.setShowAnnotation(view.getShowAnnotation());
354 af.alignPanel.setAnnotationVisible(view.getShowAnnotation());
355 af.viewport.setShowBoxes(view.getShowBoxes());
356 af.viewport.setShowText(view.getShowText());
358 ColourSchemeI cs = null;
360 if (view.getBgColour() != null)
362 if (view.getBgColour().startsWith("ucs"))
364 cs = GetUserColourScheme(jms, view.getBgColour());
368 cs = ColourSchemeProperty.getColour(al, view.getBgColour());
373 cs.setThreshold(view.getPidThreshold(), true);
374 cs.setConsensus(af.viewport.getSequenceConsensusHash());
378 af.viewport.setGlobalColourScheme(cs);
379 af.viewport.setColourAppliesToAllGroups(false);
381 if (view.getConservationSelected() && cs != null)
383 cs.setConservationInc(view.getConsThreshold());
386 af.viewport.setColourAppliesToAllGroups(true);
387 af.viewport.showSequenceFeatures = view.getShowSequenceFeatures();
389 if (jms.getFeatureSettings() != null)
391 af.viewport.featuresDisplayed = new Hashtable();
392 String[] renderOrder = new String[jms.getFeatureSettings()
394 for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++)
396 Setting setting = jms.getFeatureSettings().getSetting(fs);
398 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(
399 setting.getType(), new java.awt.Color(setting.getColour()));
401 renderOrder[fs] = setting.getType();
403 if (setting.getDisplay())
405 af.viewport.featuresDisplayed.put(setting.getType(), new Integer(
406 setting.getColour()));
409 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;
412 af.setMenusFromViewport(af.viewport);
414 Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
418 // /////////////////////////////////////
419 if (jms.getTreeCount() > 0)
423 for (int t = 0; t < jms.getTreeCount(); t++)
426 Tree tree = jms.getTree(t);
428 TreePanel tp = af.ShowNewickTree(
429 new jalview.io.NewickFile(tree.getNewick()),
430 tree.getTitle(), tree.getWidth(), tree.getHeight(),
431 tree.getXpos(), tree.getYpos());
433 tp.fitToWindow.setState(tree.getFitToWindow());
434 tp.fitToWindow_actionPerformed(null);
436 if (tree.getFontName() != null)
438 tp.setTreeFont(new java.awt.Font(tree.getFontName(), tree
439 .getFontStyle(), tree.getFontSize()));
443 tp.setTreeFont(new java.awt.Font(view.getFontName(), view
444 .getFontStyle(), tree.getFontSize()));
447 tp.showPlaceholders(tree.getMarkUnlinked());
448 tp.showBootstrap(tree.getShowBootstrap());
449 tp.showDistances(tree.getShowDistances());
451 tp.treeCanvas.threshold = tree.getThreshold();
453 if (tree.getCurrentTree())
455 af.viewport.setCurrentTree(tp.getTree());
459 } catch (Exception ex)
461 ex.printStackTrace();