2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import java.awt.Rectangle;
22 import java.lang.reflect.InvocationTargetException;
25 import java.util.Map.Entry;
26 import java.util.jar.*;
30 import org.exolab.castor.xml.*;
32 import jalview.bin.Cache;
33 import jalview.datamodel.Alignment;
34 import jalview.datamodel.AlignmentAnnotation;
35 import jalview.datamodel.AlignmentI;
36 import jalview.datamodel.SequenceI;
37 import jalview.schemabinding.version2.*;
38 import jalview.schemes.*;
39 import jalview.util.Platform;
40 import jalview.util.jarInputStreamProvider;
41 import jalview.ws.jws2.AAConsClient;
42 import jalview.ws.jws2.Jws2Discoverer;
43 import jalview.ws.jws2.dm.AAConsSettings;
44 import jalview.ws.jws2.jabaws2.Jws2Instance;
45 import jalview.ws.params.ArgumentI;
46 import jalview.ws.params.AutoCalcSetting;
47 import jalview.ws.params.WsParamSetI;
50 * Write out the current jalview desktop state as a Jalview XML stream.
52 * Note: the vamsas objects referred to here are primitive versions of the
53 * VAMSAS project schema elements - they are not the same and most likely never
57 * @version $Revision: 1.134 $
59 public class Jalview2XML
62 * create/return unique hash string for sq
65 * @return new or existing unique string for sq
67 String seqHash(SequenceI sq)
69 if (seqsToIds == null)
73 if (seqsToIds.containsKey(sq))
75 return (String) seqsToIds.get(sq);
79 // create sequential key
80 String key = "sq" + (seqsToIds.size() + 1);
81 key = makeHashCode(sq, key); // check we don't have an external reference
83 seqsToIds.put(sq, key);
92 if (seqRefIds != null)
96 if (seqsToIds != null)
106 warn("clearSeqRefs called when _cleartables was not set. Doing nothing.");
107 // seqRefIds = new Hashtable();
108 // seqsToIds = new IdentityHashMap();
114 if (seqsToIds == null)
116 seqsToIds = new IdentityHashMap();
118 if (seqRefIds == null)
120 seqRefIds = new Hashtable();
125 * SequenceI reference -> XML ID string in jalview XML. Populated as XML reps
126 * of sequence objects are created.
128 java.util.IdentityHashMap seqsToIds = null;
131 * jalview XML Sequence ID to jalview sequence object reference (both dataset
132 * and alignment sequences. Populated as XML reps of sequence objects are
135 java.util.Hashtable seqRefIds = null; // key->SequenceI resolution
137 Vector frefedSequence = null;
139 boolean raiseGUI = true; // whether errors are raised in dialog boxes or not
145 public Jalview2XML(boolean raiseGUI)
147 this.raiseGUI = raiseGUI;
150 public void resolveFrefedSequences()
152 if (frefedSequence.size() > 0)
154 int r = 0, rSize = frefedSequence.size();
157 Object[] ref = (Object[]) frefedSequence.elementAt(r);
160 String sref = (String) ref[0];
161 if (seqRefIds.containsKey(sref))
163 if (ref[1] instanceof jalview.datamodel.Mapping)
165 SequenceI seq = (SequenceI) seqRefIds.get(sref);
166 while (seq.getDatasetSequence() != null)
168 seq = seq.getDatasetSequence();
170 ((jalview.datamodel.Mapping) ref[1]).setTo(seq);
174 if (ref[1] instanceof jalview.datamodel.AlignedCodonFrame)
176 SequenceI seq = (SequenceI) seqRefIds.get(sref);
177 while (seq.getDatasetSequence() != null)
179 seq = seq.getDatasetSequence();
182 && ref[2] instanceof jalview.datamodel.Mapping)
184 jalview.datamodel.Mapping mp = (jalview.datamodel.Mapping) ref[2];
185 ((jalview.datamodel.AlignedCodonFrame) ref[1]).addMap(
186 seq, mp.getTo(), mp.getMap());
191 .println("IMPLEMENTATION ERROR: Unimplemented forward sequence references for AlcodonFrames involving "
192 + ref[2].getClass() + " type objects.");
198 .println("IMPLEMENTATION ERROR: Unimplemented forward sequence references for "
199 + ref[1].getClass() + " type objects.");
202 frefedSequence.remove(r);
208 .println("IMPLEMENTATION WARNING: Unresolved forward reference for hash string "
210 + " with objecttype "
211 + ref[1].getClass());
218 frefedSequence.remove(r);
226 * This maintains a list of viewports, the key being the seqSetId. Important
227 * to set historyItem and redoList for multiple views
229 Hashtable viewportsAdded;
231 Hashtable annotationIds = new Hashtable();
233 String uniqueSetSuffix = "";
236 * List of pdbfiles added to Jar
238 Vector pdbfiles = null;
240 // SAVES SEVERAL ALIGNMENT WINDOWS TO SAME JARFILE
241 public void SaveState(File statefile)
245 FileOutputStream fos = new FileOutputStream(statefile);
246 JarOutputStream jout = new JarOutputStream(fos);
249 } catch (Exception e)
251 // TODO: inform user of the problem - they need to know if their data was
253 if (errorMessage == null)
255 errorMessage = "Couldn't write Jalview Archive to output file '"
256 + statefile + "' - See console error log for details";
260 errorMessage += "(output file was '" + statefile + "')";
268 * Writes a jalview project archive to the given Jar output stream.
272 public void SaveState(JarOutputStream jout)
274 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
284 // NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
285 // //////////////////////////////////////////////////
286 // NOTE ALSO new PrintWriter must be used for each new JarEntry
287 PrintWriter out = null;
289 Vector shortNames = new Vector();
292 for (int i = frames.length - 1; i > -1; i--)
294 if (frames[i] instanceof AlignFrame)
296 AlignFrame af = (AlignFrame) frames[i];
299 && skipList.containsKey(af.getViewport()
300 .getSequenceSetId()))
305 String shortName = af.getTitle();
307 if (shortName.indexOf(File.separatorChar) > -1)
309 shortName = shortName.substring(shortName
310 .lastIndexOf(File.separatorChar) + 1);
315 while (shortNames.contains(shortName))
317 if (shortName.endsWith("_" + (count - 1)))
319 shortName = shortName
320 .substring(0, shortName.lastIndexOf("_"));
323 shortName = shortName.concat("_" + count);
327 shortNames.addElement(shortName);
329 if (!shortName.endsWith(".xml"))
331 shortName = shortName + ".xml";
334 int ap, apSize = af.alignPanels.size();
335 for (ap = 0; ap < apSize; ap++)
337 AlignmentPanel apanel = (AlignmentPanel) af.alignPanels
339 String fileName = apSize == 1 ? shortName : ap + shortName;
340 if (!fileName.endsWith(".xml"))
342 fileName = fileName + ".xml";
345 SaveState(apanel, fileName, jout);
352 } catch (Exception foo)
357 } catch (Exception ex)
359 // TODO: inform user of the problem - they need to know if their data was
361 if (errorMessage == null)
363 errorMessage = "Couldn't write Jalview Archive - see error output for details";
365 ex.printStackTrace();
369 // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW
370 public boolean SaveAlignment(AlignFrame af, String jarFile,
375 int ap, apSize = af.alignPanels.size();
376 FileOutputStream fos = new FileOutputStream(jarFile);
377 JarOutputStream jout = new JarOutputStream(fos);
378 for (ap = 0; ap < apSize; ap++)
380 AlignmentPanel apanel = (AlignmentPanel) af.alignPanels
382 String jfileName = apSize == 1 ? fileName : fileName + ap;
383 if (!jfileName.endsWith(".xml"))
385 jfileName = jfileName + ".xml";
387 SaveState(apanel, jfileName, jout);
393 } catch (Exception foo)
399 } catch (Exception ex)
401 errorMessage = "Couldn't Write alignment view to Jalview Archive - see error output for details";
402 ex.printStackTrace();
408 * create a JalviewModel from an algnment view and marshall it to a
412 * panel to create jalview model for
414 * name of alignment panel written to output stream
420 public JalviewModel SaveState(AlignmentPanel ap, String fileName,
421 JarOutputStream jout)
424 Vector jmolViewIds = new Vector(); //
425 Vector userColours = new Vector();
427 AlignViewport av = ap.av;
429 JalviewModel object = new JalviewModel();
430 object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel());
432 object.setCreationDate(new java.util.Date(System.currentTimeMillis()));
433 object.setVersion(jalview.bin.Cache.getProperty("VERSION"));
435 jalview.datamodel.AlignmentI jal = av.getAlignment();
437 if (av.hasHiddenRows())
439 jal = jal.getHiddenSequences().getFullAlignment();
442 SequenceSet vamsasSet = new SequenceSet();
444 JalviewModelSequence jms = new JalviewModelSequence();
446 vamsasSet.setGapChar(jal.getGapCharacter() + "");
448 if (jal.getDataset() != null)
450 // dataset id is the dataset's hashcode
451 vamsasSet.setDatasetId(getDatasetIdRef(jal.getDataset()));
453 if (jal.getProperties() != null)
455 Enumeration en = jal.getProperties().keys();
456 while (en.hasMoreElements())
458 String key = en.nextElement().toString();
459 SequenceSetProperties ssp = new SequenceSetProperties();
461 ssp.setValue(jal.getProperties().get(key).toString());
462 vamsasSet.addSequenceSetProperties(ssp);
467 Set<String> calcIdSet=new HashSet<String>();
471 jalview.datamodel.SequenceI jds;
472 for (int i = 0; i < jal.getHeight(); i++)
474 jds = jal.getSequenceAt(i);
477 if (seqRefIds.get(id) != null)
479 // This happens for two reasons: 1. multiple views are being serialised.
480 // 2. the hashCode has collided with another sequence's code. This DOES
481 // HAPPEN! (PF00072.15.stk does this)
482 // JBPNote: Uncomment to debug writing out of files that do not read
483 // back in due to ArrayOutOfBoundExceptions.
484 // System.err.println("vamsasSeq backref: "+id+"");
485 // System.err.println(jds.getName()+"
486 // "+jds.getStart()+"-"+jds.getEnd()+" "+jds.getSequenceAsString());
487 // System.err.println("Hashcode: "+seqHash(jds));
488 // SequenceI rsq = (SequenceI) seqRefIds.get(id + "");
489 // System.err.println(rsq.getName()+"
490 // "+rsq.getStart()+"-"+rsq.getEnd()+" "+rsq.getSequenceAsString());
491 // System.err.println("Hashcode: "+seqHash(rsq));
495 vamsasSeq = createVamsasSequence(id, jds);
496 vamsasSet.addSequence(vamsasSeq);
497 seqRefIds.put(id, jds);
501 jseq.setStart(jds.getStart());
502 jseq.setEnd(jds.getEnd());
503 jseq.setColour(av.getSequenceColour(jds).getRGB());
505 jseq.setId(id); // jseq id should be a string not a number
507 if (av.hasHiddenRows())
509 jseq.setHidden(av.getAlignment().getHiddenSequences().isHidden(jds));
511 if (av.isHiddenRepSequence(jal.getSequenceAt(i)))
513 jalview.datamodel.SequenceI[] reps = av.getRepresentedSequences(jal.getSequenceAt(i)).getSequencesInOrder(jal);
515 for (int h = 0; h < reps.length; h++)
517 if (reps[h] != jal.getSequenceAt(i))
519 jseq.addHiddenSequences(jal.findIndex(reps[h]));
525 if (jds.getDatasetSequence().getSequenceFeatures() != null)
527 jalview.datamodel.SequenceFeature[] sf = jds.getDatasetSequence()
528 .getSequenceFeatures();
530 while (index < sf.length)
532 Features features = new Features();
534 features.setBegin(sf[index].getBegin());
535 features.setEnd(sf[index].getEnd());
536 features.setDescription(sf[index].getDescription());
537 features.setType(sf[index].getType());
538 features.setFeatureGroup(sf[index].getFeatureGroup());
539 features.setScore(sf[index].getScore());
540 if (sf[index].links != null)
542 for (int l = 0; l < sf[index].links.size(); l++)
544 OtherData keyValue = new OtherData();
545 keyValue.setKey("LINK_" + l);
546 keyValue.setValue(sf[index].links.elementAt(l).toString());
547 features.addOtherData(keyValue);
550 if (sf[index].otherDetails != null)
553 Enumeration keys = sf[index].otherDetails.keys();
554 while (keys.hasMoreElements())
556 key = keys.nextElement().toString();
557 OtherData keyValue = new OtherData();
558 keyValue.setKey(key);
559 keyValue.setValue(sf[index].otherDetails.get(key).toString());
560 features.addOtherData(keyValue);
564 jseq.addFeatures(features);
569 if (jds.getDatasetSequence().getPDBId() != null)
571 Enumeration en = jds.getDatasetSequence().getPDBId().elements();
572 while (en.hasMoreElements())
574 Pdbids pdb = new Pdbids();
575 jalview.datamodel.PDBEntry entry = (jalview.datamodel.PDBEntry) en
578 pdb.setId(entry.getId());
579 pdb.setType(entry.getType());
582 // This must have been loaded, is it still visible?
583 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
584 String matchedFile = null;
585 for (int f = frames.length - 1; f > -1; f--)
587 if (frames[f] instanceof AppJmol)
589 jmol = (AppJmol) frames[f];
590 for (int peid = 0; peid < jmol.jmb.pdbentry.length; peid++)
592 if (!jmol.jmb.pdbentry[peid].getId().equals(entry.getId())
593 && !(entry.getId().length() > 4 && entry
597 jmol.jmb.pdbentry[peid].getId()
600 if (matchedFile == null)
602 matchedFile = jmol.jmb.pdbentry[peid].getFile();
604 else if (!matchedFile.equals(jmol.jmb.pdbentry[peid]
608 .warn("Probably lost some PDB-Sequence mappings for this structure file (which apparently has same PDB Entry code): "
609 + jmol.jmb.pdbentry[peid].getFile());
613 // can get at it if the ID
614 // match is ambiguous (e.g.
616 String statestring = jmol.jmb.viewer.getStateInfo();
618 for (int smap = 0; smap < jmol.jmb.sequence[peid].length; smap++)
620 // if (jal.findIndex(jmol.jmb.sequence[peid][smap]) > -1)
621 if (jds==jmol.jmb.sequence[peid][smap])
623 StructureState state = new StructureState();
624 state.setVisible(true);
625 state.setXpos(jmol.getX());
626 state.setYpos(jmol.getY());
627 state.setWidth(jmol.getWidth());
628 state.setHeight(jmol.getHeight());
629 state.setViewId(jmol.getViewId());
630 state.setAlignwithAlignPanel(jmol.isUsedforaligment(ap));
631 state.setColourwithAlignPanel(jmol
632 .isUsedforcolourby(ap));
633 state.setColourByJmol(jmol.isColouredByJmol());
634 if (!jmolViewIds.contains(state.getViewId()))
636 // Make sure we only store a Jmol state once in each XML
638 jmolViewIds.addElement(state.getViewId());
639 state.setContent(statestring.replaceAll("\n", ""));
643 state.setContent("# duplicate state");
645 pdb.addStructureState(state);
652 if (matchedFile != null || entry.getFile() != null)
654 if (entry.getFile() != null)
657 matchedFile = entry.getFile();
659 pdb.setFile(matchedFile); // entry.getFile());
660 if (pdbfiles == null)
662 pdbfiles = new Vector();
665 if (!pdbfiles.contains(entry.getId()))
667 pdbfiles.addElement(entry.getId());
670 File file = new File(matchedFile);
671 if (file.exists() && jout != null)
673 byte[] data = new byte[(int) file.length()];
674 jout.putNextEntry(new JarEntry(entry.getId()));
675 DataInputStream dis = new DataInputStream(
676 new FileInputStream(file));
679 DataOutputStream dout = new DataOutputStream(jout);
680 dout.write(data, 0, data.length);
684 } catch (Exception ex)
686 ex.printStackTrace();
692 if (entry.getProperty() != null)
694 PdbentryItem item = new PdbentryItem();
695 Hashtable properties = entry.getProperty();
696 Enumeration en2 = properties.keys();
697 while (en2.hasMoreElements())
699 Property prop = new Property();
700 String key = en2.nextElement().toString();
702 prop.setValue(properties.get(key).toString());
703 item.addProperty(prop);
705 pdb.addPdbentryItem(item);
715 if (av.hasHiddenRows())
717 jal = av.getAlignment();
720 if (jal.getCodonFrames() != null && jal.getCodonFrames().length > 0)
722 jalview.datamodel.AlignedCodonFrame[] jac = jal.getCodonFrames();
723 for (int i = 0; i < jac.length; i++)
725 AlcodonFrame alc = new AlcodonFrame();
726 vamsasSet.addAlcodonFrame(alc);
727 for (int p = 0; p < jac[i].aaWidth; p++)
729 Alcodon cmap = new Alcodon();
730 if (jac[i].codons[p] != null)
732 // Null codons indicate a gapped column in the translated peptide
734 cmap.setPos1(jac[i].codons[p][0]);
735 cmap.setPos2(jac[i].codons[p][1]);
736 cmap.setPos3(jac[i].codons[p][2]);
738 alc.addAlcodon(cmap);
740 if (jac[i].getProtMappings() != null
741 && jac[i].getProtMappings().length > 0)
743 SequenceI[] dnas = jac[i].getdnaSeqs();
744 jalview.datamodel.Mapping[] pmaps = jac[i].getProtMappings();
745 for (int m = 0; m < pmaps.length; m++)
747 AlcodMap alcmap = new AlcodMap();
748 alcmap.setDnasq(seqHash(dnas[m]));
749 alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null,
751 alc.addAlcodMap(alcmap);
758 // /////////////////////////////////
759 if (av.currentTree != null)
761 // FIND ANY ASSOCIATED TREES
762 // NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT
763 if (Desktop.desktop != null)
765 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
767 for (int t = 0; t < frames.length; t++)
769 if (frames[t] instanceof TreePanel)
771 TreePanel tp = (TreePanel) frames[t];
773 if (tp.treeCanvas.av.getAlignment() == jal)
775 Tree tree = new Tree();
776 tree.setTitle(tp.getTitle());
777 tree.setCurrentTree((av.currentTree == tp.getTree()));
778 tree.setNewick(tp.getTree().toString());
779 tree.setThreshold(tp.treeCanvas.threshold);
781 tree.setFitToWindow(tp.fitToWindow.getState());
782 tree.setFontName(tp.getTreeFont().getName());
783 tree.setFontSize(tp.getTreeFont().getSize());
784 tree.setFontStyle(tp.getTreeFont().getStyle());
785 tree.setMarkUnlinked(tp.placeholdersMenu.getState());
787 tree.setShowBootstrap(tp.bootstrapMenu.getState());
788 tree.setShowDistances(tp.distanceMenu.getState());
790 tree.setHeight(tp.getHeight());
791 tree.setWidth(tp.getWidth());
792 tree.setXpos(tp.getX());
793 tree.setYpos(tp.getY());
794 tree.setId(makeHashCode(tp, null));
803 * store forward refs from an annotationRow to any groups
805 IdentityHashMap groupRefs = new IdentityHashMap();
806 if (jal.getAlignmentAnnotation() != null)
808 jalview.datamodel.AlignmentAnnotation[] aa = jal
809 .getAlignmentAnnotation();
811 for (int i = 0; i < aa.length; i++)
813 Annotation an = new Annotation();
815 if (aa[i].annotationId != null)
817 annotationIds.put(aa[i].annotationId, aa[i]);
820 an.setId(aa[i].annotationId);
822 an.setVisible(aa[i].visible);
824 an.setDescription(aa[i].description);
826 if (aa[i].sequenceRef != null)
828 // TODO later annotation sequenceRef should be the XML ID of the
829 // sequence rather than its display name
830 an.setSequenceRef(aa[i].sequenceRef.getName());
832 if (aa[i].groupRef != null)
834 Object groupIdr = groupRefs.get(aa[i].groupRef);
835 if (groupIdr == null)
837 // make a locally unique String
838 groupRefs.put(aa[i].groupRef,
839 groupIdr = ("" + System.currentTimeMillis()
840 + aa[i].groupRef.getName() + groupRefs.size()));
842 an.setGroupRef(groupIdr.toString());
845 // store all visualization attributes for annotation
846 an.setGraphHeight(aa[i].graphHeight);
847 an.setCentreColLabels(aa[i].centreColLabels);
848 an.setScaleColLabels(aa[i].scaleColLabel);
849 an.setShowAllColLabels(aa[i].showAllColLabels);
850 an.setBelowAlignment(aa[i].belowAlignment);
855 an.setGraphType(aa[i].graph);
856 an.setGraphGroup(aa[i].graphGroup);
857 if (aa[i].getThreshold() != null)
859 ThresholdLine line = new ThresholdLine();
860 line.setLabel(aa[i].getThreshold().label);
861 line.setValue(aa[i].getThreshold().value);
862 line.setColour(aa[i].getThreshold().colour.getRGB());
863 an.setThresholdLine(line);
871 an.setLabel(aa[i].label);
873 if (aa[i] == av.getAlignmentQualityAnnot() || aa[i] == av.getAlignmentConservationAnnotation()
874 || aa[i] == av.getAlignmentConsensusAnnotation() || aa[i].autoCalculated)
876 // new way of indicating autocalculated annotation -
877 an.setAutoCalculated(aa[i].autoCalculated);
879 if (aa[i].hasScore())
881 an.setScore(aa[i].getScore());
884 if (aa[i].getCalcId()!=null)
886 calcIdSet.add(aa[i].getCalcId());
887 an.setCalcId(aa[i].getCalcId());
890 AnnotationElement ae;
891 if (aa[i].annotations != null)
893 an.setScoreOnly(false);
894 for (int a = 0; a < aa[i].annotations.length; a++)
896 if ((aa[i] == null) || (aa[i].annotations[a] == null))
901 ae = new AnnotationElement();
902 if (aa[i].annotations[a].description != null)
903 ae.setDescription(aa[i].annotations[a].description);
904 if (aa[i].annotations[a].displayCharacter != null)
905 ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter);
907 if (!Float.isNaN(aa[i].annotations[a].value))
908 ae.setValue(aa[i].annotations[a].value);
911 if (aa[i].annotations[a].secondaryStructure != ' '
912 && aa[i].annotations[a].secondaryStructure != '\0')
913 ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure
916 if (aa[i].annotations[a].colour != null
917 && aa[i].annotations[a].colour != java.awt.Color.black)
919 ae.setColour(aa[i].annotations[a].colour.getRGB());
922 an.addAnnotationElement(ae);
923 if (aa[i].autoCalculated)
925 // only write one non-null entry into the annotation row -
926 // sufficient to get the visualization attributes necessary to
934 an.setScoreOnly(true);
936 vamsasSet.addAnnotation(an);
940 if (jal.getGroups() != null)
942 JGroup[] groups = new JGroup[jal.getGroups().size()];
944 for (jalview.datamodel.SequenceGroup sg:jal.getGroups())
946 groups[++i] = new JGroup();
948 groups[i].setStart(sg.getStartRes());
949 groups[i].setEnd(sg.getEndRes());
950 groups[i].setName(sg.getName());
951 if (groupRefs.containsKey(sg))
953 // group has references so set it's ID field
954 groups[i].setId(groupRefs.get(sg).toString());
958 if (sg.cs.conservationApplied())
960 groups[i].setConsThreshold(sg.cs.getConservationInc());
962 if (sg.cs instanceof jalview.schemes.UserColourScheme)
964 groups[i].setColour(SetUserColourScheme(sg.cs, userColours,
970 .setColour(ColourSchemeProperty.getColourName(sg.cs));
973 else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient)
976 .setColour(ColourSchemeProperty
977 .getColourName(((jalview.schemes.AnnotationColourGradient) sg.cs)
980 else if (sg.cs instanceof jalview.schemes.UserColourScheme)
983 .setColour(SetUserColourScheme(sg.cs, userColours, jms));
987 groups[i].setColour(ColourSchemeProperty.getColourName(sg.cs));
990 groups[i].setPidThreshold(sg.cs.getThreshold());
993 groups[i].setOutlineColour(sg.getOutlineColour().getRGB());
994 groups[i].setDisplayBoxes(sg.getDisplayBoxes());
995 groups[i].setDisplayText(sg.getDisplayText());
996 groups[i].setColourText(sg.getColourText());
997 groups[i].setTextCol1(sg.textColour.getRGB());
998 groups[i].setTextCol2(sg.textColour2.getRGB());
999 groups[i].setTextColThreshold(sg.thresholdTextColour);
1000 groups[i].setShowUnconserved(sg.getShowNonconserved());
1001 groups[i].setIgnoreGapsinConsensus(sg.getIgnoreGapsConsensus());
1002 groups[i].setShowConsensusHistogram(sg.isShowConsensusHistogram());
1003 groups[i].setShowSequenceLogo(sg.isShowSequenceLogo());
1004 for (int s = 0; s < sg.getSize(); s++)
1006 jalview.datamodel.Sequence seq = (jalview.datamodel.Sequence) sg
1008 groups[i].addSeq(seqHash(seq));
1012 jms.setJGroup(groups);
1015 // /////////SAVE VIEWPORT
1016 Viewport view = new Viewport();
1017 view.setTitle(ap.alignFrame.getTitle());
1018 view.setSequenceSetId(makeHashCode(av.getSequenceSetId(),
1019 av.getSequenceSetId()));
1020 view.setId(av.getViewId());
1021 view.setViewName(av.viewName);
1022 view.setGatheredViews(av.gatherViewsHere);
1024 if (ap.av.explodedPosition != null)
1026 view.setXpos(av.explodedPosition.x);
1027 view.setYpos(av.explodedPosition.y);
1028 view.setWidth(av.explodedPosition.width);
1029 view.setHeight(av.explodedPosition.height);
1033 view.setXpos(ap.alignFrame.getBounds().x);
1034 view.setYpos(ap.alignFrame.getBounds().y);
1035 view.setWidth(ap.alignFrame.getBounds().width);
1036 view.setHeight(ap.alignFrame.getBounds().height);
1039 view.setStartRes(av.startRes);
1040 view.setStartSeq(av.startSeq);
1042 if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)
1044 view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(),
1047 else if (av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient)
1049 jalview.schemes.AnnotationColourGradient acg = (jalview.schemes.AnnotationColourGradient) av
1050 .getGlobalColourScheme();
1052 AnnotationColours ac = new AnnotationColours();
1053 ac.setAboveThreshold(acg.getAboveThreshold());
1054 ac.setThreshold(acg.getAnnotationThreshold());
1055 ac.setAnnotation(acg.getAnnotation());
1056 if (acg.getBaseColour() instanceof jalview.schemes.UserColourScheme)
1058 ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(),
1063 ac.setColourScheme(ColourSchemeProperty.getColourName(acg
1067 ac.setMaxColour(acg.getMaxColour().getRGB());
1068 ac.setMinColour(acg.getMinColour().getRGB());
1069 view.setAnnotationColours(ac);
1070 view.setBgColour("AnnotationColourGradient");
1074 view.setBgColour(ColourSchemeProperty.getColourName(av
1075 .getGlobalColourScheme()));
1078 ColourSchemeI cs = av.getGlobalColourScheme();
1082 if (cs.conservationApplied())
1084 view.setConsThreshold(cs.getConservationInc());
1085 if (cs instanceof jalview.schemes.UserColourScheme)
1087 view.setBgColour(SetUserColourScheme(cs, userColours, jms));
1091 if (cs instanceof ResidueColourScheme)
1093 view.setPidThreshold(cs.getThreshold());
1097 view.setConservationSelected(av.getConservationSelected());
1098 view.setPidSelected(av.getAbovePIDThreshold());
1099 view.setFontName(av.font.getName());
1100 view.setFontSize(av.font.getSize());
1101 view.setFontStyle(av.font.getStyle());
1102 view.setRenderGaps(av.renderGaps);
1103 view.setShowAnnotation(av.getShowAnnotation());
1104 view.setShowBoxes(av.getShowBoxes());
1105 view.setShowColourText(av.getColourText());
1106 view.setShowFullId(av.getShowJVSuffix());
1107 view.setRightAlignIds(av.rightAlignIds);
1108 view.setShowSequenceFeatures(av.showSequenceFeatures);
1109 view.setShowText(av.getShowText());
1110 view.setShowUnconserved(av.getShowUnconserved());
1111 view.setWrapAlignment(av.getWrapAlignment());
1112 view.setTextCol1(av.textColour.getRGB());
1113 view.setTextCol2(av.textColour2.getRGB());
1114 view.setTextColThreshold(av.thresholdTextColour);
1115 view.setShowConsensusHistogram(av.isShowConsensusHistogram());
1116 view.setShowSequenceLogo(av.isShowSequenceLogo());
1117 view.setShowGroupConsensus(av.isShowGroupConsensus());
1118 view.setShowGroupConservation(av.isShowGroupConservation());
1119 view.setShowNPfeatureTooltip(av.isShowNpFeats());
1120 view.setShowDbRefTooltip(av.isShowDbRefs());
1121 view.setFollowHighlight(av.followHighlight);
1122 view.setFollowSelection(av.followSelection);
1123 view.setIgnoreGapsinConsensus(av.getIgnoreGapsConsensus());
1124 if (av.featuresDisplayed != null)
1126 jalview.schemabinding.version2.FeatureSettings fs = new jalview.schemabinding.version2.FeatureSettings();
1128 String[] renderOrder = ap.seqPanel.seqCanvas.getFeatureRenderer().renderOrder;
1130 Vector settingsAdded = new Vector();
1131 Object gstyle = null;
1132 GraduatedColor gcol = null;
1133 if (renderOrder != null)
1135 for (int ro = 0; ro < renderOrder.length; ro++)
1137 gstyle = ap.seqPanel.seqCanvas.getFeatureRenderer()
1138 .getFeatureStyle(renderOrder[ro]);
1139 Setting setting = new Setting();
1140 setting.setType(renderOrder[ro]);
1141 if (gstyle instanceof GraduatedColor)
1143 gcol = (GraduatedColor) gstyle;
1144 setting.setColour(gcol.getMaxColor().getRGB());
1145 setting.setMincolour(gcol.getMinColor().getRGB());
1146 setting.setMin(gcol.getMin());
1147 setting.setMax(gcol.getMax());
1148 setting.setColourByLabel(gcol.isColourByLabel());
1149 setting.setAutoScale(gcol.isAutoScale());
1150 setting.setThreshold(gcol.getThresh());
1151 setting.setThreshstate(gcol.getThreshType());
1155 setting.setColour(ap.seqPanel.seqCanvas.getFeatureRenderer()
1156 .getColour(renderOrder[ro]).getRGB());
1159 setting.setDisplay(av.featuresDisplayed
1160 .containsKey(renderOrder[ro]));
1161 float rorder = ap.seqPanel.seqCanvas.getFeatureRenderer()
1162 .getOrder(renderOrder[ro]);
1165 setting.setOrder(rorder);
1167 fs.addSetting(setting);
1168 settingsAdded.addElement(renderOrder[ro]);
1172 // Make sure we save none displayed feature settings
1173 Iterator en = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours
1174 .keySet().iterator();
1175 while (en.hasNext())
1177 String key = en.next().toString();
1178 if (settingsAdded.contains(key))
1183 Setting setting = new Setting();
1184 setting.setType(key);
1185 setting.setColour(ap.seqPanel.seqCanvas.getFeatureRenderer()
1186 .getColour(key).getRGB());
1188 setting.setDisplay(false);
1189 float rorder = ap.seqPanel.seqCanvas.getFeatureRenderer().getOrder(
1193 setting.setOrder(rorder);
1195 fs.addSetting(setting);
1196 settingsAdded.addElement(key);
1198 en = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups.keySet().iterator();
1199 Vector groupsAdded = new Vector();
1200 while (en.hasNext())
1202 String grp = en.next().toString();
1203 if (groupsAdded.contains(grp))
1207 Group g = new Group();
1209 g.setDisplay(((Boolean) ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups
1210 .get(grp)).booleanValue());
1212 groupsAdded.addElement(grp);
1214 jms.setFeatureSettings(fs);
1218 if (av.hasHiddenColumns())
1220 if (av.getColumnSelection() == null
1221 || av.getColumnSelection().getHiddenColumns() == null)
1223 warn("REPORT BUG: avoided null columnselection bug (DMAM reported). Please contact Jim about this.");
1227 for (int c = 0; c < av.getColumnSelection().getHiddenColumns()
1230 int[] region = (int[]) av.getColumnSelection().getHiddenColumns()
1232 HiddenColumns hc = new HiddenColumns();
1233 hc.setStart(region[0]);
1234 hc.setEnd(region[1]);
1235 view.addHiddenColumns(hc);
1239 if (calcIdSet.size()>0)
1241 for (String calcId:calcIdSet)
1243 if (calcId.trim().length()>0) {
1244 view.addCalcIdParam(createCalcIdParam(calcId, av));
1249 jms.addViewport(view);
1251 object.setJalviewModelSequence(jms);
1252 object.getVamsasModel().addSequenceSet(vamsasSet);
1254 if (jout != null && fileName != null)
1256 // We may not want to write the object to disk,
1257 // eg we can copy the alignViewport to a new view object
1258 // using save and then load
1261 JarEntry entry = new JarEntry(fileName);
1262 jout.putNextEntry(entry);
1263 PrintWriter pout = new PrintWriter(new OutputStreamWriter(jout,
1265 org.exolab.castor.xml.Marshaller marshaller = new org.exolab.castor.xml.Marshaller(
1267 marshaller.marshal(object);
1270 } catch (Exception ex)
1272 // TODO: raise error in GUI if marshalling failed.
1273 ex.printStackTrace();
1279 private CalcIdParam createCalcIdParam(String calcId, AlignViewport av)
1281 AutoCalcSetting settings = av.getCalcIdSettingsFor(calcId);
1282 if (settings != null)
1284 CalcIdParam vCalcIdParam = new CalcIdParam();
1285 vCalcIdParam.setCalcId(calcId);
1286 vCalcIdParam.addServiceURL(settings.getServiceURI());
1287 // generic URI allowing a third party to resolve another instance of the
1288 // service used for this calculation
1289 for (String urls:settings.getServiceURLs())
1291 vCalcIdParam.addServiceURL(urls);
1293 vCalcIdParam.setVersion("1.0");
1294 if (settings.getPreset() != null)
1296 WsParamSetI setting = settings.getPreset();
1297 vCalcIdParam.setName(setting.getName());
1298 vCalcIdParam.setDescription(setting.getDescription());
1302 vCalcIdParam.setName("");
1303 vCalcIdParam.setDescription("Last used parameters");
1305 // need to be able to recover 1) settings 2) user-defined presets or
1306 // recreate settings from preset 3) predefined settings provided by
1307 // service - or settings that can be transferred (or discarded)
1308 vCalcIdParam.setParameters(settings
1310 vCalcIdParam.setAutoUpdate(settings.isAutoUpdate());
1311 // todo - decide if updateImmediately is needed for any projects.
1313 return vCalcIdParam;
1318 private boolean recoverCalcIdParam(CalcIdParam calcIdParam,
1321 if (calcIdParam.getVersion().equals("1.0"))
1323 Jws2Instance service=Jws2Discoverer.getDiscoverer().getPreferredServiceFor(calcIdParam.getServiceURL());
1326 WsParamSetI parmSet=null;
1328 service.getParamStore().parseServiceParameterFile(calcIdParam.getName(), calcIdParam.getDescription(), calcIdParam.getServiceURL(), calcIdParam.getParameters());
1329 } catch (IOException x)
1331 warn("Couldn't parse parameter data for "+calcIdParam.getCalcId(), x);
1334 List<ArgumentI> argList=null;
1335 if (calcIdParam.getName().length()>0) {
1336 parmSet = service.getParamStore().getPreset(calcIdParam.getName());
1339 // TODO : check we have a good match with settings in AACons - otherwise we'll need to create a new preset
1343 argList = parmSet.getArguments();
1346 AAConsSettings settings = new AAConsSettings(calcIdParam.isAutoUpdate(), service, parmSet, argList);
1347 av.setCalcIdSettingsFor(calcIdParam.getCalcId(), settings, calcIdParam.isNeedsUpdate());
1349 warn("Cannot resolve a service for the parameters used in this project. Try configuring a JABAWS server.");
1354 throw new Error("Unsupported Version for calcIdparam "
1355 + calcIdParam.toString());
1359 * External mapping between jalview objects and objects yielding a valid and
1360 * unique object ID string. This is null for normal Jalview project IO, but
1361 * non-null when a jalview project is being read or written as part of a
1364 IdentityHashMap jv2vobj = null;
1367 * Construct a unique ID for jvobj using either existing bindings or if none
1368 * exist, the result of the hashcode call for the object.
1371 * jalview data object
1372 * @return unique ID for referring to jvobj
1374 private String makeHashCode(Object jvobj, String altCode)
1376 if (jv2vobj != null)
1378 Object id = jv2vobj.get(jvobj);
1381 return id.toString();
1383 // check string ID mappings
1384 if (jvids2vobj != null && jvobj instanceof String)
1386 id = jvids2vobj.get(jvobj);
1390 return id.toString();
1392 // give up and warn that something has gone wrong
1393 warn("Cannot find ID for object in external mapping : " + jvobj);
1399 * return local jalview object mapped to ID, if it exists
1403 * @return null or object bound to idcode
1405 private Object retrieveExistingObj(String idcode)
1407 if (idcode != null && vobj2jv != null)
1409 return vobj2jv.get(idcode);
1415 * binding from ID strings from external mapping table to jalview data model
1418 private Hashtable vobj2jv;
1420 private Sequence createVamsasSequence(String id, SequenceI jds)
1422 return createVamsasSequence(true, id, jds, null);
1425 private Sequence createVamsasSequence(boolean recurse, String id,
1426 SequenceI jds, SequenceI parentseq)
1428 Sequence vamsasSeq = new Sequence();
1429 vamsasSeq.setId(id);
1430 vamsasSeq.setName(jds.getName());
1431 vamsasSeq.setSequence(jds.getSequenceAsString());
1432 vamsasSeq.setDescription(jds.getDescription());
1433 jalview.datamodel.DBRefEntry[] dbrefs = null;
1434 if (jds.getDatasetSequence() != null)
1436 vamsasSeq.setDsseqid(seqHash(jds.getDatasetSequence()));
1437 if (jds.getDatasetSequence().getDBRef() != null)
1439 dbrefs = jds.getDatasetSequence().getDBRef();
1444 vamsasSeq.setDsseqid(id); // so we can tell which sequences really are
1445 // dataset sequences only
1446 dbrefs = jds.getDBRef();
1450 for (int d = 0; d < dbrefs.length; d++)
1452 DBRef dbref = new DBRef();
1453 dbref.setSource(dbrefs[d].getSource());
1454 dbref.setVersion(dbrefs[d].getVersion());
1455 dbref.setAccessionId(dbrefs[d].getAccessionId());
1456 if (dbrefs[d].hasMap())
1458 Mapping mp = createVamsasMapping(dbrefs[d].getMap(), parentseq,
1460 dbref.setMapping(mp);
1462 vamsasSeq.addDBRef(dbref);
1468 private Mapping createVamsasMapping(jalview.datamodel.Mapping jmp,
1469 SequenceI parentseq, SequenceI jds, boolean recurse)
1472 if (jmp.getMap() != null)
1476 jalview.util.MapList mlst = jmp.getMap();
1477 int r[] = mlst.getFromRanges();
1478 for (int s = 0; s < r.length; s += 2)
1480 MapListFrom mfrom = new MapListFrom();
1481 mfrom.setStart(r[s]);
1482 mfrom.setEnd(r[s + 1]);
1483 mp.addMapListFrom(mfrom);
1485 r = mlst.getToRanges();
1486 for (int s = 0; s < r.length; s += 2)
1488 MapListTo mto = new MapListTo();
1490 mto.setEnd(r[s + 1]);
1491 mp.addMapListTo(mto);
1493 mp.setMapFromUnit(mlst.getFromRatio());
1494 mp.setMapToUnit(mlst.getToRatio());
1495 if (jmp.getTo() != null)
1497 MappingChoice mpc = new MappingChoice();
1499 && (parentseq != jmp.getTo() || parentseq
1500 .getDatasetSequence() != jmp.getTo()))
1502 mpc.setSequence(createVamsasSequence(false, seqHash(jmp.getTo()),
1508 SequenceI ps = null;
1509 if (parentseq != jmp.getTo()
1510 && parentseq.getDatasetSequence() != jmp.getTo())
1512 // chaining dbref rather than a handshaking one
1513 jmpid = seqHash(ps = jmp.getTo());
1517 jmpid = seqHash(ps = parentseq);
1519 mpc.setDseqFor(jmpid);
1520 if (!seqRefIds.containsKey(mpc.getDseqFor()))
1522 jalview.bin.Cache.log.debug("creatign new DseqFor ID");
1523 seqRefIds.put(mpc.getDseqFor(), ps);
1527 jalview.bin.Cache.log.debug("reusing DseqFor ID");
1530 mp.setMappingChoice(mpc);
1536 String SetUserColourScheme(jalview.schemes.ColourSchemeI cs,
1537 Vector userColours, JalviewModelSequence jms)
1540 jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs;
1541 boolean newucs = false;
1542 if (!userColours.contains(ucs))
1544 userColours.add(ucs);
1547 id = "ucs" + userColours.indexOf(ucs);
1550 // actually create the scheme's entry in the XML model
1551 java.awt.Color[] colours = ucs.getColours();
1552 jalview.schemabinding.version2.UserColours uc = new jalview.schemabinding.version2.UserColours();
1553 jalview.schemabinding.version2.UserColourScheme jbucs = new jalview.schemabinding.version2.UserColourScheme();
1555 for (int i = 0; i < colours.length; i++)
1557 jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
1558 col.setName(ResidueProperties.aa[i]);
1559 col.setRGB(jalview.util.Format.getHexString(colours[i]));
1560 jbucs.addColour(col);
1562 if (ucs.getLowerCaseColours() != null)
1564 colours = ucs.getLowerCaseColours();
1565 for (int i = 0; i < colours.length; i++)
1567 jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
1568 col.setName(ResidueProperties.aa[i].toLowerCase());
1569 col.setRGB(jalview.util.Format.getHexString(colours[i]));
1570 jbucs.addColour(col);
1575 uc.setUserColourScheme(jbucs);
1576 jms.addUserColours(uc);
1582 jalview.schemes.UserColourScheme GetUserColourScheme(
1583 JalviewModelSequence jms, String id)
1585 UserColours[] uc = jms.getUserColours();
1586 UserColours colours = null;
1588 for (int i = 0; i < uc.length; i++)
1590 if (uc[i].getId().equals(id))
1598 java.awt.Color[] newColours = new java.awt.Color[24];
1600 for (int i = 0; i < 24; i++)
1602 newColours[i] = new java.awt.Color(Integer.parseInt(colours
1603 .getUserColourScheme().getColour(i).getRGB(), 16));
1606 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
1609 if (colours.getUserColourScheme().getColourCount() > 24)
1611 newColours = new java.awt.Color[23];
1612 for (int i = 0; i < 23; i++)
1614 newColours[i] = new java.awt.Color(Integer.parseInt(colours
1615 .getUserColourScheme().getColour(i + 24).getRGB(), 16));
1617 ucs.setLowerCaseColours(newColours);
1624 * contains last error message (if any) encountered by XML loader.
1626 String errorMessage = null;
1629 * flag to control whether the Jalview2XML_V1 parser should be deferred to if
1630 * exceptions are raised during project XML parsing
1632 public boolean attemptversion1parse = true;
1635 * Load a jalview project archive from a jar file
1638 * - HTTP URL or filename
1640 public AlignFrame LoadJalviewAlign(final String file)
1643 jalview.gui.AlignFrame af = null;
1647 // UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING
1648 // Workaround is to make sure caller implements the JarInputStreamProvider
1650 // so we can re-open the jar input stream for each entry.
1652 jarInputStreamProvider jprovider = createjarInputStreamProvider(file);
1653 af = LoadJalviewAlign(jprovider);
1654 } catch (MalformedURLException e)
1656 errorMessage = "Invalid URL format for '" + file + "'";
1662 private jarInputStreamProvider createjarInputStreamProvider(
1663 final String file) throws MalformedURLException
1666 errorMessage = null;
1667 uniqueSetSuffix = null;
1669 viewportsAdded = null;
1670 frefedSequence = null;
1672 if (file.startsWith("http://"))
1674 url = new URL(file);
1676 final URL _url = url;
1677 return new jarInputStreamProvider()
1681 public JarInputStream getJarInputStream() throws IOException
1685 return new JarInputStream(_url.openStream());
1689 return new JarInputStream(new FileInputStream(file));
1694 public String getFilename()
1702 * Recover jalview session from a jalview project archive. Caller may
1703 * initialise uniqueSetSuffix, seqRefIds, viewportsAdded and frefedSequence
1704 * themselves. Any null fields will be initialised with default values,
1705 * non-null fields are left alone.
1710 public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider)
1712 errorMessage = null;
1713 if (uniqueSetSuffix == null)
1715 uniqueSetSuffix = System.currentTimeMillis() % 100000 + "";
1717 if (seqRefIds == null)
1719 seqRefIds = new Hashtable();
1721 if (viewportsAdded == null)
1723 viewportsAdded = new Hashtable();
1725 if (frefedSequence == null)
1727 frefedSequence = new Vector();
1730 jalview.gui.AlignFrame af = null;
1731 Hashtable gatherToThisFrame = new Hashtable();
1732 final String file = jprovider.getFilename();
1735 JarInputStream jin = null;
1736 JarEntry jarentry = null;
1741 jin = jprovider.getJarInputStream();
1742 for (int i = 0; i < entryCount; i++)
1744 jarentry = jin.getNextJarEntry();
1747 if (jarentry != null && jarentry.getName().endsWith(".xml"))
1749 InputStreamReader in = new InputStreamReader(jin, "UTF-8");
1750 JalviewModel object = new JalviewModel();
1752 Unmarshaller unmar = new Unmarshaller(object);
1753 unmar.setValidation(false);
1754 object = (JalviewModel) unmar.unmarshal(in);
1755 if (true) // !skipViewport(object))
1757 af = LoadFromObject(object, file, true, jprovider);
1758 if (af.viewport.gatherViewsHere)
1760 gatherToThisFrame.put(af.viewport.getSequenceSetId(), af);
1765 else if (jarentry != null)
1767 // Some other file here.
1770 } while (jarentry != null);
1771 resolveFrefedSequences();
1772 } catch (java.io.FileNotFoundException ex)
1774 ex.printStackTrace();
1775 errorMessage = "Couldn't locate Jalview XML file : " + file;
1776 System.err.println("Exception whilst loading jalview XML file : "
1778 } catch (java.net.UnknownHostException ex)
1780 ex.printStackTrace();
1781 errorMessage = "Couldn't locate Jalview XML file : " + file;
1782 System.err.println("Exception whilst loading jalview XML file : "
1784 } catch (Exception ex)
1786 System.err.println("Parsing as Jalview Version 2 file failed.");
1787 ex.printStackTrace(System.err);
1788 if (attemptversion1parse)
1790 // Is Version 1 Jar file?
1793 af = new Jalview2XML_V1(raiseGUI).LoadJalviewAlign(jprovider);
1794 } catch (Exception ex2)
1796 System.err.println("Exception whilst loading as jalviewXMLV1:");
1797 ex2.printStackTrace();
1801 if (Desktop.instance != null)
1803 Desktop.instance.stopLoading();
1807 System.out.println("Successfully loaded archive file");
1810 ex.printStackTrace();
1812 System.err.println("Exception whilst loading jalview XML file : "
1814 } catch (OutOfMemoryError e)
1816 // Don't use the OOM Window here
1817 errorMessage = "Out of memory loading jalview XML file";
1818 System.err.println("Out of memory whilst loading jalview XML file");
1819 e.printStackTrace();
1822 if (Desktop.instance != null)
1824 Desktop.instance.stopLoading();
1827 Enumeration en = gatherToThisFrame.elements();
1828 while (en.hasMoreElements())
1830 Desktop.instance.gatherViews((AlignFrame) en.nextElement());
1832 if (errorMessage != null)
1840 * check errorMessage for a valid error message and raise an error box in the
1841 * GUI or write the current errorMessage to stderr and then clear the error
1844 protected void reportErrors()
1846 reportErrors(false);
1849 protected void reportErrors(final boolean saving)
1851 if (errorMessage != null)
1853 final String finalErrorMessage = errorMessage;
1856 javax.swing.SwingUtilities.invokeLater(new Runnable()
1861 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1862 finalErrorMessage, "Error "
1863 + (saving ? "saving" : "loading")
1864 + " Jalview file", JOptionPane.WARNING_MESSAGE);
1870 System.err.println("Problem loading Jalview file: " + errorMessage);
1873 errorMessage = null;
1876 Hashtable alreadyLoadedPDB;
1879 * when set, local views will be updated from view stored in JalviewXML
1880 * Currently (28th Sep 2008) things will go horribly wrong in vamsas document
1881 * sync if this is set to true.
1883 private final boolean updateLocalViews = false;
1885 String loadPDBFile(jarInputStreamProvider jprovider, String pdbId)
1887 if (alreadyLoadedPDB == null)
1888 alreadyLoadedPDB = new Hashtable();
1890 if (alreadyLoadedPDB.containsKey(pdbId))
1891 return alreadyLoadedPDB.get(pdbId).toString();
1895 JarInputStream jin = jprovider.getJarInputStream();
1897 * if (jprovider.startsWith("http://")) { jin = new JarInputStream(new
1898 * URL(jprovider).openStream()); } else { jin = new JarInputStream(new
1899 * FileInputStream(jprovider)); }
1902 JarEntry entry = null;
1905 entry = jin.getNextJarEntry();
1906 } while (entry != null && !entry.getName().equals(pdbId));
1909 BufferedReader in = new BufferedReader(new InputStreamReader(jin));
1910 File outFile = File.createTempFile("jalview_pdb", ".txt");
1911 outFile.deleteOnExit();
1912 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
1915 while ((data = in.readLine()) != null)
1922 } catch (Exception foo)
1927 String t=outFile.getAbsolutePath();
1928 alreadyLoadedPDB.put(pdbId, t);
1933 warn("Couldn't find PDB file entry in Jalview Jar for " + pdbId);
1935 } catch (Exception ex)
1937 ex.printStackTrace();
1943 private class JvAnnotRow
1945 public JvAnnotRow(int i, AlignmentAnnotation jaa)
1952 * persisted version of annotation row from which to take vis properties
1954 public jalview.datamodel.AlignmentAnnotation template;
1957 * original position of the annotation row in the alignment
1963 * Load alignment frame from jalview XML DOM object
1968 * filename source string
1969 * @param loadTreesAndStructures
1970 * when false only create Viewport
1972 * data source provider
1973 * @return alignment frame created from view stored in DOM
1975 AlignFrame LoadFromObject(JalviewModel object, String file,
1976 boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
1978 SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
1979 Sequence[] vamsasSeq = vamsasSet.getSequence();
1981 JalviewModelSequence jms = object.getJalviewModelSequence();
1983 Viewport view = jms.getViewport(0);
1984 // ////////////////////////////////
1987 Vector hiddenSeqs = null;
1988 jalview.datamodel.Sequence jseq;
1990 ArrayList tmpseqs = new ArrayList();
1992 boolean multipleView = false;
1994 JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
1995 int vi = 0; // counter in vamsasSeq array
1996 for (int i = 0; i < JSEQ.length; i++)
1998 String seqId = JSEQ[i].getId();
2000 if (seqRefIds.get(seqId) != null)
2002 tmpseqs.add(seqRefIds.get(seqId));
2003 multipleView = true;
2007 jseq = new jalview.datamodel.Sequence(vamsasSeq[vi].getName(),
2008 vamsasSeq[vi].getSequence());
2009 jseq.setDescription(vamsasSeq[vi].getDescription());
2010 jseq.setStart(JSEQ[i].getStart());
2011 jseq.setEnd(JSEQ[i].getEnd());
2012 jseq.setVamsasId(uniqueSetSuffix + seqId);
2013 seqRefIds.put(vamsasSeq[vi].getId(), jseq);
2018 if (JSEQ[i].getHidden())
2020 if (hiddenSeqs == null)
2022 hiddenSeqs = new Vector();
2025 hiddenSeqs.addElement(seqRefIds
2032 // Create the alignment object from the sequence set
2033 // ///////////////////////////////
2034 jalview.datamodel.Sequence[] orderedSeqs = new jalview.datamodel.Sequence[tmpseqs
2037 tmpseqs.toArray(orderedSeqs);
2039 jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(
2042 // / Add the alignment properties
2043 for (int i = 0; i < vamsasSet.getSequenceSetPropertiesCount(); i++)
2045 SequenceSetProperties ssp = vamsasSet.getSequenceSetProperties(i);
2046 al.setProperty(ssp.getKey(), ssp.getValue());
2050 // SequenceFeatures are added to the DatasetSequence,
2051 // so we must create or recover the dataset before loading features
2052 // ///////////////////////////////
2053 if (vamsasSet.getDatasetId() == null || vamsasSet.getDatasetId() == "")
2055 // older jalview projects do not have a dataset id.
2056 al.setDataset(null);
2060 recoverDatasetFor(vamsasSet, al);
2062 // ///////////////////////////////
2064 Hashtable pdbloaded = new Hashtable();
2067 // load sequence features, database references and any associated PDB
2068 // structures for the alignment
2069 for (int i = 0; i < vamsasSeq.length; i++)
2071 if (JSEQ[i].getFeaturesCount() > 0)
2073 Features[] features = JSEQ[i].getFeatures();
2074 for (int f = 0; f < features.length; f++)
2076 jalview.datamodel.SequenceFeature sf = new jalview.datamodel.SequenceFeature(
2077 features[f].getType(), features[f].getDescription(),
2078 features[f].getStatus(), features[f].getBegin(),
2079 features[f].getEnd(), features[f].getFeatureGroup());
2081 sf.setScore(features[f].getScore());
2082 for (int od = 0; od < features[f].getOtherDataCount(); od++)
2084 OtherData keyValue = features[f].getOtherData(od);
2085 if (keyValue.getKey().startsWith("LINK"))
2087 sf.addLink(keyValue.getValue());
2091 sf.setValue(keyValue.getKey(), keyValue.getValue());
2096 al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
2099 if (vamsasSeq[i].getDBRefCount() > 0)
2101 addDBRefs(al.getSequenceAt(i).getDatasetSequence(), vamsasSeq[i]);
2103 if (JSEQ[i].getPdbidsCount() > 0)
2105 Pdbids[] ids = JSEQ[i].getPdbids();
2106 for (int p = 0; p < ids.length; p++)
2108 jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
2109 entry.setId(ids[p].getId());
2110 entry.setType(ids[p].getType());
2111 if (ids[p].getFile() != null)
2113 if (!pdbloaded.containsKey(ids[p].getFile()))
2115 entry.setFile(loadPDBFile(jprovider, ids[p].getId()));
2119 entry.setFile(pdbloaded.get(ids[p].getId()).toString());
2123 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
2127 } // end !multipleview
2129 // ///////////////////////////////
2130 // LOAD SEQUENCE MAPPINGS
2132 if (vamsasSet.getAlcodonFrameCount() > 0)
2134 // TODO Potentially this should only be done once for all views of an
2136 AlcodonFrame[] alc = vamsasSet.getAlcodonFrame();
2137 for (int i = 0; i < alc.length; i++)
2139 jalview.datamodel.AlignedCodonFrame cf = new jalview.datamodel.AlignedCodonFrame(
2140 alc[i].getAlcodonCount());
2141 if (alc[i].getAlcodonCount() > 0)
2143 Alcodon[] alcods = alc[i].getAlcodon();
2144 for (int p = 0; p < cf.codons.length; p++)
2146 if (alcods[p].hasPos1() && alcods[p].hasPos2()
2147 && alcods[p].hasPos3())
2149 // translated codons require three valid positions
2150 cf.codons[p] = new int[3];
2151 cf.codons[p][0] = (int) alcods[p].getPos1();
2152 cf.codons[p][1] = (int) alcods[p].getPos2();
2153 cf.codons[p][2] = (int) alcods[p].getPos3();
2157 cf.codons[p] = null;
2161 if (alc[i].getAlcodMapCount() > 0)
2163 AlcodMap[] maps = alc[i].getAlcodMap();
2164 for (int m = 0; m < maps.length; m++)
2166 SequenceI dnaseq = (SequenceI) seqRefIds
2167 .get(maps[m].getDnasq());
2169 jalview.datamodel.Mapping mapping = null;
2170 // attach to dna sequence reference.
2171 if (maps[m].getMapping() != null)
2173 mapping = addMapping(maps[m].getMapping());
2177 cf.addMap(dnaseq, mapping.getTo(), mapping.getMap());
2182 frefedSequence.add(new Object[]
2183 { maps[m].getDnasq(), cf, mapping });
2187 al.addCodonFrame(cf);
2192 // ////////////////////////////////
2194 ArrayList<JvAnnotRow> autoAlan = new ArrayList<JvAnnotRow>();
2196 * store any annotations which forward reference a group's ID
2198 Hashtable<String, ArrayList<jalview.datamodel.AlignmentAnnotation>> groupAnnotRefs = new Hashtable<String, ArrayList<jalview.datamodel.AlignmentAnnotation>>();
2200 if (vamsasSet.getAnnotationCount() > 0)
2202 Annotation[] an = vamsasSet.getAnnotation();
2204 for (int i = 0; i < an.length; i++)
2207 * test if annotation is automatically calculated for this view only
2209 boolean autoForView = false;
2210 if (an[i].getLabel().equals("Quality")
2211 || an[i].getLabel().equals("Conservation")
2212 || an[i].getLabel().equals("Consensus"))
2214 // Kludge for pre 2.5 projects which lacked the autocalculated flag
2216 if (!an[i].hasAutoCalculated())
2218 an[i].setAutoCalculated(true);
2222 || (an[i].hasAutoCalculated() && an[i].isAutoCalculated()))
2224 // remove ID - we don't recover annotation from other views for
2225 // view-specific annotation
2229 // set visiblity for other annotation in this view
2230 if (an[i].getId() != null
2231 && annotationIds.containsKey(an[i].getId()))
2233 jalview.datamodel.AlignmentAnnotation jda = (jalview.datamodel.AlignmentAnnotation) annotationIds
2234 .get(an[i].getId());
2235 // in principle Visible should always be true for annotation displayed
2236 // in multiple views
2237 if (an[i].hasVisible())
2238 jda.visible = an[i].getVisible();
2240 al.addAnnotation(jda);
2244 // Construct new annotation from model.
2245 AnnotationElement[] ae = an[i].getAnnotationElement();
2246 jalview.datamodel.Annotation[] anot = null;
2248 if (!an[i].getScoreOnly())
2250 anot = new jalview.datamodel.Annotation[al.getWidth()];
2251 for (int aa = 0; aa < ae.length && aa < anot.length; aa++)
2253 if (ae[aa].getPosition() >= anot.length)
2256 anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(
2258 ae[aa].getDisplayCharacter(), ae[aa].getDescription(),
2259 (ae[aa].getSecondaryStructure() == null || ae[aa]
2260 .getSecondaryStructure().length() == 0) ? ' '
2261 : ae[aa].getSecondaryStructure().charAt(0),
2265 // JBPNote: Consider verifying dataflow for IO of secondary
2266 // structure annotation read from Stockholm files
2267 // this was added to try to ensure that
2268 // if (anot[ae[aa].getPosition()].secondaryStructure>' ')
2270 // anot[ae[aa].getPosition()].displayCharacter = "";
2272 anot[ae[aa].getPosition()].colour = new java.awt.Color(
2273 ae[aa].getColour());
2276 jalview.datamodel.AlignmentAnnotation jaa = null;
2278 if (an[i].getGraph())
2280 float llim = 0, hlim = 0;
2281 // if (autoForView || an[i].isAutoCalculated()) {
2284 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
2285 an[i].getDescription(), anot, llim, hlim,
2286 an[i].getGraphType());
2288 jaa.graphGroup = an[i].getGraphGroup();
2290 if (an[i].getThresholdLine() != null)
2292 jaa.setThreshold(new jalview.datamodel.GraphLine(an[i]
2293 .getThresholdLine().getValue(), an[i]
2294 .getThresholdLine().getLabel(), new java.awt.Color(
2295 an[i].getThresholdLine().getColour())));
2298 if (autoForView || an[i].isAutoCalculated())
2300 // Hardwire the symbol display line to ensure that labels for
2301 // histograms are displayed
2307 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
2308 an[i].getDescription(), anot);
2312 // register new annotation
2313 if (an[i].getId() != null)
2315 annotationIds.put(an[i].getId(), jaa);
2316 jaa.annotationId = an[i].getId();
2318 // recover sequence association
2319 if (an[i].getSequenceRef() != null)
2321 if (al.findName(an[i].getSequenceRef()) != null)
2323 jaa.createSequenceMapping(
2324 al.findName(an[i].getSequenceRef()), 1, true);
2325 al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(
2330 // and make a note of any group association
2331 if (an[i].getGroupRef() != null && an[i].getGroupRef().length() > 0)
2333 ArrayList<jalview.datamodel.AlignmentAnnotation> aal = groupAnnotRefs
2334 .get(an[i].getGroupRef());
2337 aal = new ArrayList<jalview.datamodel.AlignmentAnnotation>();
2338 groupAnnotRefs.put(an[i].getGroupRef(), aal);
2343 if (an[i].hasScore())
2345 jaa.setScore(an[i].getScore());
2347 if (an[i].hasVisible())
2348 jaa.visible = an[i].getVisible();
2350 if (an[i].hasCentreColLabels())
2351 jaa.centreColLabels = an[i].getCentreColLabels();
2353 if (an[i].hasScaleColLabels())
2355 jaa.scaleColLabel = an[i].getScaleColLabels();
2357 if (an[i].hasAutoCalculated() && an[i].isAutoCalculated())
2359 // newer files have an 'autoCalculated' flag and store calculation
2360 // state in viewport properties
2361 jaa.autoCalculated = true; // means annotation will be marked for
2362 // update at end of load.
2364 if (an[i].hasGraphHeight())
2366 jaa.graphHeight = an[i].getGraphHeight();
2368 if (an[i].hasBelowAlignment())
2370 jaa.belowAlignment=an[i].isBelowAlignment();
2372 jaa.setCalcId(an[i].getCalcId());
2374 if (jaa.autoCalculated)
2376 autoAlan.add(new JvAnnotRow(i, jaa));
2379 // if (!autoForView)
2381 // add autocalculated group annotation and any user created annotation
2383 al.addAnnotation(jaa);
2388 // ///////////////////////
2390 // Create alignment markup and styles for this view
2391 if (jms.getJGroupCount() > 0)
2393 JGroup[] groups = jms.getJGroup();
2395 for (int i = 0; i < groups.length; i++)
2397 ColourSchemeI cs = null;
2399 if (groups[i].getColour() != null)
2401 if (groups[i].getColour().startsWith("ucs"))
2403 cs = GetUserColourScheme(jms, groups[i].getColour());
2407 cs = ColourSchemeProperty.getColour(al, groups[i].getColour());
2412 cs.setThreshold(groups[i].getPidThreshold(), true);
2416 Vector seqs = new Vector();
2418 for (int s = 0; s < groups[i].getSeqCount(); s++)
2420 String seqId = groups[i].getSeq(s) + "";
2421 jalview.datamodel.SequenceI ts = (jalview.datamodel.SequenceI) seqRefIds
2426 seqs.addElement(ts);
2430 if (seqs.size() < 1)
2435 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(
2436 seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(),
2437 groups[i].getDisplayText(), groups[i].getColourText(),
2438 groups[i].getStart(), groups[i].getEnd());
2440 sg.setOutlineColour(new java.awt.Color(groups[i].getOutlineColour()));
2442 sg.textColour = new java.awt.Color(groups[i].getTextCol1());
2443 sg.textColour2 = new java.awt.Color(groups[i].getTextCol2());
2444 sg.setShowNonconserved(groups[i].hasShowUnconserved() ? groups[i]
2445 .isShowUnconserved() : false);
2446 sg.thresholdTextColour = groups[i].getTextColThreshold();
2447 if (groups[i].hasShowConsensusHistogram())
2449 sg.setShowConsensusHistogram(groups[i].isShowConsensusHistogram());
2452 if (groups[i].hasShowSequenceLogo())
2454 sg.setshowSequenceLogo(groups[i].isShowSequenceLogo());
2456 if (groups[i].hasIgnoreGapsinConsensus())
2458 sg.setIgnoreGapsConsensus(groups[i].getIgnoreGapsinConsensus());
2460 if (groups[i].getConsThreshold() != 0)
2462 jalview.analysis.Conservation c = new jalview.analysis.Conservation(
2463 "All", ResidueProperties.propHash, 3,
2464 sg.getSequences(null), 0, sg.getWidth() - 1);
2466 c.verdict(false, 25);
2467 sg.cs.setConservation(c);
2470 if (groups[i].getId() != null && groupAnnotRefs.size() > 0)
2472 // re-instate unique group/annotation row reference
2473 ArrayList<jalview.datamodel.AlignmentAnnotation> jaal = groupAnnotRefs
2474 .get(groups[i].getId());
2477 for (jalview.datamodel.AlignmentAnnotation jaa : jaal)
2480 if (jaa.autoCalculated)
2482 // match up and try to set group autocalc alignment row for this
2484 if (jaa.label.startsWith("Consensus for "))
2486 sg.setConsensus(jaa);
2488 // match up and try to set group autocalc alignment row for this
2490 if (jaa.label.startsWith("Conservation for "))
2492 sg.setConservationRow(jaa);
2503 // ///////////////////////////////
2506 // If we just load in the same jar file again, the sequenceSetId
2507 // will be the same, and we end up with multiple references
2508 // to the same sequenceSet. We must modify this id on load
2509 // so that each load of the file gives a unique id
2510 String uniqueSeqSetId = view.getSequenceSetId() + uniqueSetSuffix;
2511 String viewId = (view.getId() == null ? null : view.getId()
2513 AlignFrame af = null;
2514 AlignViewport av = null;
2515 // now check to see if we really need to create a new viewport.
2516 if (multipleView && viewportsAdded.size() == 0)
2518 // We recovered an alignment for which a viewport already exists.
2519 // TODO: fix up any settings necessary for overlaying stored state onto
2520 // state recovered from another document. (may not be necessary).
2521 // we may need a binding from a viewport in memory to one recovered from
2523 // and then recover its containing af to allow the settings to be applied.
2524 // TODO: fix for vamsas demo
2526 .println("About to recover a viewport for existing alignment: Sequence set ID is "
2528 Object seqsetobj = retrieveExistingObj(uniqueSeqSetId);
2529 if (seqsetobj != null)
2531 if (seqsetobj instanceof String)
2533 uniqueSeqSetId = (String) seqsetobj;
2535 .println("Recovered extant sequence set ID mapping for ID : New Sequence set ID is "
2541 .println("Warning : Collision between sequence set ID string and existing jalview object mapping.");
2546 AlignmentPanel ap = null;
2547 boolean isnewview = true;
2550 // Check to see if this alignment already has a view id == viewId
2551 jalview.gui.AlignmentPanel views[] = Desktop
2552 .getAlignmentPanels(uniqueSeqSetId);
2553 if (views != null && views.length > 0)
2555 for (int v = 0; v < views.length; v++)
2557 if (views[v].av.getViewId().equalsIgnoreCase(viewId))
2559 // recover the existing alignpanel, alignframe, viewport
2560 af = views[v].alignFrame;
2563 // TODO: could even skip resetting view settings if we don't want to
2564 // change the local settings from other jalview processes
2573 af = loadViewport(file, JSEQ, hiddenSeqs, al, jms, view,
2574 uniqueSeqSetId, viewId, autoAlan);
2579 // /////////////////////////////////////
2580 if (loadTreesAndStructures && jms.getTreeCount() > 0)
2584 for (int t = 0; t < jms.getTreeCount(); t++)
2587 Tree tree = jms.getTree(t);
2589 TreePanel tp = (TreePanel) retrieveExistingObj(tree.getId());
2592 tp = af.ShowNewickTree(
2593 new jalview.io.NewickFile(tree.getNewick()),
2594 tree.getTitle(), tree.getWidth(), tree.getHeight(),
2595 tree.getXpos(), tree.getYpos());
2596 if (tree.getId() != null)
2598 // perhaps bind the tree id to something ?
2603 // update local tree attributes ?
2604 // TODO: should check if tp has been manipulated by user - if so its
2605 // settings shouldn't be modified
2606 tp.setTitle(tree.getTitle());
2607 tp.setBounds(new Rectangle(tree.getXpos(), tree.getYpos(), tree
2608 .getWidth(), tree.getHeight()));
2609 tp.av = av; // af.viewport; // TODO: verify 'associate with all
2612 tp.treeCanvas.av = av; // af.viewport;
2613 tp.treeCanvas.ap = ap; // af.alignPanel;
2618 warn("There was a problem recovering stored Newick tree: \n"
2619 + tree.getNewick());
2623 tp.fitToWindow.setState(tree.getFitToWindow());
2624 tp.fitToWindow_actionPerformed(null);
2626 if (tree.getFontName() != null)
2628 tp.setTreeFont(new java.awt.Font(tree.getFontName(), tree
2629 .getFontStyle(), tree.getFontSize()));
2633 tp.setTreeFont(new java.awt.Font(view.getFontName(), view
2634 .getFontStyle(), tree.getFontSize()));
2637 tp.showPlaceholders(tree.getMarkUnlinked());
2638 tp.showBootstrap(tree.getShowBootstrap());
2639 tp.showDistances(tree.getShowDistances());
2641 tp.treeCanvas.threshold = tree.getThreshold();
2643 if (tree.getCurrentTree())
2645 af.viewport.setCurrentTree(tp.getTree());
2649 } catch (Exception ex)
2651 ex.printStackTrace();
2655 // //LOAD STRUCTURES
2656 if (loadTreesAndStructures)
2658 // run through all PDB ids on the alignment, and collect mappings between
2659 // jmol view ids and all sequences referring to it
2660 Hashtable<String, Object[]> jmolViewIds = new Hashtable();
2662 for (int i = 0; i < JSEQ.length; i++)
2664 if (JSEQ[i].getPdbidsCount() > 0)
2666 Pdbids[] ids = JSEQ[i].getPdbids();
2667 for (int p = 0; p < ids.length; p++)
2669 for (int s = 0; s < ids[p].getStructureStateCount(); s++)
2671 // check to see if we haven't already created this structure view
2672 String sviewid = (ids[p].getStructureState(s).getViewId() == null) ? null
2673 : ids[p].getStructureState(s).getViewId()
2675 jalview.datamodel.PDBEntry jpdb = new jalview.datamodel.PDBEntry();
2676 // Originally : ids[p].getFile()
2677 // : TODO: verify external PDB file recovery still works in normal
2678 // jalview project load
2679 jpdb.setFile(loadPDBFile(jprovider, ids[p].getId()));
2680 jpdb.setId(ids[p].getId());
2682 int x = ids[p].getStructureState(s).getXpos();
2683 int y = ids[p].getStructureState(s).getYpos();
2684 int width = ids[p].getStructureState(s).getWidth();
2685 int height = ids[p].getStructureState(s).getHeight();
2687 // Probably don't need to do this anymore...
2688 // Desktop.desktop.getComponentAt(x, y);
2689 // TODO: NOW: check that this recovers the PDB file correctly.
2690 String pdbFile = loadPDBFile(jprovider, ids[p].getId());
2691 jalview.datamodel.SequenceI seq = (jalview.datamodel.SequenceI) seqRefIds
2692 .get(JSEQ[i].getId() + "");
2693 if (sviewid == null)
2695 sviewid = "_jalview_pre2_4_" + x + "," + y + "," + width
2698 if (!jmolViewIds.containsKey(sviewid))
2700 jmolViewIds.put(sviewid, new Object[]
2702 { x, y, width, height }, "",
2703 new Hashtable<String, Object[]>(), new boolean[]
2704 { false, false, true } });
2705 // Legacy pre-2.7 conversion JAL-823 :
2706 // do not assume any view has to be linked for colour by
2710 // assemble String[] { pdb files }, String[] { id for each
2711 // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
2712 // seqs_file 2}, boolean[] {
2713 // linkAlignPanel,superposeWithAlignpanel}} from hash
2714 Object[] jmoldat = jmolViewIds.get(sviewid);
2715 ((boolean[]) jmoldat[3])[0] |= ids[p].getStructureState(s)
2716 .hasAlignwithAlignPanel() ? ids[p].getStructureState(
2717 s).getAlignwithAlignPanel() : false;
2718 // never colour by linked panel if not specified
2719 ((boolean[]) jmoldat[3])[1] |= ids[p].getStructureState(s)
2720 .hasColourwithAlignPanel() ? ids[p]
2721 .getStructureState(s).getColourwithAlignPanel()
2723 // default for pre-2.7 projects is that Jmol colouring is enabled
2724 ((boolean[]) jmoldat[3])[2] &= ids[p].getStructureState(s)
2725 .hasColourByJmol() ? ids[p].getStructureState(s)
2726 .getColourByJmol() : true;
2728 if (((String) jmoldat[1]).length() < ids[p]
2729 .getStructureState(s).getContent().length())
2732 jmoldat[1] = ids[p].getStructureState(s).getContent();
2735 if (ids[p].getFile() != null)
2737 File mapkey=new File(ids[p].getFile());
2738 Object[] seqstrmaps = (Object[]) ((Hashtable) jmoldat[2])
2740 if (seqstrmaps == null)
2742 ((Hashtable) jmoldat[2]).put(
2744 seqstrmaps = new Object[]
2745 { pdbFile, ids[p].getId(), new Vector(),
2748 if (!((Vector) seqstrmaps[2]).contains(seq))
2750 ((Vector) seqstrmaps[2]).addElement(seq);
2751 // ((Vector)seqstrmaps[3]).addElement(n) :
2752 // in principle, chains
2753 // should be stored here : do we need to
2754 // TODO: store and recover seq/pdb_id :
2760 errorMessage = ("The Jmol views in this project were imported\nfrom an older version of Jalview.\nPlease review the sequence colour associations\nin the Colour by section of the Jmol View menu.\n\nIn the case of problems, see note at\nhttp://issues.jalview.org/browse/JAL-747");
2769 // Instantiate the associated Jmol views
2770 for (Entry<String, Object[]> entry : jmolViewIds.entrySet())
2772 String sviewid = entry.getKey();
2773 Object[] svattrib = entry.getValue();
2774 int[] geom = (int[]) svattrib[0];
2775 String state = (String) svattrib[1];
2776 Hashtable<File, Object[]> oldFiles = (Hashtable<File, Object[]>) svattrib[2];
2777 final boolean useinJmolsuperpos = ((boolean[]) svattrib[3])[0], usetoColourbyseq = ((boolean[]) svattrib[3])[1], jmolColouring = ((boolean[]) svattrib[3])[2];
2778 int x = geom[0], y = geom[1], width = geom[2], height = geom[3];
2779 // collate the pdbfile -> sequence mappings from this view
2780 Vector<String> pdbfilenames = new Vector<String>();
2781 Vector<SequenceI[]> seqmaps = new Vector<SequenceI[]>();
2782 Vector<String> pdbids = new Vector<String>();
2784 // Search to see if we've already created this Jmol view
2785 AppJmol comp = null;
2786 JInternalFrame[] frames = null;
2791 frames = Desktop.desktop.getAllFrames();
2792 } catch (ArrayIndexOutOfBoundsException e)
2794 // occasional No such child exceptions are thrown here...
2799 } catch (Exception f)
2804 } while (frames == null);
2805 // search for any Jmol windows already open from other
2806 // alignment views that exactly match the stored structure state
2807 for (int f = 0; comp == null && f < frames.length; f++)
2809 if (frames[f] instanceof AppJmol)
2812 && ((AppJmol) frames[f]).getViewId().equals(sviewid))
2814 // post jalview 2.4 schema includes structure view id
2815 comp = (AppJmol) frames[f];
2817 else if (frames[f].getX() == x && frames[f].getY() == y
2818 && frames[f].getHeight() == height
2819 && frames[f].getWidth() == width)
2821 comp = (AppJmol) frames[f];
2828 // create a new Jmol window.
2829 // First parse the Jmol state to translate filenames loaded into the
2830 // view, and record the order in which files are shown in the Jmol
2831 // view, so we can add the sequence mappings in same order.
2832 StringBuffer newFileLoc = null;
2833 int cp = 0, ncp, ecp;
2834 while ((ncp = state.indexOf("load ", cp)) > -1)
2836 if (newFileLoc == null)
2838 newFileLoc = new StringBuffer();
2841 // look for next filename in load statement
2842 newFileLoc.append(state.substring(cp,
2843 ncp = (state.indexOf("\"", ncp + 1) + 1)));
2844 String oldfilenam = state.substring(ncp,
2845 ecp = state.indexOf("\"", ncp));
2846 // recover the new mapping data for this old filename
2847 // have to normalize filename - since Jmol and jalview do filename
2848 // translation differently.
2849 Object[] filedat = oldFiles.get(new File(oldfilenam));
2850 newFileLoc.append(Platform.escapeString((String) filedat[0]));
2851 pdbfilenames.addElement((String) filedat[0]);
2852 pdbids.addElement((String) filedat[1]);
2853 seqmaps.addElement(((Vector<SequenceI>) filedat[2])
2854 .toArray(new SequenceI[0]));
2855 newFileLoc.append("\"");
2856 cp = ecp + 1; // advance beyond last \" and set cursor so we can
2857 // look for next file statement.
2858 } while ((ncp=state.indexOf("/*file*/",cp))>-1);
2862 // just append rest of state
2863 newFileLoc.append(state.substring(cp));
2868 .print("Ignoring incomplete Jmol state for PDB ids: ");
2869 newFileLoc = new StringBuffer(state);
2870 newFileLoc.append("; load append ");
2871 for (File id : oldFiles.keySet())
2873 // add this and any other pdb files that should be present in
2875 Object[] filedat = oldFiles.get(id);
2877 newFileLoc.append(((String) filedat[0]));
2878 pdbfilenames.addElement((String) filedat[0]);
2879 pdbids.addElement((String) filedat[1]);
2880 seqmaps.addElement(((Vector<SequenceI>) filedat[2])
2881 .toArray(new SequenceI[0]));
2882 newFileLoc.append(" \"");
2883 newFileLoc.append((String) filedat[0]);
2884 newFileLoc.append("\"");
2887 newFileLoc.append(";");
2890 if (newFileLoc != null)
2892 int histbug = newFileLoc.indexOf("history = ");
2894 int diff = histbug == -1 ? -1 : newFileLoc.indexOf(";",
2896 String val = (diff == -1) ? null : newFileLoc.substring(
2898 if (val != null && val.length() >= 4)
2900 if (val.contains("e"))
2902 if (val.trim().equals("true"))
2910 newFileLoc.replace(histbug, diff, val);
2913 // TODO: assemble String[] { pdb files }, String[] { id for each
2914 // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
2915 // seqs_file 2}} from hash
2916 final String[] pdbf = pdbfilenames
2917 .toArray(new String[pdbfilenames.size()]), id = pdbids
2918 .toArray(new String[pdbids.size()]);
2919 final SequenceI[][] sq = seqmaps
2920 .toArray(new SequenceI[seqmaps.size()][]);
2921 final String fileloc = newFileLoc.toString(), vid = sviewid;
2922 final AlignFrame alf = af;
2923 final java.awt.Rectangle rect = new java.awt.Rectangle(x, y,
2927 javax.swing.SwingUtilities.invokeAndWait(new Runnable()
2932 AppJmol sview = null;
2935 sview = new AppJmol(pdbf, id, sq, alf.alignPanel,
2936 useinJmolsuperpos, usetoColourbyseq,
2937 jmolColouring, fileloc, rect, vid);
2938 } catch (OutOfMemoryError ex)
2940 new OOMWarning("restoring structure view for PDB id "
2941 + id, (OutOfMemoryError) ex.getCause());
2942 if (sview != null && sview.isVisible())
2944 sview.closeViewer();
2945 sview.setVisible(false);
2951 } catch (InvocationTargetException ex)
2953 warn("Unexpected error when opening Jmol view.", ex);
2955 } catch (InterruptedException e)
2957 // e.printStackTrace();
2963 // if (comp != null)
2965 // NOTE: if the jalview project is part of a shared session then
2966 // view synchronization should/could be done here.
2968 // add mapping for sequences in this view to an already open Jmol
2970 for (File id : oldFiles.keySet())
2972 // add this and any other pdb files that should be present in the
2974 Object[] filedat = oldFiles.get(id);
2975 String pdbFile = (String) filedat[0];
2976 SequenceI[] seq = ((Vector<SequenceI>) filedat[2])
2977 .toArray(new SequenceI[0]);
2978 comp.jmb.ssm.setMapping(seq, null, pdbFile,
2979 jalview.io.AppletFormatAdapter.FILE);
2980 comp.jmb.addSequenceForStructFile(pdbFile, seq);
2982 // and add the AlignmentPanel's reference to the Jmol view
2983 comp.addAlignmentPanel(ap);
2984 if (useinJmolsuperpos)
2986 comp.useAlignmentPanelForSuperposition(ap);
2990 comp.excludeAlignmentPanelForSuperposition(ap);
2992 if (usetoColourbyseq)
2994 comp.useAlignmentPanelForColourbyseq(ap,
2999 comp.excludeAlignmentPanelForColourbyseq(ap);
3005 // and finally return.
3009 AlignFrame loadViewport(String file, JSeq[] JSEQ, Vector hiddenSeqs,
3010 Alignment al, JalviewModelSequence jms, Viewport view,
3011 String uniqueSeqSetId, String viewId,
3012 ArrayList<JvAnnotRow> autoAlan)
3014 AlignFrame af = null;
3015 af = new AlignFrame(al, view.getWidth(), view.getHeight(),
3016 uniqueSeqSetId, viewId);
3018 af.setFileName(file, "Jalview");
3020 for (int i = 0; i < JSEQ.length; i++)
3022 af.viewport.setSequenceColour(af.viewport.getAlignment().getSequenceAt(i),
3023 new java.awt.Color(JSEQ[i].getColour()));
3026 af.viewport.gatherViewsHere = view.getGatheredViews();
3028 if (view.getSequenceSetId() != null)
3030 jalview.gui.AlignViewport av = (jalview.gui.AlignViewport) viewportsAdded
3031 .get(uniqueSeqSetId);
3033 af.viewport.setSequenceSetId(uniqueSeqSetId);
3036 // propagate shared settings to this new view
3037 af.viewport.historyList = av.historyList;
3038 af.viewport.redoList = av.redoList;
3042 viewportsAdded.put(uniqueSeqSetId, af.viewport);
3044 // TODO: check if this method can be called repeatedly without
3045 // side-effects if alignpanel already registered.
3046 PaintRefresher.Register(af.alignPanel, uniqueSeqSetId);
3048 // apply Hidden regions to view.
3049 if (hiddenSeqs != null)
3051 for (int s = 0; s < JSEQ.length; s++)
3053 jalview.datamodel.SequenceGroup hidden = new jalview.datamodel.SequenceGroup();
3055 for (int r = 0; r < JSEQ[s].getHiddenSequencesCount(); r++)
3058 al.getSequenceAt(JSEQ[s].getHiddenSequences(r)), false);
3060 af.viewport.hideRepSequences(al.getSequenceAt(s), hidden);
3063 jalview.datamodel.SequenceI[] hseqs = new jalview.datamodel.SequenceI[hiddenSeqs
3066 for (int s = 0; s < hiddenSeqs.size(); s++)
3068 hseqs[s] = (jalview.datamodel.SequenceI) hiddenSeqs.elementAt(s);
3071 af.viewport.hideSequence(hseqs);
3074 // recover view properties and display parameters
3075 if (view.getViewName() != null)
3077 af.viewport.viewName = view.getViewName();
3078 af.setInitialTabVisible();
3080 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
3083 af.viewport.setShowAnnotation(view.getShowAnnotation());
3084 af.viewport.setAbovePIDThreshold(view.getPidSelected());
3086 af.viewport.setColourText(view.getShowColourText());
3088 af.viewport.setConservationSelected(view.getConservationSelected());
3089 af.viewport.setShowJVSuffix(view.getShowFullId());
3090 af.viewport.rightAlignIds = view.getRightAlignIds();
3091 af.viewport.setFont(new java.awt.Font(view.getFontName(), view
3092 .getFontStyle(), view.getFontSize()));
3093 af.alignPanel.fontChanged();
3094 af.viewport.setRenderGaps(view.getRenderGaps());
3095 af.viewport.setWrapAlignment(view.getWrapAlignment());
3096 af.alignPanel.setWrapAlignment(view.getWrapAlignment());
3097 af.viewport.setShowAnnotation(view.getShowAnnotation());
3098 af.alignPanel.setAnnotationVisible(view.getShowAnnotation());
3100 af.viewport.setShowBoxes(view.getShowBoxes());
3102 af.viewport.setShowText(view.getShowText());
3104 af.viewport.textColour = new java.awt.Color(view.getTextCol1());
3105 af.viewport.textColour2 = new java.awt.Color(view.getTextCol2());
3106 af.viewport.thresholdTextColour = view.getTextColThreshold();
3107 af.viewport.setShowUnconserved(view.hasShowUnconserved() ? view
3108 .isShowUnconserved() : false);
3109 af.viewport.setStartRes(view.getStartRes());
3110 af.viewport.setStartSeq(view.getStartSeq());
3112 ColourSchemeI cs = null;
3113 // apply colourschemes
3114 if (view.getBgColour() != null)
3116 if (view.getBgColour().startsWith("ucs"))
3118 cs = GetUserColourScheme(jms, view.getBgColour());
3120 else if (view.getBgColour().startsWith("Annotation"))
3122 // int find annotation
3123 if (af.viewport.getAlignment().getAlignmentAnnotation() != null)
3125 for (int i = 0; i < af.viewport.getAlignment()
3126 .getAlignmentAnnotation().length; i++)
3128 if (af.viewport.getAlignment().getAlignmentAnnotation()[i].label
3129 .equals(view.getAnnotationColours().getAnnotation()))
3131 if (af.viewport.getAlignment().getAlignmentAnnotation()[i]
3132 .getThreshold() == null)
3134 af.viewport.getAlignment().getAlignmentAnnotation()[i]
3135 .setThreshold(new jalview.datamodel.GraphLine(view
3136 .getAnnotationColours().getThreshold(),
3137 "Threshold", java.awt.Color.black)
3142 if (view.getAnnotationColours().getColourScheme()
3145 cs = new AnnotationColourGradient(
3146 af.viewport.getAlignment().getAlignmentAnnotation()[i],
3147 new java.awt.Color(view.getAnnotationColours()
3148 .getMinColour()), new java.awt.Color(view
3149 .getAnnotationColours().getMaxColour()),
3150 view.getAnnotationColours().getAboveThreshold());
3152 else if (view.getAnnotationColours().getColourScheme()
3155 cs = new AnnotationColourGradient(
3156 af.viewport.getAlignment().getAlignmentAnnotation()[i],
3157 GetUserColourScheme(jms, view
3158 .getAnnotationColours().getColourScheme()),
3159 view.getAnnotationColours().getAboveThreshold());
3163 cs = new AnnotationColourGradient(
3164 af.viewport.getAlignment().getAlignmentAnnotation()[i],
3165 ColourSchemeProperty.getColour(al, view
3166 .getAnnotationColours().getColourScheme()),
3167 view.getAnnotationColours().getAboveThreshold());
3170 // Also use these settings for all the groups
3171 if (al.getGroups() != null)
3173 for (int g = 0; g < al.getGroups().size(); g++)
3175 jalview.datamodel.SequenceGroup sg = al
3176 .getGroups().get(g);
3185 * (view.getAnnotationColours().getColourScheme().equals("None"
3186 * )) { sg.cs = new AnnotationColourGradient(
3187 * af.viewport.getAlignment().getAlignmentAnnotation()[i], new
3188 * java.awt.Color(view.getAnnotationColours().
3189 * getMinColour()), new
3190 * java.awt.Color(view.getAnnotationColours().
3192 * view.getAnnotationColours().getAboveThreshold()); } else
3195 sg.cs = new AnnotationColourGradient(
3196 af.viewport.getAlignment().getAlignmentAnnotation()[i],
3197 sg.cs, view.getAnnotationColours()
3198 .getAboveThreshold());
3212 cs = ColourSchemeProperty.getColour(al, view.getBgColour());
3217 cs.setThreshold(view.getPidThreshold(), true);
3218 cs.setConsensus(af.viewport.getSequenceConsensusHash());
3222 af.viewport.setGlobalColourScheme(cs);
3223 af.viewport.setColourAppliesToAllGroups(false);
3225 if (view.getConservationSelected() && cs != null)
3227 cs.setConservationInc(view.getConsThreshold());
3230 af.changeColour(cs);
3232 af.viewport.setColourAppliesToAllGroups(true);
3234 if (view.getShowSequenceFeatures())
3236 af.viewport.showSequenceFeatures = true;
3238 if (view.hasCentreColumnLabels())
3240 af.viewport.setCentreColumnLabels(view.getCentreColumnLabels());
3242 if (view.hasIgnoreGapsinConsensus())
3244 af.viewport.setIgnoreGapsConsensus(view
3245 .getIgnoreGapsinConsensus(), null);
3247 if (view.hasFollowHighlight())
3249 af.viewport.followHighlight = view.getFollowHighlight();
3251 if (view.hasFollowSelection())
3253 af.viewport.followSelection = view.getFollowSelection();
3255 if (view.hasShowConsensusHistogram())
3257 af.viewport.setShowConsensusHistogram(view
3258 .getShowConsensusHistogram());
3262 af.viewport.setShowConsensusHistogram(true);
3264 if (view.hasShowSequenceLogo())
3266 af.viewport.setShowSequenceLogo(view.getShowSequenceLogo());
3270 af.viewport.setShowSequenceLogo(false);
3272 if (view.hasShowDbRefTooltip())
3274 af.viewport.setShowDbRefs(view.getShowDbRefTooltip());
3276 if (view.hasShowNPfeatureTooltip())
3278 af.viewport.setShowNpFeats(view.hasShowNPfeatureTooltip());
3280 if (view.hasShowGroupConsensus())
3282 af.viewport.setShowGroupConsensus(view.getShowGroupConsensus());
3286 af.viewport.setShowGroupConsensus(false);
3288 if (view.hasShowGroupConservation())
3290 af.viewport.setShowGroupConservation(view.getShowGroupConservation());
3294 af.viewport.setShowGroupConservation(false);
3297 // recover featre settings
3298 if (jms.getFeatureSettings() != null)
3300 af.viewport.featuresDisplayed = new Hashtable();
3301 String[] renderOrder = new String[jms.getFeatureSettings()
3302 .getSettingCount()];
3303 for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++)
3305 Setting setting = jms.getFeatureSettings().getSetting(fs);
3306 if (setting.hasMincolour())
3308 GraduatedColor gc = setting.hasMin() ? new GraduatedColor(
3309 new java.awt.Color(setting.getMincolour()),
3310 new java.awt.Color(setting.getColour()),
3311 setting.getMin(), setting.getMax()) : new GraduatedColor(
3312 new java.awt.Color(setting.getMincolour()),
3313 new java.awt.Color(setting.getColour()), 0, 1);
3314 if (setting.hasThreshold())
3316 gc.setThresh(setting.getThreshold());
3317 gc.setThreshType(setting.getThreshstate());
3319 gc.setAutoScaled(true); // default
3320 if (setting.hasAutoScale())
3322 gc.setAutoScaled(setting.getAutoScale());
3324 if (setting.hasColourByLabel())
3326 gc.setColourByLabel(setting.getColourByLabel());
3328 // and put in the feature colour table.
3329 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(
3330 setting.getType(), gc);
3334 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(
3336 new java.awt.Color(setting.getColour()));
3338 renderOrder[fs] = setting.getType();
3339 if (setting.hasOrder())
3340 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder(
3341 setting.getType(), setting.getOrder());
3343 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder(
3345 fs / jms.getFeatureSettings().getSettingCount());
3346 if (setting.getDisplay())
3348 af.viewport.featuresDisplayed.put(setting.getType(), new Integer(
3349 setting.getColour()));
3352 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;
3354 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureGroups = fgtable = new Hashtable();
3355 for (int gs = 0; gs < jms.getFeatureSettings().getGroupCount(); gs++)
3357 Group grp = jms.getFeatureSettings().getGroup(gs);
3358 fgtable.put(grp.getName(), new Boolean(grp.getDisplay()));
3362 if (view.getHiddenColumnsCount() > 0)
3364 for (int c = 0; c < view.getHiddenColumnsCount(); c++)
3366 af.viewport.hideColumns(view.getHiddenColumns(c).getStart(), view
3367 .getHiddenColumns(c).getEnd() // +1
3372 af.setMenusFromViewport(af.viewport);
3373 // TODO: we don't need to do this if the viewport is aready visible.
3374 Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
3376 af.alignPanel.updateAnnotation(false); // recompute any autoannotation
3377 reorderAutoannotation(af, al, autoAlan);
3381 private void reorderAutoannotation(AlignFrame af, Alignment al,
3382 ArrayList<JvAnnotRow> autoAlan)
3384 // copy over visualization settings for autocalculated annotation in the
3386 if (al.getAlignmentAnnotation() != null)
3389 * Kludge for magic autoannotation names (see JAL-811)
3391 String[] magicNames = new String[]
3392 { "Consensus", "Quality", "Conservation" };
3393 JvAnnotRow nullAnnot = new JvAnnotRow(-1, null);
3394 Hashtable<String, JvAnnotRow> visan = new Hashtable<String, JvAnnotRow>();
3395 for (String nm : magicNames)
3397 visan.put(nm, nullAnnot);
3399 for (JvAnnotRow auan : autoAlan)
3401 visan.put(auan.template.label, auan);
3403 int hSize = al.getAlignmentAnnotation().length;
3404 ArrayList<JvAnnotRow> reorder = new ArrayList<JvAnnotRow>();
3405 for (int h = 0; h < hSize; h++)
3407 jalview.datamodel.AlignmentAnnotation jalan = al
3408 .getAlignmentAnnotation()[h];
3409 if (jalan.autoCalculated)
3411 JvAnnotRow valan = visan.get(jalan.label);
3414 // delete the auto calculated row from the alignment
3415 al.deleteAnnotation(al.getAlignmentAnnotation()[h], false);
3418 if (valan != nullAnnot)
3420 if (jalan != valan.template)
3422 // newly created autoannotation row instance
3423 // so keep a reference to the visible annotation row
3424 // and copy over all relevant attributes
3425 if (valan.template.graphHeight >= 0)
3428 jalan.graphHeight = valan.template.graphHeight;
3430 jalan.visible = valan.template.visible;
3432 reorder.add(new JvAnnotRow(valan.order, jalan));
3437 int s = 0, srt[] = new int[reorder.size()];
3438 JvAnnotRow[] rws = new JvAnnotRow[reorder.size()];
3439 for (JvAnnotRow jvar : reorder)
3442 srt[s++] = jvar.order;
3445 jalview.util.QuickSort.sort(srt, rws);
3446 // and re-insert the annotation at its correct position
3447 for (JvAnnotRow jvar : rws)
3449 al.addAnnotation(jvar.template, jvar.order);
3451 af.alignPanel.adjustAnnotationHeight();
3455 Hashtable skipList = null;
3458 * TODO remove this method
3461 * @return AlignFrame bound to sequenceSetId from view, if one exists. private
3462 * AlignFrame getSkippedFrame(Viewport view) { if (skipList==null) {
3463 * throw new Error("Implementation Error. No skipList defined for this
3464 * Jalview2XML instance."); } return (AlignFrame)
3465 * skipList.get(view.getSequenceSetId()); }
3469 * Check if the Jalview view contained in object should be skipped or not.
3472 * @return true if view's sequenceSetId is a key in skipList
3474 private boolean skipViewport(JalviewModel object)
3476 if (skipList == null)
3481 if (skipList.containsKey(id = object.getJalviewModelSequence()
3482 .getViewport()[0].getSequenceSetId()))
3484 if (Cache.log != null && Cache.log.isDebugEnabled())
3486 Cache.log.debug("Skipping seuqence set id " + id);
3493 public void AddToSkipList(AlignFrame af)
3495 if (skipList == null)
3497 skipList = new Hashtable();
3499 skipList.put(af.getViewport().getSequenceSetId(), af);
3502 public void clearSkipList()
3504 if (skipList != null)
3511 private void recoverDatasetFor(SequenceSet vamsasSet, Alignment al)
3513 jalview.datamodel.Alignment ds = getDatasetFor(vamsasSet.getDatasetId());
3514 Vector dseqs = null;
3517 // create a list of new dataset sequences
3518 dseqs = new Vector();
3520 for (int i = 0, iSize = vamsasSet.getSequenceCount(); i < iSize; i++)
3522 Sequence vamsasSeq = vamsasSet.getSequence(i);
3523 ensureJalviewDatasetSequence(vamsasSeq, ds, dseqs);
3525 // create a new dataset
3528 SequenceI[] dsseqs = new SequenceI[dseqs.size()];
3529 dseqs.copyInto(dsseqs);
3530 ds = new jalview.datamodel.Alignment(dsseqs);
3531 debug("Created new dataset " + vamsasSet.getDatasetId()
3532 + " for alignment " + System.identityHashCode(al));
3533 addDatasetRef(vamsasSet.getDatasetId(), ds);
3535 // set the dataset for the newly imported alignment.
3536 if (al.getDataset() == null)
3545 * sequence definition to create/merge dataset sequence for
3549 * vector to add new dataset sequence to
3551 private void ensureJalviewDatasetSequence(Sequence vamsasSeq,
3552 AlignmentI ds, Vector dseqs)
3554 // JBP TODO: Check this is called for AlCodonFrames to support recovery of
3556 jalview.datamodel.Sequence sq = (jalview.datamodel.Sequence) seqRefIds
3557 .get(vamsasSeq.getId());
3558 jalview.datamodel.SequenceI dsq = null;
3559 if (sq != null && sq.getDatasetSequence() != null)
3561 dsq = sq.getDatasetSequence();
3564 String sqid = vamsasSeq.getDsseqid();
3567 // need to create or add a new dataset sequence reference to this sequence
3570 dsq = (jalview.datamodel.SequenceI) seqRefIds.get(sqid);
3575 // make a new dataset sequence
3576 dsq = sq.createDatasetSequence();
3579 // make up a new dataset reference for this sequence
3580 sqid = seqHash(dsq);
3582 dsq.setVamsasId(uniqueSetSuffix + sqid);
3583 seqRefIds.put(sqid, dsq);
3588 dseqs.addElement(dsq);
3593 ds.addSequence(dsq);
3599 { // make this dataset sequence sq's dataset sequence
3600 sq.setDatasetSequence(dsq);
3604 // TODO: refactor this as a merge dataset sequence function
3605 // now check that sq (the dataset sequence) sequence really is the union of
3606 // all references to it
3607 // boolean pre = sq.getStart() < dsq.getStart();
3608 // boolean post = sq.getEnd() > dsq.getEnd();
3612 StringBuffer sb = new StringBuffer();
3613 String newres = jalview.analysis.AlignSeq.extractGaps(
3614 jalview.util.Comparison.GapChars, sq.getSequenceAsString());
3615 if (!newres.equalsIgnoreCase(dsq.getSequenceAsString())
3616 && newres.length() > dsq.getLength())
3618 // Update with the longer sequence.
3622 * if (pre) { sb.insert(0, newres .substring(0, dsq.getStart() -
3623 * sq.getStart())); dsq.setStart(sq.getStart()); } if (post) {
3624 * sb.append(newres.substring(newres.length() - sq.getEnd() -
3625 * dsq.getEnd())); dsq.setEnd(sq.getEnd()); }
3627 dsq.setSequence(sb.toString());
3629 // TODO: merges will never happen if we 'know' we have the real dataset
3630 // sequence - this should be detected when id==dssid
3631 System.err.println("DEBUG Notice: Merged dataset sequence"); // ("
3632 // + (pre ? "prepended" : "") + " "
3633 // + (post ? "appended" : ""));
3638 java.util.Hashtable datasetIds = null;
3640 java.util.IdentityHashMap dataset2Ids = null;
3642 private Alignment getDatasetFor(String datasetId)
3644 if (datasetIds == null)
3646 datasetIds = new Hashtable();
3649 if (datasetIds.containsKey(datasetId))
3651 return (Alignment) datasetIds.get(datasetId);
3656 private void addDatasetRef(String datasetId, Alignment dataset)
3658 if (datasetIds == null)
3660 datasetIds = new Hashtable();
3662 datasetIds.put(datasetId, dataset);
3666 * make a new dataset ID for this jalview dataset alignment
3671 private String getDatasetIdRef(jalview.datamodel.Alignment dataset)
3673 if (dataset.getDataset() != null)
3675 warn("Serious issue! Dataset Object passed to getDatasetIdRef is not a Jalview DATASET alignment...");
3677 String datasetId = makeHashCode(dataset, null);
3678 if (datasetId == null)
3680 // make a new datasetId and record it
3681 if (dataset2Ids == null)
3683 dataset2Ids = new IdentityHashMap();
3687 datasetId = (String) dataset2Ids.get(dataset);
3689 if (datasetId == null)
3691 datasetId = "ds" + dataset2Ids.size() + 1;
3692 dataset2Ids.put(dataset, datasetId);
3698 private void addDBRefs(SequenceI datasetSequence, Sequence sequence)
3700 for (int d = 0; d < sequence.getDBRefCount(); d++)
3702 DBRef dr = sequence.getDBRef(d);
3703 jalview.datamodel.DBRefEntry entry = new jalview.datamodel.DBRefEntry(
3704 sequence.getDBRef(d).getSource(), sequence.getDBRef(d)
3705 .getVersion(), sequence.getDBRef(d).getAccessionId());
3706 if (dr.getMapping() != null)
3708 entry.setMap(addMapping(dr.getMapping()));
3710 datasetSequence.addDBRef(entry);
3714 private jalview.datamodel.Mapping addMapping(Mapping m)
3716 SequenceI dsto = null;
3717 // Mapping m = dr.getMapping();
3718 int fr[] = new int[m.getMapListFromCount() * 2];
3719 Enumeration f = m.enumerateMapListFrom();
3720 for (int _i = 0; f.hasMoreElements(); _i += 2)
3722 MapListFrom mf = (MapListFrom) f.nextElement();
3723 fr[_i] = mf.getStart();
3724 fr[_i + 1] = mf.getEnd();
3726 int fto[] = new int[m.getMapListToCount() * 2];
3727 f = m.enumerateMapListTo();
3728 for (int _i = 0; f.hasMoreElements(); _i += 2)
3730 MapListTo mf = (MapListTo) f.nextElement();
3731 fto[_i] = mf.getStart();
3732 fto[_i + 1] = mf.getEnd();
3734 jalview.datamodel.Mapping jmap = new jalview.datamodel.Mapping(dsto,
3735 fr, fto, (int) m.getMapFromUnit(), (int) m.getMapToUnit());
3736 if (m.getMappingChoice() != null)
3738 MappingChoice mc = m.getMappingChoice();
3739 if (mc.getDseqFor() != null)
3741 String dsfor = "" + mc.getDseqFor();
3742 if (seqRefIds.containsKey(dsfor))
3747 jmap.setTo((SequenceI) seqRefIds.get(dsfor));
3751 frefedSequence.add(new Object[]
3758 * local sequence definition
3760 Sequence ms = mc.getSequence();
3761 jalview.datamodel.Sequence djs = null;
3762 String sqid = ms.getDsseqid();
3763 if (sqid != null && sqid.length() > 0)
3766 * recover dataset sequence
3768 djs = (jalview.datamodel.Sequence) seqRefIds.get(sqid);
3773 .println("Warning - making up dataset sequence id for DbRef sequence map reference");
3774 sqid = ((Object) ms).toString(); // make up a new hascode for
3775 // undefined dataset sequence hash
3776 // (unlikely to happen)
3782 * make a new dataset sequence and add it to refIds hash
3784 djs = new jalview.datamodel.Sequence(ms.getName(),
3786 djs.setStart(jmap.getMap().getToLowest());
3787 djs.setEnd(jmap.getMap().getToHighest());
3788 djs.setVamsasId(uniqueSetSuffix + sqid);
3790 seqRefIds.put(sqid, djs);
3793 jalview.bin.Cache.log.debug("about to recurse on addDBRefs.");
3802 public jalview.gui.AlignmentPanel copyAlignPanel(AlignmentPanel ap,
3803 boolean keepSeqRefs)
3806 jalview.schemabinding.version2.JalviewModel jm = SaveState(ap, null,
3812 jm.getJalviewModelSequence().getViewport(0).setSequenceSetId(null);
3816 uniqueSetSuffix = "";
3817 jm.getJalviewModelSequence().getViewport(0).setId(null); // we don't
3822 if (this.frefedSequence == null)
3824 frefedSequence = new Vector();
3827 viewportsAdded = new Hashtable();
3829 AlignFrame af = LoadFromObject(jm, null, false, null);
3830 af.alignPanels.clear();
3831 af.closeMenuItem_actionPerformed(true);
3834 * if(ap.av.getAlignment().getAlignmentAnnotation()!=null) { for(int i=0;
3835 * i<ap.av.getAlignment().getAlignmentAnnotation().length; i++) {
3836 * if(!ap.av.getAlignment().getAlignmentAnnotation()[i].autoCalculated) {
3837 * af.alignPanel.av.getAlignment().getAlignmentAnnotation()[i] =
3838 * ap.av.getAlignment().getAlignmentAnnotation()[i]; } } }
3841 return af.alignPanel;
3845 * flag indicating if hashtables should be cleared on finalization TODO this
3846 * flag may not be necessary
3848 private final boolean _cleartables = true;
3850 private Hashtable jvids2vobj;
3855 * @see java.lang.Object#finalize()
3858 protected void finalize() throws Throwable
3860 // really make sure we have no buried refs left.
3865 this.seqRefIds = null;
3866 this.seqsToIds = null;
3870 private void warn(String msg)
3875 private void warn(String msg, Exception e)
3877 if (Cache.log != null)
3881 Cache.log.warn(msg, e);
3885 Cache.log.warn(msg);
3890 System.err.println("Warning: " + msg);
3893 e.printStackTrace();
3898 private void debug(String string)
3900 debug(string, null);
3903 private void debug(String msg, Exception e)
3905 if (Cache.log != null)
3909 Cache.log.debug(msg, e);
3913 Cache.log.debug(msg);
3918 System.err.println("Warning: " + msg);
3921 e.printStackTrace();
3927 * set the object to ID mapping tables used to write/recover objects and XML
3928 * ID strings for the jalview project. If external tables are provided then
3929 * finalize and clearSeqRefs will not clear the tables when the Jalview2XML
3930 * object goes out of scope. - also populates the datasetIds hashtable with
3931 * alignment objects containing dataset sequences
3934 * Map from ID strings to jalview datamodel
3936 * Map from jalview datamodel to ID strings
3940 public void setObjectMappingTables(Hashtable vobj2jv,
3941 IdentityHashMap jv2vobj)
3943 this.jv2vobj = jv2vobj;
3944 this.vobj2jv = vobj2jv;
3945 Iterator ds = jv2vobj.keySet().iterator();
3947 while (ds.hasNext())
3949 Object jvobj = ds.next();
3950 id = jv2vobj.get(jvobj).toString();
3951 if (jvobj instanceof jalview.datamodel.Alignment)
3953 if (((jalview.datamodel.Alignment) jvobj).getDataset() == null)
3955 addDatasetRef(id, (jalview.datamodel.Alignment) jvobj);
3958 else if (jvobj instanceof jalview.datamodel.Sequence)
3960 // register sequence object so the XML parser can recover it.
3961 if (seqRefIds == null)
3963 seqRefIds = new Hashtable();
3965 if (seqsToIds == null)
3967 seqsToIds = new IdentityHashMap();
3969 seqRefIds.put(jv2vobj.get(jvobj).toString(), jvobj);
3970 seqsToIds.put(jvobj, id);
3972 else if (jvobj instanceof jalview.datamodel.AlignmentAnnotation)
3974 if (annotationIds == null)
3976 annotationIds = new Hashtable();
3979 annotationIds.put(anid = jv2vobj.get(jvobj).toString(), jvobj);
3980 jalview.datamodel.AlignmentAnnotation jvann = (jalview.datamodel.AlignmentAnnotation) jvobj;
3981 if (jvann.annotationId == null)
3983 jvann.annotationId = anid;
3985 if (!jvann.annotationId.equals(anid))
3987 // TODO verify that this is the correct behaviour
3988 this.warn("Overriding Annotation ID for " + anid
3989 + " from different id : " + jvann.annotationId);
3990 jvann.annotationId = anid;
3993 else if (jvobj instanceof String)
3995 if (jvids2vobj == null)
3997 jvids2vobj = new Hashtable();
3998 jvids2vobj.put(jvobj, jv2vobj.get(jvobj).toString());
4002 Cache.log.debug("Ignoring " + jvobj.getClass() + " (ID = " + id);
4007 * set the uniqueSetSuffix used to prefix/suffix object IDs for jalview
4008 * objects created from the project archive. If string is null (default for
4009 * construction) then suffix will be set automatically.
4013 public void setUniqueSetSuffix(String string)
4015 uniqueSetSuffix = string;
4020 * uses skipList2 as the skipList for skipping views on sequence sets
4021 * associated with keys in the skipList
4025 public void setSkipList(Hashtable skipList2)
4027 skipList = skipList2;