2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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
21 import java.awt.Rectangle;
25 import java.util.jar.*;
29 import org.exolab.castor.xml.*;
31 import uk.ac.vamsas.objects.utils.MapList;
32 import jalview.bin.Cache;
33 import jalview.datamodel.Alignment;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.SequenceI;
36 import jalview.schemabinding.version2.*;
37 import jalview.schemes.*;
38 import jalview.structure.StructureSelectionManager;
39 import jalview.util.jarInputStreamProvider;
42 * Write out the current jalview desktop state as a Jalview XML stream.
44 * Note: the vamsas objects referred to here are primitive versions of the
45 * VAMSAS project schema elements - they are not the same and most likely never
51 public class Jalview2XML
54 * create/return unique hash string for sq
57 * @return new or existing unique string for sq
59 String seqHash(SequenceI sq)
61 if (seqsToIds == null)
65 if (seqsToIds.containsKey(sq))
67 return (String) seqsToIds.get(sq);
71 // create sequential key
72 String key = "sq" + (seqsToIds.size() + 1);
73 key = makeHashCode(sq, key); // check we don't have an external reference
75 seqsToIds.put(sq, key);
84 if (seqRefIds != null)
88 if (seqsToIds != null)
98 warn("clearSeqRefs called when _cleartables was not set. Doing nothing.");
99 // seqRefIds = new Hashtable();
100 // seqsToIds = new IdentityHashMap();
106 if (seqsToIds == null)
108 seqsToIds = new IdentityHashMap();
110 if (seqRefIds == null)
112 seqRefIds = new Hashtable();
117 * SequenceI reference -> XML ID string in jalview XML. Populated as XML reps
118 * of sequence objects are created.
120 java.util.IdentityHashMap seqsToIds = null;
123 * jalview XML Sequence ID to jalview sequence object reference (both dataset
124 * and alignment sequences. Populated as XML reps of sequence objects are
127 java.util.Hashtable seqRefIds = null; // key->SequenceI resolution
129 Vector frefedSequence = null;
131 boolean raiseGUI = true; // whether errors are raised in dialog boxes or not
137 public Jalview2XML(boolean raiseGUI)
139 this.raiseGUI = raiseGUI;
142 public void resolveFrefedSequences()
144 if (frefedSequence.size() > 0)
146 int r = 0, rSize = frefedSequence.size();
149 Object[] ref = (Object[]) frefedSequence.elementAt(r);
152 String sref = (String) ref[0];
153 if (seqRefIds.containsKey(sref))
155 if (ref[1] instanceof jalview.datamodel.Mapping)
157 SequenceI seq = (SequenceI) seqRefIds.get(sref);
158 while (seq.getDatasetSequence() != null)
160 seq = seq.getDatasetSequence();
162 ((jalview.datamodel.Mapping) ref[1]).setTo(seq);
166 if (ref[1] instanceof jalview.datamodel.AlignedCodonFrame)
168 SequenceI seq = (SequenceI) seqRefIds.get(sref);
169 while (seq.getDatasetSequence() != null)
171 seq = seq.getDatasetSequence();
174 && ref[2] instanceof jalview.datamodel.Mapping)
176 jalview.datamodel.Mapping mp = (jalview.datamodel.Mapping) ref[2];
177 ((jalview.datamodel.AlignedCodonFrame) ref[1]).addMap(
178 seq, mp.getTo(), mp.getMap());
183 .println("IMPLEMENTATION ERROR: Unimplemented forward sequence references for AlcodonFrames involving "
184 + ref[2].getClass() + " type objects.");
190 .println("IMPLEMENTATION ERROR: Unimplemented forward sequence references for "
191 + ref[1].getClass() + " type objects.");
194 frefedSequence.remove(r);
200 .println("IMPLEMENTATION WARNING: Unresolved forward reference for hash string "
202 + " with objecttype "
203 + ref[1].getClass());
210 frefedSequence.remove(r);
218 * This maintains a list of viewports, the key being the seqSetId. Important
219 * to set historyItem and redoList for multiple views
221 Hashtable viewportsAdded;
223 Hashtable annotationIds = new Hashtable();
225 String uniqueSetSuffix = "";
228 * List of pdbfiles added to Jar
230 Vector pdbfiles = null;
232 // SAVES SEVERAL ALIGNMENT WINDOWS TO SAME JARFILE
233 public void SaveState(File statefile)
237 FileOutputStream fos = new FileOutputStream(statefile);
238 JarOutputStream jout = new JarOutputStream(fos);
241 } catch (Exception e)
243 // TODO: inform user of the problem - they need to know if their data was
245 if (errorMessage == null)
247 errorMessage = "Couldn't write Jalview Archive to output file '"
248 + statefile + "' - See console error log for details";
252 errorMessage += "(output file was '" + statefile + "')";
260 * Writes a jalview project archive to the given Jar output stream.
264 public void SaveState(JarOutputStream jout)
266 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
276 // NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
277 // //////////////////////////////////////////////////
278 // NOTE ALSO new PrintWriter must be used for each new JarEntry
279 PrintWriter out = null;
281 Vector shortNames = new Vector();
284 for (int i = frames.length - 1; i > -1; i--)
286 if (frames[i] instanceof AlignFrame)
288 AlignFrame af = (AlignFrame) frames[i];
291 && skipList.containsKey(af.getViewport()
292 .getSequenceSetId()))
297 String shortName = af.getTitle();
299 if (shortName.indexOf(File.separatorChar) > -1)
301 shortName = shortName.substring(shortName
302 .lastIndexOf(File.separatorChar) + 1);
307 while (shortNames.contains(shortName))
309 if (shortName.endsWith("_" + (count - 1)))
311 shortName = shortName
312 .substring(0, shortName.lastIndexOf("_"));
315 shortName = shortName.concat("_" + count);
319 shortNames.addElement(shortName);
321 if (!shortName.endsWith(".xml"))
323 shortName = shortName + ".xml";
326 int ap, apSize = af.alignPanels.size();
327 for (ap = 0; ap < apSize; ap++)
329 AlignmentPanel apanel = (AlignmentPanel) af.alignPanels
331 String fileName = apSize == 1 ? shortName : ap + shortName;
332 if (!fileName.endsWith(".xml"))
334 fileName = fileName + ".xml";
337 SaveState(apanel, fileName, jout);
344 } catch (Exception foo)
349 } catch (Exception ex)
351 // TODO: inform user of the problem - they need to know if their data was
353 if (errorMessage == null)
355 errorMessage = "Couldn't write Jalview Archive - see error output for details";
357 ex.printStackTrace();
361 // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW
362 public boolean SaveAlignment(AlignFrame af, String jarFile,
367 int ap, apSize = af.alignPanels.size();
368 FileOutputStream fos = new FileOutputStream(jarFile);
369 JarOutputStream jout = new JarOutputStream(fos);
370 for (ap = 0; ap < apSize; ap++)
372 AlignmentPanel apanel = (AlignmentPanel) af.alignPanels
374 String jfileName = apSize == 1 ? fileName : fileName + ap;
375 if (!jfileName.endsWith(".xml"))
377 jfileName = jfileName + ".xml";
379 SaveState(apanel, jfileName, jout);
385 } catch (Exception foo)
391 } catch (Exception ex)
393 errorMessage = "Couldn't Write alignment view to Jalview Archive - see error output for details";
394 ex.printStackTrace();
400 * create a JalviewModel from an algnment view and marshall it to a
404 * panel to create jalview model for
406 * name of alignment panel written to output stream
412 public JalviewModel SaveState(AlignmentPanel ap, String fileName,
413 JarOutputStream jout)
417 Vector userColours = new Vector();
419 AlignViewport av = ap.av;
421 JalviewModel object = new JalviewModel();
422 object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel());
424 object.setCreationDate(new java.util.Date(System.currentTimeMillis()));
425 object.setVersion(jalview.bin.Cache.getProperty("VERSION"));
427 jalview.datamodel.AlignmentI jal = av.alignment;
429 if (av.hasHiddenRows)
431 jal = jal.getHiddenSequences().getFullAlignment();
434 SequenceSet vamsasSet = new SequenceSet();
436 JalviewModelSequence jms = new JalviewModelSequence();
438 vamsasSet.setGapChar(jal.getGapCharacter() + "");
440 if (jal.getDataset() != null)
442 // dataset id is the dataset's hashcode
443 vamsasSet.setDatasetId(getDatasetIdRef(jal.getDataset()));
445 if (jal.getProperties() != null)
447 Enumeration en = jal.getProperties().keys();
448 while (en.hasMoreElements())
450 String key = en.nextElement().toString();
451 SequenceSetProperties ssp = new SequenceSetProperties();
453 ssp.setValue(jal.getProperties().get(key).toString());
454 vamsasSet.addSequenceSetProperties(ssp);
462 jalview.datamodel.SequenceI jds;
463 for (int i = 0; i < jal.getHeight(); i++)
465 jds = jal.getSequenceAt(i);
468 if (seqRefIds.get(id) != null)
470 // This happens for two reasons: 1. multiple views are being serialised.
471 // 2. the hashCode has collided with another sequence's code. This DOES
472 // HAPPEN! (PF00072.15.stk does this)
473 // JBPNote: Uncomment to debug writing out of files that do not read
474 // back in due to ArrayOutOfBoundExceptions.
475 // System.err.println("vamsasSeq backref: "+id+"");
476 // System.err.println(jds.getName()+"
477 // "+jds.getStart()+"-"+jds.getEnd()+" "+jds.getSequenceAsString());
478 // System.err.println("Hashcode: "+seqHash(jds));
479 // SequenceI rsq = (SequenceI) seqRefIds.get(id + "");
480 // System.err.println(rsq.getName()+"
481 // "+rsq.getStart()+"-"+rsq.getEnd()+" "+rsq.getSequenceAsString());
482 // System.err.println("Hashcode: "+seqHash(rsq));
486 vamsasSeq = createVamsasSequence(id, jds);
487 vamsasSet.addSequence(vamsasSeq);
488 seqRefIds.put(id, jds);
492 jseq.setStart(jds.getStart());
493 jseq.setEnd(jds.getEnd());
494 jseq.setColour(av.getSequenceColour(jds).getRGB());
496 jseq.setId(id); // jseq id should be a string not a number
498 if (av.hasHiddenRows)
500 jseq.setHidden(av.alignment.getHiddenSequences().isHidden(jds));
502 if (av.hiddenRepSequences != null
503 && av.hiddenRepSequences.containsKey(jal.getSequenceAt(i)))
505 jalview.datamodel.SequenceI[] reps = ((jalview.datamodel.SequenceGroup) av.hiddenRepSequences
506 .get(jal.getSequenceAt(i))).getSequencesInOrder(jal);
508 for (int h = 0; h < reps.length; h++)
510 if (reps[h] != jal.getSequenceAt(i))
512 jseq.addHiddenSequences(jal.findIndex(reps[h]));
518 if (jds.getDatasetSequence().getSequenceFeatures() != null)
520 jalview.datamodel.SequenceFeature[] sf = jds.getDatasetSequence()
521 .getSequenceFeatures();
523 while (index < sf.length)
525 Features features = new Features();
527 features.setBegin(sf[index].getBegin());
528 features.setEnd(sf[index].getEnd());
529 features.setDescription(sf[index].getDescription());
530 features.setType(sf[index].getType());
531 features.setFeatureGroup(sf[index].getFeatureGroup());
532 features.setScore(sf[index].getScore());
533 if (sf[index].links != null)
535 for (int l = 0; l < sf[index].links.size(); l++)
537 OtherData keyValue = new OtherData();
538 keyValue.setKey("LINK_" + l);
539 keyValue.setValue(sf[index].links.elementAt(l).toString());
540 features.addOtherData(keyValue);
543 if (sf[index].otherDetails != null)
546 Enumeration keys = sf[index].otherDetails.keys();
547 while (keys.hasMoreElements())
549 key = keys.nextElement().toString();
550 OtherData keyValue = new OtherData();
551 keyValue.setKey(key);
552 keyValue.setValue(sf[index].otherDetails.get(key).toString());
553 features.addOtherData(keyValue);
557 jseq.addFeatures(features);
562 if (jds.getDatasetSequence().getPDBId() != null)
564 Enumeration en = jds.getDatasetSequence().getPDBId().elements();
565 while (en.hasMoreElements())
567 Pdbids pdb = new Pdbids();
568 jalview.datamodel.PDBEntry entry = (jalview.datamodel.PDBEntry) en
571 pdb.setId(entry.getId());
572 pdb.setType(entry.getType());
575 // This must have been loaded, is it still visible?
576 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
577 String matchedFile = null;
578 for (int f = frames.length - 1; f > -1; f--)
580 if (frames[f] instanceof AppJmol)
582 jmol = (AppJmol) frames[f];
583 if (!jmol.pdbentry.getId().equals(entry.getId())
584 && !(entry.getId().length() > 4 && entry.getId()
585 .toLowerCase().startsWith(
586 jmol.pdbentry.getId().toLowerCase())))
588 matchedFile = jmol.pdbentry.getFile(); // record the file so we
589 // can get at it if the ID
590 // match is ambiguous (e.g.
592 StructureState state = new StructureState();
593 state.setVisible(true);
594 state.setXpos(jmol.getX());
595 state.setYpos(jmol.getY());
596 state.setWidth(jmol.getWidth());
597 state.setHeight(jmol.getHeight());
598 state.setViewId(jmol.getViewId());
599 String statestring = jmol.viewer.getStateInfo();
602 state.setContent(statestring.replaceAll("\n", ""));
604 for (int s = 0; s < jmol.sequence.length; s++)
606 if (jal.findIndex(jmol.sequence[s]) > -1)
608 pdb.addStructureState(state);
614 if (matchedFile != null || entry.getFile() != null)
616 if (entry.getFile() != null)
619 matchedFile = entry.getFile();
621 pdb.setFile(matchedFile); // entry.getFile());
622 if (pdbfiles == null)
624 pdbfiles = new Vector();
627 if (!pdbfiles.contains(entry.getId()))
629 pdbfiles.addElement(entry.getId());
632 File file = new File(matchedFile);
633 if (file.exists() && jout != null)
635 byte[] data = new byte[(int) file.length()];
636 jout.putNextEntry(new JarEntry(entry.getId()));
637 DataInputStream dis = new DataInputStream(
638 new FileInputStream(file));
641 DataOutputStream dout = new DataOutputStream(jout);
642 dout.write(data, 0, data.length);
646 } catch (Exception ex)
648 ex.printStackTrace();
654 if (entry.getProperty() != null)
656 PdbentryItem item = new PdbentryItem();
657 Hashtable properties = entry.getProperty();
658 Enumeration en2 = properties.keys();
659 while (en2.hasMoreElements())
661 Property prop = new Property();
662 String key = en2.nextElement().toString();
664 prop.setValue(properties.get(key).toString());
665 item.addProperty(prop);
667 pdb.addPdbentryItem(item);
677 if (av.hasHiddenRows)
682 if (jal.getCodonFrames() != null && jal.getCodonFrames().length > 0)
684 jalview.datamodel.AlignedCodonFrame[] jac = jal.getCodonFrames();
685 for (int i = 0; i < jac.length; i++)
687 AlcodonFrame alc = new AlcodonFrame();
688 vamsasSet.addAlcodonFrame(alc);
689 for (int p = 0; p < jac[i].aaWidth; p++)
691 Alcodon cmap = new Alcodon();
692 if (jac[i].codons[p] != null)
694 // Null codons indicate a gapped column in the translated peptide
696 cmap.setPos1(jac[i].codons[p][0]);
697 cmap.setPos2(jac[i].codons[p][1]);
698 cmap.setPos3(jac[i].codons[p][2]);
700 alc.addAlcodon(cmap);
702 if (jac[i].getProtMappings() != null
703 && jac[i].getProtMappings().length > 0)
705 SequenceI[] dnas = jac[i].getdnaSeqs();
706 jalview.datamodel.Mapping[] pmaps = jac[i].getProtMappings();
707 for (int m = 0; m < pmaps.length; m++)
709 AlcodMap alcmap = new AlcodMap();
710 alcmap.setDnasq(seqHash(dnas[m]));
711 alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null,
713 alc.addAlcodMap(alcmap);
720 // /////////////////////////////////
721 if (av.currentTree != null)
723 // FIND ANY ASSOCIATED TREES
724 // NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT
725 if (Desktop.desktop != null)
727 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
729 for (int t = 0; t < frames.length; t++)
731 if (frames[t] instanceof TreePanel)
733 TreePanel tp = (TreePanel) frames[t];
735 if (tp.treeCanvas.av.alignment == jal)
737 Tree tree = new Tree();
738 tree.setTitle(tp.getTitle());
739 tree.setCurrentTree((av.currentTree == tp.getTree()));
740 tree.setNewick(tp.getTree().toString());
741 tree.setThreshold(tp.treeCanvas.threshold);
743 tree.setFitToWindow(tp.fitToWindow.getState());
744 tree.setFontName(tp.getTreeFont().getName());
745 tree.setFontSize(tp.getTreeFont().getSize());
746 tree.setFontStyle(tp.getTreeFont().getStyle());
747 tree.setMarkUnlinked(tp.placeholdersMenu.getState());
749 tree.setShowBootstrap(tp.bootstrapMenu.getState());
750 tree.setShowDistances(tp.distanceMenu.getState());
752 tree.setHeight(tp.getHeight());
753 tree.setWidth(tp.getWidth());
754 tree.setXpos(tp.getX());
755 tree.setYpos(tp.getY());
756 tree.setId(makeHashCode(tp, null));
765 if (jal.getAlignmentAnnotation() != null)
767 jalview.datamodel.AlignmentAnnotation[] aa = jal
768 .getAlignmentAnnotation();
770 for (int i = 0; i < aa.length; i++)
772 Annotation an = new Annotation();
774 if (aa[i].annotationId != null)
776 annotationIds.put(aa[i].annotationId, aa[i]);
779 an.setId(aa[i].annotationId);
781 if (aa[i] == av.quality || aa[i] == av.conservation
782 || aa[i] == av.consensus)
784 an.setLabel(aa[i].label);
786 vamsasSet.addAnnotation(an);
790 an.setVisible(aa[i].visible);
792 an.setDescription(aa[i].description);
794 if (aa[i].sequenceRef != null)
796 // TODO later annotation sequenceRef should be the XML ID of the
797 // sequence rather than its display name
798 an.setSequenceRef(aa[i].sequenceRef.getName());
804 an.setGraphType(aa[i].graph);
805 an.setGraphGroup(aa[i].graphGroup);
806 if (aa[i].getThreshold() != null)
808 ThresholdLine line = new ThresholdLine();
809 line.setLabel(aa[i].getThreshold().label);
810 line.setValue(aa[i].getThreshold().value);
811 line.setColour(aa[i].getThreshold().colour.getRGB());
812 an.setThresholdLine(line);
820 an.setLabel(aa[i].label);
821 if (aa[i].hasScore())
823 an.setScore(aa[i].getScore());
825 AnnotationElement ae;
826 if (aa[i].annotations != null)
828 an.setScoreOnly(false);
829 for (int a = 0; a < aa[i].annotations.length; a++)
831 if ((aa[i] == null) || (aa[i].annotations[a] == null))
836 ae = new AnnotationElement();
837 if (aa[i].annotations[a].description != null)
838 ae.setDescription(aa[i].annotations[a].description);
839 if (aa[i].annotations[a].displayCharacter != null)
840 ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter);
842 if (!Float.isNaN(aa[i].annotations[a].value))
843 ae.setValue(aa[i].annotations[a].value);
846 if (aa[i].annotations[a].secondaryStructure != ' '
847 && aa[i].annotations[a].secondaryStructure != '\0')
849 .setSecondaryStructure(aa[i].annotations[a].secondaryStructure
852 if (aa[i].annotations[a].colour != null
853 && aa[i].annotations[a].colour != java.awt.Color.black)
855 ae.setColour(aa[i].annotations[a].colour.getRGB());
858 an.addAnnotationElement(ae);
863 an.setScoreOnly(true);
865 vamsasSet.addAnnotation(an);
870 if (jal.getGroups() != null)
872 JGroup[] groups = new JGroup[jal.getGroups().size()];
874 for (int i = 0; i < groups.length; i++)
876 groups[i] = new JGroup();
878 jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) jal
879 .getGroups().elementAt(i);
880 groups[i].setStart(sg.getStartRes());
881 groups[i].setEnd(sg.getEndRes());
882 groups[i].setName(sg.getName()); // TODO later sequence group should
883 // specify IDs of sequences, not just
887 if (sg.cs.conservationApplied())
889 groups[i].setConsThreshold(sg.cs.getConservationInc());
891 if (sg.cs instanceof jalview.schemes.UserColourScheme)
893 groups[i].setColour(SetUserColourScheme(sg.cs, userColours,
899 .setColour(ColourSchemeProperty.getColourName(sg.cs));
902 else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient)
905 .setColour(ColourSchemeProperty
906 .getColourName(((jalview.schemes.AnnotationColourGradient) sg.cs)
909 else if (sg.cs instanceof jalview.schemes.UserColourScheme)
912 .setColour(SetUserColourScheme(sg.cs, userColours, jms));
916 groups[i].setColour(ColourSchemeProperty.getColourName(sg.cs));
919 groups[i].setPidThreshold(sg.cs.getThreshold());
922 groups[i].setOutlineColour(sg.getOutlineColour().getRGB());
923 groups[i].setDisplayBoxes(sg.getDisplayBoxes());
924 groups[i].setDisplayText(sg.getDisplayText());
925 groups[i].setColourText(sg.getColourText());
926 groups[i].setTextCol1(sg.textColour.getRGB());
927 groups[i].setTextCol2(sg.textColour2.getRGB());
928 groups[i].setTextColThreshold(sg.thresholdTextColour);
929 groups[i].setShowUnconserved(sg.getShowunconserved());
930 for (int s = 0; s < sg.getSize(); s++)
932 jalview.datamodel.Sequence seq = (jalview.datamodel.Sequence) sg
934 groups[i].addSeq(seqHash(seq));
938 jms.setJGroup(groups);
941 // /////////SAVE VIEWPORT
942 Viewport view = new Viewport();
943 view.setTitle(ap.alignFrame.getTitle());
944 view.setSequenceSetId(makeHashCode(av.getSequenceSetId(), av
945 .getSequenceSetId()));
946 view.setId(av.getViewId());
947 view.setViewName(av.viewName);
948 view.setGatheredViews(av.gatherViewsHere);
950 if (ap.av.explodedPosition != null)
952 view.setXpos(av.explodedPosition.x);
953 view.setYpos(av.explodedPosition.y);
954 view.setWidth(av.explodedPosition.width);
955 view.setHeight(av.explodedPosition.height);
959 view.setXpos(ap.alignFrame.getBounds().x);
960 view.setYpos(ap.alignFrame.getBounds().y);
961 view.setWidth(ap.alignFrame.getBounds().width);
962 view.setHeight(ap.alignFrame.getBounds().height);
965 view.setStartRes(av.startRes);
966 view.setStartSeq(av.startSeq);
968 if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)
970 view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(),
973 else if (av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient)
975 jalview.schemes.AnnotationColourGradient acg = (jalview.schemes.AnnotationColourGradient) av
976 .getGlobalColourScheme();
978 AnnotationColours ac = new AnnotationColours();
979 ac.setAboveThreshold(acg.getAboveThreshold());
980 ac.setThreshold(acg.getAnnotationThreshold());
981 ac.setAnnotation(acg.getAnnotation());
982 if (acg.getBaseColour() instanceof jalview.schemes.UserColourScheme)
984 ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(),
989 ac.setColourScheme(ColourSchemeProperty.getColourName(acg
993 ac.setMaxColour(acg.getMaxColour().getRGB());
994 ac.setMinColour(acg.getMinColour().getRGB());
995 view.setAnnotationColours(ac);
996 view.setBgColour("AnnotationColourGradient");
1000 view.setBgColour(ColourSchemeProperty.getColourName(av
1001 .getGlobalColourScheme()));
1004 ColourSchemeI cs = av.getGlobalColourScheme();
1008 if (cs.conservationApplied())
1010 view.setConsThreshold(cs.getConservationInc());
1011 if (cs instanceof jalview.schemes.UserColourScheme)
1013 view.setBgColour(SetUserColourScheme(cs, userColours, jms));
1017 if (cs instanceof ResidueColourScheme)
1019 view.setPidThreshold(cs.getThreshold());
1023 view.setConservationSelected(av.getConservationSelected());
1024 view.setPidSelected(av.getAbovePIDThreshold());
1025 view.setFontName(av.font.getName());
1026 view.setFontSize(av.font.getSize());
1027 view.setFontStyle(av.font.getStyle());
1028 view.setRenderGaps(av.renderGaps);
1029 view.setShowAnnotation(av.getShowAnnotation());
1030 view.setShowBoxes(av.getShowBoxes());
1031 view.setShowColourText(av.getColourText());
1032 view.setShowFullId(av.getShowJVSuffix());
1033 view.setRightAlignIds(av.rightAlignIds);
1034 view.setShowSequenceFeatures(av.showSequenceFeatures);
1035 view.setShowText(av.getShowText());
1036 view.setShowUnconserved(av.getShowUnconserved());
1037 view.setWrapAlignment(av.getWrapAlignment());
1038 view.setTextCol1(av.textColour.getRGB());
1039 view.setTextCol2(av.textColour2.getRGB());
1040 view.setTextColThreshold(av.thresholdTextColour);
1042 if (av.featuresDisplayed != null)
1044 jalview.schemabinding.version2.FeatureSettings fs = new jalview.schemabinding.version2.FeatureSettings();
1046 String[] renderOrder = ap.seqPanel.seqCanvas.getFeatureRenderer().renderOrder;
1048 Vector settingsAdded = new Vector();
1049 for (int ro = 0; ro < renderOrder.length; ro++)
1051 Setting setting = new Setting();
1052 setting.setType(renderOrder[ro]);
1053 setting.setColour(ap.seqPanel.seqCanvas.getFeatureRenderer()
1054 .getColour(renderOrder[ro]).getRGB());
1056 setting.setDisplay(av.featuresDisplayed
1057 .containsKey(renderOrder[ro]));
1058 float rorder = ap.seqPanel.seqCanvas.getFeatureRenderer().getOrder(
1062 setting.setOrder(rorder);
1064 fs.addSetting(setting);
1065 settingsAdded.addElement(renderOrder[ro]);
1068 // Make sure we save none displayed feature settings
1069 Enumeration en = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours
1071 while (en.hasMoreElements())
1073 String key = en.nextElement().toString();
1074 if (settingsAdded.contains(key))
1079 Setting setting = new Setting();
1080 setting.setType(key);
1081 setting.setColour(ap.seqPanel.seqCanvas.getFeatureRenderer()
1082 .getColour(key).getRGB());
1084 setting.setDisplay(false);
1085 float rorder = ap.seqPanel.seqCanvas.getFeatureRenderer().getOrder(
1089 setting.setOrder(rorder);
1091 fs.addSetting(setting);
1092 settingsAdded.addElement(key);
1094 en = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups.keys();
1095 Vector groupsAdded = new Vector();
1096 while (en.hasMoreElements())
1098 String grp = en.nextElement().toString();
1099 if (groupsAdded.contains(grp))
1103 Group g = new Group();
1106 .setDisplay(((Boolean) ap.seqPanel.seqCanvas
1107 .getFeatureRenderer().featureGroups.get(grp))
1110 groupsAdded.addElement(grp);
1112 jms.setFeatureSettings(fs);
1116 if (av.hasHiddenColumns)
1118 if (av.getColumnSelection() == null
1119 || av.getColumnSelection().getHiddenColumns() == null)
1121 warn("REPORT BUG: avoided null columnselection bug (DMAM reported). Please contact Jim about this.");
1125 for (int c = 0; c < av.getColumnSelection().getHiddenColumns()
1128 int[] region = (int[]) av.getColumnSelection().getHiddenColumns()
1130 HiddenColumns hc = new HiddenColumns();
1131 hc.setStart(region[0]);
1132 hc.setEnd(region[1]);
1133 view.addHiddenColumns(hc);
1138 jms.addViewport(view);
1140 object.setJalviewModelSequence(jms);
1141 object.getVamsasModel().addSequenceSet(vamsasSet);
1143 if (jout != null && fileName != null)
1145 // We may not want to write the object to disk,
1146 // eg we can copy the alignViewport to a new view object
1147 // using save and then load
1150 JarEntry entry = new JarEntry(fileName);
1151 jout.putNextEntry(entry);
1152 PrintWriter pout = new PrintWriter(new OutputStreamWriter(jout,
1154 org.exolab.castor.xml.Marshaller marshaller = new org.exolab.castor.xml.Marshaller(
1156 marshaller.marshal(object);
1159 } catch (Exception ex)
1161 // TODO: raise error in GUI if marshalling failed.
1162 ex.printStackTrace();
1169 * External mapping between jalview objects and objects yielding a valid and
1170 * unique object ID string. This is null for normal Jalview project IO, but
1171 * non-null when a jalview project is being read or written as part of a
1174 IdentityHashMap jv2vobj = null;
1177 * Construct a unique ID for jvobj using either existing bindings or if none
1178 * exist, the result of the hashcode call for the object.
1181 * jalview data object
1182 * @return unique ID for referring to jvobj
1184 private String makeHashCode(Object jvobj, String altCode)
1186 if (jv2vobj != null)
1188 Object id = jv2vobj.get(jvobj);
1191 return id.toString();
1193 // check string ID mappings
1194 if (jvids2vobj != null && jvobj instanceof String)
1196 id = jvids2vobj.get(jvobj);
1200 return id.toString();
1202 // give up and warn that something has gone wrong
1203 warn("Cannot find ID for object in external mapping : " + jvobj);
1209 * return local jalview object mapped to ID, if it exists
1213 * @return null or object bound to idcode
1215 private Object retrieveExistingObj(String idcode)
1217 if (idcode != null && vobj2jv != null)
1219 return vobj2jv.get(idcode);
1225 * binding from ID strings from external mapping table to jalview data model
1228 private Hashtable vobj2jv;
1230 private Sequence createVamsasSequence(String id, SequenceI jds)
1232 return createVamsasSequence(true, id, jds, null);
1235 private Sequence createVamsasSequence(boolean recurse, String id,
1236 SequenceI jds, SequenceI parentseq)
1238 Sequence vamsasSeq = new Sequence();
1239 vamsasSeq.setId(id);
1240 vamsasSeq.setName(jds.getName());
1241 vamsasSeq.setSequence(jds.getSequenceAsString());
1242 vamsasSeq.setDescription(jds.getDescription());
1243 jalview.datamodel.DBRefEntry[] dbrefs = null;
1244 if (jds.getDatasetSequence() != null)
1246 vamsasSeq.setDsseqid(seqHash(jds.getDatasetSequence()));
1247 if (jds.getDatasetSequence().getDBRef() != null)
1249 dbrefs = jds.getDatasetSequence().getDBRef();
1254 vamsasSeq.setDsseqid(id); // so we can tell which sequences really are
1255 // dataset sequences only
1256 dbrefs = jds.getDBRef();
1260 for (int d = 0; d < dbrefs.length; d++)
1262 DBRef dbref = new DBRef();
1263 dbref.setSource(dbrefs[d].getSource());
1264 dbref.setVersion(dbrefs[d].getVersion());
1265 dbref.setAccessionId(dbrefs[d].getAccessionId());
1266 if (dbrefs[d].hasMap())
1268 Mapping mp = createVamsasMapping(dbrefs[d].getMap(), parentseq,
1270 dbref.setMapping(mp);
1272 vamsasSeq.addDBRef(dbref);
1278 private Mapping createVamsasMapping(jalview.datamodel.Mapping jmp,
1279 SequenceI parentseq, SequenceI jds, boolean recurse)
1282 if (jmp.getMap() != null)
1286 jalview.util.MapList mlst = jmp.getMap();
1287 int r[] = mlst.getFromRanges();
1288 for (int s = 0; s < r.length; s += 2)
1290 MapListFrom mfrom = new MapListFrom();
1291 mfrom.setStart(r[s]);
1292 mfrom.setEnd(r[s + 1]);
1293 mp.addMapListFrom(mfrom);
1295 r = mlst.getToRanges();
1296 for (int s = 0; s < r.length; s += 2)
1298 MapListTo mto = new MapListTo();
1300 mto.setEnd(r[s + 1]);
1301 mp.addMapListTo(mto);
1303 mp.setMapFromUnit(mlst.getFromRatio());
1304 mp.setMapToUnit(mlst.getToRatio());
1305 if (jmp.getTo() != null)
1307 MappingChoice mpc = new MappingChoice();
1309 && (parentseq != jmp.getTo() || parentseq
1310 .getDatasetSequence() != jmp.getTo()))
1312 mpc.setSequence(createVamsasSequence(false, seqHash(jmp.getTo()),
1318 SequenceI ps = null;
1319 if (parentseq != jmp.getTo()
1320 && parentseq.getDatasetSequence() != jmp.getTo())
1322 // chaining dbref rather than a handshaking one
1323 jmpid = seqHash(ps = jmp.getTo());
1327 jmpid = seqHash(ps = parentseq);
1329 mpc.setDseqFor(jmpid);
1330 if (!seqRefIds.containsKey(mpc.getDseqFor()))
1332 jalview.bin.Cache.log.debug("creatign new DseqFor ID");
1333 seqRefIds.put(mpc.getDseqFor(), ps);
1337 jalview.bin.Cache.log.debug("reusing DseqFor ID");
1340 mp.setMappingChoice(mpc);
1346 String SetUserColourScheme(jalview.schemes.ColourSchemeI cs,
1347 Vector userColours, JalviewModelSequence jms)
1350 jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs;
1352 if (!userColours.contains(ucs))
1354 userColours.add(ucs);
1356 java.awt.Color[] colours = ucs.getColours();
1357 jalview.schemabinding.version2.UserColours uc = new jalview.schemabinding.version2.UserColours();
1358 jalview.schemabinding.version2.UserColourScheme jbucs = new jalview.schemabinding.version2.UserColourScheme();
1360 for (int i = 0; i < colours.length; i++)
1362 jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
1363 col.setName(ResidueProperties.aa[i]);
1364 col.setRGB(jalview.util.Format.getHexString(colours[i]));
1365 jbucs.addColour(col);
1367 if (ucs.getLowerCaseColours() != null)
1369 colours = ucs.getLowerCaseColours();
1370 for (int i = 0; i < colours.length; i++)
1372 jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
1373 col.setName(ResidueProperties.aa[i].toLowerCase());
1374 col.setRGB(jalview.util.Format.getHexString(colours[i]));
1375 jbucs.addColour(col);
1379 id = "ucs" + userColours.indexOf(ucs);
1381 uc.setUserColourScheme(jbucs);
1382 jms.addUserColours(uc);
1388 jalview.schemes.UserColourScheme GetUserColourScheme(
1389 JalviewModelSequence jms, String id)
1391 UserColours[] uc = jms.getUserColours();
1392 UserColours colours = null;
1394 for (int i = 0; i < uc.length; i++)
1396 if (uc[i].getId().equals(id))
1404 java.awt.Color[] newColours = new java.awt.Color[24];
1406 for (int i = 0; i < 24; i++)
1408 newColours[i] = new java.awt.Color(Integer.parseInt(colours
1409 .getUserColourScheme().getColour(i).getRGB(), 16));
1412 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
1415 if (colours.getUserColourScheme().getColourCount() > 24)
1417 newColours = new java.awt.Color[23];
1418 for (int i = 0; i < 23; i++)
1420 newColours[i] = new java.awt.Color(Integer.parseInt(colours
1421 .getUserColourScheme().getColour(i + 24).getRGB(), 16));
1423 ucs.setLowerCaseColours(newColours);
1430 * contains last error message (if any) encountered by XML loader.
1432 String errorMessage = null;
1435 * flag to control whether the Jalview2XML_V1 parser should be deferred to if
1436 * exceptions are raised during project XML parsing
1438 public boolean attemptversion1parse = true;
1441 * Load a jalview project archive from a jar file
1444 * - HTTP URL or filename
1446 public AlignFrame LoadJalviewAlign(final String file)
1449 jalview.gui.AlignFrame af = null;
1453 // UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING
1454 // Workaround is to make sure caller implements the JarInputStreamProvider
1456 // so we can re-open the jar input stream for each entry.
1458 jarInputStreamProvider jprovider = createjarInputStreamProvider(file);
1459 af = LoadJalviewAlign(jprovider);
1460 } catch (MalformedURLException e)
1462 errorMessage = "Invalid URL format for '" + file + "'";
1468 private jarInputStreamProvider createjarInputStreamProvider(
1469 final String file) throws MalformedURLException
1472 errorMessage = null;
1473 uniqueSetSuffix = null;
1475 viewportsAdded = null;
1476 frefedSequence = null;
1478 if (file.startsWith("http://"))
1480 url = new URL(file);
1482 final URL _url = url;
1483 return new jarInputStreamProvider()
1486 public JarInputStream getJarInputStream() throws IOException
1490 return new JarInputStream(_url.openStream());
1494 return new JarInputStream(new FileInputStream(file));
1498 public String getFilename()
1506 * Recover jalview session from a jalview project archive. Caller may
1507 * initialise uniqueSetSuffix, seqRefIds, viewportsAdded and frefedSequence
1508 * themselves. Any null fields will be initialised with default values,
1509 * non-null fields are left alone.
1514 public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider)
1516 errorMessage = null;
1517 if (uniqueSetSuffix == null)
1519 uniqueSetSuffix = System.currentTimeMillis() % 100000 + "";
1521 if (seqRefIds == null)
1523 seqRefIds = new Hashtable();
1525 if (viewportsAdded == null)
1527 viewportsAdded = new Hashtable();
1529 if (frefedSequence == null)
1531 frefedSequence = new Vector();
1534 jalview.gui.AlignFrame af = null;
1535 Hashtable gatherToThisFrame = new Hashtable();
1536 final String file = jprovider.getFilename();
1539 JarInputStream jin = null;
1540 JarEntry jarentry = null;
1545 jin = jprovider.getJarInputStream();
1546 for (int i = 0; i < entryCount; i++)
1548 jarentry = jin.getNextJarEntry();
1551 if (jarentry != null && jarentry.getName().endsWith(".xml"))
1553 InputStreamReader in = new InputStreamReader(jin, "UTF-8");
1554 JalviewModel object = new JalviewModel();
1556 Unmarshaller unmar = new Unmarshaller(object);
1557 unmar.setValidation(false);
1558 object = (JalviewModel) unmar.unmarshal(in);
1559 if (true) // !skipViewport(object))
1561 af = LoadFromObject(object, file, true, jprovider);
1562 if (af.viewport.gatherViewsHere)
1564 gatherToThisFrame.put(af.viewport.getSequenceSetId(), af);
1569 else if (jarentry != null)
1571 // Some other file here.
1574 } while (jarentry != null);
1575 resolveFrefedSequences();
1576 } catch (java.io.FileNotFoundException ex)
1578 ex.printStackTrace();
1579 errorMessage = "Couldn't locate Jalview XML file : " + file;
1580 System.err.println("Exception whilst loading jalview XML file : "
1582 } catch (java.net.UnknownHostException ex)
1584 ex.printStackTrace();
1585 errorMessage = "Couldn't locate Jalview XML file : " + file;
1586 System.err.println("Exception whilst loading jalview XML file : "
1588 } catch (Exception ex)
1590 System.err.println("Parsing as Jalview Version 2 file failed.");
1591 ex.printStackTrace(System.err);
1592 if (attemptversion1parse)
1594 // Is Version 1 Jar file?
1597 af = new Jalview2XML_V1(raiseGUI).LoadJalviewAlign(jprovider);
1598 } catch (Exception ex2)
1600 System.err.println("Exception whilst loading as jalviewXMLV1:");
1601 ex2.printStackTrace();
1605 if (Desktop.instance != null)
1607 Desktop.instance.stopLoading();
1611 System.out.println("Successfully loaded archive file");
1614 ex.printStackTrace();
1616 System.err.println("Exception whilst loading jalview XML file : "
1618 } catch (OutOfMemoryError e)
1620 // Don't use the OOM Window here
1621 errorMessage = "Out of memory loading jalview XML file";
1622 System.err.println("Out of memory whilst loading jalview XML file");
1623 e.printStackTrace();
1626 if (Desktop.instance != null)
1628 Desktop.instance.stopLoading();
1631 Enumeration en = gatherToThisFrame.elements();
1632 while (en.hasMoreElements())
1634 Desktop.instance.gatherViews((AlignFrame) en.nextElement());
1636 if (errorMessage != null)
1644 * check errorMessage for a valid error message and raise an error box in the
1645 * GUI or write the current errorMessage to stderr and then clear the error
1648 protected void reportErrors()
1650 reportErrors(false);
1653 protected void reportErrors(final boolean saving)
1655 if (errorMessage != null)
1657 final String finalErrorMessage = errorMessage;
1660 javax.swing.SwingUtilities.invokeLater(new Runnable()
1664 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1665 finalErrorMessage, "Error "
1666 + (saving ? "saving" : "loading")
1667 + " Jalview file", JOptionPane.WARNING_MESSAGE);
1673 System.err.println("Problem loading Jalview file: " + errorMessage);
1676 errorMessage = null;
1679 Hashtable alreadyLoadedPDB;
1682 * when set, local views will be updated from view stored in JalviewXML
1683 * Currently (28th Sep 2008) things will go horribly wrong in vamsas document
1684 * sync if this is set to true.
1686 private boolean updateLocalViews = false;
1688 String loadPDBFile(jarInputStreamProvider jprovider, String pdbId)
1690 if (alreadyLoadedPDB == null)
1691 alreadyLoadedPDB = new Hashtable();
1693 if (alreadyLoadedPDB.containsKey(pdbId))
1694 return alreadyLoadedPDB.get(pdbId).toString();
1698 JarInputStream jin = jprovider.getJarInputStream();
1700 * if (jprovider.startsWith("http://")) { jin = new JarInputStream(new
1701 * URL(jprovider).openStream()); } else { jin = new JarInputStream(new
1702 * FileInputStream(jprovider)); }
1705 JarEntry entry = null;
1708 entry = jin.getNextJarEntry();
1709 } while (entry != null && !entry.getName().equals(pdbId));
1712 BufferedReader in = new BufferedReader(new InputStreamReader(jin));
1713 File outFile = File.createTempFile("jalview_pdb", ".txt");
1714 outFile.deleteOnExit();
1715 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
1718 while ((data = in.readLine()) != null)
1725 } catch (Exception foo)
1731 alreadyLoadedPDB.put(pdbId, outFile.getAbsolutePath());
1732 return outFile.getAbsolutePath();
1736 warn("Couldn't find PDB file entry in Jalview Jar for " + pdbId);
1738 } catch (Exception ex)
1740 ex.printStackTrace();
1747 * Load alignment frame from jalview XML DOM object
1752 * filename source string
1753 * @param loadTreesAndStructures
1754 * when false only create Viewport
1756 * data source provider
1757 * @return alignment frame created from view stored in DOM
1759 AlignFrame LoadFromObject(JalviewModel object, String file,
1760 boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
1762 SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
1763 Sequence[] vamsasSeq = vamsasSet.getSequence();
1765 JalviewModelSequence jms = object.getJalviewModelSequence();
1767 Viewport view = jms.getViewport(0);
1768 // ////////////////////////////////
1771 Vector hiddenSeqs = null;
1772 jalview.datamodel.Sequence jseq;
1774 ArrayList tmpseqs = new ArrayList();
1776 boolean multipleView = false;
1778 JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
1779 int vi = 0; // counter in vamsasSeq array
1780 for (int i = 0; i < JSEQ.length; i++)
1782 String seqId = JSEQ[i].getId();
1784 if (seqRefIds.get(seqId) != null)
1786 tmpseqs.add((jalview.datamodel.Sequence) seqRefIds.get(seqId));
1787 multipleView = true;
1791 jseq = new jalview.datamodel.Sequence(vamsasSeq[vi].getName(),
1792 vamsasSeq[vi].getSequence());
1793 jseq.setDescription(vamsasSeq[vi].getDescription());
1794 jseq.setStart(JSEQ[i].getStart());
1795 jseq.setEnd(JSEQ[i].getEnd());
1796 jseq.setVamsasId(uniqueSetSuffix + seqId);
1797 seqRefIds.put(vamsasSeq[vi].getId(), jseq);
1802 if (JSEQ[i].getHidden())
1804 if (hiddenSeqs == null)
1806 hiddenSeqs = new Vector();
1809 hiddenSeqs.addElement((jalview.datamodel.Sequence) seqRefIds
1816 // Create the alignment object from the sequence set
1817 // ///////////////////////////////
1818 jalview.datamodel.Sequence[] orderedSeqs = new jalview.datamodel.Sequence[tmpseqs
1821 tmpseqs.toArray(orderedSeqs);
1823 jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(
1826 // / Add the alignment properties
1827 for (int i = 0; i < vamsasSet.getSequenceSetPropertiesCount(); i++)
1829 SequenceSetProperties ssp = vamsasSet.getSequenceSetProperties(i);
1830 al.setProperty(ssp.getKey(), ssp.getValue());
1834 // SequenceFeatures are added to the DatasetSequence,
1835 // so we must create or recover the dataset before loading features
1836 // ///////////////////////////////
1837 if (vamsasSet.getDatasetId() == null || vamsasSet.getDatasetId() == "")
1839 // older jalview projects do not have a dataset id.
1840 al.setDataset(null);
1844 recoverDatasetFor(vamsasSet, al);
1846 // ///////////////////////////////
1848 Hashtable pdbloaded = new Hashtable();
1851 // load sequence features, database references and any associated PDB
1852 // structures for the alignment
1853 for (int i = 0; i < vamsasSeq.length; i++)
1855 if (JSEQ[i].getFeaturesCount() > 0)
1857 Features[] features = JSEQ[i].getFeatures();
1858 for (int f = 0; f < features.length; f++)
1860 jalview.datamodel.SequenceFeature sf = new jalview.datamodel.SequenceFeature(
1861 features[f].getType(), features[f].getDescription(),
1862 features[f].getStatus(), features[f].getBegin(),
1863 features[f].getEnd(), features[f].getFeatureGroup());
1865 sf.setScore(features[f].getScore());
1866 for (int od = 0; od < features[f].getOtherDataCount(); od++)
1868 OtherData keyValue = features[f].getOtherData(od);
1869 if (keyValue.getKey().startsWith("LINK"))
1871 sf.addLink(keyValue.getValue());
1875 sf.setValue(keyValue.getKey(), keyValue.getValue());
1880 al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
1883 if (vamsasSeq[i].getDBRefCount() > 0)
1885 addDBRefs(al.getSequenceAt(i).getDatasetSequence(), vamsasSeq[i]);
1887 if (JSEQ[i].getPdbidsCount() > 0)
1889 Pdbids[] ids = JSEQ[i].getPdbids();
1890 for (int p = 0; p < ids.length; p++)
1892 jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
1893 entry.setId(ids[p].getId());
1894 entry.setType(ids[p].getType());
1895 if (ids[p].getFile() != null)
1897 if (!pdbloaded.containsKey(ids[p].getFile()))
1899 entry.setFile(loadPDBFile(jprovider, ids[p].getId()));
1903 entry.setFile(pdbloaded.get(ids[p].getId()).toString());
1907 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
1911 } // end !multipleview
1913 // ///////////////////////////////
1914 // LOAD SEQUENCE MAPPINGS
1916 if (vamsasSet.getAlcodonFrameCount() > 0)
1918 // TODO Potentially this should only be done once for all views of an
1920 AlcodonFrame[] alc = vamsasSet.getAlcodonFrame();
1921 for (int i = 0; i < alc.length; i++)
1923 jalview.datamodel.AlignedCodonFrame cf = new jalview.datamodel.AlignedCodonFrame(
1924 alc[i].getAlcodonCount());
1925 if (alc[i].getAlcodonCount() > 0)
1927 Alcodon[] alcods = alc[i].getAlcodon();
1928 for (int p = 0; p < cf.codons.length; p++)
1930 if (alcods[p].hasPos1() && alcods[p].hasPos2()
1931 && alcods[p].hasPos3())
1933 // translated codons require three valid positions
1934 cf.codons[p] = new int[3];
1935 cf.codons[p][0] = (int) alcods[p].getPos1();
1936 cf.codons[p][1] = (int) alcods[p].getPos2();
1937 cf.codons[p][2] = (int) alcods[p].getPos3();
1941 cf.codons[p] = null;
1945 if (alc[i].getAlcodMapCount() > 0)
1947 AlcodMap[] maps = alc[i].getAlcodMap();
1948 for (int m = 0; m < maps.length; m++)
1950 SequenceI dnaseq = (SequenceI) seqRefIds
1951 .get(maps[m].getDnasq());
1953 jalview.datamodel.Mapping mapping = null;
1954 // attach to dna sequence reference.
1955 if (maps[m].getMapping() != null)
1957 mapping = addMapping(maps[m].getMapping());
1961 cf.addMap(dnaseq, mapping.getTo(), mapping.getMap());
1966 frefedSequence.add(new Object[]
1967 { maps[m].getDnasq(), cf, mapping });
1971 al.addCodonFrame(cf);
1976 // ////////////////////////////////
1978 boolean hideQuality = true, hideConservation = true, hideConsensus = true;
1980 if (vamsasSet.getAnnotationCount() > 0)
1982 Annotation[] an = vamsasSet.getAnnotation();
1984 for (int i = 0; i < an.length; i++)
1986 // set visibility for automatic annotation for this view
1987 if (an[i].getLabel().equals("Quality"))
1989 hideQuality = false;
1992 else if (an[i].getLabel().equals("Conservation"))
1994 hideConservation = false;
1997 else if (an[i].getLabel().equals("Consensus"))
1999 hideConsensus = false;
2002 // set visiblity for other annotation in this view
2003 if (an[i].getId() != null
2004 && annotationIds.containsKey(an[i].getId()))
2006 jalview.datamodel.AlignmentAnnotation jda = (jalview.datamodel.AlignmentAnnotation) annotationIds
2007 .get(an[i].getId());
2008 // in principle Visible should always be true for annotation displayed
2009 // in multiple views
2010 if (an[i].hasVisible())
2011 jda.visible = an[i].getVisible();
2013 al.addAnnotation(jda);
2017 // Construct new annotation from model.
2018 AnnotationElement[] ae = an[i].getAnnotationElement();
2019 jalview.datamodel.Annotation[] anot = null;
2021 if (!an[i].getScoreOnly())
2023 anot = new jalview.datamodel.Annotation[al.getWidth()];
2025 for (int aa = 0; aa < ae.length && aa < anot.length; aa++)
2027 if (ae[aa].getPosition() >= anot.length)
2030 anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(
2032 ae[aa].getDisplayCharacter(), ae[aa].getDescription(), (ae[aa]
2033 .getSecondaryStructure() == null || ae[aa]
2034 .getSecondaryStructure().length() == 0) ? ' ' : ae[aa]
2035 .getSecondaryStructure().charAt(0), ae[aa].getValue()
2038 // JBPNote: Consider verifying dataflow for IO of secondary
2039 // structure annotation read from Stockholm files
2040 // this was added to try to ensure that
2041 // if (anot[ae[aa].getPosition()].secondaryStructure>' ')
2043 // anot[ae[aa].getPosition()].displayCharacter = "";
2045 anot[ae[aa].getPosition()].colour = new java.awt.Color(ae[aa]
2049 jalview.datamodel.AlignmentAnnotation jaa = null;
2051 if (an[i].getGraph())
2053 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
2054 an[i].getDescription(), anot, 0, 0, an[i].getGraphType());
2056 jaa.graphGroup = an[i].getGraphGroup();
2058 if (an[i].getThresholdLine() != null)
2060 jaa.setThreshold(new jalview.datamodel.GraphLine(an[i]
2061 .getThresholdLine().getValue(), an[i]
2062 .getThresholdLine().getLabel(), new java.awt.Color(
2063 an[i].getThresholdLine().getColour())));
2070 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
2071 an[i].getDescription(), anot);
2073 // register new annotation
2074 if (an[i].getId() != null)
2076 annotationIds.put(an[i].getId(), jaa);
2077 jaa.annotationId = an[i].getId();
2079 // recover sequence association
2080 if (an[i].getSequenceRef() != null)
2082 if (al.findName(an[i].getSequenceRef()) != null)
2084 jaa.createSequenceMapping(al.findName(an[i].getSequenceRef()),
2086 al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa);
2089 if (an[i].hasScore())
2091 jaa.setScore(an[i].getScore());
2094 if (an[i].hasVisible())
2095 jaa.visible = an[i].getVisible();
2097 al.addAnnotation(jaa);
2101 // ///////////////////////
2103 // Create alignment markup and styles for this view
2104 if (jms.getJGroupCount() > 0)
2106 JGroup[] groups = jms.getJGroup();
2108 for (int i = 0; i < groups.length; i++)
2110 ColourSchemeI cs = null;
2112 if (groups[i].getColour() != null)
2114 if (groups[i].getColour().startsWith("ucs"))
2116 cs = GetUserColourScheme(jms, groups[i].getColour());
2120 cs = ColourSchemeProperty.getColour(al, groups[i].getColour());
2125 cs.setThreshold(groups[i].getPidThreshold(), true);
2129 Vector seqs = new Vector();
2131 for (int s = 0; s < groups[i].getSeqCount(); s++)
2133 String seqId = groups[i].getSeq(s) + "";
2134 jalview.datamodel.SequenceI ts = (jalview.datamodel.SequenceI) seqRefIds
2139 seqs.addElement(ts);
2143 if (seqs.size() < 1)
2148 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(
2149 seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(),
2150 groups[i].getDisplayText(), groups[i].getColourText(),
2151 groups[i].getStart(), groups[i].getEnd());
2154 .setOutlineColour(new java.awt.Color(groups[i]
2155 .getOutlineColour()));
2157 sg.textColour = new java.awt.Color(groups[i].getTextCol1());
2158 sg.textColour2 = new java.awt.Color(groups[i].getTextCol2());
2159 sg.setShowunconserved(groups[i].hasShowUnconserved() ? groups[i]
2160 .isShowUnconserved() : false);
2161 sg.thresholdTextColour = groups[i].getTextColThreshold();
2163 if (groups[i].getConsThreshold() != 0)
2165 jalview.analysis.Conservation c = new jalview.analysis.Conservation(
2166 "All", ResidueProperties.propHash, 3, sg
2167 .getSequences(null), 0, sg.getWidth() - 1);
2169 c.verdict(false, 25);
2170 sg.cs.setConservation(c);
2177 // ///////////////////////////////
2180 // If we just load in the same jar file again, the sequenceSetId
2181 // will be the same, and we end up with multiple references
2182 // to the same sequenceSet. We must modify this id on load
2183 // so that each load of the file gives a unique id
2184 String uniqueSeqSetId = view.getSequenceSetId() + uniqueSetSuffix;
2185 String viewId = (view.getId() == null ? null : view.getId()
2187 AlignFrame af = null;
2188 AlignViewport av = null;
2189 // now check to see if we really need to create a new viewport.
2190 if (multipleView && viewportsAdded.size() == 0)
2192 // We recovered an alignment for which a viewport already exists.
2193 // TODO: fix up any settings necessary for overlaying stored state onto
2194 // state recovered from another document. (may not be necessary).
2195 // we may need a binding from a viewport in memory to one recovered from
2197 // and then recover its containing af to allow the settings to be applied.
2198 // TODO: fix for vamsas demo
2200 .println("About to recover a viewport for existing alignment: Sequence set ID is "
2202 Object seqsetobj = retrieveExistingObj(uniqueSeqSetId);
2203 if (seqsetobj != null)
2205 if (seqsetobj instanceof String)
2207 uniqueSeqSetId = (String) seqsetobj;
2209 .println("Recovered extant sequence set ID mapping for ID : New Sequence set ID is "
2215 .println("Warning : Collision between sequence set ID string and existing jalview object mapping.");
2220 AlignmentPanel ap = null;
2221 boolean isnewview = true;
2224 // Check to see if this alignment already has a view id == viewId
2225 jalview.gui.AlignmentPanel views[] = Desktop
2226 .getAlignmentPanels(uniqueSeqSetId);
2227 if (views != null && views.length > 0)
2229 for (int v = 0; v < views.length; v++)
2231 if (views[v].av.getViewId().equalsIgnoreCase(viewId))
2233 // recover the existing alignpanel, alignframe, viewport
2234 af = views[v].alignFrame;
2237 // TODO: could even skip resetting view settings if we don't want to
2238 // change the local settings from other jalview processes
2247 af = loadViewport(file, JSEQ, hiddenSeqs, al, hideConsensus,
2248 hideQuality, hideConservation, jms, view, uniqueSeqSetId,
2254 // /////////////////////////////////////
2255 if (loadTreesAndStructures && jms.getTreeCount() > 0)
2259 for (int t = 0; t < jms.getTreeCount(); t++)
2262 Tree tree = jms.getTree(t);
2264 TreePanel tp = (TreePanel) retrieveExistingObj(tree.getId());
2267 tp = af.ShowNewickTree(new jalview.io.NewickFile(tree
2268 .getNewick()), tree.getTitle(), tree.getWidth(), tree
2269 .getHeight(), tree.getXpos(), tree.getYpos());
2270 if (tree.getId() != null)
2272 // perhaps bind the tree id to something ?
2277 // update local tree attributes ?
2278 // TODO: should check if tp has been manipulated by user - if so its
2279 // settings shouldn't be modified
2280 tp.setTitle(tree.getTitle());
2281 tp.setBounds(new Rectangle(tree.getXpos(), tree.getYpos(), tree
2282 .getWidth(), tree.getHeight()));
2283 tp.av = av; // af.viewport; // TODO: verify 'associate with all
2286 tp.treeCanvas.av = av; // af.viewport;
2287 tp.treeCanvas.ap = ap; // af.alignPanel;
2292 warn("There was a problem recovering stored Newick tree: \n"
2293 + tree.getNewick());
2297 tp.fitToWindow.setState(tree.getFitToWindow());
2298 tp.fitToWindow_actionPerformed(null);
2300 if (tree.getFontName() != null)
2302 tp.setTreeFont(new java.awt.Font(tree.getFontName(), tree
2303 .getFontStyle(), tree.getFontSize()));
2307 tp.setTreeFont(new java.awt.Font(view.getFontName(), view
2308 .getFontStyle(), tree.getFontSize()));
2311 tp.showPlaceholders(tree.getMarkUnlinked());
2312 tp.showBootstrap(tree.getShowBootstrap());
2313 tp.showDistances(tree.getShowDistances());
2315 tp.treeCanvas.threshold = tree.getThreshold();
2317 if (tree.getCurrentTree())
2319 af.viewport.setCurrentTree(tp.getTree());
2323 } catch (Exception ex)
2325 ex.printStackTrace();
2329 // //LOAD STRUCTURES
2330 if (loadTreesAndStructures)
2332 for (int i = 0; i < JSEQ.length; i++)
2334 if (JSEQ[i].getPdbidsCount() > 0)
2336 Pdbids[] ids = JSEQ[i].getPdbids();
2337 for (int p = 0; p < ids.length; p++)
2339 for (int s = 0; s < ids[p].getStructureStateCount(); s++)
2341 // check to see if we haven't already created this structure view
2342 String sviewid = (ids[p].getStructureState(s).getViewId() == null) ? null
2343 : ids[p].getStructureState(s).getViewId()
2345 jalview.datamodel.PDBEntry jpdb = new jalview.datamodel.PDBEntry();
2346 // Originally : ids[p].getFile()
2347 // : TODO: verify external PDB file recovery still works in normal
2348 // jalview project load
2349 jpdb.setFile(loadPDBFile(jprovider, ids[p].getId()));
2350 jpdb.setId(ids[p].getId());
2352 int x = ids[p].getStructureState(s).getXpos();
2353 int y = ids[p].getStructureState(s).getYpos();
2354 int width = ids[p].getStructureState(s).getWidth();
2355 int height = ids[p].getStructureState(s).getHeight();
2356 AppJmol comp = null;
2357 JInternalFrame[] frames = null;
2362 frames = Desktop.desktop.getAllFrames();
2363 } catch (ArrayIndexOutOfBoundsException e)
2365 // occasional No such child exceptions are thrown here...
2370 } catch (Exception f)
2375 } while (frames == null);
2376 // search for any Jmol windows already open from other
2377 // alignment views that exactly match the stored structure state
2378 for (int f = 0; comp == null && f < frames.length; f++)
2380 if (frames[f] instanceof AppJmol)
2383 && ((AppJmol) frames[f]).getViewId().equals(
2386 // post jalview 2.4 schema includes structure view id
2387 comp = (AppJmol) frames[f];
2389 else if (frames[f].getX() == x && frames[f].getY() == y
2390 && frames[f].getHeight() == height
2391 && frames[f].getWidth() == width)
2393 comp = (AppJmol) frames[f];
2397 // Probably don't need to do this anymore...
2398 // Desktop.desktop.getComponentAt(x, y);
2399 // TODO: NOW: check that this recovers the PDB file correctly.
2400 String pdbFile = loadPDBFile(jprovider, ids[p].getId());
2402 jalview.datamodel.SequenceI[] seq = new jalview.datamodel.SequenceI[]
2403 { (jalview.datamodel.SequenceI) seqRefIds.get(JSEQ[i].getId()
2408 // create a new Jmol window
2409 String state = ids[p].getStructureState(s).getContent();
2410 StringBuffer newFileLoc = null;
2411 if (state.indexOf("load") > -1)
2413 newFileLoc = new StringBuffer(state.substring(0, state
2414 .indexOf("\"", state.indexOf("load")) + 1));
2416 newFileLoc.append(jpdb.getFile());
2417 newFileLoc.append(state.substring(state.indexOf("\"",
2418 state.indexOf("load \"") + 6)));
2423 .println("Ignoring incomplete Jmol state for PDB "
2426 newFileLoc = new StringBuffer(state);
2427 newFileLoc.append("; load \"");
2428 newFileLoc.append(jpdb.getFile());
2429 newFileLoc.append("\";");
2432 if (newFileLoc != null)
2434 new AppJmol(pdbFile, ids[p].getId(), seq, af.alignPanel,
2435 newFileLoc.toString(), new java.awt.Rectangle(x,
2436 y, width, height), sviewid);
2441 // if (comp != null)
2443 // NOTE: if the jalview project is part of a shared session then
2444 // view synchronization should/could be done here.
2446 // add mapping for this sequence to the already open Jmol
2447 // instance (if it doesn't already exist)
2449 StructureSelectionManager.getStructureSelectionManager()
2450 .setMapping(seq, null, pdbFile,
2451 jalview.io.AppletFormatAdapter.FILE);
2453 ((AppJmol) comp).addSequence(seq);
2464 AlignFrame loadViewport(String file, JSeq[] JSEQ, Vector hiddenSeqs,
2465 Alignment al, boolean hideConsensus, boolean hideQuality,
2466 boolean hideConservation, JalviewModelSequence jms,
2467 Viewport view, String uniqueSeqSetId, String viewId)
2469 AlignFrame af = null;
2470 af = new AlignFrame(al, view.getWidth(), view.getHeight(),
2471 uniqueSeqSetId, viewId);
2473 af.setFileName(file, "Jalview");
2475 for (int i = 0; i < JSEQ.length; i++)
2477 af.viewport.setSequenceColour(af.viewport.alignment.getSequenceAt(i),
2478 new java.awt.Color(JSEQ[i].getColour()));
2481 af.viewport.gatherViewsHere = view.getGatheredViews();
2483 if (view.getSequenceSetId() != null)
2485 jalview.gui.AlignViewport av = (jalview.gui.AlignViewport) viewportsAdded
2486 .get(uniqueSeqSetId);
2488 af.viewport.sequenceSetID = uniqueSeqSetId;
2491 // propagate shared settings to this new view
2492 af.viewport.historyList = av.historyList;
2493 af.viewport.redoList = av.redoList;
2497 viewportsAdded.put(uniqueSeqSetId, af.viewport);
2499 // TODO: check if this method can be called repeatedly without
2500 // side-effects if alignpanel already registered.
2501 PaintRefresher.Register(af.alignPanel, uniqueSeqSetId);
2503 // apply Hidden regions to view.
2504 if (hiddenSeqs != null)
2506 for (int s = 0; s < JSEQ.length; s++)
2508 jalview.datamodel.SequenceGroup hidden = new jalview.datamodel.SequenceGroup();
2510 for (int r = 0; r < JSEQ[s].getHiddenSequencesCount(); r++)
2512 hidden.addSequence(al
2513 .getSequenceAt(JSEQ[s].getHiddenSequences(r)), false);
2515 af.viewport.hideRepSequences(al.getSequenceAt(s), hidden);
2518 jalview.datamodel.SequenceI[] hseqs = new jalview.datamodel.SequenceI[hiddenSeqs
2521 for (int s = 0; s < hiddenSeqs.size(); s++)
2523 hseqs[s] = (jalview.datamodel.SequenceI) hiddenSeqs.elementAt(s);
2526 af.viewport.hideSequence(hseqs);
2529 // set visibility of annotation in view
2530 if ((hideConsensus || hideQuality || hideConservation)
2531 && al.getAlignmentAnnotation() != null)
2533 int hSize = al.getAlignmentAnnotation().length;
2534 for (int h = 0; h < hSize; h++)
2536 if ((hideConsensus && al.getAlignmentAnnotation()[h].label
2537 .equals("Consensus"))
2538 || (hideQuality && al.getAlignmentAnnotation()[h].label
2540 || (hideConservation && al.getAlignmentAnnotation()[h].label
2541 .equals("Conservation")))
2543 al.deleteAnnotation(al.getAlignmentAnnotation()[h]);
2548 af.alignPanel.adjustAnnotationHeight();
2550 // recover view properties and display parameters
2551 if (view.getViewName() != null)
2553 af.viewport.viewName = view.getViewName();
2554 af.setInitialTabVisible();
2556 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(), view
2559 af.viewport.setShowAnnotation(view.getShowAnnotation());
2560 af.viewport.setAbovePIDThreshold(view.getPidSelected());
2562 af.viewport.setColourText(view.getShowColourText());
2564 af.viewport.setConservationSelected(view.getConservationSelected());
2565 af.viewport.setShowJVSuffix(view.getShowFullId());
2566 af.viewport.rightAlignIds = view.getRightAlignIds();
2567 af.viewport.setFont(new java.awt.Font(view.getFontName(), view
2568 .getFontStyle(), view.getFontSize()));
2569 af.alignPanel.fontChanged();
2570 af.viewport.setRenderGaps(view.getRenderGaps());
2571 af.viewport.setWrapAlignment(view.getWrapAlignment());
2572 af.alignPanel.setWrapAlignment(view.getWrapAlignment());
2573 af.viewport.setShowAnnotation(view.getShowAnnotation());
2574 af.alignPanel.setAnnotationVisible(view.getShowAnnotation());
2576 af.viewport.setShowBoxes(view.getShowBoxes());
2578 af.viewport.setShowText(view.getShowText());
2580 af.viewport.textColour = new java.awt.Color(view.getTextCol1());
2581 af.viewport.textColour2 = new java.awt.Color(view.getTextCol2());
2582 af.viewport.thresholdTextColour = view.getTextColThreshold();
2583 af.viewport.setShowUnconserved(view.hasShowUnconserved() ? view
2584 .isShowUnconserved() : false);
2585 af.viewport.setStartRes(view.getStartRes());
2586 af.viewport.setStartSeq(view.getStartSeq());
2588 ColourSchemeI cs = null;
2589 // apply colourschemes
2590 if (view.getBgColour() != null)
2592 if (view.getBgColour().startsWith("ucs"))
2594 cs = GetUserColourScheme(jms, view.getBgColour());
2596 else if (view.getBgColour().startsWith("Annotation"))
2598 // int find annotation
2599 for (int i = 0; i < af.viewport.alignment.getAlignmentAnnotation().length; i++)
2601 if (af.viewport.alignment.getAlignmentAnnotation()[i].label
2602 .equals(view.getAnnotationColours().getAnnotation()))
2604 if (af.viewport.alignment.getAlignmentAnnotation()[i]
2605 .getThreshold() == null)
2607 af.viewport.alignment.getAlignmentAnnotation()[i]
2608 .setThreshold(new jalview.datamodel.GraphLine(view
2609 .getAnnotationColours().getThreshold(),
2610 "Threshold", java.awt.Color.black)
2615 if (view.getAnnotationColours().getColourScheme()
2618 cs = new AnnotationColourGradient(af.viewport.alignment
2619 .getAlignmentAnnotation()[i], new java.awt.Color(view
2620 .getAnnotationColours().getMinColour()),
2621 new java.awt.Color(view.getAnnotationColours()
2622 .getMaxColour()), view.getAnnotationColours()
2623 .getAboveThreshold());
2625 else if (view.getAnnotationColours().getColourScheme()
2628 cs = new AnnotationColourGradient(af.viewport.alignment
2629 .getAlignmentAnnotation()[i], GetUserColourScheme(
2630 jms, view.getAnnotationColours().getColourScheme()),
2631 view.getAnnotationColours().getAboveThreshold());
2635 cs = new AnnotationColourGradient(af.viewport.alignment
2636 .getAlignmentAnnotation()[i], ColourSchemeProperty
2637 .getColour(al, view.getAnnotationColours()
2638 .getColourScheme()), view
2639 .getAnnotationColours().getAboveThreshold());
2642 // Also use these settings for all the groups
2643 if (al.getGroups() != null)
2645 for (int g = 0; g < al.getGroups().size(); g++)
2647 jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) al
2648 .getGroups().elementAt(g);
2657 * (view.getAnnotationColours().getColourScheme().equals("None"
2658 * )) { sg.cs = new AnnotationColourGradient(
2659 * af.viewport.alignment.getAlignmentAnnotation()[i], new
2660 * java.awt.Color(view.getAnnotationColours(). getMinColour()),
2661 * new java.awt.Color(view.getAnnotationColours().
2663 * view.getAnnotationColours().getAboveThreshold()); } else
2666 sg.cs = new AnnotationColourGradient(
2667 af.viewport.alignment.getAlignmentAnnotation()[i],
2668 sg.cs, view.getAnnotationColours()
2669 .getAboveThreshold());
2682 cs = ColourSchemeProperty.getColour(al, view.getBgColour());
2687 cs.setThreshold(view.getPidThreshold(), true);
2688 cs.setConsensus(af.viewport.hconsensus);
2692 af.viewport.setGlobalColourScheme(cs);
2693 af.viewport.setColourAppliesToAllGroups(false);
2695 if (view.getConservationSelected() && cs != null)
2697 cs.setConservationInc(view.getConsThreshold());
2700 af.changeColour(cs);
2702 af.viewport.setColourAppliesToAllGroups(true);
2704 if (view.getShowSequenceFeatures())
2706 af.viewport.showSequenceFeatures = true;
2708 // recover featre settings
2709 if (jms.getFeatureSettings() != null)
2711 af.viewport.featuresDisplayed = new Hashtable();
2712 String[] renderOrder = new String[jms.getFeatureSettings()
2713 .getSettingCount()];
2714 for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++)
2716 Setting setting = jms.getFeatureSettings().getSetting(fs);
2717 if (setting.hasMincolour())
2719 // TODO: determine how to set data independent bounds for a graduated
2720 // colour scheme's range.
2721 GraduatedColor gc = new GraduatedColor(new java.awt.Color(setting
2723 new java.awt.Color(setting.getColour()), 0, 1);
2724 if (setting.hasThreshold())
2726 gc.setThresh(setting.getThreshold());
2727 gc.setThreshType(setting.getThreshstate());
2732 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(
2734 new java.awt.Color(setting.getColour()));
2736 renderOrder[fs] = setting.getType();
2737 if (setting.hasOrder())
2738 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder(
2739 setting.getType(), setting.getOrder());
2741 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder(
2743 fs / jms.getFeatureSettings().getSettingCount());
2744 if (setting.getDisplay())
2746 af.viewport.featuresDisplayed.put(setting.getType(), new Integer(
2747 setting.getColour()));
2750 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;
2752 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureGroups = fgtable = new Hashtable();
2753 for (int gs = 0; gs < jms.getFeatureSettings().getGroupCount(); gs++)
2755 Group grp = jms.getFeatureSettings().getGroup(gs);
2756 fgtable.put(grp.getName(), new Boolean(grp.getDisplay()));
2760 if (view.getHiddenColumnsCount() > 0)
2762 for (int c = 0; c < view.getHiddenColumnsCount(); c++)
2764 af.viewport.hideColumns(view.getHiddenColumns(c).getStart(), view
2765 .getHiddenColumns(c).getEnd() // +1
2770 af.setMenusFromViewport(af.viewport);
2771 // TODO: we don't need to do this if the viewport is aready visible.
2772 Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(), view
2777 Hashtable skipList = null;
2780 * TODO remove this method
2783 * @return AlignFrame bound to sequenceSetId from view, if one exists. private
2784 * AlignFrame getSkippedFrame(Viewport view) { if (skipList==null) {
2785 * throw new Error("Implementation Error. No skipList defined for this
2786 * Jalview2XML instance."); } return (AlignFrame)
2787 * skipList.get(view.getSequenceSetId()); }
2791 * Check if the Jalview view contained in object should be skipped or not.
2794 * @return true if view's sequenceSetId is a key in skipList
2796 private boolean skipViewport(JalviewModel object)
2798 if (skipList == null)
2803 if (skipList.containsKey(id = object.getJalviewModelSequence()
2804 .getViewport()[0].getSequenceSetId()))
2806 if (Cache.log != null && Cache.log.isDebugEnabled())
2808 Cache.log.debug("Skipping seuqence set id " + id);
2815 public void AddToSkipList(AlignFrame af)
2817 if (skipList == null)
2819 skipList = new Hashtable();
2821 skipList.put(af.getViewport().getSequenceSetId(), af);
2824 public void clearSkipList()
2826 if (skipList != null)
2833 private void recoverDatasetFor(SequenceSet vamsasSet, Alignment al)
2835 jalview.datamodel.Alignment ds = getDatasetFor(vamsasSet.getDatasetId());
2836 Vector dseqs = null;
2839 // create a list of new dataset sequences
2840 dseqs = new Vector();
2842 for (int i = 0, iSize = vamsasSet.getSequenceCount(); i < iSize; i++)
2844 Sequence vamsasSeq = vamsasSet.getSequence(i);
2845 ensureJalviewDatasetSequence(vamsasSeq, ds, dseqs);
2847 // create a new dataset
2850 SequenceI[] dsseqs = new SequenceI[dseqs.size()];
2851 dseqs.copyInto(dsseqs);
2852 ds = new jalview.datamodel.Alignment(dsseqs);
2853 debug("Created new dataset " + vamsasSet.getDatasetId()
2854 + " for alignment " + System.identityHashCode(al));
2855 addDatasetRef(vamsasSet.getDatasetId(), ds);
2857 // set the dataset for the newly imported alignment.
2858 if (al.getDataset() == null)
2867 * sequence definition to create/merge dataset sequence for
2871 * vector to add new dataset sequence to
2873 private void ensureJalviewDatasetSequence(Sequence vamsasSeq,
2874 AlignmentI ds, Vector dseqs)
2876 // JBP TODO: Check this is called for AlCodonFrames to support recovery of
2878 jalview.datamodel.Sequence sq = (jalview.datamodel.Sequence) seqRefIds
2879 .get(vamsasSeq.getId());
2880 jalview.datamodel.SequenceI dsq = null;
2881 if (sq != null && sq.getDatasetSequence() != null)
2883 dsq = (jalview.datamodel.SequenceI) sq.getDatasetSequence();
2886 String sqid = vamsasSeq.getDsseqid();
2889 // need to create or add a new dataset sequence reference to this sequence
2892 dsq = (jalview.datamodel.SequenceI) seqRefIds.get(sqid);
2897 // make a new dataset sequence
2898 dsq = sq.createDatasetSequence();
2901 // make up a new dataset reference for this sequence
2902 sqid = seqHash(dsq);
2904 dsq.setVamsasId(uniqueSetSuffix + sqid);
2905 seqRefIds.put(sqid, dsq);
2910 dseqs.addElement(dsq);
2915 ds.addSequence(dsq);
2921 { // make this dataset sequence sq's dataset sequence
2922 sq.setDatasetSequence(dsq);
2926 // TODO: refactor this as a merge dataset sequence function
2927 // now check that sq (the dataset sequence) sequence really is the union of
2928 // all references to it
2929 // boolean pre = sq.getStart() < dsq.getStart();
2930 // boolean post = sq.getEnd() > dsq.getEnd();
2934 StringBuffer sb = new StringBuffer();
2935 String newres = jalview.analysis.AlignSeq.extractGaps(
2936 jalview.util.Comparison.GapChars, sq.getSequenceAsString());
2937 if (!newres.equalsIgnoreCase(dsq.getSequenceAsString())
2938 && newres.length() > dsq.getLength())
2940 // Update with the longer sequence.
2944 * if (pre) { sb.insert(0, newres .substring(0, dsq.getStart() -
2945 * sq.getStart())); dsq.setStart(sq.getStart()); } if (post) {
2946 * sb.append(newres.substring(newres.length() - sq.getEnd() -
2947 * dsq.getEnd())); dsq.setEnd(sq.getEnd()); }
2949 dsq.setSequence(sb.toString());
2951 // TODO: merges will never happen if we 'know' we have the real dataset
2952 // sequence - this should be detected when id==dssid
2953 System.err.println("DEBUG Notice: Merged dataset sequence"); // ("
2954 // + (pre ? "prepended" : "") + " "
2955 // + (post ? "appended" : ""));
2960 java.util.Hashtable datasetIds = null;
2962 java.util.IdentityHashMap dataset2Ids = null;
2964 private Alignment getDatasetFor(String datasetId)
2966 if (datasetIds == null)
2968 datasetIds = new Hashtable();
2971 if (datasetIds.containsKey(datasetId))
2973 return (Alignment) datasetIds.get(datasetId);
2978 private void addDatasetRef(String datasetId, Alignment dataset)
2980 if (datasetIds == null)
2982 datasetIds = new Hashtable();
2984 datasetIds.put(datasetId, dataset);
2988 * make a new dataset ID for this jalview dataset alignment
2993 private String getDatasetIdRef(jalview.datamodel.Alignment dataset)
2995 if (dataset.getDataset() != null)
2997 warn("Serious issue! Dataset Object passed to getDatasetIdRef is not a Jalview DATASET alignment...");
2999 String datasetId = makeHashCode(dataset, null);
3000 if (datasetId == null)
3002 // make a new datasetId and record it
3003 if (dataset2Ids == null)
3005 dataset2Ids = new IdentityHashMap();
3009 datasetId = (String) dataset2Ids.get(dataset);
3011 if (datasetId == null)
3013 datasetId = "ds" + dataset2Ids.size() + 1;
3014 dataset2Ids.put(dataset, datasetId);
3020 private void addDBRefs(SequenceI datasetSequence, Sequence sequence)
3022 for (int d = 0; d < sequence.getDBRefCount(); d++)
3024 DBRef dr = sequence.getDBRef(d);
3025 jalview.datamodel.DBRefEntry entry = new jalview.datamodel.DBRefEntry(
3026 sequence.getDBRef(d).getSource(), sequence.getDBRef(d)
3027 .getVersion(), sequence.getDBRef(d).getAccessionId());
3028 if (dr.getMapping() != null)
3030 entry.setMap(addMapping(dr.getMapping()));
3032 datasetSequence.addDBRef(entry);
3036 private jalview.datamodel.Mapping addMapping(Mapping m)
3038 SequenceI dsto = null;
3039 // Mapping m = dr.getMapping();
3040 int fr[] = new int[m.getMapListFromCount() * 2];
3041 Enumeration f = m.enumerateMapListFrom();
3042 for (int _i = 0; f.hasMoreElements(); _i += 2)
3044 MapListFrom mf = (MapListFrom) f.nextElement();
3045 fr[_i] = mf.getStart();
3046 fr[_i + 1] = mf.getEnd();
3048 int fto[] = new int[m.getMapListToCount() * 2];
3049 f = m.enumerateMapListTo();
3050 for (int _i = 0; f.hasMoreElements(); _i += 2)
3052 MapListTo mf = (MapListTo) f.nextElement();
3053 fto[_i] = mf.getStart();
3054 fto[_i + 1] = mf.getEnd();
3056 jalview.datamodel.Mapping jmap = new jalview.datamodel.Mapping(dsto,
3057 fr, fto, (int) m.getMapFromUnit(), (int) m.getMapToUnit());
3058 if (m.getMappingChoice() != null)
3060 MappingChoice mc = m.getMappingChoice();
3061 if (mc.getDseqFor() != null)
3063 String dsfor = "" + mc.getDseqFor();
3064 if (seqRefIds.containsKey(dsfor))
3069 jmap.setTo((SequenceI) seqRefIds.get(dsfor));
3073 frefedSequence.add(new Object[]
3080 * local sequence definition
3082 Sequence ms = mc.getSequence();
3083 jalview.datamodel.Sequence djs = null;
3084 String sqid = ms.getDsseqid();
3085 if (sqid != null && sqid.length() > 0)
3088 * recover dataset sequence
3090 djs = (jalview.datamodel.Sequence) seqRefIds.get(sqid);
3095 .println("Warning - making up dataset sequence id for DbRef sequence map reference");
3096 sqid = ((Object) ms).toString(); // make up a new hascode for
3097 // undefined dataset sequence hash
3098 // (unlikely to happen)
3104 * make a new dataset sequence and add it to refIds hash
3106 djs = new jalview.datamodel.Sequence(ms.getName(), ms
3108 djs.setStart(jmap.getMap().getToLowest());
3109 djs.setEnd(jmap.getMap().getToHighest());
3110 djs.setVamsasId(uniqueSetSuffix + sqid);
3112 seqRefIds.put(sqid, djs);
3115 jalview.bin.Cache.log.debug("about to recurse on addDBRefs.");
3124 public jalview.gui.AlignmentPanel copyAlignPanel(AlignmentPanel ap,
3125 boolean keepSeqRefs)
3128 jalview.schemabinding.version2.JalviewModel jm = SaveState(ap, null,
3134 jm.getJalviewModelSequence().getViewport(0).setSequenceSetId(null);
3138 uniqueSetSuffix = "";
3139 jm.getJalviewModelSequence().getViewport(0).setId(null); // we don't
3144 if (this.frefedSequence == null)
3146 frefedSequence = new Vector();
3149 viewportsAdded = new Hashtable();
3151 AlignFrame af = LoadFromObject(jm, null, false, null);
3152 af.alignPanels.clear();
3153 af.closeMenuItem_actionPerformed(true);
3156 * if(ap.av.alignment.getAlignmentAnnotation()!=null) { for(int i=0;
3157 * i<ap.av.alignment.getAlignmentAnnotation().length; i++) {
3158 * if(!ap.av.alignment.getAlignmentAnnotation()[i].autoCalculated) {
3159 * af.alignPanel.av.alignment.getAlignmentAnnotation()[i] =
3160 * ap.av.alignment.getAlignmentAnnotation()[i]; } } }
3163 return af.alignPanel;
3167 * flag indicating if hashtables should be cleared on finalization TODO this
3168 * flag may not be necessary
3170 private boolean _cleartables = true;
3172 private Hashtable jvids2vobj;
3177 * @see java.lang.Object#finalize()
3179 protected void finalize() throws Throwable
3181 // really make sure we have no buried refs left.
3186 this.seqRefIds = null;
3187 this.seqsToIds = null;
3191 private void warn(String msg)
3196 private void warn(String msg, Exception e)
3198 if (Cache.log != null)
3202 Cache.log.warn(msg, e);
3206 Cache.log.warn(msg);
3211 System.err.println("Warning: " + msg);
3214 e.printStackTrace();
3219 private void debug(String string)
3221 debug(string, null);
3224 private void debug(String msg, Exception e)
3226 if (Cache.log != null)
3230 Cache.log.debug(msg, e);
3234 Cache.log.debug(msg);
3239 System.err.println("Warning: " + msg);
3242 e.printStackTrace();
3248 * set the object to ID mapping tables used to write/recover objects and XML
3249 * ID strings for the jalview project. If external tables are provided then
3250 * finalize and clearSeqRefs will not clear the tables when the Jalview2XML
3251 * object goes out of scope. - also populates the datasetIds hashtable with
3252 * alignment objects containing dataset sequences
3255 * Map from ID strings to jalview datamodel
3257 * Map from jalview datamodel to ID strings
3261 public void setObjectMappingTables(Hashtable vobj2jv,
3262 IdentityHashMap jv2vobj)
3264 this.jv2vobj = jv2vobj;
3265 this.vobj2jv = vobj2jv;
3266 Iterator ds = jv2vobj.keySet().iterator();
3268 while (ds.hasNext())
3270 Object jvobj = ds.next();
3271 id = jv2vobj.get(jvobj).toString();
3272 if (jvobj instanceof jalview.datamodel.Alignment)
3274 if (((jalview.datamodel.Alignment) jvobj).getDataset() == null)
3276 addDatasetRef(id, (jalview.datamodel.Alignment) jvobj);
3279 else if (jvobj instanceof jalview.datamodel.Sequence)
3281 // register sequence object so the XML parser can recover it.
3282 if (seqRefIds == null)
3284 seqRefIds = new Hashtable();
3286 if (seqsToIds == null)
3288 seqsToIds = new IdentityHashMap();
3290 seqRefIds.put(jv2vobj.get(jvobj).toString(), jvobj);
3291 seqsToIds.put(jvobj, id);
3293 else if (jvobj instanceof jalview.datamodel.AlignmentAnnotation)
3295 if (annotationIds == null)
3297 annotationIds = new Hashtable();
3300 annotationIds.put(anid = jv2vobj.get(jvobj).toString(), jvobj);
3301 jalview.datamodel.AlignmentAnnotation jvann = (jalview.datamodel.AlignmentAnnotation) jvobj;
3302 if (jvann.annotationId == null)
3304 jvann.annotationId = anid;
3306 if (!jvann.annotationId.equals(anid))
3308 // TODO verify that this is the correct behaviour
3309 this.warn("Overriding Annotation ID for " + anid
3310 + " from different id : " + jvann.annotationId);
3311 jvann.annotationId = anid;
3314 else if (jvobj instanceof String)
3316 if (jvids2vobj == null)
3318 jvids2vobj = new Hashtable();
3319 jvids2vobj.put(jvobj, jv2vobj.get(jvobj).toString());
3323 Cache.log.debug("Ignoring " + jvobj.getClass() + " (ID = " + id);
3328 * set the uniqueSetSuffix used to prefix/suffix object IDs for jalview
3329 * objects created from the project archive. If string is null (default for
3330 * construction) then suffix will be set automatically.
3334 public void setUniqueSetSuffix(String string)
3336 uniqueSetSuffix = string;
3341 * uses skipList2 as the skipList for skipping views on sequence sets
3342 * associated with keys in the skipList
3346 public void setSkipList(Hashtable skipList2)
3348 skipList = skipList2;