X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FJalview2XML.java;h=28840e7117691a845ce9c8cd42344030669fdaa8;hb=dea32f71ff7f8a80cc8494864b6605921d81fafa;hp=89a7bfc5aaf51fa2ca3b946eaeabfaab956dae68;hpb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;p=jalview.git diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 89a7bfc..28840e7 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -1,590 +1,824 @@ /* -* 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.io.*; + +import jalview.schemes.*; + import java.io.*; + +import java.net.*; + import java.util.*; + import java.util.jar.*; +import javax.swing.*; + import jalview.binding.*; -import jalview.schemes.*; -import javax.swing.JInternalFrame; -import java.net.URL; -import jalview.io.SequenceFeatureFetcher; +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ public class Jalview2XML { + // SAVES SEVERAL ALIGNEMENT WINDOWS TO SAME JARFILE + public static 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 == null) { - if (frames[i] instanceof AlignFrame) - { - AlignFrame af = (AlignFrame) frames[i]; + return; + } + + try + { + FileOutputStream fos = new FileOutputStream(statefile); + JarOutputStream jout = new JarOutputStream(fos); - String shortName = af.getTitle(); + //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS + //////////////////////////////////////////////////// + PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, + "UTF-8")); - if(shortName.indexOf(File.separatorChar)>-1) - shortName = shortName.substring( - shortName.lastIndexOf(File.separatorChar)+1); + Vector shortNames = new Vector(); - int count=1; - while( shortNames.contains(shortName) ) + //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]; - shortName = shortName.concat("_"+count); - count++; - } - shortNames.addElement(shortName); + String shortName = af.getTitle(); - if(!shortName.endsWith(".xml")) - shortName = shortName+".xml"; + if (shortName.indexOf(File.separatorChar) > -1) + { + shortName = shortName.substring(shortName.lastIndexOf( + File.separatorChar) + 1); + } - SaveState( af, creation, shortName, jout, out); - } - } - out.close(); - jout.close(); - } - catch(Exception ex){ex.printStackTrace();} - } + int count = 1; - // 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")); + while (shortNames.contains(shortName)) + { + if (shortName.endsWith("_" + (count - 1))) + { + shortName = shortName.substring(0, + shortName.lastIndexOf("_")); + } - SaveState(af, System.currentTimeMillis(), fileName, jout, out); - out.close(); - jout.close(); - }catch(Exception ex){} - } + shortName = shortName.concat("_" + count); + count++; + } - public static void SaveState( AlignFrame af, long timeStamp, - String fileName, JarOutputStream jout, PrintWriter out) - { + shortNames.addElement(shortName); - Vector seqids = new Vector(); - Vector userColours = new Vector(); + if (!shortName.endsWith(".xml")) + { + shortName = shortName + ".xml"; + } - AlignViewport av = af.viewport; + SaveState(af, creation, shortName, jout, out); + } + } - JalviewModel object = new JalviewModel(); - object.setVamsasModel( new VamsasModel() ); + out.close(); + jout.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } - object.setCreationDate( new java.util.Date(timeStamp) ); + // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW + public static void SaveAlignment(AlignFrame af, String jarFile, + String fileName) + { + try + { + FileOutputStream fos = new FileOutputStream(jarFile); + JarOutputStream jout = new JarOutputStream(fos); - jalview.datamodel.AlignmentI jal = af.viewport.alignment; + //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS + //////////////////////////////////////////////////// + PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, + "UTF-8")); - SequenceSet vamsasSet = new SequenceSet(); - Sequence vamsasSeq; - JalviewModelSequence jms = new JalviewModelSequence(); + SaveState(af, System.currentTimeMillis(), fileName, jout, out); + out.close(); + jout.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } - vamsasSet.setGapChar(jal.getGapCharacter()+""); + /** + * DOCUMENT ME! + * + * @param af DOCUMENT ME! + * @param timeStamp DOCUMENT ME! + * @param fileName DOCUMENT ME! + * @param jout DOCUMENT ME! + * @param out DOCUMENT ME! + */ + public static void SaveState(AlignFrame af, long timeStamp, + String fileName, JarOutputStream jout, PrintWriter out) + { + Vector seqids = new Vector(); + Vector userColours = new Vector(); - JSeq jseq; + AlignViewport av = af.viewport; + JalviewModel object = new JalviewModel(); + object.setVamsasModel(new jalview.binding.VamsasModel()); - //SAVE SEQUENCES - int id = 0; - for(int i=0; i 0) { - InputStreamReader in = new InputStreamReader(jin, "UTF-8"); - object = (JalviewModel) object.unmarshal(in); - LoadFromObject(object); - entryCount++; + 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()); + } + + cs.setThreshold(groups[i].getPidThreshold(), true); + } + + Vector seqs = new Vector(); + int[] ids = groups[i].getSeq(); + + for (int s = 0; s < ids.length; s++) + { + seqs.addElement((jalview.datamodel.SequenceI) seqids.elementAt( + ids[s])); + } + + jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(seqs, + 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())); + + if (groups[i].getConsThreshold() != 0) + { + jalview.analysis.Conservation c = new jalview.analysis.Conservation("All", + ResidueProperties.propHash, 3, sg.sequences, 0, + sg.getWidth() - 1); + c.calculate(); + c.verdict(false, 25); + sg.cs.setConservation(c); + } + + al.addGroup(sg); + } } - }while(jarentry!=null); - } - catch(Exception ex) - { System.err.println("Exception whilst loading jalview XML file : "+ex+"\n"); - ex.printStackTrace(); return; } - - } - - static void LoadFromObject(JalviewModel object) - { - Vector seqids = new Vector(); - SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0); - Sequence [] vamsasSeq = vamsasSet.getSequence(); - - JalviewModelSequence jms = object.getJalviewModelSequence(); - ////////////////////////////////// - //LOAD SEQUENCES - jalview.datamodel.Sequence [] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length]; - JSeq [] JSEQ = object.getJalviewModelSequence().getJSeq(); - for(int i=0; i0) - { - 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; s 0) + { + try + { + for (int t = 0; t < jms.getTreeCount(); t++) + { - if (cs instanceof ResidueColourScheme) - ( (ResidueColourScheme) cs).setThreshold(view.getPidThreshold()); - else if (cs instanceof ScoreColourScheme) - ( (ScoreColourScheme) cs).setThreshold(view.getPidThreshold()); + Tree tree = jms.getTree(t); - } - af.viewport.setGlobalColourScheme( cs ); + 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); - af.viewport.setColourAppliesToAllGroups(false); - af.changeColour(af.viewport.getGlobalColourScheme()); - af.viewport.setColourAppliesToAllGroups(true); + 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())); - System.out.println(view.getShowSequenceFeatures()); - if( view.getShowSequenceFeatures() ); - { - SequenceFeatureFetcher sft = new SequenceFeatureFetcher(al, af.alignPanel); - } + tp.showPlaceholders(tree.getMarkUnlinked()); + tp.showBootstrap(tree.getShowBootstrap()); + tp.showDistances(tree.getShowDistances()); - //LOAD TREES - THIS RELEASE ONLY ALLOWS 1 TREE - if(object.getVamsasModel().getTreeCount()>0) - { - try{ - af.ShowNewickTree(new jalview.io.NewickFile( - (String)object.getVamsasModel().getTree(0)), "Tree"); - }catch(Exception ex){ex.printStackTrace();} - } + tp.treeCanvas.threshold = tree.getThreshold(); - } -} + if (tree.getCurrentTree()) + af.viewport.setCurrentTree(tp.getTree()); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + return af; + } +}