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.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.datamodel.PDBEntry;
38 import jalview.schemes.ColourSchemeI;
39 import jalview.schemes.ColourSchemeProperty;
40 import jalview.schemes.ResidueProperties;
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.util.Hashtable;
48 import java.util.Vector;
49 import java.util.jar.JarEntry;
50 import java.util.jar.JarInputStream;
52 import javax.swing.JOptionPane;
54 import org.exolab.castor.xml.IDResolver;
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 class NoDescIDResolver implements IDResolver
132 public Object resolve(String idref)
134 System.out.println(idref + " used");
139 if (jarentry != null)
141 InputStreamReader in = new InputStreamReader(jin, "UTF-8");
142 JalviewModel object = new JalviewModel();
144 object = object.unmarshal(in);
146 af = LoadFromObject(object, file);
149 } while (jarentry != null);
150 } catch (final java.net.UnknownHostException ex)
152 ex.printStackTrace();
155 javax.swing.SwingUtilities.invokeLater(new Runnable()
160 System.err.println("Couldn't locate Jalview XML file : " + ex
162 JOptionPane.showInternalMessageDialog(Desktop.desktop,
163 MessageManager.formatMessage("label.couldnt_locate",
165 { file }), MessageManager
166 .getString("label.url_not_found"),
167 JOptionPane.WARNING_MESSAGE);
172 } catch (Exception ex)
174 System.err.println("Exception whilst loading jalview XML file : ");
175 ex.printStackTrace();
178 javax.swing.SwingUtilities.invokeLater(new Runnable()
183 JOptionPane.showInternalMessageDialog(Desktop.desktop,
184 MessageManager.formatMessage("label.error_loading_file_params", new String[]{file}), MessageManager.getString("label.error_loading_jalview_file"),
185 JOptionPane.WARNING_MESSAGE);
194 AlignFrame LoadFromObject(JalviewModel object, String file)
196 Vector seqids = new Vector();
197 SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
198 Sequence[] vamsasSeq = vamsasSet.getSequence();
200 JalviewModelSequence jms = object.getJalviewModelSequence();
202 // ////////////////////////////////
204 jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];
205 JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
206 for (int i = 0; i < vamsasSeq.length; i++)
208 jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),
209 vamsasSeq[i].getSequence());
210 jseqs[i].setStart(JSEQ[i].getStart());
211 jseqs[i].setEnd(JSEQ[i].getEnd());
212 seqids.add(jseqs[i]);
215 // /SequenceFeatures are added to the DatasetSequence,
216 // so we must create the dataset before loading features
217 // ///////////////////////////////
218 jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);
220 // ///////////////////////////////
222 for (int i = 0; i < vamsasSeq.length; i++)
224 if (JSEQ[i].getFeaturesCount() > 0)
226 Features[] features = JSEQ[i].getFeatures();
227 for (int f = 0; f < features.length; f++)
229 jalview.datamodel.SequenceFeature sf = new jalview.datamodel.SequenceFeature(
230 features[f].getType(), features[f].getDescription(),
231 features[f].getStatus(), features[f].getBegin(),
232 features[f].getEnd(), null);
234 al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
237 if (JSEQ[i].getPdbidsCount() > 0)
239 Pdbids[] ids = JSEQ[i].getPdbids();
240 for (int p = 0; p < ids.length; p++)
242 jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
243 entry.setId(ids[p].getId());
244 if (ids[p].getType() != null)
246 if (ids[p].getType().equalsIgnoreCase("PDB"))
248 entry.setType(PDBEntry.Type.PDB);
252 entry.setType(PDBEntry.Type.FILE);
255 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
256 StructureSelectionManager.getStructureSelectionManager(
257 Desktop.instance).registerPDBEntry(entry);
263 // ///////////////////////////////
264 // ////////////////////////////////
266 if (vamsasSet.getAnnotation() != null)
268 Annotation[] an = vamsasSet.getAnnotation();
270 for (int i = 0; i < an.length; i++)
272 AnnotationElement[] ae = an[i].getAnnotationElement();
273 jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al
276 for (int aa = 0; aa < ae.length; aa++)
278 anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(
279 ae[aa].getDisplayCharacter(), ae[aa].getDescription(),
280 ae[aa].getSecondaryStructure().charAt(0),
284 jalview.datamodel.AlignmentAnnotation jaa = null;
286 if (an[i].getGraph())
288 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
289 an[i].getDescription(), anot, 0, 0,
290 jalview.datamodel.AlignmentAnnotation.BAR_GRAPH);
294 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
295 an[i].getDescription(), anot);
298 al.addAnnotation(jaa);
302 // ///////////////////////////////
304 Viewport[] views = jms.getViewport();
305 Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER
307 AlignFrame af = new AlignFrame(al, view.getWidth(), view.getHeight());
309 af.setFileName(file, "Jalview");
311 for (int i = 0; i < JSEQ.length; i++)
313 af.viewport.setSequenceColour(af.viewport.getAlignment()
314 .getSequenceAt(i), new java.awt.Color(JSEQ[i].getColour()));
317 // af.changeColour() );
318 // ///////////////////////
320 if (jms.getJGroupCount() > 0)
322 JGroup[] groups = jms.getJGroup();
324 for (int i = 0; i < groups.length; i++)
326 ColourSchemeI cs = null;
328 if (groups[i].getColour() != null)
330 if (groups[i].getColour().startsWith("ucs"))
332 cs = GetUserColourScheme(jms, groups[i].getColour());
336 cs = ColourSchemeProperty.getColour(al, groups[i].getColour());
341 cs.setThreshold(groups[i].getPidThreshold(), true);
346 Vector seqs = new Vector();
347 int[] ids = groups[i].getSeq();
349 for (int s = 0; s < ids.length; s++)
351 seqs.addElement(seqids
355 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(
356 seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(),
357 groups[i].getDisplayText(), groups[i].getColourText(),
358 groups[i].getStart(), groups[i].getEnd());
360 sg.setOutlineColour(new java.awt.Color(groups[i].getOutlineColour()));
362 if (groups[i].getConsThreshold() != 0)
364 jalview.analysis.Conservation c = new jalview.analysis.Conservation(
365 "All", ResidueProperties.propHash, 3,
366 sg.getSequences(null), 0, sg.getWidth() - 1);
368 c.verdict(false, 25);
369 sg.cs.setConservation(c);
376 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
378 af.viewport.setStartRes(view.getStartRes());
379 af.viewport.setStartSeq(view.getStartSeq());
380 af.viewport.setShowAnnotation(view.getShowAnnotation());
381 af.viewport.setAbovePIDThreshold(view.getPidSelected());
382 af.viewport.setColourText(view.getShowColourText());
383 af.viewport.setConservationSelected(view.getConservationSelected());
384 af.viewport.setShowJVSuffix(view.getShowFullId());
386 new java.awt.Font(view.getFontName(), view.getFontStyle(), view
387 .getFontSize()), true);
389 af.viewport.setRenderGaps(view.getRenderGaps());
390 af.viewport.setWrapAlignment(view.getWrapAlignment());
392 af.viewport.setShowAnnotation(view.isShowAnnotation());
393 af.viewport.setShowBoxes(view.getShowBoxes());
394 af.viewport.setShowText(view.getShowText());
396 ColourSchemeI cs = null;
398 if (view.getBgColour() != null)
400 if (view.getBgColour().startsWith("ucs"))
402 cs = GetUserColourScheme(jms, view.getBgColour());
406 cs = ColourSchemeProperty.getColour(al, view.getBgColour());
411 cs.setThreshold(view.getPidThreshold(), true);
412 cs.setConsensus(af.viewport.getSequenceConsensusHash());
416 af.viewport.setGlobalColourScheme(cs);
417 af.viewport.setColourAppliesToAllGroups(false);
418 af.alignPanel.updateLayout();
420 if (view.getConservationSelected() && cs != null)
422 cs.setConservationInc(view.getConsThreshold());
425 af.viewport.setColourAppliesToAllGroups(true);
426 af.viewport.setShowSequenceFeatures(view.getShowSequenceFeatures());
428 if (jms.getFeatureSettings() != null)
430 Hashtable featuresDisplayed = new Hashtable();
431 Hashtable featureColours = new Hashtable();
432 String[] renderOrder = new String[jms.getFeatureSettings()
434 for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++)
436 Setting setting = jms.getFeatureSettings().getSetting(fs);
439 setting.getType(), new java.awt.Color(setting.getColour()));
441 renderOrder[fs] = setting.getType();
443 if (setting.getDisplay())
445 featuresDisplayed.put(setting.getType(), new Integer(
446 setting.getColour()));
449 FeatureRendererSettings frs = new FeatureRendererSettings(renderOrder, new Hashtable(), featureColours, 1.0f, null);
450 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer().transferSettings(frs);
453 af.setMenusFromViewport(af.viewport);
455 Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
459 // /////////////////////////////////////
460 if (jms.getTreeCount() > 0)
464 for (int t = 0; t < jms.getTreeCount(); t++)
467 Tree tree = jms.getTree(t);
469 TreePanel tp = af.ShowNewickTree(
470 new jalview.io.NewickFile(tree.getNewick()),
471 tree.getTitle(), tree.getWidth(), tree.getHeight(),
472 tree.getXpos(), tree.getYpos());
474 tp.fitToWindow.setState(tree.getFitToWindow());
475 tp.fitToWindow_actionPerformed(null);
477 if (tree.getFontName() != null)
479 tp.setTreeFont(new java.awt.Font(tree.getFontName(), tree
480 .getFontStyle(), tree.getFontSize()));
484 tp.setTreeFont(new java.awt.Font(view.getFontName(), view
485 .getFontStyle(), tree.getFontSize()));
488 tp.showPlaceholders(tree.getMarkUnlinked());
489 tp.showBootstrap(tree.getShowBootstrap());
490 tp.showDistances(tree.getShowDistances());
492 tp.treeCanvas.threshold = tree.getThreshold();
494 if (tree.getCurrentTree())
496 af.viewport.setCurrentTree(tp.getTree());
500 } catch (Exception ex)
502 ex.printStackTrace();