--- /dev/null
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
+package jalview.gui;\r
+\r
+import jalview.schemes.*;\r
+\r
+import jalview.gui.*;\r
+\r
+import java.io.*;\r
+\r
+import java.net.*;\r
+\r
+import java.util.*;\r
+\r
+import java.util.jar.*;\r
+\r
+import javax.swing.*;\r
+\r
+import org.exolab.castor.xml.*;\r
+\r
+import jalview.binding.*;\r
+\r
+\r
+\r
+\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
+public class Jalview2XML_V1\r
+{\r
+ jalview.schemes.UserColourScheme GetUserColourScheme(\r
+ JalviewModelSequence jms, String id)\r
+ {\r
+ UserColours[] uc = jms.getUserColours();\r
+ UserColours colours = null;\r
+\r
+ for (int i = 0; i < uc.length; i++)\r
+ {\r
+ if (uc[i].getId().equals(id))\r
+ {\r
+ colours = uc[i];\r
+\r
+ break;\r
+ }\r
+ }\r
+\r
+ int csize = colours.getUserColourScheme().getColourCount();\r
+ java.awt.Color[] newColours = new java.awt.Color[csize];\r
+\r
+ for (int i = 0; i < csize; i++)\r
+ {\r
+ newColours[i] = new java.awt.Color(Integer.parseInt(\r
+ colours.getUserColourScheme().getColour(i).getRGB(), 16));\r
+ }\r
+\r
+ return new jalview.schemes.UserColourScheme(newColours);\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param file DOCUMENT ME!\r
+ */\r
+ public AlignFrame LoadJalviewAlign(String file)\r
+ {\r
+\r
+ jalview.gui.AlignFrame af = null;\r
+\r
+ try\r
+ {\r
+ //UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING\r
+ URL url = null;\r
+\r
+ if (file.startsWith("http://"))\r
+ {\r
+ url = new URL(file);\r
+ }\r
+\r
+ JarInputStream jin = null;\r
+ JarEntry jarentry = null;\r
+ int entryCount = 1;\r
+\r
+ do\r
+ {\r
+ if (url != null)\r
+ {\r
+ jin = new JarInputStream(url.openStream());\r
+ }\r
+ else\r
+ {\r
+ jin = new JarInputStream(new FileInputStream(file));\r
+ }\r
+\r
+ for (int i = 0; i < entryCount; i++)\r
+ {\r
+ jarentry = jin.getNextJarEntry();\r
+\r
+ }\r
+\r
+\r
+ class NoDescIDResolver implements IDResolver\r
+ {\r
+ public Object resolve(String idref)\r
+ {\r
+ System.out.println(idref+" used");\r
+ return null;\r
+ }\r
+ }\r
+\r
+\r
+ if (jarentry != null)\r
+ {\r
+ InputStreamReader in = new InputStreamReader(jin, "UTF-8");\r
+ JalviewModel object = new JalviewModel();\r
+\r
+ object = (JalviewModel) object.unmarshal(in);\r
+\r
+ af = LoadFromObject(object);\r
+ entryCount++;\r
+ }\r
+ }\r
+ while (jarentry != null);\r
+ }\r
+ catch(java.net.UnknownHostException ex)\r
+ {\r
+ ex.printStackTrace();\r
+ System.err.println("Couldn't locate Jalview XML file : " +\r
+ ex + "\n");\r
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+ "Couldn't locate " + file,\r
+ "URL not found",\r
+ JOptionPane.WARNING_MESSAGE);\r
+\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ System.err.println("Exception whilst loading jalview XML file : " +\r
+ ex + "\n");\r
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+ "Error loading " + file,\r
+ "Error loading Jalview file",\r
+ JOptionPane.WARNING_MESSAGE);\r
+\r
+ }\r
+\r
+ return af;\r
+ }\r
+\r
+ AlignFrame LoadFromObject(JalviewModel object)\r
+ {\r
+ Vector seqids = new Vector();\r
+ SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);\r
+ Sequence[] vamsasSeq = vamsasSet.getSequence();\r
+\r
+ JalviewModelSequence jms = object.getJalviewModelSequence();\r
+\r
+ //////////////////////////////////\r
+ //LOAD SEQUENCES\r
+ jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];\r
+ JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();\r
+ for (int i = 0; i < vamsasSeq.length; i++)\r
+ {\r
+ jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),\r
+ vamsasSeq[i].getSequence());\r
+ jseqs[i].setStart(JSEQ[i].getStart());\r
+ jseqs[i].setEnd(JSEQ[i].getEnd());\r
+ jseqs[i].setColor(new java.awt.Color(JSEQ[i].getColour()));\r
+ seqids.add(jseqs[i]);\r
+ }\r
+\r
+ ///SequenceFeatures are added to the DatasetSequence,\r
+ // so we must create the dataset before loading features\r
+ /////////////////////////////////\r
+ jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);\r
+ al.setDataset(null);\r
+ /////////////////////////////////\r
+\r
+ for (int i = 0; i < vamsasSeq.length; i++)\r
+ {\r
+ if (JSEQ[i].getFeaturesCount() > 0)\r
+ {\r
+ Features[] features = JSEQ[i].getFeatures();\r
+ for (int f = 0; f < features.length; f++)\r
+ {\r
+ jalview.datamodel.SequenceFeature sf\r
+ = new jalview.datamodel.SequenceFeature(features[f].getType(),\r
+ features[f].getDescription(), features[f].getStatus(),\r
+ features[f].getBegin(), features[f].getEnd(),\r
+ null);\r
+\r
+ al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);\r
+ }\r
+ }\r
+ if (JSEQ[i].getPdbidsCount() > 0)\r
+ {\r
+ Pdbids[] ids = JSEQ[i].getPdbids();\r
+ for (int p = 0; p < ids.length; p++)\r
+ {\r
+ jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();\r
+ entry.setId(ids[p].getId());\r
+ entry.setType(ids[p].getType());\r
+ al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);\r
+ }\r
+\r
+ }\r
+ }\r
+\r
+ /////////////////////////////////\r
+ //////////////////////////////////\r
+ //LOAD ANNOTATIONS\r
+ if (vamsasSet.getAnnotation() != null)\r
+ {\r
+ Annotation[] an = vamsasSet.getAnnotation();\r
+\r
+ for (int i = 0; i < an.length; i++)\r
+ {\r
+ AnnotationElement[] ae = an[i].getAnnotationElement();\r
+ jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al.getWidth()];\r
+\r
+ for (int aa = 0; aa < ae.length; aa++)\r
+ {\r
+ anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(ae[aa].getDisplayCharacter(),\r
+ ae[aa].getDescription(),\r
+ ae[aa].getSecondaryStructure().charAt(0),\r
+ ae[aa].getValue());\r
+ }\r
+\r
+ jalview.datamodel.AlignmentAnnotation jaa = null;\r
+\r
+ if (an[i].getGraph())\r
+ {\r
+ jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),\r
+ an[i].getDescription(), anot, 0, 0,\r
+ jalview.datamodel.AlignmentAnnotation.BAR_GRAPH);\r
+ }\r
+ else\r
+ {\r
+ jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),\r
+ an[i].getDescription(), anot);\r
+ }\r
+\r
+ al.addAnnotation(jaa);\r
+ }\r
+ }\r
+\r
+\r
+ /////////////////////////////////\r
+ // LOAD VIEWPORT\r
+ Viewport[] views = jms.getViewport();\r
+ Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER\r
+\r
+ AlignFrame af = new AlignFrame(al);\r
+\r
+\r
+ // af.changeColour() );\r
+ /////////////////////////\r
+ //LOAD GROUPS\r
+ if (jms.getJGroupCount() > 0)\r
+ {\r
+ JGroup[] groups = jms.getJGroup();\r
+\r
+ for (int i = 0; i < groups.length; i++)\r
+ {\r
+ ColourSchemeI cs = null;\r
+\r
+ if (groups[i].getColour() != null)\r
+ {\r
+ if (groups[i].getColour().startsWith("ucs"))\r
+ {\r
+ cs = GetUserColourScheme(jms, groups[i].getColour());\r
+ }\r
+ else\r
+ {\r
+ cs = ColourSchemeProperty.getColour(al,\r
+ groups[i].getColour());\r
+ }\r
+\r
+ cs.setThreshold(groups[i].getPidThreshold(), true);\r
+ }\r
+\r
+ Vector seqs = new Vector();\r
+ int[] ids = groups[i].getSeq();\r
+\r
+ for (int s = 0; s < ids.length; s++)\r
+ {\r
+ seqs.addElement((jalview.datamodel.SequenceI) seqids.elementAt(\r
+ ids[s]));\r
+ }\r
+\r
+ jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(seqs,\r
+ groups[i].getName(), cs, groups[i].getDisplayBoxes(),\r
+ groups[i].getDisplayText(), groups[i].getColourText(),\r
+ groups[i].getStart(), groups[i].getEnd());\r
+\r
+ sg.setOutlineColour(new java.awt.Color(\r
+ groups[i].getOutlineColour()));\r
+\r
+ if (groups[i].getConsThreshold() != 0)\r
+ {\r
+ jalview.analysis.Conservation c = new jalview.analysis.Conservation("All",\r
+ ResidueProperties.propHash, 3, sg.sequences, 0,\r
+ sg.getWidth() - 1);\r
+ c.calculate();\r
+ c.verdict(false, 25);\r
+ sg.cs.setConservation(c);\r
+ }\r
+\r
+ al.addGroup(sg);\r
+ }\r
+ }\r
+\r
+\r
+\r
+ af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),\r
+ view.getHeight());\r
+ af.viewport.setStartRes(view.getStartRes());\r
+ af.viewport.setStartSeq(view.getStartSeq());\r
+ af.viewport.setShowAnnotation(view.getShowAnnotation());\r
+ af.viewport.showConservation = view.getShowConservation();\r
+ af.viewport.showQuality = view.getShowQuality();\r
+ af.viewport.showIdentity = view.getShowIdentity();\r
+ af.viewport.setAbovePIDThreshold(view.getPidSelected());\r
+ af.abovePIDThreshold.setSelected(view.getPidSelected());\r
+ af.viewport.setColourText(view.getShowColourText());\r
+ af.colourTextMenuItem.setSelected(view.getShowColourText());\r
+ af.viewport.setConservationSelected(view.getConservationSelected());\r
+ af.conservationMenuItem.setSelected(view.getConservationSelected());\r
+\r
+ af.viewport.setShowJVSuffix(view.getShowFullId());\r
+ af.seqLimits.setSelected(view.getShowFullId());\r
+\r
+ af.viewport.setFont(new java.awt.Font(view.getFontName(),\r
+ view.getFontStyle(), view.getFontSize()));\r
+ af.alignPanel.fontChanged();\r
+\r
+ af.viewport.setRenderGaps(view.getRenderGaps());\r
+ af.renderGapsMenuItem.setSelected(view.getRenderGaps());\r
+\r
+ af.viewport.setWrapAlignment(view.getWrapAlignment());\r
+ af.wrapMenuItem.setSelected(view.getWrapAlignment());\r
+\r
+ if (view.getWrapAlignment())\r
+ {\r
+ af.alignPanel.setWrapAlignment(view.getWrapAlignment());\r
+ }\r
+ else\r
+ {\r
+ af.annotationPanelMenuItem.setState(view.getShowAnnotation());\r
+ af.viewport.setShowAnnotation(view.getShowAnnotation());\r
+ af.alignPanel.setAnnotationVisible(view.getShowAnnotation());\r
+ }\r
+\r
+ af.viewport.setShowBoxes(view.getShowBoxes());\r
+ af.viewBoxesMenuItem.setSelected(view.getShowBoxes());\r
+ af.viewport.setShowText(view.getShowText());\r
+ af.viewTextMenuItem.setSelected(view.getShowText());\r
+\r
+ ColourSchemeI cs = null;\r
+\r
+ if (view.getBgColour() != null)\r
+ {\r
+ if (view.getBgColour().startsWith("ucs"))\r
+ {\r
+ cs = GetUserColourScheme(jms, view.getBgColour());\r
+ }\r
+ else\r
+ {\r
+ cs = ColourSchemeProperty.getColour(al, view.getBgColour());\r
+ }\r
+\r
+ if(cs!=null)\r
+ {\r
+ cs.setThreshold(view.getPidThreshold(), true);\r
+ cs.setConsensus(af.viewport.vconsensus);\r
+ }\r
+ }\r
+\r
+ af.setColourSelected(view.getBgColour());\r
+ af.viewport.setGlobalColourScheme(cs);\r
+ af.viewport.setColourAppliesToAllGroups(false);\r
+ af.changeColour(cs);\r
+ if (view.getConservationSelected() && cs!=null)\r
+ {\r
+ cs.setConservationInc(view.getConsThreshold());\r
+ }\r
+\r
+ af.viewport.setColourAppliesToAllGroups(true);\r
+\r
+ if (view.getShowSequenceFeatures())\r
+ {\r
+ af.viewport.showSequenceFeatures = true;\r
+ af.showSeqFeatures.setSelected(true);\r
+ }\r
+\r
+ if(jms.getFeatureSettings()!=null)\r
+ {\r
+ af.viewport.featuresDisplayed = new Hashtable();\r
+ String [] renderOrder = new String[jms.getFeatureSettings().getSettingCount()];\r
+ for(int fs=0; fs<jms.getFeatureSettings().getSettingCount(); fs++)\r
+ {\r
+ Setting setting = jms.getFeatureSettings().getSetting(fs);\r
+\r
+ af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(setting.getType(),\r
+ new java.awt.Color(setting.getColour()));\r
+\r
+ renderOrder[fs] = setting.getType();\r
+\r
+ if(setting.getDisplay())\r
+ af.viewport.featuresDisplayed.put(\r
+ setting.getType(), new Integer(setting.getColour()));\r
+ }\r
+ af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;\r
+ }\r
+\r
+\r
+ Desktop.addInternalFrame(af, view.getTitle(),\r
+ view.getWidth(), view.getHeight());\r
+\r
+ //LOAD TREES\r
+ ///////////////////////////////////////\r
+ if (jms.getTreeCount() > 0)\r
+ {\r
+ try\r
+ {\r
+ for (int t = 0; t < jms.getTreeCount(); t++)\r
+ {\r
+\r
+ Tree tree = jms.getTree(t);\r
+\r
+ TreePanel tp = af.ShowNewickTree(new jalview.io.NewickFile(\r
+ tree.getNewick()), tree.getTitle(),\r
+ tree.getWidth(), tree.getHeight(),\r
+ tree.getXpos(), tree.getYpos());\r
+\r
+ tp.fitToWindow.setState(tree.getFitToWindow());\r
+ tp.fitToWindow_actionPerformed(null);\r
+\r
+ if(tree.getFontName()!=null)\r
+ tp.setTreeFont(new java.awt.Font(tree.getFontName(),\r
+ tree.getFontStyle(),\r
+ tree.getFontSize()));\r
+ else\r
+ tp.setTreeFont(new java.awt.Font(view.getFontName(),\r
+ view.getFontStyle(),\r
+ tree.getFontSize()));\r
+\r
+ tp.showPlaceholders(tree.getMarkUnlinked());\r
+ tp.showBootstrap(tree.getShowBootstrap());\r
+ tp.showDistances(tree.getShowDistances());\r
+\r
+ tp.treeCanvas.threshold = tree.getThreshold();\r
+\r
+ if (tree.getCurrentTree())\r
+ af.viewport.setCurrentTree(tp.getTree());\r
+ }\r
+\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+\r
+ }\r
+\r
+ return af;\r
+ }\r
+}\r
+\r