2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 import jalview.schemes.*;
32 import java.util.jar.*;
36 import org.exolab.castor.xml.*;
38 import jalview.schemabinding.version2.*;
49 public class Jalview2XML
51 // SAVES SEVERAL ALIGNMENT WINDOWS TO SAME JARFILE
52 public void SaveState(File statefile)
54 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
63 FileOutputStream fos = new FileOutputStream(statefile);
64 JarOutputStream jout = new JarOutputStream(fos);
66 //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
67 ////////////////////////////////////////////////////
68 PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,
71 Vector shortNames = new Vector();
74 for (int i = frames.length - 1; i > -1; i--)
76 if (frames[i] instanceof AlignFrame)
78 AlignFrame af = (AlignFrame) frames[i];
80 String shortName = af.getTitle();
82 if (shortName.indexOf(File.separatorChar) > -1)
84 shortName = shortName.substring(shortName.lastIndexOf(
85 File.separatorChar) + 1);
90 while (shortNames.contains(shortName))
92 if (shortName.endsWith("_" + (count - 1)))
94 shortName = shortName.substring(0,
95 shortName.lastIndexOf("_"));
98 shortName = shortName.concat("_" + count);
102 shortNames.addElement(shortName);
104 if (!shortName.endsWith(".xml"))
106 shortName = shortName + ".xml";
109 int ap, apSize= af.alignPanels.size();
110 for (ap = 0; ap < apSize; ap++)
112 AlignmentPanel apanel = (AlignmentPanel) af.alignPanels.
115 if (apanel.av.explodedPosition == null)
116 apanel.av.explodedPosition = af.getBounds();
119 apSize == 1 ? shortName : ap+shortName,
130 ex.printStackTrace();
134 // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW
135 public void SaveAlignment(AlignFrame af, String jarFile,
140 int ap, apSize= af.alignPanels.size();
141 FileOutputStream fos = new FileOutputStream(jarFile);
142 JarOutputStream jout = new JarOutputStream(fos);
143 PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,
145 for( ap=0; ap<apSize; ap++)
147 AlignmentPanel apanel = (AlignmentPanel)af.alignPanels.elementAt(ap);
149 if (apanel.av.explodedPosition == null)
150 apanel.av.explodedPosition = af.getBounds();
153 apSize==1?fileName:fileName+ap,
162 ex.printStackTrace();
169 * @param af DOCUMENT ME!
170 * @param timeStamp DOCUMENT ME!
171 * @param fileName DOCUMENT ME!
172 * @param jout DOCUMENT ME!
173 * @param out DOCUMENT ME!
175 public void SaveState(AlignmentPanel ap,
177 JarOutputStream jout,
180 if (seqRefIds == null)
181 seqRefIds = new Hashtable();
183 Vector userColours = new Vector();
185 AlignViewport av = ap.av;
187 JalviewModel object = new JalviewModel();
188 object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel());
190 object.setCreationDate(new java.util.Date(System.currentTimeMillis()));
191 object.setVersion(jalview.bin.Cache.getProperty("VERSION"));
193 jalview.datamodel.AlignmentI jal = av.alignment;
197 jal = jal.getHiddenSequences().getFullAlignment();
200 SequenceSet vamsasSet = new SequenceSet();
202 JalviewModelSequence jms = new JalviewModelSequence();
204 vamsasSet.setGapChar(jal.getGapCharacter() + "");
207 Vector pdbfiles = null;
211 for (int i = 0; i < jal.getHeight(); i++)
213 id = jal.getSequenceAt(i).hashCode();
215 if(seqRefIds.get(id+"")!=null)
221 vamsasSeq = new Sequence();
222 vamsasSeq.setId(id + "");
223 vamsasSeq.setName(jal.getSequenceAt(i).getName());
224 vamsasSeq.setSequence(jal.getSequenceAt(i).getSequence());
225 vamsasSeq.setDescription(jal.getSequenceAt(i).getDescription());
227 if (jal.getSequenceAt(i).getDatasetSequence().getDBRef() != null)
229 jalview.datamodel.DBRefEntry[] dbrefs =
230 jal.getSequenceAt(i).getDatasetSequence().getDBRef();
232 for (int d = 0; d < dbrefs.length; d++)
234 DBRef dbref = new DBRef();
235 dbref.setSource(dbrefs[d].getSource());
236 dbref.setVersion(dbrefs[d].getVersion());
237 dbref.setAccessionId(dbrefs[d].getAccessionId());
238 vamsasSeq.addDBRef(dbref);
242 vamsasSet.addSequence(vamsasSeq);
243 seqRefIds.put(id+"", vamsasSeq);
247 jseq.setStart(jal.getSequenceAt(i).getStart());
248 jseq.setEnd(jal.getSequenceAt(i).getEnd());
249 jseq.setColour(jal.getSequenceAt(i).getColor().getRGB());
253 if (av.hasHiddenRows)
255 jseq.setHidden(av.alignment.getHiddenSequences().isHidden(
256 jal.getSequenceAt(i)));
258 if(jal.getSequenceAt(i).getHiddenSequences()!=null)
260 jalview.datamodel.SequenceI [] reps =
261 jal.getSequenceAt(i).getHiddenSequences().getSequencesInOrder(jal);
263 for(int h=0; h<reps.length; h++)
265 jseq.addHiddenSequences(
266 jal.findIndex(reps[h])
273 if(jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures()!=null)
275 jalview.datamodel.SequenceFeature[] sf
276 = jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures();
278 while(index < sf.length)
280 Features features = new Features();
282 features.setBegin(sf[index].getBegin());
283 features.setEnd(sf[index].getEnd());
284 features.setDescription(sf[index].getDescription());
285 features.setType(sf[index].getType());
286 features.setFeatureGroup(sf[index].getFeatureGroup());
287 features.setScore(sf[index].getScore());
288 if(sf[index].links!=null)
290 for(int l=0; l<sf[index].links.size(); l++)
292 OtherData keyValue = new OtherData();
293 keyValue.setKey("LINK_"+l);
294 keyValue.setValue(sf[index].links.elementAt(l).toString());
295 features.addOtherData(keyValue);
298 if(sf[index].otherDetails!=null)
301 Enumeration keys = sf[index].otherDetails.keys();
302 while(keys.hasMoreElements())
304 key = keys.nextElement().toString();
305 OtherData keyValue = new OtherData();
306 keyValue.setKey( key );
308 sf[index].otherDetails.get(key).toString());
309 features.addOtherData(keyValue);
313 jseq.addFeatures(features);
318 if(jal.getSequenceAt(i).getDatasetSequence().getPDBId()!=null)
320 Enumeration en = jal.getSequenceAt(i).getDatasetSequence().getPDBId().elements();
321 while(en.hasMoreElements())
323 Pdbids pdb = new Pdbids();
324 jalview.datamodel.PDBEntry entry
325 = (jalview.datamodel.PDBEntry)en.nextElement();
327 pdb.setId(entry.getId());
328 pdb.setType(entry.getType());
330 if(entry.getFile()!=null)
333 pdbfiles = new Vector();
336 if(!pdbfiles.contains(entry.getId()))
338 pdbfiles.addElement(entry.getId());
341 File file = new File(entry.getFile());
344 byte[] data = new byte[ (int) file.length()];
345 jout.putNextEntry(new JarEntry(entry.getId()));
346 DataInputStream dis = new DataInputStream(new
347 FileInputStream(file));
350 DataOutputStream dout = new DataOutputStream(jout);
351 dout.write(data, 0, data.length);
357 ex.printStackTrace();
363 if(entry.getProperty()!=null)
365 PdbentryItem item = new PdbentryItem();
366 Hashtable properties = entry.getProperty();
367 Enumeration en2 = properties.keys();
368 while(en2.hasMoreElements())
370 Property prop = new Property();
371 String key = en2.nextElement().toString();
373 prop.setValue( properties.get(key).toString() );
374 item.addProperty(prop);
376 pdb.addPdbentryItem(item);
391 ///////////////////////////////////
392 if (av.currentTree != null)
394 // FIND ANY ASSOCIATED TREES
395 // NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT
396 if (Desktop.desktop != null)
398 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
400 for (int t = 0; t < frames.length; t++)
402 if (frames[t] instanceof TreePanel)
404 TreePanel tp = (TreePanel) frames[t];
406 if (tp.treeCanvas.av.alignment == jal)
408 Tree tree = new Tree();
409 tree.setTitle(tp.getTitle());
410 tree.setCurrentTree( (av.currentTree == tp.getTree()));
411 tree.setNewick(tp.getTree().toString());
412 tree.setThreshold(tp.treeCanvas.threshold);
414 tree.setFitToWindow(tp.fitToWindow.getState());
415 tree.setFontName(tp.getTreeFont().getName());
416 tree.setFontSize(tp.getTreeFont().getSize());
417 tree.setFontStyle(tp.getTreeFont().getStyle());
418 tree.setMarkUnlinked(tp.placeholdersMenu.getState());
420 tree.setShowBootstrap(tp.bootstrapMenu.getState());
421 tree.setShowDistances(tp.distanceMenu.getState());
423 tree.setHeight(tp.getHeight());
424 tree.setWidth(tp.getWidth());
425 tree.setXpos(tp.getX());
426 tree.setYpos(tp.getY());
436 if (jal.getAlignmentAnnotation() != null)
438 jalview.datamodel.AlignmentAnnotation[] aa = jal.getAlignmentAnnotation();
440 for (int i = 0; i < aa.length; i++)
442 Annotation an = new Annotation();
444 if (aa[i].label.equals("Quality") ||
445 aa[i].label.equals("Conservation") ||
446 aa[i].label.equals("Consensus"))
448 an.setLabel(aa[i].label);
450 vamsasSet.addAnnotation(an);
455 an.setDescription(aa[i].description);
457 if(aa[i].sequenceRef!=null)
459 an.setSequenceRef(aa[i].sequenceRef.getName());
465 an.setGraphType(aa[i].graph);
466 an.setGraphGroup(aa[i].graphGroup);
467 if(aa[i].getThreshold()!=null)
469 ThresholdLine line = new ThresholdLine();
470 line.setLabel(aa[i].getThreshold().label);
471 line.setValue(aa[i].getThreshold().value);
472 line.setColour(aa[i].getThreshold().colour.getRGB());
473 an.setThresholdLine(line);
479 an.setLabel(aa[i].label);
481 AnnotationElement ae;
483 for (int a = 0; a < aa[i].annotations.length; a++)
485 if ((aa[i] == null) || (aa[i].annotations[a] == null))
490 ae = new AnnotationElement();
491 ae.setDescription(aa[i].annotations[a].description);
492 ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter);
493 ae.setValue(aa[i].annotations[a].value);
495 ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure +
498 if(aa[i].annotations[a].colour!=java.awt.Color.black)
499 ae.setColour(aa[i].annotations[a].colour.getRGB());
501 an.addAnnotationElement(ae);
504 vamsasSet.addAnnotation(an);
509 if (jal.getGroups() != null)
511 JGroup[] groups = new JGroup[jal.getGroups().size()];
513 for (int i = 0; i < groups.length; i++)
515 groups[i] = new JGroup();
517 jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) jal.getGroups()
519 groups[i].setStart(sg.getStartRes());
520 groups[i].setEnd(sg.getEndRes());
521 groups[i].setName(sg.getName());
524 if (sg.cs.conservationApplied())
526 groups[i].setConsThreshold(sg.cs.getConservationInc());
528 if (sg.cs instanceof jalview.schemes.UserColourScheme)
530 groups[i].setColour(SetUserColourScheme(sg.cs,
536 groups[i].setColour(ColourSchemeProperty.getColourName(sg.
540 else if(sg.cs instanceof jalview.schemes.AnnotationColourGradient)
543 ColourSchemeProperty.getColourName(
544 ( (jalview.schemes.AnnotationColourGradient) sg.cs).getBaseColour()));
546 else if (sg.cs instanceof jalview.schemes.UserColourScheme)
548 groups[i].setColour(SetUserColourScheme(sg.cs, userColours,
553 groups[i].setColour(ColourSchemeProperty.getColourName(
557 groups[i].setPidThreshold(sg.cs.getThreshold());
560 groups[i].setOutlineColour(sg.getOutlineColour().getRGB());
561 groups[i].setDisplayBoxes(sg.getDisplayBoxes());
562 groups[i].setDisplayText(sg.getDisplayText());
563 groups[i].setColourText(sg.getColourText());
565 for (int s = 0; s < sg.getSize(false); s++)
567 jalview.datamodel.Sequence seq =
568 (jalview.datamodel.Sequence) sg.getSequenceAt(s);
569 groups[i].addSeq(seq.hashCode());
573 jms.setJGroup(groups);
577 ///////////SAVE VIEWPORT
578 Viewport view = new Viewport();
579 view.setTitle(ap.alignFrame.getTitle());
580 view.setSequenceSetId(av.getSequenceSetId());
581 view.setViewName(av.viewName);
582 view.setGatheredViews(av.gatherViewsHere);
584 view.setXpos(av.explodedPosition.x);
585 view.setYpos(av.explodedPosition.y);
586 view.setWidth(av.explodedPosition.width);
587 view.setHeight(av.explodedPosition.height);
588 view.setStartRes(av.startRes);
589 view.setStartSeq(av.startSeq);
591 if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)
593 view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(),
596 else if(av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient)
598 jalview.schemes.AnnotationColourGradient acg
599 = (jalview.schemes.AnnotationColourGradient)av.getGlobalColourScheme();
601 AnnotationColours ac = new AnnotationColours();
602 ac.setAboveThreshold(acg.getAboveThreshold());
603 ac.setThreshold(acg.getAnnotationThreshold());
604 ac.setAnnotation(acg.getAnnotation());
605 if(acg.getBaseColour() instanceof jalview.schemes.UserColourScheme)
606 ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(),
609 ac.setColourScheme(ColourSchemeProperty.getColourName(acg.getBaseColour()));
611 ac.setMaxColour(acg.getMaxColour().getRGB());
612 ac.setMinColour(acg.getMinColour().getRGB());
613 view.setAnnotationColours(ac);
614 view.setBgColour("AnnotationColourGradient");
618 view.setBgColour(ColourSchemeProperty.getColourName(
619 av.getGlobalColourScheme()));
622 ColourSchemeI cs = av.getGlobalColourScheme();
626 if (cs.conservationApplied())
628 view.setConsThreshold(cs.getConservationInc());
629 if (cs instanceof jalview.schemes.UserColourScheme)
630 view.setBgColour(SetUserColourScheme(cs, userColours, jms));
633 if (cs instanceof ResidueColourScheme)
635 view.setPidThreshold(cs.getThreshold());
639 view.setConservationSelected(av.getConservationSelected());
640 view.setPidSelected(av.getAbovePIDThreshold());
641 view.setFontName(av.font.getName());
642 view.setFontSize(av.font.getSize());
643 view.setFontStyle(av.font.getStyle());
644 view.setRenderGaps(av.renderGaps);
645 view.setShowAnnotation(av.getShowAnnotation());
646 view.setShowBoxes(av.getShowBoxes());
647 view.setShowColourText(av.getColourText());
648 view.setShowFullId(av.getShowJVSuffix());
649 view.setShowSequenceFeatures(av.showSequenceFeatures);
650 view.setShowText(av.getShowText());
651 view.setWrapAlignment(av.getWrapAlignment());
653 if(av.featuresDisplayed!=null)
655 jalview.schemabinding.version2.FeatureSettings fs
656 = new jalview.schemabinding.version2.FeatureSettings();
658 String [] renderOrder =
659 ap.seqPanel.seqCanvas.getFeatureRenderer().renderOrder;
661 Vector settingsAdded = new Vector();
662 for(int ro=0; ro<renderOrder.length; ro++)
664 Setting setting = new Setting();
665 setting.setType(renderOrder[ro]);
667 ap.seqPanel.seqCanvas.getFeatureRenderer().getColour(renderOrder[ro]).getRGB()
671 av.featuresDisplayed.containsKey(renderOrder[ro])
674 fs.addSetting(setting);
675 settingsAdded.addElement(renderOrder[ro]);
678 //Make sure we save none displayed feature settings
680 ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours.keys();
681 while(en.hasMoreElements())
683 String key = en.nextElement().toString();
684 if(settingsAdded.contains(key))
687 Setting setting = new Setting();
688 setting.setType(key);
690 ap.seqPanel.seqCanvas.getFeatureRenderer().getColour(key).getRGB()
693 setting.setDisplay(false);
695 fs.addSetting(setting);
696 settingsAdded.addElement(key);
699 jms.setFeatureSettings(fs);
703 if(av.hasHiddenColumns)
705 for(int c=0; c<av.getColumnSelection().getHiddenColumns().size(); c++)
707 int [] region = (int[]) av.getColumnSelection().getHiddenColumns().elementAt(c);
708 HiddenColumns hc = new HiddenColumns();
709 hc.setStart(region[0]);
710 hc.setEnd(region[1]);
711 view.addHiddenColumns(hc);
715 jms.addViewport(view);
718 object.setJalviewModelSequence(jms);
719 object.getVamsasModel().addSequenceSet(vamsasSet);
723 if (!fileName.endsWith(".xml"))
725 fileName = fileName + ".xml";
728 JarEntry entry = new JarEntry(fileName);
729 jout.putNextEntry(entry);
735 ex.printStackTrace();
739 String SetUserColourScheme(jalview.schemes.ColourSchemeI cs,
740 Vector userColours, JalviewModelSequence jms)
743 jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs;
745 if (!userColours.contains(ucs))
747 userColours.add(ucs);
749 java.awt.Color[] colours = ucs.getColours();
750 jalview.schemabinding.version2.UserColours uc = new jalview.schemabinding.version2.UserColours();
751 jalview.schemabinding.version2.UserColourScheme jbucs = new jalview.schemabinding.version2.UserColourScheme();
753 for (int i = 0; i < colours.length; i++)
755 jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
756 col.setName(ResidueProperties.aa[i]);
757 col.setRGB(jalview.util.Format.getHexString(colours[i]));
758 jbucs.addColour(col);
760 if(ucs.getLowerCaseColours()!=null)
762 colours = ucs.getLowerCaseColours();
763 for (int i = 0; i < colours.length; i++)
765 jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
766 col.setName(ResidueProperties.aa[i].toLowerCase());
767 col.setRGB(jalview.util.Format.getHexString(colours[i]));
768 jbucs.addColour(col);
772 id = "ucs" + userColours.indexOf(ucs);
774 uc.setUserColourScheme(jbucs);
775 jms.addUserColours(uc);
781 jalview.schemes.UserColourScheme GetUserColourScheme(
782 JalviewModelSequence jms, String id)
784 UserColours[] uc = jms.getUserColours();
785 UserColours colours = null;
787 for (int i = 0; i < uc.length; i++)
789 if (uc[i].getId().equals(id))
797 java.awt.Color[] newColours = new java.awt.Color[24];
799 for (int i = 0; i < 24; i++)
801 newColours[i] = new java.awt.Color(Integer.parseInt(
802 colours.getUserColourScheme().getColour(i).getRGB(), 16));
805 jalview.schemes.UserColourScheme ucs =
806 new jalview.schemes.UserColourScheme(newColours);
808 if (colours.getUserColourScheme().getColourCount() > 24)
810 newColours = new java.awt.Color[23];
811 for (int i = 0; i < 23; i++)
813 newColours[i] = new java.awt.Color(Integer.parseInt(
814 colours.getUserColourScheme().getColour(i+24).getRGB(), 16));
816 ucs.setLowerCaseColours(newColours);
827 * @param file DOCUMENT ME!
829 public AlignFrame LoadJalviewAlign(final String file)
831 jalview.gui.AlignFrame af = null;
833 seqRefIds = new Hashtable();
834 Vector gatherToThisFrame= new Vector();
838 //UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING
841 if (file.startsWith("http://"))
846 JarInputStream jin = null;
847 JarEntry jarentry = null;
854 jin = new JarInputStream(url.openStream());
858 jin = new JarInputStream(new FileInputStream(file));
861 for (int i = 0; i < entryCount; i++)
863 jarentry = jin.getNextJarEntry();
866 if (jarentry != null && jarentry.getName().endsWith(".xml"))
868 InputStreamReader in = new InputStreamReader(jin, "UTF-8");
869 JalviewModel object = new JalviewModel();
871 Unmarshaller unmar = new Unmarshaller(object);
872 unmar.setValidation(false);
873 object = (JalviewModel) unmar.unmarshal( in );
875 af = LoadFromObject(object, file);
876 if(af.viewport.gatherViewsHere)
878 gatherToThisFrame.add(af);
882 else if (jarentry != null)
884 //Some other file here.
888 while (jarentry != null);
890 catch(java.net.UnknownHostException ex)
892 ex.printStackTrace();
893 System.err.println("Couldn't locate Jalview XML file : " +
896 javax.swing.SwingUtilities.invokeLater(new Runnable()
900 JOptionPane.showInternalMessageDialog(Desktop.desktop,
901 "Couldn't locate " + file,
903 JOptionPane.WARNING_MESSAGE);
909 //Is Version 1 Jar file?
910 af = new Jalview2XML_V1().LoadJalviewAlign(file);
914 System.out.println("Successfully loaded archive file");
918 System.err.println("Exception whilst loading jalview XML file : " +
920 javax.swing.SwingUtilities.invokeLater(new Runnable()
925 JOptionPane.showInternalMessageDialog(Desktop.desktop,
926 "Error loading " + file,
927 "Error loading Jalview file",
928 JOptionPane.WARNING_MESSAGE);
932 if (Desktop.instance != null)
933 Desktop.instance.stopLoading();
935 for (int i = 0; i < gatherToThisFrame.size(); i++)
937 Desktop.instance.gatherViews(
938 (AlignFrame) gatherToThisFrame.elementAt(i));
944 String loadPDBFile(String file, String pdbId)
948 JarInputStream jin = null;
950 if (file.startsWith("http://"))
952 jin = new JarInputStream(new URL(file).openStream());
956 jin = new JarInputStream(new FileInputStream(file));
959 JarEntry entry = null;
962 entry = jin.getNextJarEntry();
964 while (!entry.getName().equals(pdbId));
966 BufferedReader in = new BufferedReader(new InputStreamReader(jin));
967 File outFile = File.createTempFile("jalview_pdb", ".txt");
968 outFile.deleteOnExit();
969 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
972 while ( (data = in.readLine()) != null)
977 return outFile.getAbsolutePath();
982 ex.printStackTrace();
989 AlignFrame LoadFromObject(JalviewModel object, String file)
991 SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
992 Sequence[] vamsasSeq = vamsasSet.getSequence();
994 JalviewModelSequence jms = object.getJalviewModelSequence();
996 Viewport[] views = jms.getViewport();
997 Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER
999 //////////////////////////////////
1002 Vector hiddenSeqs = null;
1003 jalview.datamodel.Sequence jseq;
1005 ArrayList tmpseqs = new ArrayList();
1008 boolean multipleView = false;
1010 JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
1011 for (int i = 0; i < JSEQ.length; i++)
1013 String seqId = JSEQ[i].getId() + "";
1015 if (seqRefIds.get(seqId) != null)
1017 tmpseqs.add( (jalview.datamodel.Sequence) seqRefIds.get(seqId));
1018 multipleView = true;
1022 jseq = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),
1023 vamsasSeq[i].getSequence());
1024 jseq.setDescription(vamsasSeq[i].getDescription());
1025 jseq.setStart(JSEQ[i].getStart());
1026 jseq.setEnd(JSEQ[i].getEnd());
1027 jseq.setColor(new java.awt.Color(JSEQ[i].getColour()));
1028 seqRefIds.put(vamsasSeq[i].getId(), jseq);
1029 tmpseqs.add( jseq );
1033 if (JSEQ[i].getHidden())
1035 if (hiddenSeqs == null)
1036 hiddenSeqs = new Vector();
1039 hiddenSeqs.addElement(
1040 (jalview.datamodel.Sequence) seqRefIds.get(seqId));
1045 ///SequenceFeatures are added to the DatasetSequence,
1046 // so we must create the dataset before loading features
1047 /////////////////////////////////
1050 jalview.datamodel.Sequence[] orderedSeqs = new jalview.datamodel.Sequence[
1053 tmpseqs.toArray(orderedSeqs) ;
1056 jalview.datamodel.Alignment al =
1057 new jalview.datamodel.Alignment(orderedSeqs);
1059 al.setDataset(null);
1060 /////////////////////////////////
1063 Hashtable pdbloaded = new Hashtable();
1066 for (int i = 0; i < vamsasSeq.length; i++)
1068 if (JSEQ[i].getFeaturesCount() > 0)
1070 Features[] features = JSEQ[i].getFeatures();
1071 for (int f = 0; f < features.length; f++)
1073 jalview.datamodel.SequenceFeature sf
1074 = new jalview.datamodel.SequenceFeature(features[f].getType(),
1075 features[f].getDescription(), features[f].getStatus(),
1076 features[f].getBegin(), features[f].getEnd(),
1077 features[f].getFeatureGroup());
1079 sf.setScore(features[f].getScore());
1080 for (int od = 0; od < features[f].getOtherDataCount(); od++)
1082 OtherData keyValue = features[f].getOtherData(od);
1083 if (keyValue.getKey().startsWith("LINK"))
1084 sf.addLink(keyValue.getValue());
1086 sf.setValue(keyValue.getKey(), keyValue.getValue());
1090 al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
1093 if (JSEQ[i].getPdbidsCount() > 0)
1095 Pdbids[] ids = JSEQ[i].getPdbids();
1096 for (int p = 0; p < ids.length; p++)
1098 jalview.datamodel.PDBEntry entry = new jalview.datamodel.
1100 entry.setId(ids[p].getId());
1101 entry.setType(ids[p].getType());
1102 if (ids[p].getFile() != null)
1104 if (!pdbloaded.containsKey(ids[p].getFile()))
1106 String tmppdb = loadPDBFile(file, ids[p].getId());
1107 entry.setFile(tmppdb);
1108 pdbloaded.put(ids[p].getId(), tmppdb);
1111 entry.setFile(pdbloaded.get(ids[p].getId()).toString());
1114 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
1117 if (vamsasSeq[i].getDBRefCount() > 0)
1119 for (int d = 0; d < vamsasSeq[i].getDBRefCount(); d++)
1121 jalview.datamodel.DBRefEntry entry =
1122 new jalview.datamodel.DBRefEntry(
1123 vamsasSeq[i].getDBRef(d).getSource(),
1124 vamsasSeq[i].getDBRef(d).getVersion(),
1125 vamsasSeq[i].getDBRef(d).getAccessionId()
1127 al.getSequenceAt(i).getDatasetSequence().addDBRef(entry);
1135 /////////////////////////////////
1136 //////////////////////////////////
1138 boolean hideQuality = true,
1139 hideConservation = true,
1140 hideConsensus = true;
1142 if (vamsasSet.getAnnotationCount()>0)
1144 Annotation[] an = vamsasSet.getAnnotation();
1146 for (int i = 0; i < an.length; i++)
1148 if (an[i].getLabel().equals("Quality"))
1150 hideQuality = false;
1153 else if(an[i].getLabel().equals("Conservation"))
1155 hideConservation = false;
1158 else if(an[i].getLabel().equals("Consensus"))
1160 hideConsensus = false;
1164 AnnotationElement[] ae = an[i].getAnnotationElement();
1165 jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al.getWidth()];
1167 for (int aa = 0; aa < ae.length; aa++)
1169 anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(ae[aa].getDisplayCharacter(),
1170 ae[aa].getDescription(),
1171 ae[aa].getSecondaryStructure().length()==0?' ':ae[aa].getSecondaryStructure().charAt(0),
1173 anot[ae[aa].getPosition()].colour = new java.awt.Color( ae[aa].getColour() );
1176 jalview.datamodel.AlignmentAnnotation jaa = null;
1178 if (an[i].getGraph())
1180 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
1181 an[i].getDescription(), anot, 0, 0,
1182 an[i].getGraphType());
1184 jaa.graphGroup = an[i].getGraphGroup();
1186 if (an[i].getThresholdLine() != null)
1188 jaa.setThreshold(new jalview.datamodel.GraphLine(
1189 an[i].getThresholdLine().getValue(),
1190 an[i].getThresholdLine().getLabel(),
1191 new java.awt.Color(an[i].getThresholdLine().getColour()))
1199 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
1200 an[i].getDescription(), anot);
1203 if(an[i].getSequenceRef()!=null)
1205 jaa.createSequenceMapping(
1206 al.findName(an[i].getSequenceRef()), 1, true
1208 al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa);
1211 al.addAnnotation(jaa);
1216 // af.changeColour() );
1217 /////////////////////////
1219 if (jms.getJGroupCount() > 0)
1221 JGroup[] groups = jms.getJGroup();
1223 for (int i = 0; i < groups.length; i++)
1225 ColourSchemeI cs = null;
1227 if (groups[i].getColour() != null)
1229 if (groups[i].getColour().startsWith("ucs"))
1231 cs = GetUserColourScheme(jms, groups[i].getColour());
1235 cs = ColourSchemeProperty.getColour(al,
1236 groups[i].getColour());
1240 cs.setThreshold(groups[i].getPidThreshold(), true);
1243 Vector seqs = new Vector();
1245 for (int s = 0; s < groups[i].getSeqCount(); s++)
1247 String seqId = groups[i].getSeq(s)+"";
1248 seqs.addElement((jalview.datamodel.SequenceI) seqRefIds.get(seqId));
1251 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(seqs,
1252 groups[i].getName(), cs, groups[i].getDisplayBoxes(),
1253 groups[i].getDisplayText(), groups[i].getColourText(),
1254 groups[i].getStart(), groups[i].getEnd());
1256 sg.setOutlineColour(new java.awt.Color(
1257 groups[i].getOutlineColour()));
1259 if (groups[i].getConsThreshold() != 0)
1261 jalview.analysis.Conservation c = new jalview.analysis.Conservation("All",
1262 ResidueProperties.propHash, 3, sg.getSequences(false), 0,
1265 c.verdict(false, 25);
1266 sg.cs.setConservation(c);
1274 /////////////////////////////////
1277 AlignFrame af = new AlignFrame(al,
1281 af.viewport.sequenceSetID = view.getSequenceSetId();
1283 af.viewport.gatherViewsHere = view.getGatheredViews();
1285 if (view.getSequenceSetId() != null)
1286 PaintRefresher.Register(af.alignPanel, view.getSequenceSetId());
1288 if(hiddenSeqs!=null)
1290 for(int s=0; s<JSEQ.length; s++)
1292 for(int r=0; r<JSEQ[s].getHiddenSequencesCount(); r++)
1294 al.getSequenceAt(s).addHiddenSequence(
1295 al.getSequenceAt( JSEQ[s].getHiddenSequences(r) )
1300 jalview.datamodel.SequenceI [] hseqs = new
1301 jalview.datamodel.SequenceI[hiddenSeqs.size()];
1303 for(int s=0; s<hiddenSeqs.size(); s++)
1304 hseqs[s] = (jalview.datamodel.SequenceI)hiddenSeqs.elementAt(s);
1306 af.viewport.hideSequence( hseqs );
1311 if((hideConsensus || hideQuality || hideConservation)
1312 && al.getAlignmentAnnotation()!=null)
1314 int hSize = al.getAlignmentAnnotation().length;
1315 for (int h = 0; h < hSize; h++)
1319 al.getAlignmentAnnotation()[h].label.equals("Consensus"))
1322 al.getAlignmentAnnotation()[h].label.equals("Quality"))
1324 (hideConservation &&
1325 al.getAlignmentAnnotation()[h].label.equals("Conservation")))
1327 al.deleteAnnotation(al.getAlignmentAnnotation()[h]);
1332 af.alignPanel.adjustAnnotationHeight();
1335 af.viewport.viewName = view.getViewName();
1336 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
1338 af.viewport.setStartRes(view.getStartRes());
1339 af.viewport.setStartSeq(view.getStartSeq());
1340 af.viewport.setShowAnnotation(view.getShowAnnotation());
1341 af.viewport.showConservation = !hideConservation;
1342 af.viewport.showQuality = !hideQuality;
1343 af.viewport.showIdentity = !hideConsensus;
1345 af.viewport.setAbovePIDThreshold(view.getPidSelected());
1346 af.abovePIDThreshold.setSelected(view.getPidSelected());
1347 af.viewport.setColourText(view.getShowColourText());
1348 af.colourTextMenuItem.setSelected(view.getShowColourText());
1349 af.viewport.setConservationSelected(view.getConservationSelected());
1350 af.conservationMenuItem.setSelected(view.getConservationSelected());
1352 af.viewport.setShowJVSuffix(view.getShowFullId());
1353 af.seqLimits.setSelected(view.getShowFullId());
1355 af.viewport.setFont(new java.awt.Font(view.getFontName(),
1356 view.getFontStyle(), view.getFontSize()));
1357 af.alignPanel.fontChanged();
1359 af.viewport.setRenderGaps(view.getRenderGaps());
1360 af.renderGapsMenuItem.setSelected(view.getRenderGaps());
1362 af.viewport.setWrapAlignment(view.getWrapAlignment());
1363 af.wrapMenuItem.setSelected(view.getWrapAlignment());
1365 af.alignPanel.setWrapAlignment(view.getWrapAlignment());
1367 af.annotationPanelMenuItem.setState(view.getShowAnnotation());
1368 af.viewport.setShowAnnotation(view.getShowAnnotation());
1369 af.alignPanel.setAnnotationVisible(view.getShowAnnotation());
1371 af.viewport.setShowBoxes(view.getShowBoxes());
1372 af.viewBoxesMenuItem.setSelected(view.getShowBoxes());
1373 af.viewport.setShowText(view.getShowText());
1374 af.viewTextMenuItem.setSelected(view.getShowText());
1376 ColourSchemeI cs = null;
1378 if (view.getBgColour() != null)
1380 if (view.getBgColour().startsWith("ucs"))
1382 cs = GetUserColourScheme(jms, view.getBgColour());
1384 else if(view.getBgColour().startsWith("Annotation"))
1386 //int find annotation
1387 for (int i = 0; i < af.viewport.alignment.getAlignmentAnnotation().length; i++)
1389 if (af.viewport.alignment.getAlignmentAnnotation()[i].label.
1390 equals(view.getAnnotationColours().getAnnotation()))
1392 if (af.viewport.alignment.getAlignmentAnnotation()[i].
1393 getThreshold() == null)
1395 af.viewport.alignment.getAlignmentAnnotation()[i].
1397 new jalview.datamodel.GraphLine(
1398 view.getAnnotationColours().getThreshold(),
1399 "Threshold", java.awt.Color.black)
1405 if (view.getAnnotationColours().getColourScheme().equals(
1408 cs = new AnnotationColourGradient(
1409 af.viewport.alignment.getAlignmentAnnotation()[i],
1410 new java.awt.Color(view.getAnnotationColours().
1412 new java.awt.Color(view.getAnnotationColours().
1414 view.getAnnotationColours().getAboveThreshold());
1416 else if (view.getAnnotationColours().getColourScheme().
1419 cs = new AnnotationColourGradient(
1420 af.viewport.alignment.getAlignmentAnnotation()[i],
1421 GetUserColourScheme(jms, view.getAnnotationColours().
1423 view.getAnnotationColours().getAboveThreshold()
1428 cs = new AnnotationColourGradient(
1429 af.viewport.alignment.getAlignmentAnnotation()[i],
1430 ColourSchemeProperty.getColour(al,
1431 view.getAnnotationColours().getColourScheme()),
1432 view.getAnnotationColours().getAboveThreshold()
1436 // Also use these settings for all the groups
1437 if (al.getGroups() != null)
1438 for (int g = 0; g < al.getGroups().size(); g++)
1440 jalview.datamodel.SequenceGroup sg
1441 = (jalview.datamodel.SequenceGroup)al.getGroups().elementAt(g);
1447 /* if (view.getAnnotationColours().getColourScheme().equals("None"))
1449 sg.cs = new AnnotationColourGradient(
1450 af.viewport.alignment.getAlignmentAnnotation()[i],
1451 new java.awt.Color(view.getAnnotationColours().
1453 new java.awt.Color(view.getAnnotationColours().
1455 view.getAnnotationColours().getAboveThreshold());
1459 sg.cs = new AnnotationColourGradient(
1460 af.viewport.alignment.getAlignmentAnnotation()[i],
1462 view.getAnnotationColours().getAboveThreshold()
1476 cs = ColourSchemeProperty.getColour(al, view.getBgColour());
1481 cs.setThreshold(view.getPidThreshold(), true);
1482 cs.setConsensus(af.viewport.hconsensus);
1486 af.setColourSelected(view.getBgColour());
1487 af.viewport.setGlobalColourScheme(cs);
1488 af.viewport.setColourAppliesToAllGroups(false);
1489 af.changeColour(cs);
1490 if (view.getConservationSelected() && cs!=null)
1492 cs.setConservationInc(view.getConsThreshold());
1495 af.viewport.setColourAppliesToAllGroups(true);
1497 if (view.getShowSequenceFeatures())
1499 af.viewport.showSequenceFeatures = true;
1500 af.showSeqFeatures.setSelected(true);
1503 if(jms.getFeatureSettings()!=null)
1505 af.viewport.featuresDisplayed = new Hashtable();
1506 String [] renderOrder = new String[jms.getFeatureSettings().getSettingCount()];
1507 for(int fs=0; fs<jms.getFeatureSettings().getSettingCount(); fs++)
1509 Setting setting = jms.getFeatureSettings().getSetting(fs);
1511 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(setting.getType(),
1512 new java.awt.Color(setting.getColour()));
1514 renderOrder[fs] = setting.getType();
1516 if(setting.getDisplay())
1517 af.viewport.featuresDisplayed.put(
1518 setting.getType(), new Integer(setting.getColour()));
1520 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;
1523 if (view.getHiddenColumnsCount() > 0)
1525 for (int c = 0; c < view.getHiddenColumnsCount(); c++)
1527 af.viewport.hideColumns(
1528 view.getHiddenColumns(c).getStart(),
1529 view.getHiddenColumns(c).getEnd() //+1
1535 Desktop.addInternalFrame(af, view.getTitle(),
1536 view.getWidth(), view.getHeight());
1539 ///////////////////////////////////////
1540 if (jms.getTreeCount() > 0)
1544 for (int t = 0; t < jms.getTreeCount(); t++)
1547 Tree tree = jms.getTree(t);
1549 TreePanel tp = af.ShowNewickTree(new jalview.io.NewickFile(
1550 tree.getNewick()), tree.getTitle(),
1551 tree.getWidth(), tree.getHeight(),
1552 tree.getXpos(), tree.getYpos());
1554 tp.fitToWindow.setState(tree.getFitToWindow());
1555 tp.fitToWindow_actionPerformed(null);
1557 if(tree.getFontName()!=null)
1558 tp.setTreeFont(new java.awt.Font(tree.getFontName(),
1559 tree.getFontStyle(),
1560 tree.getFontSize()));
1562 tp.setTreeFont(new java.awt.Font(view.getFontName(),
1563 view.getFontStyle(),
1564 tree.getFontSize()));
1566 tp.showPlaceholders(tree.getMarkUnlinked());
1567 tp.showBootstrap(tree.getShowBootstrap());
1568 tp.showDistances(tree.getShowDistances());
1570 tp.treeCanvas.threshold = tree.getThreshold();
1572 if (tree.getCurrentTree())
1573 af.viewport.setCurrentTree(tp.getTree());
1577 catch (Exception ex)
1579 ex.printStackTrace();