X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FJalview2XML.java;h=b8466f0872e22923a9c7688fbf447c40add60d08;hb=61505ac1511435b067e647f5c7c9050e5c1eef41;hp=bfd97f03b7c0ec5235a91b091db2231dc6286780;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index bfd97f0..b8466f0 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -18,694 +18,1445 @@ */ package jalview.gui; + +import jalview.schemes.*; + +import jalview.gui.*; + import java.io.*; + import java.net.*; + import java.util.*; + import java.util.jar.*; import javax.swing.*; -import jalview.binding.*; -import jalview.io.*; -import jalview.schemes.*; +import org.exolab.castor.xml.*; -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(); +import jalview.schemabinding.version2.*; - 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(); +/** + * 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(); - //REVERSE ORDER - for (int i = frames.length - 1; i > -1; i--) - { - if (frames[i] instanceof AlignFrame) + if (frames == null) { - AlignFrame af = (AlignFrame) frames[i]; + 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; + Vector shortNames = new Vector(); - while (shortNames.contains(shortName)) - { - if (shortName.endsWith("_" + (count - 1))) + //REVERSE ORDER + for (int i = frames.length - 1; i > -1; i--) { - shortName = shortName.substring(0, - shortName.lastIndexOf("_")); - } + if (frames[i] instanceof AlignFrame) + { + AlignFrame af = (AlignFrame) frames[i]; - shortName = shortName.concat("_" + count); - count++; - } + String shortName = af.getTitle(); - shortNames.addElement(shortName); + if (shortName.indexOf(File.separatorChar) > -1) + { + shortName = shortName.substring(shortName.lastIndexOf( + File.separatorChar) + 1); + } - if (!shortName.endsWith(".xml")) - { - shortName = shortName + ".xml"; - } + int count = 1; - SaveState(af, creation, shortName, jout, out); - } - } + while (shortNames.contains(shortName)) + { + if (shortName.endsWith("_" + (count - 1))) + { + shortName = shortName.substring(0, + shortName.lastIndexOf("_")); + } - out.close(); - jout.close(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } + shortName = shortName.concat("_" + count); + count++; + } - // 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); + shortNames.addElement(shortName); + + if (!shortName.endsWith(".xml")) + { + shortName = shortName + ".xml"; + } - //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS - //////////////////////////////////////////////////// - PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, - "UTF-8")); + SaveState(af, creation, shortName, jout, out); + } + } - SaveState(af, System.currentTimeMillis(), fileName, jout, out); - out.close(); - jout.close(); + out.close(); + jout.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } } - catch (Exception ex) + + // 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); - public static void SaveState(AlignFrame af, long timeStamp, - String fileName, JarOutputStream jout, - PrintWriter out) - { - Vector seqids = new Vector(); - Vector userColours = new Vector(); + //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS + //////////////////////////////////////////////////// + PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, + "UTF-8")); - AlignViewport av = af.viewport; + SaveState(af, System.currentTimeMillis(), fileName, jout, out); + out.close(); + jout.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } - JalviewModel object = new JalviewModel(); - object.setVamsasModel(new VamsasModel()); + /** + * 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(); - object.setCreationDate(new java.util.Date(timeStamp)); + AlignViewport av = af.viewport; - jalview.datamodel.AlignmentI jal = af.viewport.alignment; + JalviewModel object = new JalviewModel(); + object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel()); - SequenceSet vamsasSet = new SequenceSet(); - Sequence vamsasSeq; - JalviewModelSequence jms = new JalviewModelSequence(); + object.setCreationDate(new java.util.Date(timeStamp)); + object.setVersion(jalview.bin.Cache.getProperty("VERSION")); - vamsasSet.setGapChar(jal.getGapCharacter() + ""); + jalview.datamodel.AlignmentI jal = af.viewport.alignment; + jalview.datamodel.AlignmentI jalhidden = null; - JSeq jseq; + if(av.hasHiddenRows) + { + jalhidden = jal; + jal = jal.getHiddenSequences().getFullAlignment(); + } - //SAVE SEQUENCES - int id = 0; - for (int i = 0; i < jal.getHeight(); i++) - { - seqids.add(jal.getSequenceAt(i)); + SequenceSet vamsasSet = new SequenceSet(); + Sequence vamsasSeq; + JalviewModelSequence jms = new JalviewModelSequence(); - vamsasSeq = new Sequence(); - vamsasSeq.setId(id + ""); - vamsasSeq.setName(jal.getSequenceAt(i).getName()); - vamsasSeq.setSequence(jal.getSequenceAt(i).getSequence()); + vamsasSet.setGapChar(jal.getGapCharacter() + ""); - jseq = new JSeq(); - jseq.setStart(jal.getSequenceAt(i).getStart()); - jseq.setEnd(jal.getSequenceAt(i).getEnd()); + JSeq jseq; + Vector pdbfiles = null; - jseq.setColour(jal.getSequenceAt(i).getColor().getRGB()); + //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); + } } - vamsasSet.addAnnotation(an); - } - } + //SAVE GROUPS + if (jal.getGroups() != null) + { + JGroup[] groups = new JGroup[jal.getGroups().size()]; - //SAVE GROUPS - if (jal.getGroups() != null) - { - JGroup[] groups = new JGroup[jal.getGroups().size()]; + for (int i = 0; i < groups.length; i++) + { + groups[i] = new JGroup(); + + jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) jal.getGroups() + .elementAt(i); + groups[i].setStart(sg.getStartRes()); + groups[i].setEnd(sg.getEndRes()); + groups[i].setName(sg.getName()); + if(sg.cs!=null) + { + if (sg.cs.conservationApplied()) + { + groups[i].setConsThreshold(sg.cs.getConservationInc()); + + if (sg.cs instanceof jalview.schemes.UserColourScheme) + { + groups[i].setColour(SetUserColourScheme(sg.cs, + userColours, + jms)); + } + else + { + groups[i].setColour(ColourSchemeProperty.getColourName(sg. + cs)); + } + } + else if(sg.cs instanceof jalview.schemes.AnnotationColourGradient) + { + groups[i].setColour( + ColourSchemeProperty.getColourName( + ( (jalview.schemes.AnnotationColourGradient) sg.cs).getBaseColour())); + } + else if (sg.cs instanceof jalview.schemes.UserColourScheme) + { + groups[i].setColour(SetUserColourScheme(sg.cs, userColours, + jms)); + } + else + { + groups[i].setColour(ColourSchemeProperty.getColourName( + sg.cs)); + } + + groups[i].setPidThreshold(sg.cs.getThreshold()); + } + + groups[i].setOutlineColour(sg.getOutlineColour().getRGB()); + groups[i].setDisplayBoxes(sg.getDisplayBoxes()); + groups[i].setDisplayText(sg.getDisplayText()); + groups[i].setColourText(sg.getColourText()); + + for (int s = 0; s < sg.getSize(false); s++) + { + jalview.datamodel.Sequence seq = (jalview.datamodel.Sequence) sg.getSequenceAt(s); + int index = seqids.indexOf(seq); + groups[i].addSeq(index); + } + } + + jms.setJGroup(groups); + } - for (int i = 0; i < groups.length; i++) - { - groups[i] = new JGroup(); - jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) - jal.getGroups() - .elementAt(i); - groups[i].setStart(sg.getStartRes()); - groups[i].setEnd(sg.getEndRes()); - groups[i].setName(sg.getName()); + ///////////SAVE VIEWPORT + Viewport view = new Viewport(); + view.setTitle(af.getTitle()); + view.setXpos(af.getX()); + view.setYpos(af.getY()); + view.setWidth(af.getWidth()); + view.setHeight(af.getHeight()); + view.setStartRes(av.startRes); + view.setStartSeq(av.startSeq); - if (sg.cs instanceof ConservationColourScheme) + if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme) { - groups[i].setConsThreshold( ( (ConservationColourScheme) sg.cs).inc); + view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(), + userColours, jms)); } - - if (sg.cs instanceof ResidueColourScheme) + else if(av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient) { - groups[i].setPidThreshold( ( (ResidueColourScheme) sg.cs). - getThreshold()); + jalview.schemes.AnnotationColourGradient acg + = (jalview.schemes.AnnotationColourGradient)av.getGlobalColourScheme(); + + AnnotationColours ac = new AnnotationColours(); + ac.setAboveThreshold(acg.getAboveThreshold()); + ac.setThreshold(acg.getAnnotationThreshold()); + ac.setAnnotation(acg.getAnnotation()); + if(acg.getBaseColour() instanceof jalview.schemes.UserColourScheme) + ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(), + userColours, jms)); + else + ac.setColourScheme(ColourSchemeProperty.getColourName(acg.getBaseColour())); + + ac.setMaxColour(acg.getMaxColour().getRGB()); + ac.setMinColour(acg.getMinColour().getRGB()); + view.setAnnotationColours(ac); + view.setBgColour("AnnotationColourGradient"); } - else if (sg.cs instanceof ScoreColourScheme) + else { - groups[i].setPidThreshold( ( (ScoreColourScheme) sg.cs).getThreshold()); + view.setBgColour(ColourSchemeProperty.getColourName( + av.getGlobalColourScheme())); } - if (sg.cs instanceof jalview.schemes.UserColourScheme) + ColourSchemeI cs = av.getGlobalColourScheme(); + + if(cs!=null) { - groups[i].setColour(SetUserColourScheme(sg.cs, userColours, - jms)); + if (cs.conservationApplied()) + { + view.setConsThreshold(cs.getConservationInc()); + if (cs instanceof jalview.schemes.UserColourScheme) + view.setBgColour(SetUserColourScheme(cs, userColours, jms)); + } + + if (cs instanceof ResidueColourScheme) + { + view.setPidThreshold(cs.getThreshold()); + } } - else + + view.setConservationSelected(av.getConservationSelected()); + view.setPidSelected(av.getAbovePIDThreshold()); + view.setFontName(av.font.getName()); + view.setFontSize(av.font.getSize()); + view.setFontStyle(av.font.getStyle()); + view.setRenderGaps(av.renderGaps); + view.setShowAnnotation(av.getShowAnnotation()); + view.setShowBoxes(av.getShowBoxes()); + view.setShowColourText(av.getColourText()); + view.setShowConservation(av.showConservation); + view.setShowFullId(av.getShowJVSuffix()); + view.setShowIdentity(av.showIdentity); + view.setShowQuality(av.showQuality); + view.setShowSequenceFeatures(av.showSequenceFeatures); + view.setShowText(av.getShowText()); + view.setWrapAlignment(av.getWrapAlignment()); + + if(av.featuresDisplayed!=null) { - groups[i].setColour(ColourSchemeProperty.getColourName( - sg.cs)); - } + jalview.schemabinding.version2.FeatureSettings fs + = new jalview.schemabinding.version2.FeatureSettings(); + + String [] renderOrder = + af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder; + + Vector settingsAdded = new Vector(); + for(int ro=0; ro 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()); + + sf.setScore(features[f].getScore()); + for(int od=0; od 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) { - jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(), - an[i].getDescription(), anot); + 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!=null) + 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.getSequences(false), 0, + sg.getWidth() - 1); + c.calculate(); + c.verdict(false, 25); + sg.cs.setConservation(c); + } + + al.addGroup(sg); + } } - al.addAnnotation(jaa); - } - } - ///////////////////////////////// - // LOAD VIEWPORT - Viewport[] views = jms.getViewport(); - Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER + ///////////////////////////////// + // 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(); + AlignFrame af = new AlignFrame(al); - for (int i = 0; i < groups.length; i++) - { - ColourSchemeI cs = null; - - if (groups[i].getColour() != null) + if(hiddenSeqs!=null) { - if (groups[i].getColour().startsWith("ucs")) - { - cs = GetUserColourScheme(jms, groups[i].getColour()); - } - else + for(int s=0; s 0) + { + for (int c = 0; c < view.getHiddenColumnsCount(); c++) + { + af.viewport.hideColumns( + view.getHiddenColumns(c).getStart(), + view.getHiddenColumns(c).getEnd()+1 + ); + } + } - if (view.getBgColour() != null) - { - if (view.getBgColour().startsWith("ucs")) - { - cs = GetUserColourScheme(jms, view.getBgColour()); - } - else - { - cs = ColourSchemeProperty.getColour(al, view.getBgColour()); - } - if (cs instanceof ConservationColourScheme) - { - ( (ConservationColourScheme) cs).inc = view.getConsThreshold(); - } + Desktop.addInternalFrame(af, view.getTitle(), + view.getWidth(), view.getHeight()); - if (cs instanceof ResidueColourScheme) - { - ( (ResidueColourScheme) cs).setThreshold(view.getPidThreshold()); - } - else if (cs instanceof ScoreColourScheme) - { - ( (ScoreColourScheme) cs).setThreshold(view.getPidThreshold()); - } - } + //LOAD TREES + /////////////////////////////////////// + if (jms.getTreeCount() > 0) + { + try + { + for (int t = 0; t < jms.getTreeCount(); t++) + { - af.viewport.setGlobalColourScheme(cs); + Tree tree = jms.getTree(t); - af.viewport.setColourAppliesToAllGroups(false); - af.changeColour(af.viewport.getGlobalColourScheme()); - af.viewport.setColourAppliesToAllGroups(true); + TreePanel tp = af.ShowNewickTree(new jalview.io.NewickFile( + tree.getNewick()), tree.getTitle(), + tree.getWidth(), tree.getHeight(), + tree.getXpos(), tree.getYpos()); - System.out.println(view.getShowSequenceFeatures()); + tp.fitToWindow.setState(tree.getFitToWindow()); + tp.fitToWindow_actionPerformed(null); - if (view.getShowSequenceFeatures()) - { - ; - } + 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())); - { - 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; } - } } +