2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.api.FeatureColourI;
24 import jalview.api.ViewStyleI;
25 import jalview.api.structures.JalviewStructureDisplayI;
26 import jalview.bin.Cache;
27 import jalview.datamodel.AlignedCodonFrame;
28 import jalview.datamodel.Alignment;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.PDBEntry;
32 import jalview.datamodel.RnaViewerModel;
33 import jalview.datamodel.SequenceGroup;
34 import jalview.datamodel.SequenceI;
35 import jalview.datamodel.StructureViewerModel;
36 import jalview.datamodel.StructureViewerModel.StructureData;
37 import jalview.ext.varna.RnaModel;
38 import jalview.gui.StructureViewer.ViewerType;
39 import jalview.schemabinding.version2.AlcodMap;
40 import jalview.schemabinding.version2.AlcodonFrame;
41 import jalview.schemabinding.version2.Annotation;
42 import jalview.schemabinding.version2.AnnotationColours;
43 import jalview.schemabinding.version2.AnnotationElement;
44 import jalview.schemabinding.version2.CalcIdParam;
45 import jalview.schemabinding.version2.DBRef;
46 import jalview.schemabinding.version2.Features;
47 import jalview.schemabinding.version2.Group;
48 import jalview.schemabinding.version2.HiddenColumns;
49 import jalview.schemabinding.version2.JGroup;
50 import jalview.schemabinding.version2.JSeq;
51 import jalview.schemabinding.version2.JalviewModel;
52 import jalview.schemabinding.version2.JalviewModelSequence;
53 import jalview.schemabinding.version2.MapListFrom;
54 import jalview.schemabinding.version2.MapListTo;
55 import jalview.schemabinding.version2.Mapping;
56 import jalview.schemabinding.version2.MappingChoice;
57 import jalview.schemabinding.version2.OtherData;
58 import jalview.schemabinding.version2.PdbentryItem;
59 import jalview.schemabinding.version2.Pdbids;
60 import jalview.schemabinding.version2.Property;
61 import jalview.schemabinding.version2.RnaViewer;
62 import jalview.schemabinding.version2.SecondaryStructure;
63 import jalview.schemabinding.version2.Sequence;
64 import jalview.schemabinding.version2.SequenceSet;
65 import jalview.schemabinding.version2.SequenceSetProperties;
66 import jalview.schemabinding.version2.Setting;
67 import jalview.schemabinding.version2.StructureState;
68 import jalview.schemabinding.version2.ThresholdLine;
69 import jalview.schemabinding.version2.Tree;
70 import jalview.schemabinding.version2.UserColours;
71 import jalview.schemabinding.version2.Viewport;
72 import jalview.schemes.AnnotationColourGradient;
73 import jalview.schemes.ColourSchemeI;
74 import jalview.schemes.ColourSchemeProperty;
75 import jalview.schemes.FeatureColour;
76 import jalview.schemes.ResidueColourScheme;
77 import jalview.schemes.ResidueProperties;
78 import jalview.schemes.UserColourScheme;
79 import jalview.structure.StructureSelectionManager;
80 import jalview.structures.models.AAStructureBindingModel;
81 import jalview.util.MessageManager;
82 import jalview.util.Platform;
83 import jalview.util.StringUtils;
84 import jalview.util.jarInputStreamProvider;
85 import jalview.viewmodel.AlignmentViewport;
86 import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
87 import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
88 import jalview.ws.jws2.Jws2Discoverer;
89 import jalview.ws.jws2.dm.AAConSettings;
90 import jalview.ws.jws2.jabaws2.Jws2Instance;
91 import jalview.ws.params.ArgumentI;
92 import jalview.ws.params.AutoCalcSetting;
93 import jalview.ws.params.WsParamSetI;
95 import java.awt.Color;
96 import java.awt.Rectangle;
97 import java.io.BufferedReader;
98 import java.io.DataInputStream;
99 import java.io.DataOutputStream;
101 import java.io.FileInputStream;
102 import java.io.FileOutputStream;
103 import java.io.IOException;
104 import java.io.InputStreamReader;
105 import java.io.OutputStreamWriter;
106 import java.io.PrintWriter;
107 import java.lang.reflect.InvocationTargetException;
108 import java.net.MalformedURLException;
110 import java.util.ArrayList;
111 import java.util.Enumeration;
112 import java.util.HashMap;
113 import java.util.HashSet;
114 import java.util.Hashtable;
115 import java.util.IdentityHashMap;
116 import java.util.Iterator;
117 import java.util.LinkedHashMap;
118 import java.util.List;
119 import java.util.Map;
120 import java.util.Map.Entry;
121 import java.util.Set;
122 import java.util.Vector;
123 import java.util.jar.JarEntry;
124 import java.util.jar.JarInputStream;
125 import java.util.jar.JarOutputStream;
127 import javax.swing.JInternalFrame;
128 import javax.swing.JOptionPane;
129 import javax.swing.SwingUtilities;
131 import org.exolab.castor.xml.Marshaller;
132 import org.exolab.castor.xml.Unmarshaller;
135 * Write out the current jalview desktop state as a Jalview XML stream.
137 * Note: the vamsas objects referred to here are primitive versions of the
138 * VAMSAS project schema elements - they are not the same and most likely never
142 * @version $Revision: 1.134 $
144 public class Jalview2XML
146 private static final String VIEWER_PREFIX = "viewer_";
148 private static final String RNA_PREFIX = "rna_";
150 private static final String UTF_8 = "UTF-8";
152 // use this with nextCounter() to make unique names for entities
153 private int counter = 0;
156 * SequenceI reference -> XML ID string in jalview XML. Populated as XML reps
157 * of sequence objects are created.
159 IdentityHashMap<SequenceI, String> seqsToIds = null;
162 * jalview XML Sequence ID to jalview sequence object reference (both dataset
163 * and alignment sequences. Populated as XML reps of sequence objects are
166 Map<String, SequenceI> seqRefIds = null;
168 Vector<Object[]> frefedSequence = null;
170 boolean raiseGUI = true; // whether errors are raised in dialog boxes or not
173 * Map of reconstructed AlignFrame objects that appear to have come from
174 * SplitFrame objects (have a dna/protein complement view).
176 private Map<Viewport, AlignFrame> splitFrameCandidates = new HashMap<Viewport, AlignFrame>();
179 * Map from displayed rna structure models to their saved session state jar
182 private Map<RnaModel, String> rnaSessions = new HashMap<RnaModel, String>();
185 * create/return unique hash string for sq
188 * @return new or existing unique string for sq
190 String seqHash(SequenceI sq)
192 if (seqsToIds == null)
196 if (seqsToIds.containsKey(sq))
198 return seqsToIds.get(sq);
202 // create sequential key
203 String key = "sq" + (seqsToIds.size() + 1);
204 key = makeHashCode(sq, key); // check we don't have an external reference
206 seqsToIds.put(sq, key);
215 if (seqRefIds != null)
219 if (seqsToIds != null)
229 warn("clearSeqRefs called when _cleartables was not set. Doing nothing.");
230 // seqRefIds = new Hashtable();
231 // seqsToIds = new IdentityHashMap();
237 if (seqsToIds == null)
239 seqsToIds = new IdentityHashMap<SequenceI, String>();
241 if (seqRefIds == null)
243 seqRefIds = new HashMap<String, SequenceI>();
251 public Jalview2XML(boolean raiseGUI)
253 this.raiseGUI = raiseGUI;
256 public void resolveFrefedSequences()
258 if (frefedSequence.size() > 0)
260 int r = 0, rSize = frefedSequence.size();
263 Object[] ref = frefedSequence.elementAt(r);
266 String sref = (String) ref[0];
267 if (seqRefIds.containsKey(sref))
269 if (ref[1] instanceof jalview.datamodel.Mapping)
271 SequenceI seq = seqRefIds.get(sref);
272 while (seq.getDatasetSequence() != null)
274 seq = seq.getDatasetSequence();
276 ((jalview.datamodel.Mapping) ref[1]).setTo(seq);
280 if (ref[1] instanceof jalview.datamodel.AlignedCodonFrame)
282 SequenceI seq = seqRefIds.get(sref);
283 while (seq.getDatasetSequence() != null)
285 seq = seq.getDatasetSequence();
288 && ref[2] instanceof jalview.datamodel.Mapping)
290 jalview.datamodel.Mapping mp = (jalview.datamodel.Mapping) ref[2];
291 ((jalview.datamodel.AlignedCodonFrame) ref[1]).addMap(
292 seq, mp.getTo(), mp.getMap());
297 .println("IMPLEMENTATION ERROR: Unimplemented forward sequence references for AlcodonFrames involving "
298 + ref[2].getClass() + " type objects.");
304 .println("IMPLEMENTATION ERROR: Unimplemented forward sequence references for "
305 + ref[1].getClass() + " type objects.");
308 frefedSequence.remove(r);
314 .println("IMPLEMENTATION WARNING: Unresolved forward reference for hash string "
316 + " with objecttype "
317 + ref[1].getClass());
324 frefedSequence.remove(r);
332 * This maintains a map of viewports, the key being the seqSetId. Important to
333 * set historyItem and redoList for multiple views
335 Map<String, AlignViewport> viewportsAdded = new HashMap<String, AlignViewport>();
337 Map<String, AlignmentAnnotation> annotationIds = new HashMap<String, AlignmentAnnotation>();
339 String uniqueSetSuffix = "";
342 * List of pdbfiles added to Jar
344 List<String> pdbfiles = null;
346 // SAVES SEVERAL ALIGNMENT WINDOWS TO SAME JARFILE
347 public void saveState(File statefile)
349 FileOutputStream fos = null;
352 fos = new FileOutputStream(statefile);
353 JarOutputStream jout = new JarOutputStream(fos);
356 } catch (Exception e)
358 // TODO: inform user of the problem - they need to know if their data was
360 if (errorMessage == null)
362 errorMessage = "Couldn't write Jalview Archive to output file '"
363 + statefile + "' - See console error log for details";
367 errorMessage += "(output file was '" + statefile + "')";
377 } catch (IOException e)
387 * Writes a jalview project archive to the given Jar output stream.
391 public void saveState(JarOutputStream jout)
393 AlignFrame[] frames = Desktop.getAlignFrames();
400 Hashtable<String, AlignFrame> dsses = new Hashtable<String, AlignFrame>();
403 * ensure cached data is clear before starting
405 // todo tidy up seqRefIds, seqsToIds initialisation / reset
407 splitFrameCandidates.clear();
412 // NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
413 // //////////////////////////////////////////////////
415 List<String> shortNames = new ArrayList<String>();
416 List<String> viewIds = new ArrayList<String>();
419 for (int i = frames.length - 1; i > -1; i--)
421 AlignFrame af = frames[i];
425 .containsKey(af.getViewport().getSequenceSetId()))
430 String shortName = makeFilename(af, shortNames);
432 int ap, apSize = af.alignPanels.size();
434 for (ap = 0; ap < apSize; ap++)
436 AlignmentPanel apanel = af.alignPanels.get(ap);
437 String fileName = apSize == 1 ? shortName : ap + shortName;
438 if (!fileName.endsWith(".xml"))
440 fileName = fileName + ".xml";
443 saveState(apanel, fileName, jout, viewIds);
445 String dssid = getDatasetIdRef(af.getViewport().getAlignment()
447 if (!dsses.containsKey(dssid))
449 dsses.put(dssid, af);
454 writeDatasetFor(dsses, "" + jout.hashCode() + " " + uniqueSetSuffix,
460 } catch (Exception foo)
465 } catch (Exception ex)
467 // TODO: inform user of the problem - they need to know if their data was
469 if (errorMessage == null)
471 errorMessage = "Couldn't write Jalview Archive - see error output for details";
473 ex.printStackTrace();
478 * Generates a distinct file name, based on the title of the AlignFrame, by
479 * appending _n for increasing n until an unused name is generated. The new
480 * name (without its extension) is added to the list.
484 * @return the generated name, with .xml extension
486 protected String makeFilename(AlignFrame af, List<String> namesUsed)
488 String shortName = af.getTitle();
490 if (shortName.indexOf(File.separatorChar) > -1)
492 shortName = shortName.substring(shortName
493 .lastIndexOf(File.separatorChar) + 1);
498 while (namesUsed.contains(shortName))
500 if (shortName.endsWith("_" + (count - 1)))
502 shortName = shortName.substring(0, shortName.lastIndexOf("_"));
505 shortName = shortName.concat("_" + count);
509 namesUsed.add(shortName);
511 if (!shortName.endsWith(".xml"))
513 shortName = shortName + ".xml";
518 // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW
519 public boolean saveAlignment(AlignFrame af, String jarFile,
525 int apSize = af.alignPanels.size();
526 FileOutputStream fos = new FileOutputStream(jarFile);
527 JarOutputStream jout = new JarOutputStream(fos);
528 Hashtable<String, AlignFrame> dsses = new Hashtable<String, AlignFrame>();
529 List<String> viewIds = new ArrayList<String>();
531 for (AlignmentPanel apanel : af.alignPanels)
533 String jfileName = apSize == 1 ? fileName : fileName + ap;
535 if (!jfileName.endsWith(".xml"))
537 jfileName = jfileName + ".xml";
539 saveState(apanel, jfileName, jout, viewIds);
540 String dssid = getDatasetIdRef(af.getViewport().getAlignment()
542 if (!dsses.containsKey(dssid))
544 dsses.put(dssid, af);
547 writeDatasetFor(dsses, fileName, jout);
551 } catch (Exception foo)
557 } catch (Exception ex)
559 errorMessage = "Couldn't Write alignment view to Jalview Archive - see error output for details";
560 ex.printStackTrace();
565 private void writeDatasetFor(Hashtable<String, AlignFrame> dsses,
566 String fileName, JarOutputStream jout)
569 for (String dssids : dsses.keySet())
571 AlignFrame _af = dsses.get(dssids);
572 String jfileName = fileName + " Dataset for " + _af.getTitle();
573 if (!jfileName.endsWith(".xml"))
575 jfileName = jfileName + ".xml";
577 saveState(_af.alignPanel, jfileName, true, jout, null);
582 * create a JalviewModel from an alignment view and marshall it to a
586 * panel to create jalview model for
588 * name of alignment panel written to output stream
595 public JalviewModel saveState(AlignmentPanel ap, String fileName,
596 JarOutputStream jout, List<String> viewIds)
598 return saveState(ap, fileName, false, jout, viewIds);
602 * create a JalviewModel from an alignment view and marshall it to a
606 * panel to create jalview model for
608 * name of alignment panel written to output stream
610 * when true, only write the dataset for the alignment, not the data
611 * associated with the view.
617 public JalviewModel saveState(AlignmentPanel ap, String fileName,
618 boolean storeDS, JarOutputStream jout, List<String> viewIds)
622 viewIds = new ArrayList<String>();
627 List<UserColourScheme> userColours = new ArrayList<UserColourScheme>();
629 AlignViewport av = ap.av;
631 JalviewModel object = new JalviewModel();
632 object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel());
634 object.setCreationDate(new java.util.Date(System.currentTimeMillis()));
635 object.setVersion(jalview.bin.Cache.getDefault("VERSION",
636 "Development Build"));
639 * rjal is full height alignment, jal is actual alignment with full metadata
640 * but excludes hidden sequences.
642 jalview.datamodel.AlignmentI rjal = av.getAlignment(), jal = rjal;
644 if (av.hasHiddenRows())
646 rjal = jal.getHiddenSequences().getFullAlignment();
649 SequenceSet vamsasSet = new SequenceSet();
651 JalviewModelSequence jms = new JalviewModelSequence();
653 vamsasSet.setGapChar(jal.getGapCharacter() + "");
655 if (jal.getDataset() != null)
657 // dataset id is the dataset's hashcode
658 vamsasSet.setDatasetId(getDatasetIdRef(jal.getDataset()));
661 // switch jal and the dataset
662 jal = jal.getDataset();
666 if (jal.getProperties() != null)
668 Enumeration en = jal.getProperties().keys();
669 while (en.hasMoreElements())
671 String key = en.nextElement().toString();
672 SequenceSetProperties ssp = new SequenceSetProperties();
674 ssp.setValue(jal.getProperties().get(key).toString());
675 vamsasSet.addSequenceSetProperties(ssp);
680 Set<String> calcIdSet = new HashSet<String>();
683 for (final SequenceI jds : rjal.getSequences())
685 final SequenceI jdatasq = jds.getDatasetSequence() == null ? jds
686 : jds.getDatasetSequence();
687 String id = seqHash(jds);
689 if (seqRefIds.get(id) != null)
691 // This happens for two reasons: 1. multiple views are being serialised.
692 // 2. the hashCode has collided with another sequence's code. This DOES
693 // HAPPEN! (PF00072.15.stk does this)
694 // JBPNote: Uncomment to debug writing out of files that do not read
695 // back in due to ArrayOutOfBoundExceptions.
696 // System.err.println("vamsasSeq backref: "+id+"");
697 // System.err.println(jds.getName()+"
698 // "+jds.getStart()+"-"+jds.getEnd()+" "+jds.getSequenceAsString());
699 // System.err.println("Hashcode: "+seqHash(jds));
700 // SequenceI rsq = (SequenceI) seqRefIds.get(id + "");
701 // System.err.println(rsq.getName()+"
702 // "+rsq.getStart()+"-"+rsq.getEnd()+" "+rsq.getSequenceAsString());
703 // System.err.println("Hashcode: "+seqHash(rsq));
707 vamsasSeq = createVamsasSequence(id, jds);
708 vamsasSet.addSequence(vamsasSeq);
709 seqRefIds.put(id, jds);
713 jseq.setStart(jds.getStart());
714 jseq.setEnd(jds.getEnd());
715 jseq.setColour(av.getSequenceColour(jds).getRGB());
717 jseq.setId(id); // jseq id should be a string not a number
720 // Store any sequences this sequence represents
721 if (av.hasHiddenRows())
723 // use rjal, contains the full height alignment
724 jseq.setHidden(av.getAlignment().getHiddenSequences()
727 if (av.isHiddenRepSequence(jds))
729 jalview.datamodel.SequenceI[] reps = av
730 .getRepresentedSequences(jds)
731 .getSequencesInOrder(rjal);
733 for (int h = 0; h < reps.length; h++)
737 jseq.addHiddenSequences(rjal.findIndex(reps[h]));
742 // mark sequence as reference - if it is the reference for this view
745 jseq.setViewreference(jds == jal.getSeqrep());
749 // TODO: omit sequence features from each alignment view's XML dump if we
750 // are storing dataset
751 if (jds.getSequenceFeatures() != null)
753 jalview.datamodel.SequenceFeature[] sf = jds.getSequenceFeatures();
755 while (index < sf.length)
757 Features features = new Features();
759 features.setBegin(sf[index].getBegin());
760 features.setEnd(sf[index].getEnd());
761 features.setDescription(sf[index].getDescription());
762 features.setType(sf[index].getType());
763 features.setFeatureGroup(sf[index].getFeatureGroup());
764 features.setScore(sf[index].getScore());
765 if (sf[index].links != null)
767 for (int l = 0; l < sf[index].links.size(); l++)
769 OtherData keyValue = new OtherData();
770 keyValue.setKey("LINK_" + l);
771 keyValue.setValue(sf[index].links.elementAt(l).toString());
772 features.addOtherData(keyValue);
775 if (sf[index].otherDetails != null)
778 Iterator<String> keys = sf[index].otherDetails.keySet()
780 while (keys.hasNext())
783 OtherData keyValue = new OtherData();
784 keyValue.setKey(key);
785 keyValue.setValue(sf[index].otherDetails.get(key).toString());
786 features.addOtherData(keyValue);
790 jseq.addFeatures(features);
795 if (jdatasq.getAllPDBEntries() != null)
797 Enumeration en = jdatasq.getAllPDBEntries().elements();
798 while (en.hasMoreElements())
800 Pdbids pdb = new Pdbids();
801 jalview.datamodel.PDBEntry entry = (jalview.datamodel.PDBEntry) en
804 String pdbId = entry.getId();
806 pdb.setType(entry.getType());
809 * Store any structure views associated with this sequence. This
810 * section copes with duplicate entries in the project, so a dataset
811 * only view *should* be coped with sensibly.
813 // This must have been loaded, is it still visible?
814 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
815 String matchedFile = null;
816 for (int f = frames.length - 1; f > -1; f--)
818 if (frames[f] instanceof StructureViewerBase)
820 StructureViewerBase viewFrame = (StructureViewerBase) frames[f];
821 matchedFile = saveStructureState(ap, jds, pdb, entry,
822 viewIds, matchedFile, viewFrame);
824 * Only store each structure viewer's state once in the project
825 * jar. First time through only (storeDS==false)
827 String viewId = viewFrame.getViewId();
828 if (!storeDS && !viewIds.contains(viewId))
833 String viewerState = viewFrame.getStateInfo();
834 writeJarEntry(jout, getViewerJarEntryName(viewId),
835 viewerState.getBytes());
836 } catch (IOException e)
838 System.err.println("Error saving viewer state: "
845 if (matchedFile != null || entry.getFile() != null)
847 if (entry.getFile() != null)
850 matchedFile = entry.getFile();
852 pdb.setFile(matchedFile); // entry.getFile());
853 if (pdbfiles == null)
855 pdbfiles = new ArrayList<String>();
858 if (!pdbfiles.contains(pdbId))
861 copyFileToJar(jout, matchedFile, pdbId);
865 if (entry.getProperty() != null && !entry.getProperty().isEmpty())
867 PdbentryItem item = new PdbentryItem();
868 Hashtable properties = entry.getProperty();
869 Enumeration en2 = properties.keys();
870 while (en2.hasMoreElements())
872 Property prop = new Property();
873 String key = en2.nextElement().toString();
875 prop.setValue(properties.get(key).toString());
876 item.addProperty(prop);
878 pdb.addPdbentryItem(item);
885 saveRnaViewers(jout, jseq, jds, viewIds, ap, storeDS);
890 if (!storeDS && av.hasHiddenRows())
892 jal = av.getAlignment();
895 if (jal.getCodonFrames() != null)
897 List<AlignedCodonFrame> jac = jal.getCodonFrames();
898 for (AlignedCodonFrame acf : jac)
900 AlcodonFrame alc = new AlcodonFrame();
901 if (acf.getProtMappings() != null
902 && acf.getProtMappings().length > 0)
904 boolean hasMap = false;
905 SequenceI[] dnas = acf.getdnaSeqs();
906 jalview.datamodel.Mapping[] pmaps = acf.getProtMappings();
907 for (int m = 0; m < pmaps.length; m++)
909 AlcodMap alcmap = new AlcodMap();
910 alcmap.setDnasq(seqHash(dnas[m]));
911 alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null,
913 alc.addAlcodMap(alcmap);
918 vamsasSet.addAlcodonFrame(alc);
921 // TODO: delete this ? dead code from 2.8.3->2.9 ?
923 // AlcodonFrame alc = new AlcodonFrame();
924 // vamsasSet.addAlcodonFrame(alc);
925 // for (int p = 0; p < acf.aaWidth; p++)
927 // Alcodon cmap = new Alcodon();
928 // if (acf.codons[p] != null)
930 // // Null codons indicate a gapped column in the translated peptide
932 // cmap.setPos1(acf.codons[p][0]);
933 // cmap.setPos2(acf.codons[p][1]);
934 // cmap.setPos3(acf.codons[p][2]);
936 // alc.addAlcodon(cmap);
938 // if (acf.getProtMappings() != null
939 // && acf.getProtMappings().length > 0)
941 // SequenceI[] dnas = acf.getdnaSeqs();
942 // jalview.datamodel.Mapping[] pmaps = acf.getProtMappings();
943 // for (int m = 0; m < pmaps.length; m++)
945 // AlcodMap alcmap = new AlcodMap();
946 // alcmap.setDnasq(seqHash(dnas[m]));
947 // alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null,
949 // alc.addAlcodMap(alcmap);
956 // /////////////////////////////////
957 if (!storeDS && av.currentTree != null)
959 // FIND ANY ASSOCIATED TREES
960 // NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT
961 if (Desktop.desktop != null)
963 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
965 for (int t = 0; t < frames.length; t++)
967 if (frames[t] instanceof TreePanel)
969 TreePanel tp = (TreePanel) frames[t];
971 if (tp.treeCanvas.av.getAlignment() == jal)
973 Tree tree = new Tree();
974 tree.setTitle(tp.getTitle());
975 tree.setCurrentTree((av.currentTree == tp.getTree()));
976 tree.setNewick(tp.getTree().toString());
977 tree.setThreshold(tp.treeCanvas.threshold);
979 tree.setFitToWindow(tp.fitToWindow.getState());
980 tree.setFontName(tp.getTreeFont().getName());
981 tree.setFontSize(tp.getTreeFont().getSize());
982 tree.setFontStyle(tp.getTreeFont().getStyle());
983 tree.setMarkUnlinked(tp.placeholdersMenu.getState());
985 tree.setShowBootstrap(tp.bootstrapMenu.getState());
986 tree.setShowDistances(tp.distanceMenu.getState());
988 tree.setHeight(tp.getHeight());
989 tree.setWidth(tp.getWidth());
990 tree.setXpos(tp.getX());
991 tree.setYpos(tp.getY());
992 tree.setId(makeHashCode(tp, null));
1002 * store forward refs from an annotationRow to any groups
1004 IdentityHashMap<SequenceGroup, String> groupRefs = new IdentityHashMap<SequenceGroup, String>();
1007 for (SequenceI sq : jal.getSequences())
1009 // Store annotation on dataset sequences only
1010 AlignmentAnnotation[] aa = sq.getAnnotation();
1011 if (aa != null && aa.length > 0)
1013 storeAlignmentAnnotation(aa, groupRefs, av, calcIdSet, storeDS,
1020 if (jal.getAlignmentAnnotation() != null)
1022 // Store the annotation shown on the alignment.
1023 AlignmentAnnotation[] aa = jal.getAlignmentAnnotation();
1024 storeAlignmentAnnotation(aa, groupRefs, av, calcIdSet, storeDS,
1029 if (jal.getGroups() != null)
1031 JGroup[] groups = new JGroup[jal.getGroups().size()];
1033 for (jalview.datamodel.SequenceGroup sg : jal.getGroups())
1035 JGroup jGroup = new JGroup();
1036 groups[++i] = jGroup;
1038 jGroup.setStart(sg.getStartRes());
1039 jGroup.setEnd(sg.getEndRes());
1040 jGroup.setName(sg.getName());
1041 if (groupRefs.containsKey(sg))
1043 // group has references so set its ID field
1044 jGroup.setId(groupRefs.get(sg));
1048 if (sg.cs.conservationApplied())
1050 jGroup.setConsThreshold(sg.cs.getConservationInc());
1052 if (sg.cs instanceof jalview.schemes.UserColourScheme)
1054 jGroup.setColour(setUserColourScheme(sg.cs, userColours, jms));
1058 jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs));
1061 else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient)
1063 jGroup.setColour("AnnotationColourGradient");
1064 jGroup.setAnnotationColours(constructAnnotationColours(
1065 (jalview.schemes.AnnotationColourGradient) sg.cs,
1068 else if (sg.cs instanceof jalview.schemes.UserColourScheme)
1070 jGroup.setColour(setUserColourScheme(sg.cs, userColours, jms));
1074 jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs));
1077 jGroup.setPidThreshold(sg.cs.getThreshold());
1080 jGroup.setOutlineColour(sg.getOutlineColour().getRGB());
1081 jGroup.setDisplayBoxes(sg.getDisplayBoxes());
1082 jGroup.setDisplayText(sg.getDisplayText());
1083 jGroup.setColourText(sg.getColourText());
1084 jGroup.setTextCol1(sg.textColour.getRGB());
1085 jGroup.setTextCol2(sg.textColour2.getRGB());
1086 jGroup.setTextColThreshold(sg.thresholdTextColour);
1087 jGroup.setShowUnconserved(sg.getShowNonconserved());
1088 jGroup.setIgnoreGapsinConsensus(sg.getIgnoreGapsConsensus());
1089 jGroup.setShowConsensusHistogram(sg.isShowConsensusHistogram());
1090 jGroup.setShowSequenceLogo(sg.isShowSequenceLogo());
1091 jGroup.setNormaliseSequenceLogo(sg.isNormaliseSequenceLogo());
1092 for (SequenceI seq : sg.getSequences())
1094 jGroup.addSeq(seqHash(seq));
1098 jms.setJGroup(groups);
1102 // /////////SAVE VIEWPORT
1103 Viewport view = new Viewport();
1104 view.setTitle(ap.alignFrame.getTitle());
1105 view.setSequenceSetId(makeHashCode(av.getSequenceSetId(),
1106 av.getSequenceSetId()));
1107 view.setId(av.getViewId());
1108 if (av.getCodingComplement() != null)
1110 view.setComplementId(av.getCodingComplement().getViewId());
1112 view.setViewName(av.viewName);
1113 view.setGatheredViews(av.isGatherViewsHere());
1115 Rectangle size = ap.av.getExplodedGeometry();
1116 Rectangle position = size;
1119 size = ap.alignFrame.getBounds();
1120 if (av.getCodingComplement() != null)
1122 position = ((SplitFrame) ap.alignFrame.getSplitViewContainer())
1130 view.setXpos(position.x);
1131 view.setYpos(position.y);
1133 view.setWidth(size.width);
1134 view.setHeight(size.height);
1136 view.setStartRes(av.startRes);
1137 view.setStartSeq(av.startSeq);
1139 if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)
1141 view.setBgColour(setUserColourScheme(av.getGlobalColourScheme(),
1144 else if (av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient)
1146 AnnotationColours ac = constructAnnotationColours(
1147 (jalview.schemes.AnnotationColourGradient) av
1148 .getGlobalColourScheme(),
1151 view.setAnnotationColours(ac);
1152 view.setBgColour("AnnotationColourGradient");
1156 view.setBgColour(ColourSchemeProperty.getColourName(av
1157 .getGlobalColourScheme()));
1160 ColourSchemeI cs = av.getGlobalColourScheme();
1164 if (cs.conservationApplied())
1166 view.setConsThreshold(cs.getConservationInc());
1167 if (cs instanceof jalview.schemes.UserColourScheme)
1169 view.setBgColour(setUserColourScheme(cs, userColours, jms));
1173 if (cs instanceof ResidueColourScheme)
1175 view.setPidThreshold(cs.getThreshold());
1179 view.setConservationSelected(av.getConservationSelected());
1180 view.setPidSelected(av.getAbovePIDThreshold());
1181 view.setFontName(av.font.getName());
1182 view.setFontSize(av.font.getSize());
1183 view.setFontStyle(av.font.getStyle());
1184 view.setScaleProteinAsCdna(av.getViewStyle().isScaleProteinAsCdna());
1185 view.setRenderGaps(av.isRenderGaps());
1186 view.setShowAnnotation(av.isShowAnnotation());
1187 view.setShowBoxes(av.getShowBoxes());
1188 view.setShowColourText(av.getColourText());
1189 view.setShowFullId(av.getShowJVSuffix());
1190 view.setRightAlignIds(av.isRightAlignIds());
1191 view.setShowSequenceFeatures(av.isShowSequenceFeatures());
1192 view.setShowText(av.getShowText());
1193 view.setShowUnconserved(av.getShowUnconserved());
1194 view.setWrapAlignment(av.getWrapAlignment());
1195 view.setTextCol1(av.getTextColour().getRGB());
1196 view.setTextCol2(av.getTextColour2().getRGB());
1197 view.setTextColThreshold(av.getThresholdTextColour());
1198 view.setShowConsensusHistogram(av.isShowConsensusHistogram());
1199 view.setShowSequenceLogo(av.isShowSequenceLogo());
1200 view.setNormaliseSequenceLogo(av.isNormaliseSequenceLogo());
1201 view.setShowGroupConsensus(av.isShowGroupConsensus());
1202 view.setShowGroupConservation(av.isShowGroupConservation());
1203 view.setShowNPfeatureTooltip(av.isShowNPFeats());
1204 view.setShowDbRefTooltip(av.isShowDBRefs());
1205 view.setFollowHighlight(av.isFollowHighlight());
1206 view.setFollowSelection(av.followSelection);
1207 view.setIgnoreGapsinConsensus(av.isIgnoreGapsConsensus());
1208 if (av.getFeaturesDisplayed() != null)
1210 jalview.schemabinding.version2.FeatureSettings fs = new jalview.schemabinding.version2.FeatureSettings();
1212 String[] renderOrder = ap.getSeqPanel().seqCanvas
1213 .getFeatureRenderer().getRenderOrder()
1214 .toArray(new String[0]);
1216 Vector<String> settingsAdded = new Vector<String>();
1217 if (renderOrder != null)
1219 for (String featureType : renderOrder)
1221 FeatureColourI fcol = ap.getSeqPanel().seqCanvas
1222 .getFeatureRenderer()
1223 .getFeatureStyle(featureType);
1224 Setting setting = new Setting();
1225 setting.setType(featureType);
1226 if (!fcol.isSimpleColour())
1228 setting.setColour(fcol.getMaxColour().getRGB());
1229 setting.setMincolour(fcol.getMinColour().getRGB());
1230 setting.setMin(fcol.getMin());
1231 setting.setMax(fcol.getMax());
1232 setting.setColourByLabel(fcol.isColourByLabel());
1233 setting.setAutoScale(fcol.isAutoScaled());
1234 setting.setThreshold(fcol.getThreshold());
1235 // -1 = No threshold, 0 = Below, 1 = Above
1236 setting.setThreshstate(fcol.isAboveThreshold() ? 1
1237 : (fcol.isBelowThreshold() ? 0 : -1));
1241 setting.setColour(fcol.getColour().getRGB());
1244 setting.setDisplay(av.getFeaturesDisplayed().isVisible(
1246 float rorder = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
1247 .getOrder(featureType);
1250 setting.setOrder(rorder);
1252 fs.addSetting(setting);
1253 settingsAdded.addElement(featureType);
1257 // is groups actually supposed to be a map here ?
1258 Iterator<String> en = ap.getSeqPanel().seqCanvas
1259 .getFeatureRenderer()
1260 .getFeatureGroups().iterator();
1261 Vector<String> groupsAdded = new Vector<String>();
1262 while (en.hasNext())
1264 String grp = en.next();
1265 if (groupsAdded.contains(grp))
1269 Group g = new Group();
1271 g.setDisplay(((Boolean) ap.getSeqPanel().seqCanvas
1272 .getFeatureRenderer().checkGroupVisibility(grp, false))
1275 groupsAdded.addElement(grp);
1277 jms.setFeatureSettings(fs);
1280 if (av.hasHiddenColumns())
1282 if (av.getColumnSelection() == null
1283 || av.getColumnSelection().getHiddenColumns() == null)
1285 warn("REPORT BUG: avoided null columnselection bug (DMAM reported). Please contact Jim about this.");
1289 for (int c = 0; c < av.getColumnSelection().getHiddenColumns()
1292 int[] region = av.getColumnSelection().getHiddenColumns()
1294 HiddenColumns hc = new HiddenColumns();
1295 hc.setStart(region[0]);
1296 hc.setEnd(region[1]);
1297 view.addHiddenColumns(hc);
1301 if (calcIdSet.size() > 0)
1303 for (String calcId : calcIdSet)
1305 if (calcId.trim().length() > 0)
1307 CalcIdParam cidp = createCalcIdParam(calcId, av);
1308 // Some calcIds have no parameters.
1311 view.addCalcIdParam(cidp);
1317 jms.addViewport(view);
1319 object.setJalviewModelSequence(jms);
1320 object.getVamsasModel().addSequenceSet(vamsasSet);
1322 if (jout != null && fileName != null)
1324 // We may not want to write the object to disk,
1325 // eg we can copy the alignViewport to a new view object
1326 // using save and then load
1329 System.out.println("Writing jar entry " + fileName);
1330 JarEntry entry = new JarEntry(fileName);
1331 jout.putNextEntry(entry);
1332 PrintWriter pout = new PrintWriter(new OutputStreamWriter(jout,
1334 Marshaller marshaller = new Marshaller(pout);
1335 marshaller.marshal(object);
1338 } catch (Exception ex)
1340 // TODO: raise error in GUI if marshalling failed.
1341 ex.printStackTrace();
1348 * Save any Varna viewers linked to this sequence. Writes an rnaViewer element
1349 * for each viewer, with
1351 * <li>viewer geometry (position, size, split pane divider location)</li>
1352 * <li>index of the selected structure in the viewer (currently shows gapped
1354 * <li>the id of the annotation holding RNA secondary structure</li>
1355 * <li>(currently only one SS is shown per viewer, may be more in future)</li>
1357 * Varna viewer state is also written out (in native Varna XML) to separate
1358 * project jar entries. A separate entry is written for each RNA structure
1359 * displayed, with the naming convention
1361 * <li>rna_viewId_sequenceId_annotationId_[gapped|trimmed]</li>
1369 * @param storeDataset
1371 protected void saveRnaViewers(JarOutputStream jout, JSeq jseq,
1372 final SequenceI jds, List<String> viewIds, AlignmentPanel ap,
1373 boolean storeDataset)
1375 if (Desktop.desktop == null)
1379 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1380 for (int f = frames.length - 1; f > -1; f--)
1382 if (frames[f] instanceof AppVarna)
1384 AppVarna varna = (AppVarna) frames[f];
1386 * link the sequence to every viewer that is showing it and is linked to
1387 * its alignment panel
1389 if (varna.isListeningFor(jds) && ap == varna.getAlignmentPanel())
1391 String viewId = varna.getViewId();
1392 RnaViewer rna = new RnaViewer();
1393 rna.setViewId(viewId);
1394 rna.setTitle(varna.getTitle());
1395 rna.setXpos(varna.getX());
1396 rna.setYpos(varna.getY());
1397 rna.setWidth(varna.getWidth());
1398 rna.setHeight(varna.getHeight());
1399 rna.setDividerLocation(varna.getDividerLocation());
1400 rna.setSelectedRna(varna.getSelectedIndex());
1401 jseq.addRnaViewer(rna);
1404 * Store each Varna panel's state once in the project per sequence.
1405 * First time through only (storeDataset==false)
1407 // boolean storeSessions = false;
1408 // String sequenceViewId = viewId + seqsToIds.get(jds);
1409 // if (!storeDataset && !viewIds.contains(sequenceViewId))
1411 // viewIds.add(sequenceViewId);
1412 // storeSessions = true;
1414 for (RnaModel model : varna.getModels())
1416 if (model.seq == jds)
1419 * VARNA saves each view (sequence or alignment secondary
1420 * structure, gapped or trimmed) as a separate XML file
1422 String jarEntryName = rnaSessions.get(model);
1423 if (jarEntryName == null)
1426 String varnaStateFile = varna.getStateInfo(model.rna);
1427 jarEntryName = RNA_PREFIX + viewId + "_" + nextCounter();
1428 copyFileToJar(jout, varnaStateFile, jarEntryName);
1429 rnaSessions.put(model, jarEntryName);
1431 SecondaryStructure ss = new SecondaryStructure();
1432 String annotationId = varna.getAnnotation(jds).annotationId;
1433 ss.setAnnotationId(annotationId);
1434 ss.setViewerState(jarEntryName);
1435 ss.setGapped(model.gapped);
1436 ss.setTitle(model.title);
1437 rna.addSecondaryStructure(ss);
1446 * Copy the contents of a file to a new entry added to the output jar
1450 * @param jarEntryName
1452 protected void copyFileToJar(JarOutputStream jout, String infilePath,
1453 String jarEntryName)
1455 DataInputStream dis = null;
1458 File file = new File(infilePath);
1459 if (file.exists() && jout != null)
1461 dis = new DataInputStream(new FileInputStream(file));
1462 byte[] data = new byte[(int) file.length()];
1463 dis.readFully(data);
1464 writeJarEntry(jout, jarEntryName, data);
1466 } catch (Exception ex)
1468 ex.printStackTrace();
1476 } catch (IOException e)
1485 * Write the data to a new entry of given name in the output jar file
1488 * @param jarEntryName
1490 * @throws IOException
1492 protected void writeJarEntry(JarOutputStream jout, String jarEntryName,
1493 byte[] data) throws IOException
1497 System.out.println("Writing jar entry " + jarEntryName);
1498 jout.putNextEntry(new JarEntry(jarEntryName));
1499 DataOutputStream dout = new DataOutputStream(jout);
1500 dout.write(data, 0, data.length);
1507 * Save the state of a structure viewer
1512 * the archive XML element under which to save the state
1515 * @param matchedFile
1519 protected String saveStructureState(AlignmentPanel ap, SequenceI jds,
1520 Pdbids pdb, PDBEntry entry, List<String> viewIds,
1521 String matchedFile, StructureViewerBase viewFrame)
1523 final AAStructureBindingModel bindingModel = viewFrame.getBinding();
1526 * Look for any bindings for this viewer to the PDB file of interest
1527 * (including part matches excluding chain id)
1529 for (int peid = 0; peid < bindingModel.getPdbCount(); peid++)
1531 final PDBEntry pdbentry = bindingModel.getPdbEntry(peid);
1532 final String pdbId = pdbentry.getId();
1533 if (!pdbId.equals(entry.getId())
1534 && !(entry.getId().length() > 4 && entry.getId()
1535 .toLowerCase().startsWith(pdbId.toLowerCase())))
1538 * not interested in a binding to a different PDB entry here
1542 if (matchedFile == null)
1544 matchedFile = pdbentry.getFile();
1546 else if (!matchedFile.equals(pdbentry.getFile()))
1549 .warn("Probably lost some PDB-Sequence mappings for this structure file (which apparently has same PDB Entry code): "
1550 + pdbentry.getFile());
1554 // can get at it if the ID
1555 // match is ambiguous (e.g.
1558 for (int smap = 0; smap < viewFrame.getBinding().getSequence()[peid].length; smap++)
1560 // if (jal.findIndex(jmol.jmb.sequence[peid][smap]) > -1)
1561 if (jds == viewFrame.getBinding().getSequence()[peid][smap])
1563 StructureState state = new StructureState();
1564 state.setVisible(true);
1565 state.setXpos(viewFrame.getX());
1566 state.setYpos(viewFrame.getY());
1567 state.setWidth(viewFrame.getWidth());
1568 state.setHeight(viewFrame.getHeight());
1569 final String viewId = viewFrame.getViewId();
1570 state.setViewId(viewId);
1571 state.setAlignwithAlignPanel(viewFrame.isUsedforaligment(ap));
1572 state.setColourwithAlignPanel(viewFrame.isUsedforcolourby(ap));
1573 state.setColourByJmol(viewFrame.isColouredByViewer());
1574 state.setType(viewFrame.getViewerType().toString());
1575 pdb.addStructureState(state);
1582 private AnnotationColours constructAnnotationColours(
1583 AnnotationColourGradient acg, List<UserColourScheme> userColours,
1584 JalviewModelSequence jms)
1586 AnnotationColours ac = new AnnotationColours();
1587 ac.setAboveThreshold(acg.getAboveThreshold());
1588 ac.setThreshold(acg.getAnnotationThreshold());
1589 ac.setAnnotation(acg.getAnnotation());
1590 if (acg.getBaseColour() instanceof jalview.schemes.UserColourScheme)
1592 ac.setColourScheme(setUserColourScheme(acg.getBaseColour(),
1597 ac.setColourScheme(ColourSchemeProperty.getColourName(acg
1601 ac.setMaxColour(acg.getMaxColour().getRGB());
1602 ac.setMinColour(acg.getMinColour().getRGB());
1603 ac.setPerSequence(acg.isSeqAssociated());
1604 ac.setPredefinedColours(acg.isPredefinedColours());
1608 private void storeAlignmentAnnotation(AlignmentAnnotation[] aa,
1609 IdentityHashMap<SequenceGroup, String> groupRefs,
1610 AlignmentViewport av, Set<String> calcIdSet, boolean storeDS,
1611 SequenceSet vamsasSet)
1614 for (int i = 0; i < aa.length; i++)
1616 Annotation an = new Annotation();
1618 AlignmentAnnotation annotation = aa[i];
1619 if (annotation.annotationId != null)
1621 annotationIds.put(annotation.annotationId, annotation);
1624 an.setId(annotation.annotationId);
1626 an.setVisible(annotation.visible);
1628 an.setDescription(annotation.description);
1630 if (annotation.sequenceRef != null)
1632 // 2.9 JAL-1781 xref on sequence id rather than name
1633 an.setSequenceRef(seqsToIds.get(annotation.sequenceRef));
1635 if (annotation.groupRef != null)
1637 String groupIdr = groupRefs.get(annotation.groupRef);
1638 if (groupIdr == null)
1640 // make a locally unique String
1642 annotation.groupRef,
1643 groupIdr = ("" + System.currentTimeMillis()
1644 + annotation.groupRef.getName() + groupRefs
1647 an.setGroupRef(groupIdr.toString());
1650 // store all visualization attributes for annotation
1651 an.setGraphHeight(annotation.graphHeight);
1652 an.setCentreColLabels(annotation.centreColLabels);
1653 an.setScaleColLabels(annotation.scaleColLabel);
1654 an.setShowAllColLabels(annotation.showAllColLabels);
1655 an.setBelowAlignment(annotation.belowAlignment);
1657 if (annotation.graph > 0)
1660 an.setGraphType(annotation.graph);
1661 an.setGraphGroup(annotation.graphGroup);
1662 if (annotation.getThreshold() != null)
1664 ThresholdLine line = new ThresholdLine();
1665 line.setLabel(annotation.getThreshold().label);
1666 line.setValue(annotation.getThreshold().value);
1667 line.setColour(annotation.getThreshold().colour.getRGB());
1668 an.setThresholdLine(line);
1676 an.setLabel(annotation.label);
1678 if (annotation == av.getAlignmentQualityAnnot()
1679 || annotation == av.getAlignmentConservationAnnotation()
1680 || annotation == av.getAlignmentConsensusAnnotation()
1681 || annotation.autoCalculated)
1683 // new way of indicating autocalculated annotation -
1684 an.setAutoCalculated(annotation.autoCalculated);
1686 if (annotation.hasScore())
1688 an.setScore(annotation.getScore());
1691 if (annotation.getCalcId() != null)
1693 calcIdSet.add(annotation.getCalcId());
1694 an.setCalcId(annotation.getCalcId());
1696 if (annotation.hasProperties())
1698 for (String pr : annotation.getProperties())
1700 Property prop = new Property();
1702 prop.setValue(annotation.getProperty(pr));
1703 an.addProperty(prop);
1707 AnnotationElement ae;
1708 if (annotation.annotations != null)
1710 an.setScoreOnly(false);
1711 for (int a = 0; a < annotation.annotations.length; a++)
1713 if ((annotation == null) || (annotation.annotations[a] == null))
1718 ae = new AnnotationElement();
1719 if (annotation.annotations[a].description != null)
1721 ae.setDescription(annotation.annotations[a].description);
1723 if (annotation.annotations[a].displayCharacter != null)
1725 ae.setDisplayCharacter(annotation.annotations[a].displayCharacter);
1728 if (!Float.isNaN(annotation.annotations[a].value))
1730 ae.setValue(annotation.annotations[a].value);
1734 if (annotation.annotations[a].secondaryStructure > ' ')
1736 ae.setSecondaryStructure(annotation.annotations[a].secondaryStructure
1740 if (annotation.annotations[a].colour != null
1741 && annotation.annotations[a].colour != java.awt.Color.black)
1743 ae.setColour(annotation.annotations[a].colour.getRGB());
1746 an.addAnnotationElement(ae);
1747 if (annotation.autoCalculated)
1749 // only write one non-null entry into the annotation row -
1750 // sufficient to get the visualization attributes necessary to
1758 an.setScoreOnly(true);
1760 if (!storeDS || (storeDS && !annotation.autoCalculated))
1762 // skip autocalculated annotation - these are only provided for
1764 vamsasSet.addAnnotation(an);
1770 private CalcIdParam createCalcIdParam(String calcId, AlignViewport av)
1772 AutoCalcSetting settings = av.getCalcIdSettingsFor(calcId);
1773 if (settings != null)
1775 CalcIdParam vCalcIdParam = new CalcIdParam();
1776 vCalcIdParam.setCalcId(calcId);
1777 vCalcIdParam.addServiceURL(settings.getServiceURI());
1778 // generic URI allowing a third party to resolve another instance of the
1779 // service used for this calculation
1780 for (String urls : settings.getServiceURLs())
1782 vCalcIdParam.addServiceURL(urls);
1784 vCalcIdParam.setVersion("1.0");
1785 if (settings.getPreset() != null)
1787 WsParamSetI setting = settings.getPreset();
1788 vCalcIdParam.setName(setting.getName());
1789 vCalcIdParam.setDescription(setting.getDescription());
1793 vCalcIdParam.setName("");
1794 vCalcIdParam.setDescription("Last used parameters");
1796 // need to be able to recover 1) settings 2) user-defined presets or
1797 // recreate settings from preset 3) predefined settings provided by
1798 // service - or settings that can be transferred (or discarded)
1799 vCalcIdParam.setParameters(settings.getWsParamFile().replace("\n",
1801 vCalcIdParam.setAutoUpdate(settings.isAutoUpdate());
1802 // todo - decide if updateImmediately is needed for any projects.
1804 return vCalcIdParam;
1809 private boolean recoverCalcIdParam(CalcIdParam calcIdParam,
1812 if (calcIdParam.getVersion().equals("1.0"))
1814 Jws2Instance service = Jws2Discoverer.getDiscoverer()
1815 .getPreferredServiceFor(calcIdParam.getServiceURL());
1816 if (service != null)
1818 WsParamSetI parmSet = null;
1821 parmSet = service.getParamStore().parseServiceParameterFile(
1822 calcIdParam.getName(), calcIdParam.getDescription(),
1823 calcIdParam.getServiceURL(),
1824 calcIdParam.getParameters().replace("|\\n|", "\n"));
1825 } catch (IOException x)
1827 warn("Couldn't parse parameter data for "
1828 + calcIdParam.getCalcId(), x);
1831 List<ArgumentI> argList = null;
1832 if (calcIdParam.getName().length() > 0)
1834 parmSet = service.getParamStore()
1835 .getPreset(calcIdParam.getName());
1836 if (parmSet != null)
1838 // TODO : check we have a good match with settings in AACon -
1839 // otherwise we'll need to create a new preset
1844 argList = parmSet.getArguments();
1847 AAConSettings settings = new AAConSettings(
1848 calcIdParam.isAutoUpdate(), service, parmSet, argList);
1849 av.setCalcIdSettingsFor(calcIdParam.getCalcId(), settings,
1850 calcIdParam.isNeedsUpdate());
1855 warn("Cannot resolve a service for the parameters used in this project. Try configuring a JABAWS server.");
1859 throw new Error(MessageManager.formatMessage(
1860 "error.unsupported_version_calcIdparam",
1861 new Object[] { calcIdParam.toString() }));
1865 * External mapping between jalview objects and objects yielding a valid and
1866 * unique object ID string. This is null for normal Jalview project IO, but
1867 * non-null when a jalview project is being read or written as part of a
1870 IdentityHashMap jv2vobj = null;
1873 * Construct a unique ID for jvobj using either existing bindings or if none
1874 * exist, the result of the hashcode call for the object.
1877 * jalview data object
1878 * @return unique ID for referring to jvobj
1880 private String makeHashCode(Object jvobj, String altCode)
1882 if (jv2vobj != null)
1884 Object id = jv2vobj.get(jvobj);
1887 return id.toString();
1889 // check string ID mappings
1890 if (jvids2vobj != null && jvobj instanceof String)
1892 id = jvids2vobj.get(jvobj);
1896 return id.toString();
1898 // give up and warn that something has gone wrong
1899 warn("Cannot find ID for object in external mapping : " + jvobj);
1905 * return local jalview object mapped to ID, if it exists
1909 * @return null or object bound to idcode
1911 private Object retrieveExistingObj(String idcode)
1913 if (idcode != null && vobj2jv != null)
1915 return vobj2jv.get(idcode);
1921 * binding from ID strings from external mapping table to jalview data model
1924 private Hashtable vobj2jv;
1926 private Sequence createVamsasSequence(String id, SequenceI jds)
1928 return createVamsasSequence(true, id, jds, null);
1931 private Sequence createVamsasSequence(boolean recurse, String id,
1932 SequenceI jds, SequenceI parentseq)
1934 Sequence vamsasSeq = new Sequence();
1935 vamsasSeq.setId(id);
1936 vamsasSeq.setName(jds.getName());
1937 vamsasSeq.setSequence(jds.getSequenceAsString());
1938 vamsasSeq.setDescription(jds.getDescription());
1939 jalview.datamodel.DBRefEntry[] dbrefs = null;
1940 if (jds.getDatasetSequence() != null)
1942 vamsasSeq.setDsseqid(seqHash(jds.getDatasetSequence()));
1943 if (jds.getDatasetSequence().getDBRefs() != null)
1945 dbrefs = jds.getDatasetSequence().getDBRefs();
1950 vamsasSeq.setDsseqid(id); // so we can tell which sequences really are
1951 // dataset sequences only
1952 dbrefs = jds.getDBRefs();
1956 for (int d = 0; d < dbrefs.length; d++)
1958 DBRef dbref = new DBRef();
1959 dbref.setSource(dbrefs[d].getSource());
1960 dbref.setVersion(dbrefs[d].getVersion());
1961 dbref.setAccessionId(dbrefs[d].getAccessionId());
1962 if (dbrefs[d].hasMap())
1964 Mapping mp = createVamsasMapping(dbrefs[d].getMap(), parentseq,
1966 dbref.setMapping(mp);
1968 vamsasSeq.addDBRef(dbref);
1974 private Mapping createVamsasMapping(jalview.datamodel.Mapping jmp,
1975 SequenceI parentseq, SequenceI jds, boolean recurse)
1978 if (jmp.getMap() != null)
1982 jalview.util.MapList mlst = jmp.getMap();
1983 List<int[]> r = mlst.getFromRanges();
1984 for (int[] range : r)
1986 MapListFrom mfrom = new MapListFrom();
1987 mfrom.setStart(range[0]);
1988 mfrom.setEnd(range[1]);
1989 mp.addMapListFrom(mfrom);
1991 r = mlst.getToRanges();
1992 for (int[] range : r)
1994 MapListTo mto = new MapListTo();
1995 mto.setStart(range[0]);
1996 mto.setEnd(range[1]);
1997 mp.addMapListTo(mto);
1999 mp.setMapFromUnit(mlst.getFromRatio());
2000 mp.setMapToUnit(mlst.getToRatio());
2001 if (jmp.getTo() != null)
2003 MappingChoice mpc = new MappingChoice();
2005 && (parentseq != jmp.getTo() || parentseq
2006 .getDatasetSequence() != jmp.getTo()))
2008 mpc.setSequence(createVamsasSequence(false, seqHash(jmp.getTo()),
2014 SequenceI ps = null;
2015 if (parentseq != jmp.getTo()
2016 && parentseq.getDatasetSequence() != jmp.getTo())
2018 // chaining dbref rather than a handshaking one
2019 jmpid = seqHash(ps = jmp.getTo());
2023 jmpid = seqHash(ps = parentseq);
2025 mpc.setDseqFor(jmpid);
2026 if (!seqRefIds.containsKey(mpc.getDseqFor()))
2028 jalview.bin.Cache.log.debug("creatign new DseqFor ID");
2029 seqRefIds.put(mpc.getDseqFor(), ps);
2033 jalview.bin.Cache.log.debug("reusing DseqFor ID");
2036 mp.setMappingChoice(mpc);
2042 String setUserColourScheme(jalview.schemes.ColourSchemeI cs,
2043 List<UserColourScheme> userColours, JalviewModelSequence jms)
2046 jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs;
2047 boolean newucs = false;
2048 if (!userColours.contains(ucs))
2050 userColours.add(ucs);
2053 id = "ucs" + userColours.indexOf(ucs);
2056 // actually create the scheme's entry in the XML model
2057 java.awt.Color[] colours = ucs.getColours();
2058 jalview.schemabinding.version2.UserColours uc = new jalview.schemabinding.version2.UserColours();
2059 jalview.schemabinding.version2.UserColourScheme jbucs = new jalview.schemabinding.version2.UserColourScheme();
2061 for (int i = 0; i < colours.length; i++)
2063 jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
2064 col.setName(ResidueProperties.aa[i]);
2065 col.setRGB(jalview.util.Format.getHexString(colours[i]));
2066 jbucs.addColour(col);
2068 if (ucs.getLowerCaseColours() != null)
2070 colours = ucs.getLowerCaseColours();
2071 for (int i = 0; i < colours.length; i++)
2073 jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
2074 col.setName(ResidueProperties.aa[i].toLowerCase());
2075 col.setRGB(jalview.util.Format.getHexString(colours[i]));
2076 jbucs.addColour(col);
2081 uc.setUserColourScheme(jbucs);
2082 jms.addUserColours(uc);
2088 jalview.schemes.UserColourScheme getUserColourScheme(
2089 JalviewModelSequence jms, String id)
2091 UserColours[] uc = jms.getUserColours();
2092 UserColours colours = null;
2094 for (int i = 0; i < uc.length; i++)
2096 if (uc[i].getId().equals(id))
2104 java.awt.Color[] newColours = new java.awt.Color[24];
2106 for (int i = 0; i < 24; i++)
2108 newColours[i] = new java.awt.Color(Integer.parseInt(colours
2109 .getUserColourScheme().getColour(i).getRGB(), 16));
2112 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
2115 if (colours.getUserColourScheme().getColourCount() > 24)
2117 newColours = new java.awt.Color[23];
2118 for (int i = 0; i < 23; i++)
2120 newColours[i] = new java.awt.Color(Integer.parseInt(colours
2121 .getUserColourScheme().getColour(i + 24).getRGB(), 16));
2123 ucs.setLowerCaseColours(newColours);
2130 * contains last error message (if any) encountered by XML loader.
2132 String errorMessage = null;
2135 * flag to control whether the Jalview2XML_V1 parser should be deferred to if
2136 * exceptions are raised during project XML parsing
2138 public boolean attemptversion1parse = true;
2141 * Load a jalview project archive from a jar file
2144 * - HTTP URL or filename
2146 public AlignFrame loadJalviewAlign(final String file)
2149 jalview.gui.AlignFrame af = null;
2153 // create list to store references for any new Jmol viewers created
2154 newStructureViewers = new Vector<JalviewStructureDisplayI>();
2155 // UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING
2156 // Workaround is to make sure caller implements the JarInputStreamProvider
2158 // so we can re-open the jar input stream for each entry.
2160 jarInputStreamProvider jprovider = createjarInputStreamProvider(file);
2161 af = loadJalviewAlign(jprovider);
2163 } catch (MalformedURLException e)
2165 errorMessage = "Invalid URL format for '" + file + "'";
2171 SwingUtilities.invokeAndWait(new Runnable()
2176 setLoadingFinishedForNewStructureViewers();
2179 } catch (Exception x)
2181 System.err.println("Error loading alignment: " + x.getMessage());
2187 private jarInputStreamProvider createjarInputStreamProvider(
2188 final String file) throws MalformedURLException
2191 errorMessage = null;
2192 uniqueSetSuffix = null;
2194 viewportsAdded.clear();
2195 frefedSequence = null;
2197 if (file.startsWith("http://"))
2199 url = new URL(file);
2201 final URL _url = url;
2202 return new jarInputStreamProvider()
2206 public JarInputStream getJarInputStream() throws IOException
2210 return new JarInputStream(_url.openStream());
2214 return new JarInputStream(new FileInputStream(file));
2219 public String getFilename()
2227 * Recover jalview session from a jalview project archive. Caller may
2228 * initialise uniqueSetSuffix, seqRefIds, viewportsAdded and frefedSequence
2229 * themselves. Any null fields will be initialised with default values,
2230 * non-null fields are left alone.
2235 public AlignFrame loadJalviewAlign(final jarInputStreamProvider jprovider)
2237 errorMessage = null;
2238 if (uniqueSetSuffix == null)
2240 uniqueSetSuffix = System.currentTimeMillis() % 100000 + "";
2242 if (seqRefIds == null)
2244 seqRefIds = new HashMap<String, SequenceI>();
2246 if (frefedSequence == null)
2248 frefedSequence = new Vector<Object[]>();
2251 AlignFrame af = null, _af = null;
2252 Map<String, AlignFrame> gatherToThisFrame = new HashMap<String, AlignFrame>();
2253 final String file = jprovider.getFilename();
2256 JarInputStream jin = null;
2257 JarEntry jarentry = null;
2262 jin = jprovider.getJarInputStream();
2263 for (int i = 0; i < entryCount; i++)
2265 jarentry = jin.getNextJarEntry();
2268 if (jarentry != null && jarentry.getName().endsWith(".xml"))
2270 InputStreamReader in = new InputStreamReader(jin, UTF_8);
2271 JalviewModel object = new JalviewModel();
2273 Unmarshaller unmar = new Unmarshaller(object);
2274 unmar.setValidation(false);
2275 object = (JalviewModel) unmar.unmarshal(in);
2276 if (true) // !skipViewport(object))
2278 _af = loadFromObject(object, file, true, jprovider);
2279 if (object.getJalviewModelSequence().getViewportCount() > 0)
2282 if (af.viewport.isGatherViewsHere())
2284 gatherToThisFrame.put(af.viewport.getSequenceSetId(), af);
2290 else if (jarentry != null)
2292 // Some other file here.
2295 } while (jarentry != null);
2296 resolveFrefedSequences();
2297 } catch (IOException ex)
2299 ex.printStackTrace();
2300 errorMessage = "Couldn't locate Jalview XML file : " + file;
2301 System.err.println("Exception whilst loading jalview XML file : "
2303 } catch (Exception ex)
2305 System.err.println("Parsing as Jalview Version 2 file failed.");
2306 ex.printStackTrace(System.err);
2307 if (attemptversion1parse)
2309 // Is Version 1 Jar file?
2312 af = new Jalview2XML_V1(raiseGUI).LoadJalviewAlign(jprovider);
2313 } catch (Exception ex2)
2315 System.err.println("Exception whilst loading as jalviewXMLV1:");
2316 ex2.printStackTrace();
2320 if (Desktop.instance != null)
2322 Desktop.instance.stopLoading();
2326 System.out.println("Successfully loaded archive file");
2329 ex.printStackTrace();
2331 System.err.println("Exception whilst loading jalview XML file : "
2333 } catch (OutOfMemoryError e)
2335 // Don't use the OOM Window here
2336 errorMessage = "Out of memory loading jalview XML file";
2337 System.err.println("Out of memory whilst loading jalview XML file");
2338 e.printStackTrace();
2341 if (Desktop.instance != null)
2343 Desktop.instance.stopLoading();
2347 * Regather multiple views (with the same sequence set id) to the frame (if
2348 * any) that is flagged as the one to gather to, i.e. convert them to tabbed
2349 * views instead of separate frames. Note this doesn't restore a state where
2350 * some expanded views in turn have tabbed views - the last "first tab" read
2351 * in will play the role of gatherer for all.
2353 for (AlignFrame fr : gatherToThisFrame.values())
2355 Desktop.instance.gatherViews(fr);
2358 restoreSplitFrames();
2360 if (errorMessage != null)
2368 * Try to reconstruct and display SplitFrame windows, where each contains
2369 * complementary dna and protein alignments. Done by pairing up AlignFrame
2370 * objects (created earlier) which have complementary viewport ids associated.
2372 protected void restoreSplitFrames()
2374 List<SplitFrame> gatherTo = new ArrayList<SplitFrame>();
2375 List<AlignFrame> addedToSplitFrames = new ArrayList<AlignFrame>();
2376 Map<String, AlignFrame> dna = new HashMap<String, AlignFrame>();
2379 * Identify the DNA alignments
2381 for (Entry<Viewport, AlignFrame> candidate : splitFrameCandidates
2384 AlignFrame af = candidate.getValue();
2385 if (af.getViewport().getAlignment().isNucleotide())
2387 dna.put(candidate.getKey().getId(), af);
2392 * Try to match up the protein complements
2394 for (Entry<Viewport, AlignFrame> candidate : splitFrameCandidates
2397 AlignFrame af = candidate.getValue();
2398 if (!af.getViewport().getAlignment().isNucleotide())
2400 String complementId = candidate.getKey().getComplementId();
2401 // only non-null complements should be in the Map
2402 if (complementId != null && dna.containsKey(complementId))
2404 final AlignFrame dnaFrame = dna.get(complementId);
2405 SplitFrame sf = createSplitFrame(dnaFrame, af);
2406 addedToSplitFrames.add(dnaFrame);
2407 addedToSplitFrames.add(af);
2408 if (af.viewport.isGatherViewsHere())
2417 * Open any that we failed to pair up (which shouldn't happen!) as
2418 * standalone AlignFrame's.
2420 for (Entry<Viewport, AlignFrame> candidate : splitFrameCandidates
2423 AlignFrame af = candidate.getValue();
2424 if (!addedToSplitFrames.contains(af))
2426 Viewport view = candidate.getKey();
2427 Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
2429 System.err.println("Failed to restore view " + view.getTitle()
2430 + " to split frame");
2435 * Gather back into tabbed views as flagged.
2437 for (SplitFrame sf : gatherTo)
2439 Desktop.instance.gatherViews(sf);
2442 splitFrameCandidates.clear();
2446 * Construct and display one SplitFrame holding DNA and protein alignments.
2449 * @param proteinFrame
2452 protected SplitFrame createSplitFrame(AlignFrame dnaFrame,
2453 AlignFrame proteinFrame)
2455 SplitFrame splitFrame = new SplitFrame(dnaFrame, proteinFrame);
2456 String title = MessageManager.getString("label.linked_view_title");
2457 int width = (int) dnaFrame.getBounds().getWidth();
2458 int height = (int) (dnaFrame.getBounds().getHeight()
2459 + proteinFrame.getBounds().getHeight() + 50);
2462 * SplitFrame location is saved to both enclosed frames
2464 splitFrame.setLocation(dnaFrame.getX(), dnaFrame.getY());
2465 Desktop.addInternalFrame(splitFrame, title, width, height);
2468 * And compute cDNA consensus (couldn't do earlier with consensus as
2469 * mappings were not yet present)
2471 proteinFrame.viewport.alignmentChanged(proteinFrame.alignPanel);
2477 * check errorMessage for a valid error message and raise an error box in the
2478 * GUI or write the current errorMessage to stderr and then clear the error
2481 protected void reportErrors()
2483 reportErrors(false);
2486 protected void reportErrors(final boolean saving)
2488 if (errorMessage != null)
2490 final String finalErrorMessage = errorMessage;
2493 javax.swing.SwingUtilities.invokeLater(new Runnable()
2498 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2499 finalErrorMessage, "Error "
2500 + (saving ? "saving" : "loading")
2501 + " Jalview file", JOptionPane.WARNING_MESSAGE);
2507 System.err.println("Problem loading Jalview file: " + errorMessage);
2510 errorMessage = null;
2513 Map<String, String> alreadyLoadedPDB = new HashMap<String, String>();
2516 * when set, local views will be updated from view stored in JalviewXML
2517 * Currently (28th Sep 2008) things will go horribly wrong in vamsas document
2518 * sync if this is set to true.
2520 private final boolean updateLocalViews = false;
2523 * Returns the path to a temporary file holding the PDB file for the given PDB
2524 * id. The first time of asking, searches for a file of that name in the
2525 * Jalview project jar, and copies it to a new temporary file. Any repeat
2526 * requests just return the path to the file previously created.
2532 String loadPDBFile(jarInputStreamProvider jprovider, String pdbId)
2534 if (alreadyLoadedPDB.containsKey(pdbId))
2536 return alreadyLoadedPDB.get(pdbId).toString();
2539 String tempFile = copyJarEntry(jprovider, pdbId, "jalview_pdb");
2540 if (tempFile != null)
2542 alreadyLoadedPDB.put(pdbId, tempFile);
2548 * Copies the jar entry of given name to a new temporary file and returns the
2549 * path to the file, or null if the entry is not found.
2552 * @param jarEntryName
2554 * a prefix for the temporary file name, must be at least three
2558 protected String copyJarEntry(jarInputStreamProvider jprovider,
2559 String jarEntryName, String prefix)
2561 BufferedReader in = null;
2562 PrintWriter out = null;
2566 JarInputStream jin = jprovider.getJarInputStream();
2568 * if (jprovider.startsWith("http://")) { jin = new JarInputStream(new
2569 * URL(jprovider).openStream()); } else { jin = new JarInputStream(new
2570 * FileInputStream(jprovider)); }
2573 JarEntry entry = null;
2576 entry = jin.getNextJarEntry();
2577 } while (entry != null && !entry.getName().equals(jarEntryName));
2580 in = new BufferedReader(new InputStreamReader(jin, UTF_8));
2581 File outFile = File.createTempFile(prefix, ".tmp");
2582 outFile.deleteOnExit();
2583 out = new PrintWriter(new FileOutputStream(outFile));
2586 while ((data = in.readLine()) != null)
2591 String t = outFile.getAbsolutePath();
2596 warn("Couldn't find entry in Jalview Jar for " + jarEntryName);
2598 } catch (Exception ex)
2600 ex.printStackTrace();
2608 } catch (IOException e)
2622 private class JvAnnotRow
2624 public JvAnnotRow(int i, AlignmentAnnotation jaa)
2631 * persisted version of annotation row from which to take vis properties
2633 public jalview.datamodel.AlignmentAnnotation template;
2636 * original position of the annotation row in the alignment
2642 * Load alignment frame from jalview XML DOM object
2647 * filename source string
2648 * @param loadTreesAndStructures
2649 * when false only create Viewport
2651 * data source provider
2652 * @return alignment frame created from view stored in DOM
2654 AlignFrame loadFromObject(JalviewModel object, String file,
2655 boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
2657 SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
2658 Sequence[] vamsasSeq = vamsasSet.getSequence();
2660 JalviewModelSequence jms = object.getJalviewModelSequence();
2662 Viewport view = (jms.getViewportCount() > 0) ? jms.getViewport(0)
2665 // ////////////////////////////////
2668 List<SequenceI> hiddenSeqs = null;
2671 List<SequenceI> tmpseqs = new ArrayList<SequenceI>();
2673 boolean multipleView = false;
2674 SequenceI referenceseqForView = null;
2675 JSeq[] jseqs = object.getJalviewModelSequence().getJSeq();
2676 int vi = 0; // counter in vamsasSeq array
2677 for (int i = 0; i < jseqs.length; i++)
2679 String seqId = jseqs[i].getId();
2681 SequenceI tmpSeq = seqRefIds.get(seqId);
2684 tmpSeq.setStart(jseqs[i].getStart());
2685 tmpSeq.setEnd(jseqs[i].getEnd());
2686 tmpseqs.add(tmpSeq);
2687 multipleView = true;
2691 tmpSeq = new jalview.datamodel.Sequence(vamsasSeq[vi].getName(),
2692 vamsasSeq[vi].getSequence());
2693 tmpSeq.setDescription(vamsasSeq[vi].getDescription());
2694 tmpSeq.setStart(jseqs[i].getStart());
2695 tmpSeq.setEnd(jseqs[i].getEnd());
2696 tmpSeq.setVamsasId(uniqueSetSuffix + seqId);
2697 seqRefIds.put(vamsasSeq[vi].getId(), tmpSeq);
2698 tmpseqs.add(tmpSeq);
2702 if (jseqs[i].hasViewreference() && jseqs[i].getViewreference())
2704 referenceseqForView = tmpseqs.get(tmpseqs.size() - 1);
2707 if (jseqs[i].getHidden())
2709 if (hiddenSeqs == null)
2711 hiddenSeqs = new ArrayList<SequenceI>();
2714 hiddenSeqs.add(tmpSeq);
2719 // Create the alignment object from the sequence set
2720 // ///////////////////////////////
2721 SequenceI[] orderedSeqs = tmpseqs
2722 .toArray(new SequenceI[tmpseqs.size()]);
2724 AlignmentI al = new Alignment(orderedSeqs);
2726 if (referenceseqForView != null)
2728 al.setSeqrep(referenceseqForView);
2730 // / Add the alignment properties
2731 for (int i = 0; i < vamsasSet.getSequenceSetPropertiesCount(); i++)
2733 SequenceSetProperties ssp = vamsasSet.getSequenceSetProperties(i);
2734 al.setProperty(ssp.getKey(), ssp.getValue());
2738 // SequenceFeatures are added to the DatasetSequence,
2739 // so we must create or recover the dataset before loading features
2740 // ///////////////////////////////
2741 if (vamsasSet.getDatasetId() == null || vamsasSet.getDatasetId() == "")
2743 // older jalview projects do not have a dataset id.
2744 al.setDataset(null);
2748 // recover dataset - passing on flag indicating if this a 'viewless'
2749 // sequence set (a.k.a. a stored dataset for the project)
2750 recoverDatasetFor(vamsasSet, al, object.getJalviewModelSequence()
2751 .getViewportCount() == 0);
2753 // ///////////////////////////////
2755 Hashtable pdbloaded = new Hashtable(); // TODO nothing writes to this??
2758 // load sequence features, database references and any associated PDB
2759 // structures for the alignment
2760 for (int i = 0; i < vamsasSeq.length; i++)
2762 if (jseqs[i].getFeaturesCount() > 0)
2764 Features[] features = jseqs[i].getFeatures();
2765 for (int f = 0; f < features.length; f++)
2767 jalview.datamodel.SequenceFeature sf = new jalview.datamodel.SequenceFeature(
2768 features[f].getType(), features[f].getDescription(),
2769 features[f].getStatus(), features[f].getBegin(),
2770 features[f].getEnd(), features[f].getFeatureGroup());
2772 sf.setScore(features[f].getScore());
2773 for (int od = 0; od < features[f].getOtherDataCount(); od++)
2775 OtherData keyValue = features[f].getOtherData(od);
2776 if (keyValue.getKey().startsWith("LINK"))
2778 sf.addLink(keyValue.getValue());
2782 sf.setValue(keyValue.getKey(), keyValue.getValue());
2787 al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
2790 if (vamsasSeq[i].getDBRefCount() > 0)
2792 addDBRefs(al.getSequenceAt(i).getDatasetSequence(), vamsasSeq[i]);
2794 if (jseqs[i].getPdbidsCount() > 0)
2796 Pdbids[] ids = jseqs[i].getPdbids();
2797 for (int p = 0; p < ids.length; p++)
2799 jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
2800 entry.setId(ids[p].getId());
2801 if (ids[p].getType() != null)
2803 if (ids[p].getType().equalsIgnoreCase("PDB"))
2805 entry.setType(PDBEntry.Type.PDB);
2809 entry.setType(PDBEntry.Type.FILE);
2812 if (ids[p].getFile() != null)
2814 if (!pdbloaded.containsKey(ids[p].getFile()))
2816 entry.setFile(loadPDBFile(jprovider, ids[p].getId()));
2820 entry.setFile(pdbloaded.get(ids[p].getId()).toString());
2823 StructureSelectionManager.getStructureSelectionManager(
2824 Desktop.instance).registerPDBEntry(entry);
2825 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
2829 } // end !multipleview
2831 // ///////////////////////////////
2832 // LOAD SEQUENCE MAPPINGS
2834 if (vamsasSet.getAlcodonFrameCount() > 0)
2836 // TODO Potentially this should only be done once for all views of an
2838 AlcodonFrame[] alc = vamsasSet.getAlcodonFrame();
2839 for (int i = 0; i < alc.length; i++)
2841 AlignedCodonFrame cf = new AlignedCodonFrame();
2842 if (alc[i].getAlcodMapCount() > 0)
2844 AlcodMap[] maps = alc[i].getAlcodMap();
2845 for (int m = 0; m < maps.length; m++)
2847 SequenceI dnaseq = seqRefIds.get(maps[m].getDnasq());
2849 jalview.datamodel.Mapping mapping = null;
2850 // attach to dna sequence reference.
2851 if (maps[m].getMapping() != null)
2853 mapping = addMapping(maps[m].getMapping());
2855 if (dnaseq != null && mapping.getTo() != null)
2857 cf.addMap(dnaseq, mapping.getTo(), mapping.getMap());
2862 frefedSequence.add(new Object[] { maps[m].getDnasq(), cf,
2866 al.addCodonFrame(cf);
2871 // ////////////////////////////////
2873 List<JvAnnotRow> autoAlan = new ArrayList<JvAnnotRow>();
2876 * store any annotations which forward reference a group's ID
2878 Map<String, List<AlignmentAnnotation>> groupAnnotRefs = new Hashtable<String, List<AlignmentAnnotation>>();
2880 if (vamsasSet.getAnnotationCount() > 0)
2882 Annotation[] an = vamsasSet.getAnnotation();
2884 for (int i = 0; i < an.length; i++)
2886 Annotation annotation = an[i];
2889 * test if annotation is automatically calculated for this view only
2891 boolean autoForView = false;
2892 if (annotation.getLabel().equals("Quality")
2893 || annotation.getLabel().equals("Conservation")
2894 || annotation.getLabel().equals("Consensus"))
2896 // Kludge for pre 2.5 projects which lacked the autocalculated flag
2898 if (!annotation.hasAutoCalculated())
2900 annotation.setAutoCalculated(true);
2904 || (annotation.hasAutoCalculated() && annotation
2905 .isAutoCalculated()))
2907 // remove ID - we don't recover annotation from other views for
2908 // view-specific annotation
2909 annotation.setId(null);
2912 // set visiblity for other annotation in this view
2913 String annotationId = annotation.getId();
2914 if (annotationId != null && annotationIds.containsKey(annotationId))
2916 AlignmentAnnotation jda = annotationIds.get(annotationId);
2917 // in principle Visible should always be true for annotation displayed
2918 // in multiple views
2919 if (annotation.hasVisible())
2921 jda.visible = annotation.getVisible();
2924 al.addAnnotation(jda);
2928 // Construct new annotation from model.
2929 AnnotationElement[] ae = annotation.getAnnotationElement();
2930 jalview.datamodel.Annotation[] anot = null;
2931 java.awt.Color firstColour = null;
2933 if (!annotation.getScoreOnly())
2935 anot = new jalview.datamodel.Annotation[al.getWidth()];
2936 for (int aa = 0; aa < ae.length && aa < anot.length; aa++)
2938 anpos = ae[aa].getPosition();
2940 if (anpos >= anot.length)
2945 anot[anpos] = new jalview.datamodel.Annotation(
2947 ae[aa].getDisplayCharacter(), ae[aa].getDescription(),
2948 (ae[aa].getSecondaryStructure() == null || ae[aa]
2949 .getSecondaryStructure().length() == 0) ? ' '
2950 : ae[aa].getSecondaryStructure().charAt(0),
2954 // JBPNote: Consider verifying dataflow for IO of secondary
2955 // structure annotation read from Stockholm files
2956 // this was added to try to ensure that
2957 // if (anot[ae[aa].getPosition()].secondaryStructure>' ')
2959 // anot[ae[aa].getPosition()].displayCharacter = "";
2961 anot[anpos].colour = new java.awt.Color(ae[aa].getColour());
2962 if (firstColour == null)
2964 firstColour = anot[anpos].colour;
2968 jalview.datamodel.AlignmentAnnotation jaa = null;
2970 if (annotation.getGraph())
2972 float llim = 0, hlim = 0;
2973 // if (autoForView || an[i].isAutoCalculated()) {
2976 jaa = new jalview.datamodel.AlignmentAnnotation(
2977 annotation.getLabel(), annotation.getDescription(), anot,
2978 llim, hlim, annotation.getGraphType());
2980 jaa.graphGroup = annotation.getGraphGroup();
2981 jaa._linecolour = firstColour;
2982 if (annotation.getThresholdLine() != null)
2984 jaa.setThreshold(new jalview.datamodel.GraphLine(annotation
2985 .getThresholdLine().getValue(), annotation
2986 .getThresholdLine().getLabel(), new java.awt.Color(
2987 annotation.getThresholdLine().getColour())));
2990 if (autoForView || annotation.isAutoCalculated())
2992 // Hardwire the symbol display line to ensure that labels for
2993 // histograms are displayed
2999 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
3000 an[i].getDescription(), anot);
3001 jaa._linecolour = firstColour;
3003 // register new annotation
3004 if (an[i].getId() != null)
3006 annotationIds.put(an[i].getId(), jaa);
3007 jaa.annotationId = an[i].getId();
3009 // recover sequence association
3010 String sequenceRef = an[i].getSequenceRef();
3011 if (sequenceRef != null)
3013 // from 2.9 sequenceRef is to sequence id (JAL-1781)
3014 SequenceI sequence = seqRefIds.get(sequenceRef);
3015 if (sequence == null)
3017 // in pre-2.9 projects sequence ref is to sequence name
3018 sequence = al.findName(sequenceRef);
3020 if (sequence != null)
3022 jaa.createSequenceMapping(sequence, 1, true);
3023 sequence.addAlignmentAnnotation(jaa);
3026 // and make a note of any group association
3027 if (an[i].getGroupRef() != null && an[i].getGroupRef().length() > 0)
3029 List<jalview.datamodel.AlignmentAnnotation> aal = groupAnnotRefs
3030 .get(an[i].getGroupRef());
3033 aal = new ArrayList<jalview.datamodel.AlignmentAnnotation>();
3034 groupAnnotRefs.put(an[i].getGroupRef(), aal);
3039 if (an[i].hasScore())
3041 jaa.setScore(an[i].getScore());
3043 if (an[i].hasVisible())
3045 jaa.visible = an[i].getVisible();
3048 if (an[i].hasCentreColLabels())
3050 jaa.centreColLabels = an[i].getCentreColLabels();
3053 if (an[i].hasScaleColLabels())
3055 jaa.scaleColLabel = an[i].getScaleColLabels();
3057 if (an[i].hasAutoCalculated() && an[i].isAutoCalculated())
3059 // newer files have an 'autoCalculated' flag and store calculation
3060 // state in viewport properties
3061 jaa.autoCalculated = true; // means annotation will be marked for
3062 // update at end of load.
3064 if (an[i].hasGraphHeight())
3066 jaa.graphHeight = an[i].getGraphHeight();
3068 if (an[i].hasBelowAlignment())
3070 jaa.belowAlignment = an[i].isBelowAlignment();
3072 jaa.setCalcId(an[i].getCalcId());
3073 if (an[i].getPropertyCount() > 0)
3075 for (jalview.schemabinding.version2.Property prop : an[i]
3078 jaa.setProperty(prop.getName(), prop.getValue());
3081 if (jaa.autoCalculated)
3083 autoAlan.add(new JvAnnotRow(i, jaa));
3086 // if (!autoForView)
3088 // add autocalculated group annotation and any user created annotation
3090 al.addAnnotation(jaa);
3094 // ///////////////////////
3096 // Create alignment markup and styles for this view
3097 if (jms.getJGroupCount() > 0)
3099 JGroup[] groups = jms.getJGroup();
3100 boolean addAnnotSchemeGroup = false;
3101 for (int i = 0; i < groups.length; i++)
3103 JGroup jGroup = groups[i];
3104 ColourSchemeI cs = null;
3105 if (jGroup.getColour() != null)
3107 if (jGroup.getColour().startsWith("ucs"))
3109 cs = getUserColourScheme(jms, jGroup.getColour());
3111 else if (jGroup.getColour().equals("AnnotationColourGradient")
3112 && jGroup.getAnnotationColours() != null)
3114 addAnnotSchemeGroup = true;
3119 cs = ColourSchemeProperty.getColour(al, jGroup.getColour());
3124 cs.setThreshold(jGroup.getPidThreshold(), true);
3128 Vector<SequenceI> seqs = new Vector<SequenceI>();
3130 for (int s = 0; s < jGroup.getSeqCount(); s++)
3132 String seqId = jGroup.getSeq(s) + "";
3133 SequenceI ts = seqRefIds.get(seqId);
3137 seqs.addElement(ts);
3141 if (seqs.size() < 1)
3146 SequenceGroup sg = new SequenceGroup(seqs, jGroup.getName(), cs,
3147 jGroup.getDisplayBoxes(), jGroup.getDisplayText(),
3148 jGroup.getColourText(), jGroup.getStart(), jGroup.getEnd());
3150 sg.setOutlineColour(new java.awt.Color(jGroup.getOutlineColour()));
3152 sg.textColour = new java.awt.Color(jGroup.getTextCol1());
3153 sg.textColour2 = new java.awt.Color(jGroup.getTextCol2());
3154 sg.setShowNonconserved(jGroup.hasShowUnconserved() ? jGroup
3155 .isShowUnconserved() : false);
3156 sg.thresholdTextColour = jGroup.getTextColThreshold();
3157 if (jGroup.hasShowConsensusHistogram())
3159 sg.setShowConsensusHistogram(jGroup.isShowConsensusHistogram());
3162 if (jGroup.hasShowSequenceLogo())
3164 sg.setshowSequenceLogo(jGroup.isShowSequenceLogo());
3166 if (jGroup.hasNormaliseSequenceLogo())
3168 sg.setNormaliseSequenceLogo(jGroup.isNormaliseSequenceLogo());
3170 if (jGroup.hasIgnoreGapsinConsensus())
3172 sg.setIgnoreGapsConsensus(jGroup.getIgnoreGapsinConsensus());
3174 if (jGroup.getConsThreshold() != 0)
3176 jalview.analysis.Conservation c = new jalview.analysis.Conservation(
3177 "All", ResidueProperties.propHash, 3,
3178 sg.getSequences(null), 0, sg.getWidth() - 1);
3180 c.verdict(false, 25);
3181 sg.cs.setConservation(c);
3184 if (jGroup.getId() != null && groupAnnotRefs.size() > 0)
3186 // re-instate unique group/annotation row reference
3187 List<AlignmentAnnotation> jaal = groupAnnotRefs.get(jGroup
3191 for (AlignmentAnnotation jaa : jaal)
3194 if (jaa.autoCalculated)
3196 // match up and try to set group autocalc alignment row for this
3198 if (jaa.label.startsWith("Consensus for "))
3200 sg.setConsensus(jaa);
3202 // match up and try to set group autocalc alignment row for this
3204 if (jaa.label.startsWith("Conservation for "))
3206 sg.setConservationRow(jaa);
3213 if (addAnnotSchemeGroup)
3215 // reconstruct the annotation colourscheme
3216 sg.cs = constructAnnotationColour(jGroup.getAnnotationColours(),
3217 null, al, jms, false);
3223 // only dataset in this model, so just return.
3226 // ///////////////////////////////
3229 // If we just load in the same jar file again, the sequenceSetId
3230 // will be the same, and we end up with multiple references
3231 // to the same sequenceSet. We must modify this id on load
3232 // so that each load of the file gives a unique id
3233 String uniqueSeqSetId = view.getSequenceSetId() + uniqueSetSuffix;
3234 String viewId = (view.getId() == null ? null : view.getId()
3236 AlignFrame af = null;
3237 AlignViewport av = null;
3238 // now check to see if we really need to create a new viewport.
3239 if (multipleView && viewportsAdded.size() == 0)
3241 // We recovered an alignment for which a viewport already exists.
3242 // TODO: fix up any settings necessary for overlaying stored state onto
3243 // state recovered from another document. (may not be necessary).
3244 // we may need a binding from a viewport in memory to one recovered from
3246 // and then recover its containing af to allow the settings to be applied.
3247 // TODO: fix for vamsas demo
3249 .println("About to recover a viewport for existing alignment: Sequence set ID is "
3251 Object seqsetobj = retrieveExistingObj(uniqueSeqSetId);
3252 if (seqsetobj != null)
3254 if (seqsetobj instanceof String)
3256 uniqueSeqSetId = (String) seqsetobj;
3258 .println("Recovered extant sequence set ID mapping for ID : New Sequence set ID is "
3264 .println("Warning : Collision between sequence set ID string and existing jalview object mapping.");
3270 * indicate that annotation colours are applied across all groups (pre
3271 * Jalview 2.8.1 behaviour)
3273 boolean doGroupAnnColour = Jalview2XML.isVersionStringLaterThan(
3274 "2.8.1", object.getVersion());
3276 AlignmentPanel ap = null;
3277 boolean isnewview = true;
3280 // Check to see if this alignment already has a view id == viewId
3281 jalview.gui.AlignmentPanel views[] = Desktop
3282 .getAlignmentPanels(uniqueSeqSetId);
3283 if (views != null && views.length > 0)
3285 for (int v = 0; v < views.length; v++)
3287 if (views[v].av.getViewId().equalsIgnoreCase(viewId))
3289 // recover the existing alignpanel, alignframe, viewport
3290 af = views[v].alignFrame;
3293 // TODO: could even skip resetting view settings if we don't want to
3294 // change the local settings from other jalview processes
3303 af = loadViewport(file, jseqs, hiddenSeqs, al, jms, view,
3304 uniqueSeqSetId, viewId, autoAlan);
3310 * Load any trees, PDB structures and viewers
3312 * Not done if flag is false (when this method is used for New View)
3314 if (loadTreesAndStructures)
3316 loadTrees(jms, view, af, av, ap);
3317 loadPDBStructures(jprovider, jseqs, af, ap);
3318 loadRnaViewers(jprovider, jseqs, ap);
3320 // and finally return.
3325 * Instantiate and link any saved RNA (Varna) viewers. The state of the Varna
3326 * panel is restored from separate jar entries, two (gapped and trimmed) per
3327 * sequence and secondary structure.
3329 * Currently each viewer shows just one sequence and structure (gapped and
3330 * trimmed), however this method is designed to support multiple sequences or
3331 * structures in viewers if wanted in future.
3337 private void loadRnaViewers(jarInputStreamProvider jprovider,
3338 JSeq[] jseqs, AlignmentPanel ap)
3341 * scan the sequences for references to viewers; create each one the first
3342 * time it is referenced, add Rna models to existing viewers
3344 for (JSeq jseq : jseqs)
3346 for (int i = 0; i < jseq.getRnaViewerCount(); i++)
3348 RnaViewer viewer = jseq.getRnaViewer(i);
3349 AppVarna appVarna = findOrCreateVarnaViewer(viewer,
3350 uniqueSetSuffix, ap);
3352 for (int j = 0; j < viewer.getSecondaryStructureCount(); j++)
3354 SecondaryStructure ss = viewer.getSecondaryStructure(j);
3355 SequenceI seq = seqRefIds.get(jseq.getId());
3356 AlignmentAnnotation ann = this.annotationIds.get(ss
3357 .getAnnotationId());
3360 * add the structure to the Varna display (with session state copied
3361 * from the jar to a temporary file)
3363 boolean gapped = ss.isGapped();
3364 String rnaTitle = ss.getTitle();
3365 String sessionState = ss.getViewerState();
3366 String tempStateFile = copyJarEntry(jprovider, sessionState,
3368 RnaModel rna = new RnaModel(rnaTitle, ann, seq, null, gapped);
3369 appVarna.addModelSession(rna, rnaTitle, tempStateFile);
3371 appVarna.setInitialSelection(viewer.getSelectedRna());
3377 * Locate and return an already instantiated matching AppVarna, or create one
3381 * @param viewIdSuffix
3385 protected AppVarna findOrCreateVarnaViewer(RnaViewer viewer,
3386 String viewIdSuffix, AlignmentPanel ap)
3389 * on each load a suffix is appended to the saved viewId, to avoid conflicts
3390 * if load is repeated
3392 String postLoadId = viewer.getViewId() + viewIdSuffix;
3393 for (JInternalFrame frame : getAllFrames())
3395 if (frame instanceof AppVarna)
3397 AppVarna varna = (AppVarna) frame;
3398 if (postLoadId.equals(varna.getViewId()))
3400 // this viewer is already instantiated
3401 // could in future here add ap as another 'parent' of the
3402 // AppVarna window; currently just 1-to-many
3409 * viewer not found - make it
3411 RnaViewerModel model = new RnaViewerModel(postLoadId,
3412 viewer.getTitle(), viewer.getXpos(), viewer.getYpos(),
3413 viewer.getWidth(), viewer.getHeight(),
3414 viewer.getDividerLocation());
3415 AppVarna varna = new AppVarna(model, ap);
3421 * Load any saved trees
3429 protected void loadTrees(JalviewModelSequence jms, Viewport view,
3430 AlignFrame af, AlignViewport av, AlignmentPanel ap)
3432 // TODO result of automated refactoring - are all these parameters needed?
3435 for (int t = 0; t < jms.getTreeCount(); t++)
3438 Tree tree = jms.getTree(t);
3440 TreePanel tp = (TreePanel) retrieveExistingObj(tree.getId());
3443 tp = af.ShowNewickTree(
3444 new jalview.io.NewickFile(tree.getNewick()),
3445 tree.getTitle(), tree.getWidth(), tree.getHeight(),
3446 tree.getXpos(), tree.getYpos());
3447 if (tree.getId() != null)
3449 // perhaps bind the tree id to something ?
3454 // update local tree attributes ?
3455 // TODO: should check if tp has been manipulated by user - if so its
3456 // settings shouldn't be modified
3457 tp.setTitle(tree.getTitle());
3458 tp.setBounds(new Rectangle(tree.getXpos(), tree.getYpos(), tree
3459 .getWidth(), tree.getHeight()));
3460 tp.av = av; // af.viewport; // TODO: verify 'associate with all
3463 tp.treeCanvas.av = av; // af.viewport;
3464 tp.treeCanvas.ap = ap; // af.alignPanel;
3469 warn("There was a problem recovering stored Newick tree: \n"
3470 + tree.getNewick());
3474 tp.fitToWindow.setState(tree.getFitToWindow());
3475 tp.fitToWindow_actionPerformed(null);
3477 if (tree.getFontName() != null)
3479 tp.setTreeFont(new java.awt.Font(tree.getFontName(), tree
3480 .getFontStyle(), tree.getFontSize()));
3484 tp.setTreeFont(new java.awt.Font(view.getFontName(), view
3485 .getFontStyle(), tree.getFontSize()));
3488 tp.showPlaceholders(tree.getMarkUnlinked());
3489 tp.showBootstrap(tree.getShowBootstrap());
3490 tp.showDistances(tree.getShowDistances());
3492 tp.treeCanvas.threshold = tree.getThreshold();
3494 if (tree.getCurrentTree())
3496 af.viewport.setCurrentTree(tp.getTree());
3500 } catch (Exception ex)
3502 ex.printStackTrace();
3507 * Load and link any saved structure viewers.
3514 protected void loadPDBStructures(jarInputStreamProvider jprovider,
3515 JSeq[] jseqs, AlignFrame af, AlignmentPanel ap)
3518 * Run through all PDB ids on the alignment, and collect mappings between
3519 * distinct view ids and all sequences referring to that view.
3521 Map<String, StructureViewerModel> structureViewers = new LinkedHashMap<String, StructureViewerModel>();
3523 for (int i = 0; i < jseqs.length; i++)
3525 if (jseqs[i].getPdbidsCount() > 0)
3527 Pdbids[] ids = jseqs[i].getPdbids();
3528 for (int p = 0; p < ids.length; p++)
3530 final int structureStateCount = ids[p].getStructureStateCount();
3531 for (int s = 0; s < structureStateCount; s++)
3533 // check to see if we haven't already created this structure view
3534 final StructureState structureState = ids[p]
3535 .getStructureState(s);
3536 String sviewid = (structureState.getViewId() == null) ? null
3537 : structureState.getViewId() + uniqueSetSuffix;
3538 jalview.datamodel.PDBEntry jpdb = new jalview.datamodel.PDBEntry();
3539 // Originally : ids[p].getFile()
3540 // : TODO: verify external PDB file recovery still works in normal
3541 // jalview project load
3542 jpdb.setFile(loadPDBFile(jprovider, ids[p].getId()));
3543 jpdb.setId(ids[p].getId());
3545 int x = structureState.getXpos();
3546 int y = structureState.getYpos();
3547 int width = structureState.getWidth();
3548 int height = structureState.getHeight();
3550 // Probably don't need to do this anymore...
3551 // Desktop.desktop.getComponentAt(x, y);
3552 // TODO: NOW: check that this recovers the PDB file correctly.
3553 String pdbFile = loadPDBFile(jprovider, ids[p].getId());
3554 jalview.datamodel.SequenceI seq = seqRefIds.get(jseqs[i]
3556 if (sviewid == null)
3558 sviewid = "_jalview_pre2_4_" + x + "," + y + "," + width
3561 if (!structureViewers.containsKey(sviewid))
3563 structureViewers.put(sviewid,
3564 new StructureViewerModel(x, y, width, height, false,
3565 false, true, structureState.getViewId(),
3566 structureState.getType()));
3567 // Legacy pre-2.7 conversion JAL-823 :
3568 // do not assume any view has to be linked for colour by
3572 // assemble String[] { pdb files }, String[] { id for each
3573 // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
3574 // seqs_file 2}, boolean[] {
3575 // linkAlignPanel,superposeWithAlignpanel}} from hash
3576 StructureViewerModel jmoldat = structureViewers.get(sviewid);
3577 jmoldat.setAlignWithPanel(jmoldat.isAlignWithPanel()
3578 | (structureState.hasAlignwithAlignPanel() ? structureState
3579 .getAlignwithAlignPanel() : false));
3582 * Default colour by linked panel to false if not specified (e.g.
3583 * for pre-2.7 projects)
3585 boolean colourWithAlignPanel = jmoldat.isColourWithAlignPanel();
3586 colourWithAlignPanel |= (structureState
3587 .hasColourwithAlignPanel() ? structureState
3588 .getColourwithAlignPanel() : false);
3589 jmoldat.setColourWithAlignPanel(colourWithAlignPanel);
3592 * Default colour by viewer to true if not specified (e.g. for
3595 boolean colourByViewer = jmoldat.isColourByViewer();
3596 colourByViewer &= structureState.hasColourByJmol() ? structureState
3597 .getColourByJmol() : true;
3598 jmoldat.setColourByViewer(colourByViewer);
3600 if (jmoldat.getStateData().length() < structureState
3601 .getContent().length())
3604 jmoldat.setStateData(structureState.getContent());
3607 if (ids[p].getFile() != null)
3609 File mapkey = new File(ids[p].getFile());
3610 StructureData seqstrmaps = jmoldat.getFileData().get(mapkey);
3611 if (seqstrmaps == null)
3613 jmoldat.getFileData().put(
3615 seqstrmaps = jmoldat.new StructureData(pdbFile,
3618 if (!seqstrmaps.getSeqList().contains(seq))
3620 seqstrmaps.getSeqList().add(seq);
3626 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");
3633 // Instantiate the associated structure views
3634 for (Entry<String, StructureViewerModel> entry : structureViewers
3639 createOrLinkStructureViewer(entry, af, ap, jprovider);
3640 } catch (Exception e)
3642 System.err.println("Error loading structure viewer: "
3644 // failed - try the next one
3656 protected void createOrLinkStructureViewer(
3657 Entry<String, StructureViewerModel> viewerData, AlignFrame af,
3658 AlignmentPanel ap, jarInputStreamProvider jprovider)
3660 final StructureViewerModel stateData = viewerData.getValue();
3663 * Search for any viewer windows already open from other alignment views
3664 * that exactly match the stored structure state
3666 StructureViewerBase comp = findMatchingViewer(viewerData);
3670 linkStructureViewer(ap, comp, stateData);
3675 * From 2.9: stateData.type contains JMOL or CHIMERA, data is in jar entry
3676 * "viewer_"+stateData.viewId
3678 if (ViewerType.CHIMERA.toString().equals(stateData.getType()))
3680 createChimeraViewer(viewerData, af, jprovider);
3685 * else Jmol (if pre-2.9, stateData contains JMOL state string)
3687 createJmolViewer(viewerData, af, jprovider);
3692 * Create a new Chimera viewer.
3698 protected void createChimeraViewer(
3699 Entry<String, StructureViewerModel> viewerData, AlignFrame af,
3700 jarInputStreamProvider jprovider)
3702 StructureViewerModel data = viewerData.getValue();
3703 String chimeraSessionFile = data.getStateData();
3706 * Copy Chimera session from jar entry "viewer_"+viewId to a temporary file
3708 * NB this is the 'saved' viewId as in the project file XML, _not_ the
3709 * 'uniquified' sviewid used to reconstruct the viewer here
3711 String viewerJarEntryName = getViewerJarEntryName(data.getViewId());
3712 chimeraSessionFile = copyJarEntry(jprovider, viewerJarEntryName,
3715 Set<Entry<File, StructureData>> fileData = data.getFileData()
3717 List<PDBEntry> pdbs = new ArrayList<PDBEntry>();
3718 List<SequenceI[]> allseqs = new ArrayList<SequenceI[]>();
3719 for (Entry<File, StructureData> pdb : fileData)
3721 String filePath = pdb.getValue().getFilePath();
3722 String pdbId = pdb.getValue().getPdbId();
3723 // pdbs.add(new PDBEntry(filePath, pdbId));
3724 pdbs.add(new PDBEntry(pdbId, null, PDBEntry.Type.PDB, filePath));
3725 final List<SequenceI> seqList = pdb.getValue().getSeqList();
3726 SequenceI[] seqs = seqList.toArray(new SequenceI[seqList.size()]);
3730 boolean colourByChimera = data.isColourByViewer();
3731 boolean colourBySequence = data.isColourWithAlignPanel();
3733 // TODO use StructureViewer as a factory here, see JAL-1761
3734 final PDBEntry[] pdbArray = pdbs.toArray(new PDBEntry[pdbs.size()]);
3735 final SequenceI[][] seqsArray = allseqs.toArray(new SequenceI[allseqs
3737 String newViewId = viewerData.getKey();
3739 ChimeraViewFrame cvf = new ChimeraViewFrame(chimeraSessionFile,
3740 af.alignPanel, pdbArray, seqsArray, colourByChimera,
3741 colourBySequence, newViewId);
3742 cvf.setSize(data.getWidth(), data.getHeight());
3743 cvf.setLocation(data.getX(), data.getY());
3747 * Create a new Jmol window. First parse the Jmol state to translate filenames
3748 * loaded into the view, and record the order in which files are shown in the
3749 * Jmol view, so we can add the sequence mappings in same order.
3755 protected void createJmolViewer(
3756 final Entry<String, StructureViewerModel> viewerData,
3757 AlignFrame af, jarInputStreamProvider jprovider)
3759 final StructureViewerModel svattrib = viewerData.getValue();
3760 String state = svattrib.getStateData();
3763 * Pre-2.9: state element value is the Jmol state string
3765 * 2.9+: @type is "JMOL", state data is in a Jar file member named "viewer_"
3768 if (ViewerType.JMOL.toString().equals(svattrib.getType()))
3770 state = readJarEntry(jprovider,
3771 getViewerJarEntryName(svattrib.getViewId()));
3774 List<String> pdbfilenames = new ArrayList<String>();
3775 List<SequenceI[]> seqmaps = new ArrayList<SequenceI[]>();
3776 List<String> pdbids = new ArrayList<String>();
3777 StringBuilder newFileLoc = new StringBuilder(64);
3778 int cp = 0, ncp, ecp;
3779 Map<File, StructureData> oldFiles = svattrib.getFileData();
3780 while ((ncp = state.indexOf("load ", cp)) > -1)
3784 // look for next filename in load statement
3785 newFileLoc.append(state.substring(cp,
3786 ncp = (state.indexOf("\"", ncp + 1) + 1)));
3787 String oldfilenam = state.substring(ncp,
3788 ecp = state.indexOf("\"", ncp));
3789 // recover the new mapping data for this old filename
3790 // have to normalize filename - since Jmol and jalview do
3792 // translation differently.
3793 StructureData filedat = oldFiles.get(new File(oldfilenam));
3794 newFileLoc.append(Platform.escapeString(filedat.getFilePath()));
3795 pdbfilenames.add(filedat.getFilePath());
3796 pdbids.add(filedat.getPdbId());
3797 seqmaps.add(filedat.getSeqList().toArray(new SequenceI[0]));
3798 newFileLoc.append("\"");
3799 cp = ecp + 1; // advance beyond last \" and set cursor so we can
3800 // look for next file statement.
3801 } while ((ncp = state.indexOf("/*file*/", cp)) > -1);
3805 // just append rest of state
3806 newFileLoc.append(state.substring(cp));
3810 System.err.print("Ignoring incomplete Jmol state for PDB ids: ");
3811 newFileLoc = new StringBuilder(state);
3812 newFileLoc.append("; load append ");
3813 for (File id : oldFiles.keySet())
3815 // add this and any other pdb files that should be present in
3817 StructureData filedat = oldFiles.get(id);
3818 newFileLoc.append(filedat.getFilePath());
3819 pdbfilenames.add(filedat.getFilePath());
3820 pdbids.add(filedat.getPdbId());
3821 seqmaps.add(filedat.getSeqList().toArray(new SequenceI[0]));
3822 newFileLoc.append(" \"");
3823 newFileLoc.append(filedat.getFilePath());
3824 newFileLoc.append("\"");
3827 newFileLoc.append(";");
3830 if (newFileLoc.length() == 0)
3834 int histbug = newFileLoc.indexOf("history = ");
3838 * change "history = [true|false];" to "history = [1|0];"
3841 int diff = histbug == -1 ? -1 : newFileLoc.indexOf(";", histbug);
3842 String val = (diff == -1) ? null : newFileLoc
3843 .substring(histbug, diff);
3844 if (val != null && val.length() >= 4)
3846 if (val.contains("e")) // eh? what can it be?
3848 if (val.trim().equals("true"))
3856 newFileLoc.replace(histbug, diff, val);
3861 final String[] pdbf = pdbfilenames.toArray(new String[pdbfilenames
3863 final String[] id = pdbids.toArray(new String[pdbids.size()]);
3864 final SequenceI[][] sq = seqmaps
3865 .toArray(new SequenceI[seqmaps.size()][]);
3866 final String fileloc = newFileLoc.toString();
3867 final String sviewid = viewerData.getKey();
3868 final AlignFrame alf = af;
3869 final Rectangle rect = new Rectangle(svattrib.getX(), svattrib.getY(),
3870 svattrib.getWidth(), svattrib.getHeight());
3873 javax.swing.SwingUtilities.invokeAndWait(new Runnable()
3878 JalviewStructureDisplayI sview = null;
3881 sview = new StructureViewer(alf.alignPanel
3882 .getStructureSelectionManager()).createView(
3883 StructureViewer.ViewerType.JMOL, pdbf, id, sq,
3884 alf.alignPanel, svattrib, fileloc, rect, sviewid);
3885 addNewStructureViewer(sview);
3886 } catch (OutOfMemoryError ex)
3888 new OOMWarning("restoring structure view for PDB id " + id,
3889 (OutOfMemoryError) ex.getCause());
3890 if (sview != null && sview.isVisible())
3892 sview.closeViewer(false);
3893 sview.setVisible(false);
3899 } catch (InvocationTargetException ex)
3901 warn("Unexpected error when opening Jmol view.", ex);
3903 } catch (InterruptedException e)
3905 // e.printStackTrace();
3911 * Generates a name for the entry in the project jar file to hold state
3912 * information for a structure viewer
3917 protected String getViewerJarEntryName(String viewId)
3919 return VIEWER_PREFIX + viewId;
3923 * Returns any open frame that matches given structure viewer data. The match
3924 * is based on the unique viewId, or (for older project versions) the frame's
3930 protected StructureViewerBase findMatchingViewer(
3931 Entry<String, StructureViewerModel> viewerData)
3933 final String sviewid = viewerData.getKey();
3934 final StructureViewerModel svattrib = viewerData.getValue();
3935 StructureViewerBase comp = null;
3936 JInternalFrame[] frames = getAllFrames();
3937 for (JInternalFrame frame : frames)
3939 if (frame instanceof StructureViewerBase)
3942 * Post jalview 2.4 schema includes structure view id
3945 && ((StructureViewerBase) frame).getViewId()
3948 comp = (StructureViewerBase) frame;
3949 break; // break added in 2.9
3952 * Otherwise test for matching position and size of viewer frame
3954 else if (frame.getX() == svattrib.getX()
3955 && frame.getY() == svattrib.getY()
3956 && frame.getHeight() == svattrib.getHeight()
3957 && frame.getWidth() == svattrib.getWidth())
3959 comp = (StructureViewerBase) frame;
3960 // no break in faint hope of an exact match on viewId
3968 * Link an AlignmentPanel to an existing structure viewer.
3973 * @param useinViewerSuperpos
3974 * @param usetoColourbyseq
3975 * @param viewerColouring
3977 protected void linkStructureViewer(AlignmentPanel ap,
3978 StructureViewerBase viewer, StructureViewerModel stateData)
3980 // NOTE: if the jalview project is part of a shared session then
3981 // view synchronization should/could be done here.
3983 final boolean useinViewerSuperpos = stateData.isAlignWithPanel();
3984 final boolean usetoColourbyseq = stateData.isColourWithAlignPanel();
3985 final boolean viewerColouring = stateData.isColourByViewer();
3986 Map<File, StructureData> oldFiles = stateData.getFileData();
3989 * Add mapping for sequences in this view to an already open viewer
3991 final AAStructureBindingModel binding = viewer.getBinding();
3992 for (File id : oldFiles.keySet())
3994 // add this and any other pdb files that should be present in the
3996 StructureData filedat = oldFiles.get(id);
3997 String pdbFile = filedat.getFilePath();
3998 SequenceI[] seq = filedat.getSeqList().toArray(new SequenceI[0]);
3999 binding.getSsm().setMapping(seq, null, pdbFile,
4000 jalview.io.AppletFormatAdapter.FILE);
4001 binding.addSequenceForStructFile(pdbFile, seq);
4003 // and add the AlignmentPanel's reference to the view panel
4004 viewer.addAlignmentPanel(ap);
4005 if (useinViewerSuperpos)
4007 viewer.useAlignmentPanelForSuperposition(ap);
4011 viewer.excludeAlignmentPanelForSuperposition(ap);
4013 if (usetoColourbyseq)
4015 viewer.useAlignmentPanelForColourbyseq(ap, !viewerColouring);
4019 viewer.excludeAlignmentPanelForColourbyseq(ap);
4024 * Get all frames within the Desktop.
4028 protected JInternalFrame[] getAllFrames()
4030 JInternalFrame[] frames = null;
4031 // TODO is this necessary - is it safe - risk of hanging?
4036 frames = Desktop.desktop.getAllFrames();
4037 } catch (ArrayIndexOutOfBoundsException e)
4039 // occasional No such child exceptions are thrown here...
4043 } catch (InterruptedException f)
4047 } while (frames == null);
4052 * Answers true if 'version' is equal to or later than 'supported', where each
4053 * is formatted as major/minor versions like "2.8.3" or "2.3.4b1" for bugfix
4054 * changes. Development and test values for 'version' are leniently treated
4058 * - minimum version we are comparing against
4060 * - version of data being processsed
4063 public static boolean isVersionStringLaterThan(String supported,
4066 if (supported == null || version == null
4067 || version.equalsIgnoreCase("DEVELOPMENT BUILD")
4068 || version.equalsIgnoreCase("Test")
4069 || version.equalsIgnoreCase("AUTOMATED BUILD"))
4071 System.err.println("Assuming project file with "
4072 + (version == null ? "null" : version)
4073 + " is compatible with Jalview version " + supported);
4078 return StringUtils.compareVersions(version, supported, "b") >= 0;
4082 Vector<JalviewStructureDisplayI> newStructureViewers = null;
4084 protected void addNewStructureViewer(JalviewStructureDisplayI sview)
4086 if (newStructureViewers != null)
4088 sview.getBinding().setFinishedLoadingFromArchive(false);
4089 newStructureViewers.add(sview);
4093 protected void setLoadingFinishedForNewStructureViewers()
4095 if (newStructureViewers != null)
4097 for (JalviewStructureDisplayI sview : newStructureViewers)
4099 sview.getBinding().setFinishedLoadingFromArchive(true);
4101 newStructureViewers.clear();
4102 newStructureViewers = null;
4106 AlignFrame loadViewport(String file, JSeq[] JSEQ,
4107 List<SequenceI> hiddenSeqs, AlignmentI al,
4108 JalviewModelSequence jms, Viewport view, String uniqueSeqSetId,
4109 String viewId, List<JvAnnotRow> autoAlan)
4111 AlignFrame af = null;
4112 af = new AlignFrame(al, view.getWidth(), view.getHeight(),
4113 uniqueSeqSetId, viewId);
4115 af.setFileName(file, "Jalview");
4117 for (int i = 0; i < JSEQ.length; i++)
4119 af.viewport.setSequenceColour(af.viewport.getAlignment()
4120 .getSequenceAt(i), new java.awt.Color(JSEQ[i].getColour()));
4125 af.getViewport().setColourByReferenceSeq(true);
4126 af.getViewport().setDisplayReferenceSeq(true);
4129 af.viewport.setGatherViewsHere(view.getGatheredViews());
4131 if (view.getSequenceSetId() != null)
4133 AlignmentViewport av = viewportsAdded.get(uniqueSeqSetId);
4135 af.viewport.setSequenceSetId(uniqueSeqSetId);
4138 // propagate shared settings to this new view
4139 af.viewport.setHistoryList(av.getHistoryList());
4140 af.viewport.setRedoList(av.getRedoList());
4144 viewportsAdded.put(uniqueSeqSetId, af.viewport);
4146 // TODO: check if this method can be called repeatedly without
4147 // side-effects if alignpanel already registered.
4148 PaintRefresher.Register(af.alignPanel, uniqueSeqSetId);
4150 // apply Hidden regions to view.
4151 if (hiddenSeqs != null)
4153 for (int s = 0; s < JSEQ.length; s++)
4155 SequenceGroup hidden = new SequenceGroup();
4156 boolean isRepresentative = false;
4157 for (int r = 0; r < JSEQ[s].getHiddenSequencesCount(); r++)
4159 isRepresentative = true;
4160 SequenceI sequenceToHide = al.getSequenceAt(JSEQ[s]
4161 .getHiddenSequences(r));
4162 hidden.addSequence(sequenceToHide, false);
4163 // remove from hiddenSeqs list so we don't try to hide it twice
4164 hiddenSeqs.remove(sequenceToHide);
4166 if (isRepresentative)
4168 SequenceI representativeSequence = al.getSequenceAt(s);
4169 hidden.addSequence(representativeSequence, false);
4170 af.viewport.hideRepSequences(representativeSequence, hidden);
4174 SequenceI[] hseqs = hiddenSeqs.toArray(new SequenceI[hiddenSeqs
4176 af.viewport.hideSequence(hseqs);
4179 // recover view properties and display parameters
4180 if (view.getViewName() != null)
4182 af.viewport.viewName = view.getViewName();
4183 af.setInitialTabVisible();
4185 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
4188 af.viewport.setShowAnnotation(view.getShowAnnotation());
4189 af.viewport.setAbovePIDThreshold(view.getPidSelected());
4191 af.viewport.setColourText(view.getShowColourText());
4193 af.viewport.setConservationSelected(view.getConservationSelected());
4194 af.viewport.setShowJVSuffix(view.getShowFullId());
4195 af.viewport.setRightAlignIds(view.getRightAlignIds());
4196 af.viewport.setFont(
4197 new java.awt.Font(view.getFontName(), view.getFontStyle(), view
4198 .getFontSize()), true);
4199 ViewStyleI vs = af.viewport.getViewStyle();
4200 vs.setScaleProteinAsCdna(view.isScaleProteinAsCdna());
4201 af.viewport.setViewStyle(vs);
4202 // TODO: allow custom charWidth/Heights to be restored by updating them
4203 // after setting font - which means set above to false
4204 af.viewport.setRenderGaps(view.getRenderGaps());
4205 af.viewport.setWrapAlignment(view.getWrapAlignment());
4206 af.viewport.setShowAnnotation(view.getShowAnnotation());
4208 af.viewport.setShowBoxes(view.getShowBoxes());
4210 af.viewport.setShowText(view.getShowText());
4212 af.viewport.setTextColour(new java.awt.Color(view.getTextCol1()));
4213 af.viewport.setTextColour2(new java.awt.Color(view.getTextCol2()));
4214 af.viewport.setThresholdTextColour(view.getTextColThreshold());
4215 af.viewport.setShowUnconserved(view.hasShowUnconserved() ? view
4216 .isShowUnconserved() : false);
4217 af.viewport.setStartRes(view.getStartRes());
4218 af.viewport.setStartSeq(view.getStartSeq());
4219 af.alignPanel.updateLayout();
4220 ColourSchemeI cs = null;
4221 // apply colourschemes
4222 if (view.getBgColour() != null)
4224 if (view.getBgColour().startsWith("ucs"))
4226 cs = getUserColourScheme(jms, view.getBgColour());
4228 else if (view.getBgColour().startsWith("Annotation"))
4230 AnnotationColours viewAnnColour = view.getAnnotationColours();
4231 cs = constructAnnotationColour(viewAnnColour, af, al, jms, true);
4238 cs = ColourSchemeProperty.getColour(al, view.getBgColour());
4243 cs.setThreshold(view.getPidThreshold(), true);
4244 cs.setConsensus(af.viewport.getSequenceConsensusHash());
4248 af.viewport.setGlobalColourScheme(cs);
4249 af.viewport.setColourAppliesToAllGroups(false);
4251 if (view.getConservationSelected() && cs != null)
4253 cs.setConservationInc(view.getConsThreshold());
4256 af.changeColour(cs);
4258 af.viewport.setColourAppliesToAllGroups(true);
4260 af.viewport.setShowSequenceFeatures(view.getShowSequenceFeatures());
4262 if (view.hasCentreColumnLabels())
4264 af.viewport.setCentreColumnLabels(view.getCentreColumnLabels());
4266 if (view.hasIgnoreGapsinConsensus())
4268 af.viewport.setIgnoreGapsConsensus(view.getIgnoreGapsinConsensus(),
4271 if (view.hasFollowHighlight())
4273 af.viewport.setFollowHighlight(view.getFollowHighlight());
4275 if (view.hasFollowSelection())
4277 af.viewport.followSelection = view.getFollowSelection();
4279 if (view.hasShowConsensusHistogram())
4281 af.viewport.setShowConsensusHistogram(view
4282 .getShowConsensusHistogram());
4286 af.viewport.setShowConsensusHistogram(true);
4288 if (view.hasShowSequenceLogo())
4290 af.viewport.setShowSequenceLogo(view.getShowSequenceLogo());
4294 af.viewport.setShowSequenceLogo(false);
4296 if (view.hasNormaliseSequenceLogo())
4298 af.viewport.setNormaliseSequenceLogo(view.getNormaliseSequenceLogo());
4300 if (view.hasShowDbRefTooltip())
4302 af.viewport.setShowDBRefs(view.getShowDbRefTooltip());
4304 if (view.hasShowNPfeatureTooltip())
4306 af.viewport.setShowNPFeats(view.hasShowNPfeatureTooltip());
4308 if (view.hasShowGroupConsensus())
4310 af.viewport.setShowGroupConsensus(view.getShowGroupConsensus());
4314 af.viewport.setShowGroupConsensus(false);
4316 if (view.hasShowGroupConservation())
4318 af.viewport.setShowGroupConservation(view.getShowGroupConservation());
4322 af.viewport.setShowGroupConservation(false);
4325 // recover featre settings
4326 if (jms.getFeatureSettings() != null)
4328 FeaturesDisplayed fdi;
4329 af.viewport.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
4330 String[] renderOrder = new String[jms.getFeatureSettings()
4331 .getSettingCount()];
4332 Map<String, FeatureColourI> featureColours = new Hashtable<String, FeatureColourI>();
4333 Map<String, Float> featureOrder = new Hashtable<String, Float>();
4335 for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++)
4337 Setting setting = jms.getFeatureSettings().getSetting(fs);
4338 if (setting.hasMincolour())
4340 FeatureColourI gc = setting.hasMin() ? new FeatureColour(
4341 new Color(setting.getMincolour()), new Color(
4342 setting.getColour()), setting.getMin(),
4343 setting.getMax()) : new FeatureColour(new Color(
4344 setting.getMincolour()), new Color(setting.getColour()),
4346 if (setting.hasThreshold())
4348 gc.setThreshold(setting.getThreshold());
4349 int threshstate = setting.getThreshstate();
4350 // -1 = None, 0 = Below, 1 = Above threshold
4351 if (threshstate == 0)
4353 gc.setBelowThreshold(true);
4355 else if (threshstate == 1)
4357 gc.setAboveThreshold(true);
4360 gc.setAutoScaled(true); // default
4361 if (setting.hasAutoScale())
4363 gc.setAutoScaled(setting.getAutoScale());
4365 if (setting.hasColourByLabel())
4367 gc.setColourByLabel(setting.getColourByLabel());
4369 // and put in the feature colour table.
4370 featureColours.put(setting.getType(), gc);
4374 featureColours.put(setting.getType(), new FeatureColour(
4375 new Color(setting.getColour())));
4377 renderOrder[fs] = setting.getType();
4378 if (setting.hasOrder())
4380 featureOrder.put(setting.getType(), setting.getOrder());
4384 featureOrder.put(setting.getType(), new Float(fs
4385 / jms.getFeatureSettings().getSettingCount()));
4387 if (setting.getDisplay())
4389 fdi.setVisible(setting.getType());
4392 Map<String, Boolean> fgtable = new Hashtable<String, Boolean>();
4393 for (int gs = 0; gs < jms.getFeatureSettings().getGroupCount(); gs++)
4395 Group grp = jms.getFeatureSettings().getGroup(gs);
4396 fgtable.put(grp.getName(), new Boolean(grp.getDisplay()));
4398 // FeatureRendererSettings frs = new FeatureRendererSettings(renderOrder,
4399 // fgtable, featureColours, jms.getFeatureSettings().hasTransparency() ?
4400 // jms.getFeatureSettings().getTransparency() : 0.0, featureOrder);
4401 FeatureRendererSettings frs = new FeatureRendererSettings(
4402 renderOrder, fgtable, featureColours, 1.0f, featureOrder);
4403 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
4404 .transferSettings(frs);
4408 if (view.getHiddenColumnsCount() > 0)
4410 for (int c = 0; c < view.getHiddenColumnsCount(); c++)
4412 af.viewport.hideColumns(view.getHiddenColumns(c).getStart(), view
4413 .getHiddenColumns(c).getEnd() // +1
4417 if (view.getCalcIdParam() != null)
4419 for (CalcIdParam calcIdParam : view.getCalcIdParam())
4421 if (calcIdParam != null)
4423 if (recoverCalcIdParam(calcIdParam, af.viewport))
4428 warn("Couldn't recover parameters for "
4429 + calcIdParam.getCalcId());
4434 af.setMenusFromViewport(af.viewport);
4436 // TODO: we don't need to do this if the viewport is aready visible.
4438 * Add the AlignFrame to the desktop (it may be 'gathered' later), unless it
4439 * has a 'cdna/protein complement' view, in which case save it in order to
4440 * populate a SplitFrame once all views have been read in.
4442 String complementaryViewId = view.getComplementId();
4443 if (complementaryViewId == null)
4445 Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
4447 // recompute any autoannotation
4448 af.alignPanel.updateAnnotation(false, true);
4449 reorderAutoannotation(af, al, autoAlan);
4450 af.alignPanel.alignmentChanged();
4454 splitFrameCandidates.put(view, af);
4459 private ColourSchemeI constructAnnotationColour(
4460 AnnotationColours viewAnnColour, AlignFrame af, AlignmentI al,
4461 JalviewModelSequence jms, boolean checkGroupAnnColour)
4463 boolean propagateAnnColour = false;
4464 ColourSchemeI cs = null;
4465 AlignmentI annAlignment = af != null ? af.viewport.getAlignment() : al;
4466 if (checkGroupAnnColour && al.getGroups() != null
4467 && al.getGroups().size() > 0)
4469 // pre 2.8.1 behaviour
4470 // check to see if we should transfer annotation colours
4471 propagateAnnColour = true;
4472 for (jalview.datamodel.SequenceGroup sg : al.getGroups())
4474 if (sg.cs instanceof AnnotationColourGradient)
4476 propagateAnnColour = false;
4480 // int find annotation
4481 if (annAlignment.getAlignmentAnnotation() != null)
4483 for (int i = 0; i < annAlignment.getAlignmentAnnotation().length; i++)
4485 if (annAlignment.getAlignmentAnnotation()[i].label
4486 .equals(viewAnnColour.getAnnotation()))
4488 if (annAlignment.getAlignmentAnnotation()[i].getThreshold() == null)
4490 annAlignment.getAlignmentAnnotation()[i]
4491 .setThreshold(new jalview.datamodel.GraphLine(
4492 viewAnnColour.getThreshold(), "Threshold",
4493 java.awt.Color.black)
4498 if (viewAnnColour.getColourScheme().equals("None"))
4500 cs = new AnnotationColourGradient(
4501 annAlignment.getAlignmentAnnotation()[i],
4502 new java.awt.Color(viewAnnColour.getMinColour()),
4503 new java.awt.Color(viewAnnColour.getMaxColour()),
4504 viewAnnColour.getAboveThreshold());
4506 else if (viewAnnColour.getColourScheme().startsWith("ucs"))
4508 cs = new AnnotationColourGradient(
4509 annAlignment.getAlignmentAnnotation()[i],
4510 getUserColourScheme(jms,
4511 viewAnnColour.getColourScheme()),
4512 viewAnnColour.getAboveThreshold());
4516 cs = new AnnotationColourGradient(
4517 annAlignment.getAlignmentAnnotation()[i],
4518 ColourSchemeProperty.getColour(al,
4519 viewAnnColour.getColourScheme()),
4520 viewAnnColour.getAboveThreshold());
4522 if (viewAnnColour.hasPerSequence())
4524 ((AnnotationColourGradient) cs).setSeqAssociated(viewAnnColour
4527 if (viewAnnColour.hasPredefinedColours())
4529 ((AnnotationColourGradient) cs)
4530 .setPredefinedColours(viewAnnColour
4531 .isPredefinedColours());
4533 if (propagateAnnColour && al.getGroups() != null)
4535 // Also use these settings for all the groups
4536 for (int g = 0; g < al.getGroups().size(); g++)
4538 jalview.datamodel.SequenceGroup sg = al.getGroups().get(g);
4546 * if (viewAnnColour.getColourScheme().equals("None" )) { sg.cs =
4547 * new AnnotationColourGradient(
4548 * annAlignment.getAlignmentAnnotation()[i], new
4549 * java.awt.Color(viewAnnColour. getMinColour()), new
4550 * java.awt.Color(viewAnnColour. getMaxColour()),
4551 * viewAnnColour.getAboveThreshold()); } else
4554 sg.cs = new AnnotationColourGradient(
4555 annAlignment.getAlignmentAnnotation()[i], sg.cs,
4556 viewAnnColour.getAboveThreshold());
4557 if (cs instanceof AnnotationColourGradient)
4559 if (viewAnnColour.hasPerSequence())
4561 ((AnnotationColourGradient) cs)
4562 .setSeqAssociated(viewAnnColour.isPerSequence());
4564 if (viewAnnColour.hasPredefinedColours())
4566 ((AnnotationColourGradient) cs)
4567 .setPredefinedColours(viewAnnColour
4568 .isPredefinedColours());
4584 private void reorderAutoannotation(AlignFrame af, AlignmentI al,
4585 List<JvAnnotRow> autoAlan)
4587 // copy over visualization settings for autocalculated annotation in the
4589 if (al.getAlignmentAnnotation() != null)
4592 * Kludge for magic autoannotation names (see JAL-811)
4594 String[] magicNames = new String[] { "Consensus", "Quality",
4596 JvAnnotRow nullAnnot = new JvAnnotRow(-1, null);
4597 Hashtable<String, JvAnnotRow> visan = new Hashtable<String, JvAnnotRow>();
4598 for (String nm : magicNames)
4600 visan.put(nm, nullAnnot);
4602 for (JvAnnotRow auan : autoAlan)
4604 visan.put(auan.template.label
4605 + (auan.template.getCalcId() == null ? "" : "\t"
4606 + auan.template.getCalcId()), auan);
4608 int hSize = al.getAlignmentAnnotation().length;
4609 List<JvAnnotRow> reorder = new ArrayList<JvAnnotRow>();
4610 // work through any autoCalculated annotation already on the view
4611 // removing it if it should be placed in a different location on the
4612 // annotation panel.
4613 List<String> remains = new ArrayList<String>(visan.keySet());
4614 for (int h = 0; h < hSize; h++)
4616 jalview.datamodel.AlignmentAnnotation jalan = al
4617 .getAlignmentAnnotation()[h];
4618 if (jalan.autoCalculated)
4621 JvAnnotRow valan = visan.get(k = jalan.label);
4622 if (jalan.getCalcId() != null)
4624 valan = visan.get(k = jalan.label + "\t" + jalan.getCalcId());
4629 // delete the auto calculated row from the alignment
4630 al.deleteAnnotation(jalan, false);
4634 if (valan != nullAnnot)
4636 if (jalan != valan.template)
4638 // newly created autoannotation row instance
4639 // so keep a reference to the visible annotation row
4640 // and copy over all relevant attributes
4641 if (valan.template.graphHeight >= 0)
4644 jalan.graphHeight = valan.template.graphHeight;
4646 jalan.visible = valan.template.visible;
4648 reorder.add(new JvAnnotRow(valan.order, jalan));
4653 // Add any (possibly stale) autocalculated rows that were not appended to
4654 // the view during construction
4655 for (String other : remains)
4657 JvAnnotRow othera = visan.get(other);
4658 if (othera != nullAnnot && othera.template.getCalcId() != null
4659 && othera.template.getCalcId().length() > 0)
4661 reorder.add(othera);
4664 // now put the automatic annotation in its correct place
4665 int s = 0, srt[] = new int[reorder.size()];
4666 JvAnnotRow[] rws = new JvAnnotRow[reorder.size()];
4667 for (JvAnnotRow jvar : reorder)
4670 srt[s++] = jvar.order;
4673 jalview.util.QuickSort.sort(srt, rws);
4674 // and re-insert the annotation at its correct position
4675 for (JvAnnotRow jvar : rws)
4677 al.addAnnotation(jvar.template, jvar.order);
4679 af.alignPanel.adjustAnnotationHeight();
4683 Hashtable skipList = null;
4686 * TODO remove this method
4689 * @return AlignFrame bound to sequenceSetId from view, if one exists. private
4690 * AlignFrame getSkippedFrame(Viewport view) { if (skipList==null) {
4691 * throw new Error("Implementation Error. No skipList defined for this
4692 * Jalview2XML instance."); } return (AlignFrame)
4693 * skipList.get(view.getSequenceSetId()); }
4697 * Check if the Jalview view contained in object should be skipped or not.
4700 * @return true if view's sequenceSetId is a key in skipList
4702 private boolean skipViewport(JalviewModel object)
4704 if (skipList == null)
4709 if (skipList.containsKey(id = object.getJalviewModelSequence()
4710 .getViewport()[0].getSequenceSetId()))
4712 if (Cache.log != null && Cache.log.isDebugEnabled())
4714 Cache.log.debug("Skipping seuqence set id " + id);
4721 public void addToSkipList(AlignFrame af)
4723 if (skipList == null)
4725 skipList = new Hashtable();
4727 skipList.put(af.getViewport().getSequenceSetId(), af);
4730 public void clearSkipList()
4732 if (skipList != null)
4739 private void recoverDatasetFor(SequenceSet vamsasSet, AlignmentI al,
4740 boolean ignoreUnrefed)
4742 jalview.datamodel.AlignmentI ds = getDatasetFor(vamsasSet
4744 Vector dseqs = null;
4747 // create a list of new dataset sequences
4748 dseqs = new Vector();
4750 for (int i = 0, iSize = vamsasSet.getSequenceCount(); i < iSize; i++)
4752 Sequence vamsasSeq = vamsasSet.getSequence(i);
4753 ensureJalviewDatasetSequence(vamsasSeq, ds, dseqs, ignoreUnrefed);
4755 // create a new dataset
4758 SequenceI[] dsseqs = new SequenceI[dseqs.size()];
4759 dseqs.copyInto(dsseqs);
4760 ds = new jalview.datamodel.Alignment(dsseqs);
4761 debug("Created new dataset " + vamsasSet.getDatasetId()
4762 + " for alignment " + System.identityHashCode(al));
4763 addDatasetRef(vamsasSet.getDatasetId(), ds);
4765 // set the dataset for the newly imported alignment.
4766 if (al.getDataset() == null && !ignoreUnrefed)
4775 * sequence definition to create/merge dataset sequence for
4779 * vector to add new dataset sequence to
4781 private void ensureJalviewDatasetSequence(Sequence vamsasSeq,
4782 AlignmentI ds, Vector dseqs, boolean ignoreUnrefed)
4784 // JBP TODO: Check this is called for AlCodonFrames to support recovery of
4786 SequenceI sq = seqRefIds.get(vamsasSeq.getId());
4787 SequenceI dsq = null;
4788 if (sq != null && sq.getDatasetSequence() != null)
4790 dsq = sq.getDatasetSequence();
4792 if (sq == null && ignoreUnrefed)
4796 String sqid = vamsasSeq.getDsseqid();
4799 // need to create or add a new dataset sequence reference to this sequence
4802 dsq = seqRefIds.get(sqid);
4807 // make a new dataset sequence
4808 dsq = sq.createDatasetSequence();
4811 // make up a new dataset reference for this sequence
4812 sqid = seqHash(dsq);
4814 dsq.setVamsasId(uniqueSetSuffix + sqid);
4815 seqRefIds.put(sqid, dsq);
4820 dseqs.addElement(dsq);
4825 ds.addSequence(dsq);
4831 { // make this dataset sequence sq's dataset sequence
4832 sq.setDatasetSequence(dsq);
4833 // and update the current dataset alignment
4838 if (!dseqs.contains(dsq))
4845 if (ds.findIndex(dsq) < 0)
4847 ds.addSequence(dsq);
4854 // TODO: refactor this as a merge dataset sequence function
4855 // now check that sq (the dataset sequence) sequence really is the union of
4856 // all references to it
4857 // boolean pre = sq.getStart() < dsq.getStart();
4858 // boolean post = sq.getEnd() > dsq.getEnd();
4862 // StringBuffer sb = new StringBuffer();
4863 String newres = jalview.analysis.AlignSeq.extractGaps(
4864 jalview.util.Comparison.GapChars, sq.getSequenceAsString());
4865 if (!newres.equalsIgnoreCase(dsq.getSequenceAsString())
4866 && newres.length() > dsq.getLength())
4868 // Update with the longer sequence.
4872 * if (pre) { sb.insert(0, newres .substring(0, dsq.getStart() -
4873 * sq.getStart())); dsq.setStart(sq.getStart()); } if (post) {
4874 * sb.append(newres.substring(newres.length() - sq.getEnd() -
4875 * dsq.getEnd())); dsq.setEnd(sq.getEnd()); }
4877 dsq.setSequence(newres);
4879 // TODO: merges will never happen if we 'know' we have the real dataset
4880 // sequence - this should be detected when id==dssid
4882 .println("DEBUG Notice: Merged dataset sequence (if you see this often, post at http://issues.jalview.org/browse/JAL-1474)"); // ("
4883 // + (pre ? "prepended" : "") + " "
4884 // + (post ? "appended" : ""));
4890 * TODO use AlignmentI here and in related methods - needs
4891 * AlignmentI.getDataset() changed to return AlignmentI instead of Alignment
4893 Hashtable<String, AlignmentI> datasetIds = null;
4895 IdentityHashMap<AlignmentI, String> dataset2Ids = null;
4897 private AlignmentI getDatasetFor(String datasetId)
4899 if (datasetIds == null)
4901 datasetIds = new Hashtable<String, AlignmentI>();
4904 if (datasetIds.containsKey(datasetId))
4906 return datasetIds.get(datasetId);
4911 private void addDatasetRef(String datasetId, AlignmentI dataset)
4913 if (datasetIds == null)
4915 datasetIds = new Hashtable<String, AlignmentI>();
4917 datasetIds.put(datasetId, dataset);
4921 * make a new dataset ID for this jalview dataset alignment
4926 private String getDatasetIdRef(AlignmentI dataset)
4928 if (dataset.getDataset() != null)
4930 warn("Serious issue! Dataset Object passed to getDatasetIdRef is not a Jalview DATASET alignment...");
4932 String datasetId = makeHashCode(dataset, null);
4933 if (datasetId == null)
4935 // make a new datasetId and record it
4936 if (dataset2Ids == null)
4938 dataset2Ids = new IdentityHashMap<AlignmentI, String>();
4942 datasetId = dataset2Ids.get(dataset);
4944 if (datasetId == null)
4946 datasetId = "ds" + dataset2Ids.size() + 1;
4947 dataset2Ids.put(dataset, datasetId);
4953 private void addDBRefs(SequenceI datasetSequence, Sequence sequence)
4955 for (int d = 0; d < sequence.getDBRefCount(); d++)
4957 DBRef dr = sequence.getDBRef(d);
4958 jalview.datamodel.DBRefEntry entry = new jalview.datamodel.DBRefEntry(
4959 sequence.getDBRef(d).getSource(), sequence.getDBRef(d)
4960 .getVersion(), sequence.getDBRef(d).getAccessionId());
4961 if (dr.getMapping() != null)
4963 entry.setMap(addMapping(dr.getMapping()));
4965 datasetSequence.addDBRef(entry);
4969 private jalview.datamodel.Mapping addMapping(Mapping m)
4971 SequenceI dsto = null;
4972 // Mapping m = dr.getMapping();
4973 int fr[] = new int[m.getMapListFromCount() * 2];
4974 Enumeration f = m.enumerateMapListFrom();
4975 for (int _i = 0; f.hasMoreElements(); _i += 2)
4977 MapListFrom mf = (MapListFrom) f.nextElement();
4978 fr[_i] = mf.getStart();
4979 fr[_i + 1] = mf.getEnd();
4981 int fto[] = new int[m.getMapListToCount() * 2];
4982 f = m.enumerateMapListTo();
4983 for (int _i = 0; f.hasMoreElements(); _i += 2)
4985 MapListTo mf = (MapListTo) f.nextElement();
4986 fto[_i] = mf.getStart();
4987 fto[_i + 1] = mf.getEnd();
4989 jalview.datamodel.Mapping jmap = new jalview.datamodel.Mapping(dsto,
4990 fr, fto, (int) m.getMapFromUnit(), (int) m.getMapToUnit());
4991 if (m.getMappingChoice() != null)
4993 MappingChoice mc = m.getMappingChoice();
4994 if (mc.getDseqFor() != null)
4996 String dsfor = "" + mc.getDseqFor();
4997 if (seqRefIds.containsKey(dsfor))
5002 jmap.setTo(seqRefIds.get(dsfor));
5006 frefedSequence.add(new Object[] { dsfor, jmap });
5012 * local sequence definition
5014 Sequence ms = mc.getSequence();
5015 SequenceI djs = null;
5016 String sqid = ms.getDsseqid();
5017 if (sqid != null && sqid.length() > 0)
5020 * recover dataset sequence
5022 djs = seqRefIds.get(sqid);
5027 .println("Warning - making up dataset sequence id for DbRef sequence map reference");
5028 sqid = ((Object) ms).toString(); // make up a new hascode for
5029 // undefined dataset sequence hash
5030 // (unlikely to happen)
5036 * make a new dataset sequence and add it to refIds hash
5038 djs = new jalview.datamodel.Sequence(ms.getName(),
5040 djs.setStart(jmap.getMap().getToLowest());
5041 djs.setEnd(jmap.getMap().getToHighest());
5042 djs.setVamsasId(uniqueSetSuffix + sqid);
5044 seqRefIds.put(sqid, djs);
5047 jalview.bin.Cache.log.debug("about to recurse on addDBRefs.");
5056 public jalview.gui.AlignmentPanel copyAlignPanel(AlignmentPanel ap,
5057 boolean keepSeqRefs)
5060 JalviewModel jm = saveState(ap, null, null, null);
5065 jm.getJalviewModelSequence().getViewport(0).setSequenceSetId(null);
5069 uniqueSetSuffix = "";
5070 jm.getJalviewModelSequence().getViewport(0).setId(null); // we don't
5075 if (this.frefedSequence == null)
5077 frefedSequence = new Vector();
5080 viewportsAdded.clear();
5082 AlignFrame af = loadFromObject(jm, null, false, null);
5083 af.alignPanels.clear();
5084 af.closeMenuItem_actionPerformed(true);
5087 * if(ap.av.getAlignment().getAlignmentAnnotation()!=null) { for(int i=0;
5088 * i<ap.av.getAlignment().getAlignmentAnnotation().length; i++) {
5089 * if(!ap.av.getAlignment().getAlignmentAnnotation()[i].autoCalculated) {
5090 * af.alignPanel.av.getAlignment().getAlignmentAnnotation()[i] =
5091 * ap.av.getAlignment().getAlignmentAnnotation()[i]; } } }
5094 return af.alignPanel;
5098 * flag indicating if hashtables should be cleared on finalization TODO this
5099 * flag may not be necessary
5101 private final boolean _cleartables = true;
5103 private Hashtable jvids2vobj;
5108 * @see java.lang.Object#finalize()
5111 protected void finalize() throws Throwable
5113 // really make sure we have no buried refs left.
5118 this.seqRefIds = null;
5119 this.seqsToIds = null;
5123 private void warn(String msg)
5128 private void warn(String msg, Exception e)
5130 if (Cache.log != null)
5134 Cache.log.warn(msg, e);
5138 Cache.log.warn(msg);
5143 System.err.println("Warning: " + msg);
5146 e.printStackTrace();
5151 private void debug(String string)
5153 debug(string, null);
5156 private void debug(String msg, Exception e)
5158 if (Cache.log != null)
5162 Cache.log.debug(msg, e);
5166 Cache.log.debug(msg);
5171 System.err.println("Warning: " + msg);
5174 e.printStackTrace();
5180 * set the object to ID mapping tables used to write/recover objects and XML
5181 * ID strings for the jalview project. If external tables are provided then
5182 * finalize and clearSeqRefs will not clear the tables when the Jalview2XML
5183 * object goes out of scope. - also populates the datasetIds hashtable with
5184 * alignment objects containing dataset sequences
5187 * Map from ID strings to jalview datamodel
5189 * Map from jalview datamodel to ID strings
5193 public void setObjectMappingTables(Hashtable vobj2jv,
5194 IdentityHashMap jv2vobj)
5196 this.jv2vobj = jv2vobj;
5197 this.vobj2jv = vobj2jv;
5198 Iterator ds = jv2vobj.keySet().iterator();
5200 while (ds.hasNext())
5202 Object jvobj = ds.next();
5203 id = jv2vobj.get(jvobj).toString();
5204 if (jvobj instanceof jalview.datamodel.Alignment)
5206 if (((jalview.datamodel.Alignment) jvobj).getDataset() == null)
5208 addDatasetRef(id, (jalview.datamodel.Alignment) jvobj);
5211 else if (jvobj instanceof jalview.datamodel.Sequence)
5213 // register sequence object so the XML parser can recover it.
5214 if (seqRefIds == null)
5216 seqRefIds = new HashMap<String, SequenceI>();
5218 if (seqsToIds == null)
5220 seqsToIds = new IdentityHashMap<SequenceI, String>();
5222 seqRefIds.put(jv2vobj.get(jvobj).toString(), (SequenceI) jvobj);
5223 seqsToIds.put((SequenceI) jvobj, id);
5225 else if (jvobj instanceof jalview.datamodel.AlignmentAnnotation)
5228 AlignmentAnnotation jvann = (AlignmentAnnotation) jvobj;
5229 annotationIds.put(anid = jv2vobj.get(jvobj).toString(), jvann);
5230 if (jvann.annotationId == null)
5232 jvann.annotationId = anid;
5234 if (!jvann.annotationId.equals(anid))
5236 // TODO verify that this is the correct behaviour
5237 this.warn("Overriding Annotation ID for " + anid
5238 + " from different id : " + jvann.annotationId);
5239 jvann.annotationId = anid;
5242 else if (jvobj instanceof String)
5244 if (jvids2vobj == null)
5246 jvids2vobj = new Hashtable();
5247 jvids2vobj.put(jvobj, jv2vobj.get(jvobj).toString());
5252 Cache.log.debug("Ignoring " + jvobj.getClass() + " (ID = " + id);
5258 * set the uniqueSetSuffix used to prefix/suffix object IDs for jalview
5259 * objects created from the project archive. If string is null (default for
5260 * construction) then suffix will be set automatically.
5264 public void setUniqueSetSuffix(String string)
5266 uniqueSetSuffix = string;
5271 * uses skipList2 as the skipList for skipping views on sequence sets
5272 * associated with keys in the skipList
5276 public void setSkipList(Hashtable skipList2)
5278 skipList = skipList2;
5282 * Reads the jar entry of given name and returns its contents, or null if the
5283 * entry is not found.
5286 * @param jarEntryName
5289 protected String readJarEntry(jarInputStreamProvider jprovider,
5290 String jarEntryName)
5292 String result = null;
5293 BufferedReader in = null;
5298 * Reopen the jar input stream and traverse its entries to find a matching
5301 JarInputStream jin = jprovider.getJarInputStream();
5302 JarEntry entry = null;
5305 entry = jin.getNextJarEntry();
5306 } while (entry != null && !entry.getName().equals(jarEntryName));
5310 StringBuilder out = new StringBuilder(256);
5311 in = new BufferedReader(new InputStreamReader(jin, UTF_8));
5314 while ((data = in.readLine()) != null)
5318 result = out.toString();
5322 warn("Couldn't find entry in Jalview Jar for " + jarEntryName);
5324 } catch (Exception ex)
5326 ex.printStackTrace();
5334 } catch (IOException e)
5345 * Returns an incrementing counter (0, 1, 2...)
5349 private synchronized int nextCounter()