package jalview.gui; import java.io.*; import java.util.*; import java.util.jar.*; import jalview.binding.*; import jalview.schemes.*; import javax.swing.JInternalFrame; 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(); 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(); for (int i = 0; i < frames.length; i++) { if (frames[i] instanceof AlignFrame) { AlignFrame af = (AlignFrame) frames[i]; String shortName = af.getTitle(); shortName = shortName.replace('/', '_'); shortName = shortName.replace('\\', '_'); int count=1; while( shortNames.contains(shortName) ) { if(shortName.endsWith("_"+(count-1))) shortName = shortName.substring(0, shortName.lastIndexOf("_")); shortName = shortName.concat("_"+count); count++; } shortNames.addElement(shortName); if(!shortName.endsWith(".xml")) shortName = shortName+".xml"; SaveState( af, creation, shortName, jout, out); } } out.close(); jout.close(); } 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")); SaveState(af, System.currentTimeMillis(), fileName, jout, out); out.close(); jout.close(); }catch(Exception ex){} } public static void SaveState( AlignFrame af, long timeStamp, String fileName, JarOutputStream jout, PrintWriter out) { Vector seqids = new Vector(); AlignViewport av = af.viewport; JalviewModel object = new JalviewModel(); object.setVamsasModel( new VamsasModel() ); object.setCreationDate( new java.util.Date(timeStamp) ); jalview.datamodel.AlignmentI jal = af.viewport.alignment; SequenceSet vamsasSet = new SequenceSet(); Sequence vamsasSeq; JalviewModelSequence jms = new JalviewModelSequence(); vamsasSet.setGapChar(jal.getGapCharacter()+""); JSeq jseq; //SAVE SEQUENCES int id = 0; for(int i=0; i0) { JGroup[] groups = jms.getJGroup(); for (int i = 0; i < groups.length; i++) { ColourSchemeI 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();} } } }