X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FJalview2XML.java;h=95912fe7125cb13b6c667fc3a26f4fbffeecf2e6;hb=3596077c79b7aa2051b9aaa978481004b513101c;hp=89a7bfc5aaf51fa2ca3b946eaeabfaab956dae68;hpb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;p=jalview.git diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 89a7bfc..95912fe 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -1,590 +1,1389 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ - + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ package jalview.gui; + +import jalview.schemes.*; + +import jalview.gui.*; + import java.io.*; + +import java.net.*; + import java.util.*; + import java.util.jar.*; -import jalview.binding.*; -import jalview.schemes.*; -import javax.swing.JInternalFrame; -import java.net.URL; -import jalview.io.SequenceFeatureFetcher; +import javax.swing.*; +import org.exolab.castor.xml.*; +import jalview.schemabinding.version2.*; + + + + +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ public class Jalview2XML { + // SAVES SEVERAL ALIGNEMENT WINDOWS TO SAME JARFILE + public void SaveState(File statefile) + { + long creation = System.currentTimeMillis(); + JInternalFrame[] frames = Desktop.desktop.getAllFrames(); - // SAVES SEVERAL ALIGNEMENT WINDOWS TO SAME JARFILE - public static void SaveState(File statefile) - { - long creation = System.currentTimeMillis(); - JInternalFrame[] frames = Desktop.desktop.getAllFrames(); - if(frames==null) - return; - - try{ - FileOutputStream fos = new FileOutputStream(statefile); - JarOutputStream jout = new JarOutputStream(fos); - //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS - //////////////////////////////////////////////////// - PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, "UTF-8")); - - Vector shortNames = new Vector(); - //REVERSE ORDER - for (int i = frames.length-1; i > -1; i--) - { - if (frames[i] instanceof AlignFrame) - { - AlignFrame af = (AlignFrame) frames[i]; + if (frames == null) + { + return; + } - String shortName = af.getTitle(); + try + { + FileOutputStream fos = new FileOutputStream(statefile); + JarOutputStream jout = new JarOutputStream(fos); - if(shortName.indexOf(File.separatorChar)>-1) - shortName = shortName.substring( - shortName.lastIndexOf(File.separatorChar)+1); + //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS + //////////////////////////////////////////////////// + PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, + "UTF-8")); - int count=1; - while( shortNames.contains(shortName) ) + Vector shortNames = new Vector(); + + //REVERSE ORDER + for (int i = frames.length - 1; i > -1; i--) { - if(shortName.endsWith("_"+(count-1))) - shortName = shortName.substring(0, shortName.lastIndexOf("_")); + if (frames[i] instanceof AlignFrame) + { + AlignFrame af = (AlignFrame) frames[i]; + + String shortName = af.getTitle(); + + if (shortName.indexOf(File.separatorChar) > -1) + { + shortName = shortName.substring(shortName.lastIndexOf( + File.separatorChar) + 1); + } + + int count = 1; + + while (shortNames.contains(shortName)) + { + if (shortName.endsWith("_" + (count - 1))) + { + shortName = shortName.substring(0, + shortName.lastIndexOf("_")); + } - shortName = shortName.concat("_"+count); - count++; + shortName = shortName.concat("_" + count); + count++; + } + + shortNames.addElement(shortName); + + if (!shortName.endsWith(".xml")) + { + shortName = shortName + ".xml"; + } + + SaveState(af, creation, shortName, jout, out); + } } - shortNames.addElement(shortName); - if(!shortName.endsWith(".xml")) - shortName = shortName+".xml"; + out.close(); + jout.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW + public void SaveAlignment(AlignFrame af, String jarFile, + String fileName) + { + try + { + FileOutputStream fos = new FileOutputStream(jarFile); + JarOutputStream jout = new JarOutputStream(fos); - SaveState( af, creation, shortName, jout, out); - } + //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS + //////////////////////////////////////////////////// + PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, + "UTF-8")); + + SaveState(af, System.currentTimeMillis(), fileName, jout, out); + out.close(); + jout.close(); } - out.close(); - jout.close(); - } - catch(Exception ex){ex.printStackTrace();} - } + catch (Exception ex) + { + ex.printStackTrace(); + } + } - // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW - public static void SaveState( AlignFrame af, String jarFile, String fileName) - { - try{ - FileOutputStream fos = new FileOutputStream(jarFile); - JarOutputStream jout = new JarOutputStream(fos); - //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS - //////////////////////////////////////////////////// - PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, "UTF-8")); + /** + * DOCUMENT ME! + * + * @param af DOCUMENT ME! + * @param timeStamp DOCUMENT ME! + * @param fileName DOCUMENT ME! + * @param jout DOCUMENT ME! + * @param out DOCUMENT ME! + */ + public void SaveState(AlignFrame af, long timeStamp, + String fileName, JarOutputStream jout, PrintWriter out) + { + Vector seqids = new Vector(); + Vector userColours = new Vector(); - SaveState(af, System.currentTimeMillis(), fileName, jout, out); - out.close(); - jout.close(); - }catch(Exception ex){} - } + AlignViewport av = af.viewport; - public static void SaveState( AlignFrame af, long timeStamp, - String fileName, JarOutputStream jout, PrintWriter out) - { + JalviewModel object = new JalviewModel(); + object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel()); - Vector seqids = new Vector(); - Vector userColours = new Vector(); + object.setCreationDate(new java.util.Date(timeStamp)); + object.setVersion(jalview.bin.Cache.getProperty("VERSION")); - AlignViewport av = af.viewport; + jalview.datamodel.AlignmentI jal = af.viewport.alignment; + jalview.datamodel.AlignmentI jalhidden = null; - JalviewModel object = new JalviewModel(); - object.setVamsasModel( new VamsasModel() ); + if(av.hasHiddenRows) + { + jalhidden = jal; + jal = jal.getHiddenSequences().getFullAlignment(); + } - object.setCreationDate( new java.util.Date(timeStamp) ); - jalview.datamodel.AlignmentI jal = af.viewport.alignment; + SequenceSet vamsasSet = new SequenceSet(); + Sequence vamsasSeq; + JalviewModelSequence jms = new JalviewModelSequence(); - SequenceSet vamsasSet = new SequenceSet(); - Sequence vamsasSeq; - JalviewModelSequence jms = new JalviewModelSequence(); + vamsasSet.setGapChar(jal.getGapCharacter() + ""); - vamsasSet.setGapChar(jal.getGapCharacter()+""); + JSeq jseq; + Vector pdbfiles = null; - JSeq jseq; + //SAVE SEQUENCES + int id = 0; + for (int i = 0; i < jal.getHeight(); i++) + { + seqids.add(jal.getSequenceAt(i)); + vamsasSeq = new Sequence(); + vamsasSeq.setId(id + ""); + vamsasSeq.setName(jal.getSequenceAt(i).getName()); + vamsasSeq.setSequence(jal.getSequenceAt(i).getSequence()); + vamsasSeq.setDescription(jal.getSequenceAt(i).getDescription()); + + if(jal.getSequenceAt(i).getDatasetSequence().getDBRef()!=null) + { + jalview.datamodel.DBRefEntry [] dbrefs = + jal.getSequenceAt(i).getDatasetSequence().getDBRef(); + + for(int d=0; d0) + { + an.setGraph(true); + an.setGraphType(aa[i].graph); + an.setGraphGroup(aa[i].graphGroup); + if(aa[i].getThreshold()!=null) + { + ThresholdLine line = new ThresholdLine(); + line.setLabel(aa[i].getThreshold().label); + line.setValue(aa[i].getThreshold().value); + line.setColour(aa[i].getThreshold().colour.getRGB()); + an.setThresholdLine(line); + } + } + else + an.setGraph(false); + + an.setLabel(aa[i].label); + + AnnotationElement ae; + + for (int a = 0; a < aa[i].annotations.length; a++) + { + if ((aa[i] == null) || (aa[i].annotations[a] == null)) + { + continue; + } + + ae = new AnnotationElement(); + ae.setDescription(aa[i].annotations[a].description); + ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter); + ae.setValue(aa[i].annotations[a].value); + ae.setPosition(a); + ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure + + ""); + + if(aa[i].annotations[a].colour!=java.awt.Color.black) + ae.setColour(aa[i].annotations[a].colour.getRGB()); + + an.addAnnotationElement(ae); + } + + vamsasSet.addAnnotation(an); + } + } - jalview.datamodel.AlignmentAnnotation [] aa = jal.getAlignmentAnnotation(); - for(int i=0; i 0) + { + Features[] features = JSEQ[i].getFeatures(); + for (int f = 0; f < features.length; f++) + { + jalview.datamodel.SequenceFeature sf + = new jalview.datamodel.SequenceFeature(features[f].getType(), + features[f].getDescription(), features[f].getStatus(), + features[f].getBegin(), features[f].getEnd(), + features[f].getFeatureGroup()); - public static void LoadJalviewAlign(String file) - { - JalviewModel object = new JalviewModel(); - try{ - //UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING + al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf); + } + } + if (JSEQ[i].getPdbidsCount() > 0) + { + Pdbids[] ids = JSEQ[i].getPdbids(); + for (int p = 0; p < ids.length; p++) + { + jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry(); + entry.setId(ids[p].getId()); + entry.setType(ids[p].getType()); + if (ids[p].getFile() != null) + { + if (!pdbloaded.containsKey(ids[p].getFile())) + { + String tmppdb = loadPDBFile(file, ids[p].getId()); + entry.setFile(tmppdb); + pdbloaded.put(ids[p].getId(), tmppdb); + } + else + entry.setFile(pdbloaded.get(ids[p].getId()).toString()); + } + + al.getSequenceAt(i).getDatasetSequence().addPDBId(entry); + } + } + if(vamsasSeq[i].getDBRefCount()>0) + { + for(int d=0; d 0) + { + JGroup[] groups = jms.getJGroup(); - jalview.datamodel.AlignmentAnnotation jaa = null; - if(an[i].getGraph()) - jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(), - an[i].getDescription(), anot, - 0,0,1); - else - jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(), - an[i].getDescription(), anot); - al.addAnnotation(jaa); - } - } - - ///////////////////////////////// - // LOAD VIEWPORT - Viewport[] views = jms.getViewport(); - Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER - - AlignFrame af = new AlignFrame(al); - // af.changeColour() ); - - ///////////////////////// - //LOAD GROUPS - if (jms.getJGroupCount()>0) - { - JGroup[] groups = jms.getJGroup(); - for (int i = 0; i < groups.length; i++) - { - ColourSchemeI cs=null; - if(groups[i].getColour()!=null) - { - if (groups[i].getColour().startsWith("ucs")) - cs = GetUserColourScheme(jms, groups[i].getColour()); - else - cs = ColourSchemeProperty.getColour(al, groups[i].getColour()); - - if (cs instanceof ResidueColourScheme) - ( (ResidueColourScheme) cs).setThreshold(groups[i].getPidThreshold()); - else if (cs instanceof ScoreColourScheme) - ( (ScoreColourScheme) cs).setThreshold(groups[i].getPidThreshold()); - } - - jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup - (groups[i].getName(), - cs, - groups[i].getDisplayBoxes(), - groups[i].getDisplayText(), - groups[i].getColourText(), - groups[i].getStart(), - groups[i].getEnd()) ; - sg.setOutlineColour( new java.awt.Color(groups[i].getOutlineColour())); - int [] ids = groups[i].getSeq(); - for(int s=0; s0) - { - try{ - af.ShowNewickTree(new jalview.io.NewickFile( - (String)object.getVamsasModel().getTree(0)), "Tree"); - }catch(Exception ex){ex.printStackTrace();} - } + af.alignPanel.setWrapAlignment(view.getWrapAlignment()); - } -} + af.annotationPanelMenuItem.setState(view.getShowAnnotation()); + af.viewport.setShowAnnotation(view.getShowAnnotation()); + af.alignPanel.setAnnotationVisible(view.getShowAnnotation()); + + af.viewport.setShowBoxes(view.getShowBoxes()); + af.viewBoxesMenuItem.setSelected(view.getShowBoxes()); + af.viewport.setShowText(view.getShowText()); + af.viewTextMenuItem.setSelected(view.getShowText()); + + ColourSchemeI cs = null; + + if (view.getBgColour() != null) + { + if (view.getBgColour().startsWith("ucs")) + { + cs = GetUserColourScheme(jms, view.getBgColour()); + } + else if(view.getBgColour().startsWith("Annotation")) + { + //int find annotation + for (int i = 0; i < af.viewport.alignment.getAlignmentAnnotation().length; i++) + { + if (af.viewport.alignment.getAlignmentAnnotation()[i].label. + equals(view.getAnnotationColours().getAnnotation())) + { + if (af.viewport.alignment.getAlignmentAnnotation()[i]. + getThreshold() == null) + { + af.viewport.alignment.getAlignmentAnnotation()[i]. + setThreshold( + new jalview.datamodel.GraphLine( + view.getAnnotationColours().getThreshold(), + "Threshold", java.awt.Color.black) + + ); + } + + + if (view.getAnnotationColours().getColourScheme().equals( + "None")) + { + cs = new AnnotationColourGradient( + af.viewport.alignment.getAlignmentAnnotation()[i], + new java.awt.Color(view.getAnnotationColours(). + getMinColour()), + new java.awt.Color(view.getAnnotationColours(). + getMaxColour()), + view.getAnnotationColours().getAboveThreshold()); + } + else if (view.getAnnotationColours().getColourScheme(). + startsWith("ucs")) + { + cs = new AnnotationColourGradient( + af.viewport.alignment.getAlignmentAnnotation()[i], + GetUserColourScheme(jms, view.getAnnotationColours(). + getColourScheme()), + view.getAnnotationColours().getAboveThreshold() + ); + } + else + { + cs = new AnnotationColourGradient( + af.viewport.alignment.getAlignmentAnnotation()[i], + ColourSchemeProperty.getColour(al, + view.getAnnotationColours().getColourScheme()), + view.getAnnotationColours().getAboveThreshold() + ); + } + + // Also use these settings for all the groups + if (al.getGroups() != null) + for (int g = 0; g < al.getGroups().size(); g++) + { + jalview.datamodel.SequenceGroup sg + = (jalview.datamodel.SequenceGroup)al.getGroups().elementAt(g); + + if(sg.cs == null) + continue; + + + /* if (view.getAnnotationColours().getColourScheme().equals("None")) + { + sg.cs = new AnnotationColourGradient( + af.viewport.alignment.getAlignmentAnnotation()[i], + new java.awt.Color(view.getAnnotationColours(). + getMinColour()), + new java.awt.Color(view.getAnnotationColours(). + getMaxColour()), + view.getAnnotationColours().getAboveThreshold()); + } + else*/ + { + sg.cs = new AnnotationColourGradient( + af.viewport.alignment.getAlignmentAnnotation()[i], + sg.cs, + view.getAnnotationColours().getAboveThreshold() + ); + } + + } + + + break; + } + + } + } + else + { + cs = ColourSchemeProperty.getColour(al, view.getBgColour()); + } + + if(cs!=null) + { + cs.setThreshold(view.getPidThreshold(), true); + cs.setConsensus(af.viewport.vconsensus); + } + } + + af.setColourSelected(view.getBgColour()); + af.viewport.setGlobalColourScheme(cs); + af.viewport.setColourAppliesToAllGroups(false); + af.changeColour(cs); + if (view.getConservationSelected() && cs!=null) + { + cs.setConservationInc(view.getConsThreshold()); + } + + af.viewport.setColourAppliesToAllGroups(true); + + if (view.getShowSequenceFeatures()) + { + af.viewport.showSequenceFeatures = true; + af.showSeqFeatures.setSelected(true); + } + + if(jms.getFeatureSettings()!=null) + { + af.viewport.featuresDisplayed = new Hashtable(); + String [] renderOrder = new String[jms.getFeatureSettings().getSettingCount()]; + for(int fs=0; fs 0) + { + for (int c = 0; c < view.getHiddenColumnsCount(); c++) + { + af.viewport.hideColumns( + view.getHiddenColumns(c).getStart(), + view.getHiddenColumns(c).getEnd()+1 + ); + } + } + + + Desktop.addInternalFrame(af, view.getTitle(), + view.getWidth(), view.getHeight()); + + //LOAD TREES + /////////////////////////////////////// + if (jms.getTreeCount() > 0) + { + try + { + for (int t = 0; t < jms.getTreeCount(); t++) + { + + Tree tree = jms.getTree(t); + + TreePanel tp = af.ShowNewickTree(new jalview.io.NewickFile( + tree.getNewick()), tree.getTitle(), + tree.getWidth(), tree.getHeight(), + tree.getXpos(), tree.getYpos()); + + tp.fitToWindow.setState(tree.getFitToWindow()); + tp.fitToWindow_actionPerformed(null); + + if(tree.getFontName()!=null) + tp.setTreeFont(new java.awt.Font(tree.getFontName(), + tree.getFontStyle(), + tree.getFontSize())); + else + tp.setTreeFont(new java.awt.Font(view.getFontName(), + view.getFontStyle(), + tree.getFontSize())); + + tp.showPlaceholders(tree.getMarkUnlinked()); + tp.showBootstrap(tree.getShowBootstrap()); + tp.showDistances(tree.getShowDistances()); + + tp.treeCanvas.threshold = tree.getThreshold(); + if (tree.getCurrentTree()) + af.viewport.setCurrentTree(tp.getTree()); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + + return af; + } +}