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.
21 package jalview.project;
23 import jalview.analysis.Conservation;
24 import jalview.api.FeatureColourI;
25 import jalview.api.ViewStyleI;
26 import jalview.api.structures.JalviewStructureDisplayI;
27 import jalview.bin.Cache;
28 import jalview.datamodel.AlignedCodonFrame;
29 import jalview.datamodel.Alignment;
30 import jalview.datamodel.AlignmentAnnotation;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.GraphLine;
33 import jalview.datamodel.PDBEntry;
34 import jalview.datamodel.RnaViewerModel;
35 import jalview.datamodel.SequenceFeature;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.datamodel.SequenceI;
38 import jalview.datamodel.StructureViewerModel;
39 import jalview.datamodel.StructureViewerModel.StructureData;
40 import jalview.datamodel.features.FeatureMatcher;
41 import jalview.datamodel.features.FeatureMatcherI;
42 import jalview.datamodel.features.FeatureMatcherSet;
43 import jalview.datamodel.features.FeatureMatcherSetI;
44 import jalview.ext.varna.RnaModel;
45 import jalview.gui.AlignFrame;
46 import jalview.gui.AlignViewport;
47 import jalview.gui.AlignmentPanel;
48 import jalview.gui.AppVarna;
49 import jalview.gui.ChimeraViewFrame;
50 import jalview.gui.Desktop;
51 import jalview.gui.FeatureRenderer;
52 import jalview.gui.Jalview2XML_V1;
53 import jalview.gui.JvOptionPane;
54 import jalview.gui.OOMWarning;
55 import jalview.gui.PaintRefresher;
56 import jalview.gui.SplitFrame;
57 import jalview.gui.StructureViewer;
58 import jalview.gui.StructureViewer.ViewerType;
59 import jalview.gui.StructureViewerBase;
60 import jalview.gui.TreePanel;
61 import jalview.io.DataSourceType;
62 import jalview.io.FileFormat;
63 import jalview.io.NewickFile;
64 import jalview.renderer.ResidueShaderI;
65 import jalview.schemes.AnnotationColourGradient;
66 import jalview.schemes.ColourSchemeI;
67 import jalview.schemes.ColourSchemeProperty;
68 import jalview.schemes.FeatureColour;
69 import jalview.schemes.ResidueProperties;
70 import jalview.schemes.UserColourScheme;
71 import jalview.structure.StructureSelectionManager;
72 import jalview.structures.models.AAStructureBindingModel;
73 import jalview.util.Format;
74 import jalview.util.MessageManager;
75 import jalview.util.Platform;
76 import jalview.util.StringUtils;
77 import jalview.util.jarInputStreamProvider;
78 import jalview.util.matcher.Condition;
79 import jalview.viewmodel.AlignmentViewport;
80 import jalview.viewmodel.ViewportRanges;
81 import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
82 import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
83 import jalview.ws.jws2.Jws2Discoverer;
84 import jalview.ws.jws2.dm.AAConSettings;
85 import jalview.ws.jws2.jabaws2.Jws2Instance;
86 import jalview.ws.params.ArgumentI;
87 import jalview.ws.params.AutoCalcSetting;
88 import jalview.ws.params.WsParamSetI;
89 import jalview.xml.binding.jalview.AlcodonFrame;
90 import jalview.xml.binding.jalview.AlcodonFrame.AlcodMap;
91 import jalview.xml.binding.jalview.Annotation;
92 import jalview.xml.binding.jalview.Annotation.ThresholdLine;
93 import jalview.xml.binding.jalview.AnnotationColourScheme;
94 import jalview.xml.binding.jalview.AnnotationElement;
95 import jalview.xml.binding.jalview.Feature;
96 import jalview.xml.binding.jalview.Feature.OtherData;
97 import jalview.xml.binding.jalview.FeatureMatcherSet.CompoundMatcher;
98 import jalview.xml.binding.jalview.FilterBy;
99 import jalview.xml.binding.jalview.JalviewModel;
100 import jalview.xml.binding.jalview.JalviewModel.FeatureSettings;
101 import jalview.xml.binding.jalview.JalviewModel.FeatureSettings.Group;
102 import jalview.xml.binding.jalview.JalviewModel.FeatureSettings.Setting;
103 import jalview.xml.binding.jalview.JalviewModel.JGroup;
104 import jalview.xml.binding.jalview.JalviewModel.JSeq;
105 import jalview.xml.binding.jalview.JalviewModel.JSeq.Pdbids;
106 import jalview.xml.binding.jalview.JalviewModel.JSeq.Pdbids.StructureState;
107 import jalview.xml.binding.jalview.JalviewModel.JSeq.RnaViewer;
108 import jalview.xml.binding.jalview.JalviewModel.JSeq.RnaViewer.SecondaryStructure;
109 import jalview.xml.binding.jalview.JalviewModel.Tree;
110 import jalview.xml.binding.jalview.JalviewModel.UserColours;
111 import jalview.xml.binding.jalview.JalviewModel.Viewport;
112 import jalview.xml.binding.jalview.JalviewModel.Viewport.CalcIdParam;
113 import jalview.xml.binding.jalview.JalviewModel.Viewport.HiddenColumns;
114 import jalview.xml.binding.jalview.JalviewUserColours;
115 import jalview.xml.binding.jalview.JalviewUserColours.Colour;
116 import jalview.xml.binding.jalview.MapListType.MapListFrom;
117 import jalview.xml.binding.jalview.MapListType.MapListTo;
118 import jalview.xml.binding.jalview.Mapping;
119 import jalview.xml.binding.jalview.NoValueColour;
120 import jalview.xml.binding.jalview.ObjectFactory;
121 import jalview.xml.binding.jalview.Pdbentry.Property;
122 import jalview.xml.binding.jalview.Sequence;
123 import jalview.xml.binding.jalview.Sequence.DBRef;
124 import jalview.xml.binding.jalview.SequenceSet;
125 import jalview.xml.binding.jalview.SequenceSet.SequenceSetProperties;
126 import jalview.xml.binding.jalview.ThresholdType;
127 import jalview.xml.binding.jalview.VAMSAS;
129 import java.awt.Color;
130 import java.awt.Font;
131 import java.awt.Rectangle;
132 import java.io.BufferedReader;
133 import java.io.ByteArrayInputStream;
134 import java.io.DataInputStream;
135 import java.io.DataOutputStream;
137 import java.io.FileInputStream;
138 import java.io.FileOutputStream;
139 import java.io.IOException;
140 import java.io.InputStreamReader;
141 import java.io.OutputStreamWriter;
142 import java.io.PrintWriter;
143 import java.lang.reflect.InvocationTargetException;
144 import java.math.BigInteger;
145 import java.net.MalformedURLException;
147 import java.util.ArrayList;
148 import java.util.Arrays;
149 import java.util.Collections;
150 import java.util.Enumeration;
151 import java.util.GregorianCalendar;
152 import java.util.HashMap;
153 import java.util.HashSet;
154 import java.util.Hashtable;
155 import java.util.IdentityHashMap;
156 import java.util.Iterator;
157 import java.util.LinkedHashMap;
158 import java.util.List;
159 import java.util.Map;
160 import java.util.Map.Entry;
161 import java.util.Set;
162 import java.util.Vector;
163 import java.util.jar.JarEntry;
164 import java.util.jar.JarInputStream;
165 import java.util.jar.JarOutputStream;
167 import javax.swing.JInternalFrame;
168 import javax.swing.SwingUtilities;
169 import javax.xml.bind.JAXBContext;
170 import javax.xml.bind.JAXBElement;
171 import javax.xml.bind.Marshaller;
172 import javax.xml.datatype.DatatypeConfigurationException;
173 import javax.xml.datatype.DatatypeFactory;
174 import javax.xml.datatype.XMLGregorianCalendar;
175 import javax.xml.stream.XMLInputFactory;
176 import javax.xml.stream.XMLStreamReader;
179 * Write out the current jalview desktop state as a Jalview XML stream.
181 * Note: the vamsas objects referred to here are primitive versions of the
182 * VAMSAS project schema elements - they are not the same and most likely never
186 * @version $Revision: 1.134 $
188 public class Jalview2XML
191 // BH 2018 we add the .jvp binary extension to J2S so that
192 // it will declare that binary when we do the file save from the browser
194 private static void addJ2SBinaryType(String ext)
196 ext = "." + ext + "?";
201 * J2S._binaryTypes.push(ext);
208 addJ2SBinaryType(".jvp?");
211 private static final String VIEWER_PREFIX = "viewer_";
213 private static final String RNA_PREFIX = "rna_";
215 private static final String UTF_8 = "UTF-8";
217 // use this with nextCounter() to make unique names for entities
218 private int counter = 0;
221 * SequenceI reference -> XML ID string in jalview XML. Populated as XML reps
222 * of sequence objects are created.
224 IdentityHashMap<SequenceI, String> seqsToIds = null;
227 * jalview XML Sequence ID to jalview sequence object reference (both dataset
228 * and alignment sequences. Populated as XML reps of sequence objects are
231 Map<String, SequenceI> seqRefIds = null;
233 Map<String, SequenceI> incompleteSeqs = null;
235 List<SeqFref> frefedSequence = null;
237 boolean raiseGUI = true; // whether errors are raised in dialog boxes or not
240 * Map of reconstructed AlignFrame objects that appear to have come from
241 * SplitFrame objects (have a dna/protein complement view).
243 private Map<Viewport, AlignFrame> splitFrameCandidates = new HashMap<>();
246 * Map from displayed rna structure models to their saved session state jar
249 private Map<RnaModel, String> rnaSessions = new HashMap<>();
252 * A helper method for safely using the value of an optional attribute that
253 * may be null if not present in the XML. Answers the boolean value, or false
259 public static boolean safeBoolean(Boolean b)
261 return b == null ? false : b.booleanValue();
265 * A helper method for safely using the value of an optional attribute that
266 * may be null if not present in the XML. Answers the integer value, or zero
272 public static int safeInt(Integer i)
274 return i == null ? 0 : i.intValue();
278 * A helper method for safely using the value of an optional attribute that
279 * may be null if not present in the XML. Answers the float value, or zero if
285 public static float safeFloat(Float f)
287 return f == null ? 0f : f.floatValue();
291 * create/return unique hash string for sq
294 * @return new or existing unique string for sq
296 String seqHash(SequenceI sq)
298 if (seqsToIds == null)
302 if (seqsToIds.containsKey(sq))
304 return seqsToIds.get(sq);
308 // create sequential key
309 String key = "sq" + (seqsToIds.size() + 1);
310 key = makeHashCode(sq, key); // check we don't have an external reference
312 seqsToIds.put(sq, key);
319 if (seqsToIds == null)
321 seqsToIds = new IdentityHashMap<>();
323 if (seqRefIds == null)
325 seqRefIds = new HashMap<>();
327 if (incompleteSeqs == null)
329 incompleteSeqs = new HashMap<>();
331 if (frefedSequence == null)
333 frefedSequence = new ArrayList<>();
341 public Jalview2XML(boolean raiseGUI)
343 this.raiseGUI = raiseGUI;
347 * base class for resolving forward references to sequences by their ID
352 abstract class SeqFref
358 public SeqFref(String _sref, String type)
364 public String getSref()
369 public SequenceI getSrefSeq()
371 return seqRefIds.get(sref);
374 public boolean isResolvable()
376 return seqRefIds.get(sref) != null;
379 public SequenceI getSrefDatasetSeq()
381 SequenceI sq = seqRefIds.get(sref);
384 while (sq.getDatasetSequence() != null)
386 sq = sq.getDatasetSequence();
393 * @return true if the forward reference was fully resolved
395 abstract boolean resolve();
398 public String toString()
400 return type + " reference to " + sref;
405 * create forward reference for a mapping
411 public SeqFref newMappingRef(final String sref,
412 final jalview.datamodel.Mapping _jmap)
414 SeqFref fref = new SeqFref(sref, "Mapping")
416 public jalview.datamodel.Mapping jmap = _jmap;
421 SequenceI seq = getSrefDatasetSeq();
433 public SeqFref newAlcodMapRef(final String sref,
434 final AlignedCodonFrame _cf,
435 final jalview.datamodel.Mapping _jmap)
438 SeqFref fref = new SeqFref(sref, "Codon Frame")
440 AlignedCodonFrame cf = _cf;
442 public jalview.datamodel.Mapping mp = _jmap;
445 public boolean isResolvable()
447 return super.isResolvable() && mp.getTo() != null;
453 SequenceI seq = getSrefDatasetSeq();
458 cf.addMap(seq, mp.getTo(), mp.getMap());
465 public void resolveFrefedSequences()
467 Iterator<SeqFref> nextFref = frefedSequence.iterator();
468 int toresolve = frefedSequence.size();
469 int unresolved = 0, failedtoresolve = 0;
470 while (nextFref.hasNext())
472 SeqFref ref = nextFref.next();
473 if (ref.isResolvable())
485 } catch (Exception x)
488 "IMPLEMENTATION ERROR: Failed to resolve forward reference for sequence "
501 System.err.println("Jalview Project Import: There were " + unresolved
502 + " forward references left unresolved on the stack.");
504 if (failedtoresolve > 0)
506 System.err.println("SERIOUS! " + failedtoresolve
507 + " resolvable forward references failed to resolve.");
509 if (incompleteSeqs != null && incompleteSeqs.size() > 0)
512 "Jalview Project Import: There are " + incompleteSeqs.size()
513 + " sequences which may have incomplete metadata.");
514 if (incompleteSeqs.size() < 10)
516 for (SequenceI s : incompleteSeqs.values())
518 System.err.println(s.toString());
524 "Too many to report. Skipping output of incomplete sequences.");
530 * This maintains a map of viewports, the key being the seqSetId. Important to
531 * set historyItem and redoList for multiple views
533 Map<String, AlignViewport> viewportsAdded = new HashMap<>();
535 Map<String, AlignmentAnnotation> annotationIds = new HashMap<>();
537 String uniqueSetSuffix = "";
540 * List of pdbfiles added to Jar
542 List<String> pdbfiles = null;
544 // SAVES SEVERAL ALIGNMENT WINDOWS TO SAME JARFILE
545 public void saveState(File statefile)
547 FileOutputStream fos = null;
550 fos = new FileOutputStream(statefile);
551 JarOutputStream jout = new JarOutputStream(fos);
554 } catch (Exception e)
556 // TODO: inform user of the problem - they need to know if their data was
558 if (errorMessage == null)
560 errorMessage = "Couldn't write Jalview Archive to output file '"
561 + statefile + "' - See console error log for details";
565 errorMessage += "(output file was '" + statefile + "')";
575 } catch (IOException e)
585 * Writes a jalview project archive to the given Jar output stream.
589 public void saveState(JarOutputStream jout)
591 AlignFrame[] frames = Desktop.getAlignFrames();
597 saveAllFrames(Arrays.asList(frames), jout);
601 * core method for storing state for a set of AlignFrames.
604 * - frames involving all data to be exported (including containing
607 * - project output stream
609 private void saveAllFrames(List<AlignFrame> frames, JarOutputStream jout)
611 Hashtable<String, AlignFrame> dsses = new Hashtable<>();
614 * ensure cached data is clear before starting
616 // todo tidy up seqRefIds, seqsToIds initialisation / reset
618 splitFrameCandidates.clear();
623 // NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
624 // //////////////////////////////////////////////////
626 List<String> shortNames = new ArrayList<>();
627 List<String> viewIds = new ArrayList<>();
630 for (int i = frames.size() - 1; i > -1; i--)
632 AlignFrame af = frames.get(i);
634 if (skipList != null && skipList
635 .containsKey(af.getViewport().getSequenceSetId()))
640 String shortName = makeFilename(af, shortNames);
642 int apSize = af.getAlignPanels().size();
644 for (int ap = 0; ap < apSize; ap++)
646 AlignmentPanel apanel = (AlignmentPanel) af.getAlignPanels()
648 String fileName = apSize == 1 ? shortName : ap + shortName;
649 if (!fileName.endsWith(".xml"))
651 fileName = fileName + ".xml";
654 saveState(apanel, fileName, jout, viewIds);
656 String dssid = getDatasetIdRef(
657 af.getViewport().getAlignment().getDataset());
658 if (!dsses.containsKey(dssid))
660 dsses.put(dssid, af);
665 writeDatasetFor(dsses, "" + jout.hashCode() + " " + uniqueSetSuffix,
671 } catch (Exception foo)
676 } catch (Exception ex)
678 // TODO: inform user of the problem - they need to know if their data was
680 if (errorMessage == null)
682 errorMessage = "Couldn't write Jalview Archive - see error output for details";
684 ex.printStackTrace();
689 * Generates a distinct file name, based on the title of the AlignFrame, by
690 * appending _n for increasing n until an unused name is generated. The new
691 * name (without its extension) is added to the list.
695 * @return the generated name, with .xml extension
697 protected String makeFilename(AlignFrame af, List<String> namesUsed)
699 String shortName = af.getTitle();
701 if (shortName.indexOf(File.separatorChar) > -1)
703 shortName = shortName
704 .substring(shortName.lastIndexOf(File.separatorChar) + 1);
709 while (namesUsed.contains(shortName))
711 if (shortName.endsWith("_" + (count - 1)))
713 shortName = shortName.substring(0, shortName.lastIndexOf("_"));
716 shortName = shortName.concat("_" + count);
720 namesUsed.add(shortName);
722 if (!shortName.endsWith(".xml"))
724 shortName = shortName + ".xml";
729 // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW
730 public boolean saveAlignment(AlignFrame af, String jarFile,
735 FileOutputStream fos = new FileOutputStream(jarFile);
736 JarOutputStream jout = new JarOutputStream(fos);
737 List<AlignFrame> frames = new ArrayList<>();
739 // resolve splitframes
740 if (af.getViewport().getCodingComplement() != null)
742 frames = ((SplitFrame) af.getSplitViewContainer()).getAlignFrames();
748 saveAllFrames(frames, jout);
752 } catch (Exception foo)
758 } catch (Exception ex)
760 errorMessage = "Couldn't Write alignment view to Jalview Archive - see error output for details";
761 ex.printStackTrace();
766 private void writeDatasetFor(Hashtable<String, AlignFrame> dsses,
767 String fileName, JarOutputStream jout)
770 for (String dssids : dsses.keySet())
772 AlignFrame _af = dsses.get(dssids);
773 String jfileName = fileName + " Dataset for " + _af.getTitle();
774 if (!jfileName.endsWith(".xml"))
776 jfileName = jfileName + ".xml";
778 saveState(_af.alignPanel, jfileName, true, jout, null);
783 * create a JalviewModel from an alignment view and marshall it to a
787 * panel to create jalview model for
789 * name of alignment panel written to output stream
796 public JalviewModel saveState(AlignmentPanel ap, String fileName,
797 JarOutputStream jout, List<String> viewIds)
799 return saveState(ap, fileName, false, jout, viewIds);
803 * create a JalviewModel from an alignment view and marshall it to a
807 * panel to create jalview model for
809 * name of alignment panel written to output stream
811 * when true, only write the dataset for the alignment, not the data
812 * associated with the view.
818 public JalviewModel saveState(AlignmentPanel ap, String fileName,
819 boolean storeDS, JarOutputStream jout, List<String> viewIds)
823 viewIds = new ArrayList<>();
828 List<UserColourScheme> userColours = new ArrayList<>();
830 AlignViewport av = ap.av;
831 ViewportRanges vpRanges = av.getRanges();
833 final ObjectFactory objectFactory = new ObjectFactory();
834 JalviewModel object = objectFactory.createJalviewModel();
835 object.setVamsasModel(new VAMSAS());
837 // object.setCreationDate(new java.util.Date(System.currentTimeMillis()));
840 GregorianCalendar c = new GregorianCalendar();
841 DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
842 XMLGregorianCalendar now = datatypeFactory.newXMLGregorianCalendar(c);// gregorianCalendar);
843 object.setCreationDate(now);
844 } catch (DatatypeConfigurationException e)
846 System.err.println("error writing date: " + e.toString());
849 jalview.bin.Cache.getDefault("VERSION", "Development Build"));
852 * rjal is full height alignment, jal is actual alignment with full metadata
853 * but excludes hidden sequences.
855 jalview.datamodel.AlignmentI rjal = av.getAlignment(), jal = rjal;
857 if (av.hasHiddenRows())
859 rjal = jal.getHiddenSequences().getFullAlignment();
862 SequenceSet vamsasSet = new SequenceSet();
864 // JalviewModelSequence jms = new JalviewModelSequence();
866 vamsasSet.setGapChar(jal.getGapCharacter() + "");
868 if (jal.getDataset() != null)
870 // dataset id is the dataset's hashcode
871 vamsasSet.setDatasetId(getDatasetIdRef(jal.getDataset()));
874 // switch jal and the dataset
875 jal = jal.getDataset();
879 if (jal.getProperties() != null)
881 Enumeration en = jal.getProperties().keys();
882 while (en.hasMoreElements())
884 String key = en.nextElement().toString();
885 SequenceSetProperties ssp = new SequenceSetProperties();
887 ssp.setValue(jal.getProperties().get(key).toString());
888 // vamsasSet.addSequenceSetProperties(ssp);
889 vamsasSet.getSequenceSetProperties().add(ssp);
894 Set<String> calcIdSet = new HashSet<>();
895 // record the set of vamsas sequence XML POJO we create.
896 HashMap<String, Sequence> vamsasSetIds = new HashMap<>();
898 for (final SequenceI jds : rjal.getSequences())
900 final SequenceI jdatasq = jds.getDatasetSequence() == null ? jds
901 : jds.getDatasetSequence();
902 String id = seqHash(jds);
903 if (vamsasSetIds.get(id) == null)
905 if (seqRefIds.get(id) != null && !storeDS)
907 // This happens for two reasons: 1. multiple views are being
909 // 2. the hashCode has collided with another sequence's code. This
911 // HAPPEN! (PF00072.15.stk does this)
912 // JBPNote: Uncomment to debug writing out of files that do not read
913 // back in due to ArrayOutOfBoundExceptions.
914 // System.err.println("vamsasSeq backref: "+id+"");
915 // System.err.println(jds.getName()+"
916 // "+jds.getStart()+"-"+jds.getEnd()+" "+jds.getSequenceAsString());
917 // System.err.println("Hashcode: "+seqHash(jds));
918 // SequenceI rsq = (SequenceI) seqRefIds.get(id + "");
919 // System.err.println(rsq.getName()+"
920 // "+rsq.getStart()+"-"+rsq.getEnd()+" "+rsq.getSequenceAsString());
921 // System.err.println("Hashcode: "+seqHash(rsq));
925 vamsasSeq = createVamsasSequence(id, jds);
926 // vamsasSet.addSequence(vamsasSeq);
927 vamsasSet.getSequence().add(vamsasSeq);
928 vamsasSetIds.put(id, vamsasSeq);
929 seqRefIds.put(id, jds);
933 jseq.setStart(jds.getStart());
934 jseq.setEnd(jds.getEnd());
935 jseq.setColour(av.getSequenceColour(jds).getRGB());
937 jseq.setId(id); // jseq id should be a string not a number
940 // Store any sequences this sequence represents
941 if (av.hasHiddenRows())
943 // use rjal, contains the full height alignment
945 av.getAlignment().getHiddenSequences().isHidden(jds));
947 if (av.isHiddenRepSequence(jds))
949 jalview.datamodel.SequenceI[] reps = av
950 .getRepresentedSequences(jds).getSequencesInOrder(rjal);
952 for (int h = 0; h < reps.length; h++)
956 // jseq.addHiddenSequences(rjal.findIndex(reps[h]));
957 jseq.getHiddenSequences().add(rjal.findIndex(reps[h]));
962 // mark sequence as reference - if it is the reference for this view
965 jseq.setViewreference(jds == jal.getSeqrep());
969 // TODO: omit sequence features from each alignment view's XML dump if we
970 // are storing dataset
971 List<SequenceFeature> sfs = jds.getSequenceFeatures();
972 for (SequenceFeature sf : sfs)
974 // Features features = new Features();
975 Feature features = new Feature();
977 features.setBegin(sf.getBegin());
978 features.setEnd(sf.getEnd());
979 features.setDescription(sf.getDescription());
980 features.setType(sf.getType());
981 features.setFeatureGroup(sf.getFeatureGroup());
982 features.setScore(sf.getScore());
983 if (sf.links != null)
985 for (int l = 0; l < sf.links.size(); l++)
987 OtherData keyValue = new OtherData();
988 keyValue.setKey("LINK_" + l);
989 keyValue.setValue(sf.links.elementAt(l).toString());
990 // features.addOtherData(keyValue);
991 features.getOtherData().add(keyValue);
994 if (sf.otherDetails != null)
997 * save feature attributes, which may be simple strings or
998 * map valued (have sub-attributes)
1000 for (Entry<String, Object> entry : sf.otherDetails.entrySet())
1002 String key = entry.getKey();
1003 Object value = entry.getValue();
1004 if (value instanceof Map<?, ?>)
1006 for (Entry<String, Object> subAttribute : ((Map<String, Object>) value)
1009 OtherData otherData = new OtherData();
1010 otherData.setKey(key);
1011 otherData.setKey2(subAttribute.getKey());
1012 otherData.setValue(subAttribute.getValue().toString());
1013 // features.addOtherData(otherData);
1014 features.getOtherData().add(otherData);
1019 OtherData otherData = new OtherData();
1020 otherData.setKey(key);
1021 otherData.setValue(value.toString());
1022 // features.addOtherData(otherData);
1023 features.getOtherData().add(otherData);
1028 // jseq.addFeatures(features);
1029 jseq.getFeatures().add(features);
1032 if (jdatasq.getAllPDBEntries() != null)
1034 Enumeration<PDBEntry> en = jdatasq.getAllPDBEntries().elements();
1035 while (en.hasMoreElements())
1037 Pdbids pdb = new Pdbids();
1038 jalview.datamodel.PDBEntry entry = en.nextElement();
1040 String pdbId = entry.getId();
1042 pdb.setType(entry.getType());
1045 * Store any structure views associated with this sequence. This
1046 * section copes with duplicate entries in the project, so a dataset
1047 * only view *should* be coped with sensibly.
1049 // This must have been loaded, is it still visible?
1050 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1051 String matchedFile = null;
1052 for (int f = frames.length - 1; f > -1; f--)
1054 if (frames[f] instanceof StructureViewerBase)
1056 StructureViewerBase viewFrame = (StructureViewerBase) frames[f];
1057 matchedFile = saveStructureState(ap, jds, pdb, entry, viewIds,
1058 matchedFile, viewFrame);
1060 * Only store each structure viewer's state once in the project
1061 * jar. First time through only (storeDS==false)
1063 String viewId = viewFrame.getViewId();
1064 if (!storeDS && !viewIds.contains(viewId))
1066 viewIds.add(viewId);
1069 String viewerState = viewFrame.getStateInfo();
1070 writeJarEntry(jout, getViewerJarEntryName(viewId),
1071 viewerState.getBytes());
1072 } catch (IOException e)
1075 "Error saving viewer state: " + e.getMessage());
1081 if (matchedFile != null || entry.getFile() != null)
1083 if (entry.getFile() != null)
1086 matchedFile = entry.getFile();
1088 pdb.setFile(matchedFile); // entry.getFile());
1089 if (pdbfiles == null)
1091 pdbfiles = new ArrayList<>();
1094 if (!pdbfiles.contains(pdbId))
1096 pdbfiles.add(pdbId);
1097 copyFileToJar(jout, matchedFile, pdbId);
1101 Enumeration<String> props = entry.getProperties();
1102 if (props.hasMoreElements())
1104 // PdbentryItem item = new PdbentryItem();
1105 while (props.hasMoreElements())
1107 Property prop = new Property();
1108 String key = props.nextElement();
1110 prop.setValue(entry.getProperty(key).toString());
1111 // item.addProperty(prop);
1112 pdb.getProperty().add(prop);
1114 // pdb.addPdbentryItem(item);
1117 // jseq.addPdbids(pdb);
1118 jseq.getPdbids().add(pdb);
1122 saveRnaViewers(jout, jseq, jds, viewIds, ap, storeDS);
1124 // jms.addJSeq(jseq);
1125 object.getJSeq().add(jseq);
1128 if (!storeDS && av.hasHiddenRows())
1130 jal = av.getAlignment();
1134 if (storeDS && jal.getCodonFrames() != null)
1136 List<AlignedCodonFrame> jac = jal.getCodonFrames();
1137 for (AlignedCodonFrame acf : jac)
1139 AlcodonFrame alc = new AlcodonFrame();
1140 if (acf.getProtMappings() != null
1141 && acf.getProtMappings().length > 0)
1143 boolean hasMap = false;
1144 SequenceI[] dnas = acf.getdnaSeqs();
1145 jalview.datamodel.Mapping[] pmaps = acf.getProtMappings();
1146 for (int m = 0; m < pmaps.length; m++)
1148 AlcodMap alcmap = new AlcodMap();
1149 alcmap.setDnasq(seqHash(dnas[m]));
1151 createVamsasMapping(pmaps[m], dnas[m], null, false));
1152 // alc.addAlcodMap(alcmap);
1153 alc.getAlcodMap().add(alcmap);
1158 // vamsasSet.addAlcodonFrame(alc);
1159 vamsasSet.getAlcodonFrame().add(alc);
1162 // TODO: delete this ? dead code from 2.8.3->2.9 ?
1164 // AlcodonFrame alc = new AlcodonFrame();
1165 // vamsasSet.addAlcodonFrame(alc);
1166 // for (int p = 0; p < acf.aaWidth; p++)
1168 // Alcodon cmap = new Alcodon();
1169 // if (acf.codons[p] != null)
1171 // // Null codons indicate a gapped column in the translated peptide
1173 // cmap.setPos1(acf.codons[p][0]);
1174 // cmap.setPos2(acf.codons[p][1]);
1175 // cmap.setPos3(acf.codons[p][2]);
1177 // alc.addAlcodon(cmap);
1179 // if (acf.getProtMappings() != null
1180 // && acf.getProtMappings().length > 0)
1182 // SequenceI[] dnas = acf.getdnaSeqs();
1183 // jalview.datamodel.Mapping[] pmaps = acf.getProtMappings();
1184 // for (int m = 0; m < pmaps.length; m++)
1186 // AlcodMap alcmap = new AlcodMap();
1187 // alcmap.setDnasq(seqHash(dnas[m]));
1188 // alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null,
1190 // alc.addAlcodMap(alcmap);
1197 // /////////////////////////////////
1198 if (!storeDS && av.getCurrentTree() != null)
1200 // FIND ANY ASSOCIATED TREES
1201 // NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT
1202 if (Desktop.desktop != null)
1204 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1206 for (int t = 0; t < frames.length; t++)
1208 if (frames[t] instanceof TreePanel)
1210 TreePanel tp = (TreePanel) frames[t];
1212 if (tp.getTreeCanvas().getViewport().getAlignment() == jal)
1214 JalviewModel.Tree tree = new JalviewModel.Tree();
1215 tree.setTitle(tp.getTitle());
1216 tree.setCurrentTree((av.getCurrentTree() == tp.getTree()));
1217 tree.setNewick(tp.getTree().print());
1218 tree.setThreshold(tp.getTreeCanvas().getThreshold());
1220 tree.setFitToWindow(tp.fitToWindow.getState());
1221 tree.setFontName(tp.getTreeFont().getName());
1222 tree.setFontSize(tp.getTreeFont().getSize());
1223 tree.setFontStyle(tp.getTreeFont().getStyle());
1224 tree.setMarkUnlinked(tp.placeholdersMenu.getState());
1226 tree.setShowBootstrap(tp.bootstrapMenu.getState());
1227 tree.setShowDistances(tp.distanceMenu.getState());
1229 tree.setHeight(tp.getHeight());
1230 tree.setWidth(tp.getWidth());
1231 tree.setXpos(tp.getX());
1232 tree.setYpos(tp.getY());
1233 tree.setId(makeHashCode(tp, null));
1234 // jms.addTree(tree);
1235 object.getTree().add(tree);
1244 * store forward refs from an annotationRow to any groups
1246 IdentityHashMap<SequenceGroup, String> groupRefs = new IdentityHashMap<>();
1249 for (SequenceI sq : jal.getSequences())
1251 // Store annotation on dataset sequences only
1252 AlignmentAnnotation[] aa = sq.getAnnotation();
1253 if (aa != null && aa.length > 0)
1255 storeAlignmentAnnotation(aa, groupRefs, av, calcIdSet, storeDS,
1262 if (jal.getAlignmentAnnotation() != null)
1264 // Store the annotation shown on the alignment.
1265 AlignmentAnnotation[] aa = jal.getAlignmentAnnotation();
1266 storeAlignmentAnnotation(aa, groupRefs, av, calcIdSet, storeDS,
1271 if (jal.getGroups() != null)
1273 JGroup[] groups = new JGroup[jal.getGroups().size()];
1275 for (jalview.datamodel.SequenceGroup sg : jal.getGroups())
1277 JGroup jGroup = new JGroup();
1278 groups[++i] = jGroup;
1280 jGroup.setStart(sg.getStartRes());
1281 jGroup.setEnd(sg.getEndRes());
1282 jGroup.setName(sg.getName());
1283 if (groupRefs.containsKey(sg))
1285 // group has references so set its ID field
1286 jGroup.setId(groupRefs.get(sg));
1288 ColourSchemeI colourScheme = sg.getColourScheme();
1289 if (colourScheme != null)
1291 ResidueShaderI groupColourScheme = sg.getGroupColourScheme();
1292 if (groupColourScheme.conservationApplied())
1294 jGroup.setConsThreshold(groupColourScheme.getConservationInc());
1296 if (colourScheme instanceof jalview.schemes.UserColourScheme)
1299 setUserColourScheme(colourScheme, userColours,
1304 jGroup.setColour(colourScheme.getSchemeName());
1307 else if (colourScheme instanceof jalview.schemes.AnnotationColourGradient)
1309 jGroup.setColour("AnnotationColourGradient");
1310 jGroup.setAnnotationColours(constructAnnotationColours(
1311 (jalview.schemes.AnnotationColourGradient) colourScheme,
1312 userColours, object));
1314 else if (colourScheme instanceof jalview.schemes.UserColourScheme)
1317 setUserColourScheme(colourScheme, userColours, object));
1321 jGroup.setColour(colourScheme.getSchemeName());
1324 jGroup.setPidThreshold(groupColourScheme.getThreshold());
1327 jGroup.setOutlineColour(sg.getOutlineColour().getRGB());
1328 jGroup.setDisplayBoxes(sg.getDisplayBoxes());
1329 jGroup.setDisplayText(sg.getDisplayText());
1330 jGroup.setColourText(sg.getColourText());
1331 jGroup.setTextCol1(sg.textColour.getRGB());
1332 jGroup.setTextCol2(sg.textColour2.getRGB());
1333 jGroup.setTextColThreshold(sg.thresholdTextColour);
1334 jGroup.setShowUnconserved(sg.getShowNonconserved());
1335 jGroup.setIgnoreGapsinConsensus(sg.getIgnoreGapsConsensus());
1336 jGroup.setShowConsensusHistogram(sg.isShowConsensusHistogram());
1337 jGroup.setShowSequenceLogo(sg.isShowSequenceLogo());
1338 jGroup.setNormaliseSequenceLogo(sg.isNormaliseSequenceLogo());
1339 for (SequenceI seq : sg.getSequences())
1341 // jGroup.addSeq(seqHash(seq));
1342 jGroup.getSeq().add(seqHash(seq));
1346 //jms.setJGroup(groups);
1348 for (JGroup grp : groups)
1350 object.getJGroup().add(grp);
1355 // /////////SAVE VIEWPORT
1356 Viewport view = new Viewport();
1357 view.setTitle(ap.alignFrame.getTitle());
1358 view.setSequenceSetId(
1359 makeHashCode(av.getSequenceSetId(), av.getSequenceSetId()));
1360 view.setId(av.getViewId());
1361 if (av.getCodingComplement() != null)
1363 view.setComplementId(av.getCodingComplement().getViewId());
1365 view.setViewName(av.getViewName());
1366 view.setGatheredViews(av.isGatherViewsHere());
1368 Rectangle size = ap.av.getExplodedGeometry();
1369 Rectangle position = size;
1372 size = ap.alignFrame.getBounds();
1373 if (av.getCodingComplement() != null)
1375 position = ((SplitFrame) ap.alignFrame.getSplitViewContainer())
1383 view.setXpos(position.x);
1384 view.setYpos(position.y);
1386 view.setWidth(size.width);
1387 view.setHeight(size.height);
1389 view.setStartRes(vpRanges.getStartRes());
1390 view.setStartSeq(vpRanges.getStartSeq());
1392 if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)
1394 view.setBgColour(setUserColourScheme(av.getGlobalColourScheme(),
1395 userColours, object));
1398 .getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient)
1400 AnnotationColourScheme ac = constructAnnotationColours(
1401 (jalview.schemes.AnnotationColourGradient) av
1402 .getGlobalColourScheme(),
1403 userColours, object);
1405 view.setAnnotationColours(ac);
1406 view.setBgColour("AnnotationColourGradient");
1410 view.setBgColour(ColourSchemeProperty
1411 .getColourName(av.getGlobalColourScheme()));
1414 ResidueShaderI vcs = av.getResidueShading();
1415 ColourSchemeI cs = av.getGlobalColourScheme();
1419 if (vcs.conservationApplied())
1421 view.setConsThreshold(vcs.getConservationInc());
1422 if (cs instanceof jalview.schemes.UserColourScheme)
1424 view.setBgColour(setUserColourScheme(cs, userColours, object));
1427 view.setPidThreshold(vcs.getThreshold());
1430 view.setConservationSelected(av.getConservationSelected());
1431 view.setPidSelected(av.getAbovePIDThreshold());
1432 final Font font = av.getFont();
1433 view.setFontName(font.getName());
1434 view.setFontSize(font.getSize());
1435 view.setFontStyle(font.getStyle());
1436 view.setScaleProteinAsCdna(av.getViewStyle().isScaleProteinAsCdna());
1437 view.setRenderGaps(av.isRenderGaps());
1438 view.setShowAnnotation(av.isShowAnnotation());
1439 view.setShowBoxes(av.getShowBoxes());
1440 view.setShowColourText(av.getColourText());
1441 view.setShowFullId(av.getShowJVSuffix());
1442 view.setRightAlignIds(av.isRightAlignIds());
1443 view.setShowSequenceFeatures(av.isShowSequenceFeatures());
1444 view.setShowText(av.getShowText());
1445 view.setShowUnconserved(av.getShowUnconserved());
1446 view.setWrapAlignment(av.getWrapAlignment());
1447 view.setTextCol1(av.getTextColour().getRGB());
1448 view.setTextCol2(av.getTextColour2().getRGB());
1449 view.setTextColThreshold(av.getThresholdTextColour());
1450 view.setShowConsensusHistogram(av.isShowConsensusHistogram());
1451 view.setShowSequenceLogo(av.isShowSequenceLogo());
1452 view.setNormaliseSequenceLogo(av.isNormaliseSequenceLogo());
1453 view.setShowGroupConsensus(av.isShowGroupConsensus());
1454 view.setShowGroupConservation(av.isShowGroupConservation());
1455 view.setShowNPfeatureTooltip(av.isShowNPFeats());
1456 view.setShowDbRefTooltip(av.isShowDBRefs());
1457 view.setFollowHighlight(av.isFollowHighlight());
1458 view.setFollowSelection(av.followSelection);
1459 view.setIgnoreGapsinConsensus(av.isIgnoreGapsConsensus());
1460 if (av.getFeaturesDisplayed() != null)
1462 FeatureSettings fs = new FeatureSettings();
1464 FeatureRenderer fr = ap.getSeqPanel().seqCanvas
1465 .getFeatureRenderer();
1466 String[] renderOrder = fr.getRenderOrder().toArray(new String[0]);
1468 Vector<String> settingsAdded = new Vector<>();
1469 if (renderOrder != null)
1471 for (String featureType : renderOrder)
1473 FeatureSettings.Setting setting = new FeatureSettings.Setting();
1474 setting.setType(featureType);
1477 * save any filter for the feature type
1479 FeatureMatcherSetI filter = fr.getFeatureFilter(featureType);
1480 if (filter != null) {
1481 Iterator<FeatureMatcherI> filters = filter.getMatchers().iterator();
1482 FeatureMatcherI firstFilter = filters.next();
1483 setting.setMatcherSet(Jalview2XML.marshalFilter(
1484 firstFilter, filters, filter.isAnded()));
1488 * save colour scheme for the feature type
1490 FeatureColourI fcol = fr.getFeatureStyle(featureType);
1491 if (!fcol.isSimpleColour())
1493 setting.setColour(fcol.getMaxColour().getRGB());
1494 setting.setMincolour(fcol.getMinColour().getRGB());
1495 setting.setMin(fcol.getMin());
1496 setting.setMax(fcol.getMax());
1497 setting.setColourByLabel(fcol.isColourByLabel());
1498 if (fcol.isColourByAttribute())
1500 String[] attName = fcol.getAttributeName();
1501 setting.getAttributeName().add(attName[0]);
1502 if (attName.length > 1)
1504 setting.getAttributeName().add(attName[1]);
1507 setting.setAutoScale(fcol.isAutoScaled());
1508 setting.setThreshold(fcol.getThreshold());
1509 Color noColour = fcol.getNoColour();
1510 if (noColour == null)
1512 setting.setNoValueColour(NoValueColour.NONE);
1514 else if (noColour.equals(fcol.getMaxColour()))
1516 setting.setNoValueColour(NoValueColour.MAX);
1520 setting.setNoValueColour(NoValueColour.MIN);
1522 // -1 = No threshold, 0 = Below, 1 = Above
1523 setting.setThreshstate(fcol.isAboveThreshold() ? 1
1524 : (fcol.isBelowThreshold() ? 0 : -1));
1528 setting.setColour(fcol.getColour().getRGB());
1532 av.getFeaturesDisplayed().isVisible(featureType));
1534 .getOrder(featureType);
1537 setting.setOrder(rorder);
1539 /// fs.addSetting(setting);
1540 fs.getSetting().add(setting);
1541 settingsAdded.addElement(featureType);
1545 // is groups actually supposed to be a map here ?
1546 Iterator<String> en = fr.getFeatureGroups().iterator();
1547 Vector<String> groupsAdded = new Vector<>();
1548 while (en.hasNext())
1550 String grp = en.next();
1551 if (groupsAdded.contains(grp))
1555 Group g = new Group();
1557 g.setDisplay(((Boolean) fr.checkGroupVisibility(grp, false))
1560 fs.getGroup().add(g);
1561 groupsAdded.addElement(grp);
1563 // jms.setFeatureSettings(fs);
1564 object.setFeatureSettings(fs);
1567 if (av.hasHiddenColumns())
1569 jalview.datamodel.HiddenColumns hidden = av.getAlignment()
1570 .getHiddenColumns();
1573 warn("REPORT BUG: avoided null columnselection bug (DMAM reported). Please contact Jim about this.");
1577 Iterator<int[]> hiddenRegions = hidden.iterator();
1578 while (hiddenRegions.hasNext())
1580 int[] region = hiddenRegions.next();
1581 HiddenColumns hc = new HiddenColumns();
1582 hc.setStart(region[0]);
1583 hc.setEnd(region[1]);
1584 // view.addHiddenColumns(hc);
1585 view.getHiddenColumns().add(hc);
1589 if (calcIdSet.size() > 0)
1591 for (String calcId : calcIdSet)
1593 if (calcId.trim().length() > 0)
1595 CalcIdParam cidp = createCalcIdParam(calcId, av);
1596 // Some calcIds have no parameters.
1599 // view.addCalcIdParam(cidp);
1600 view.getCalcIdParam().add(cidp);
1606 // jms.addViewport(view);
1607 object.getViewport().add(view);
1609 // object.setJalviewModelSequence(jms);
1610 // object.getVamsasModel().addSequenceSet(vamsasSet);
1611 object.getVamsasModel().getSequenceSet().add(vamsasSet);
1613 if (jout != null && fileName != null)
1615 // We may not want to write the object to disk,
1616 // eg we can copy the alignViewport to a new view object
1617 // using save and then load
1620 fileName = fileName.replace('\\', '/');
1621 System.out.println("Writing jar entry " + fileName);
1622 JarEntry entry = new JarEntry(fileName);
1623 jout.putNextEntry(entry);
1624 PrintWriter pout = new PrintWriter(
1625 new OutputStreamWriter(jout, UTF_8));
1626 JAXBContext jaxbContext = JAXBContext
1627 .newInstance(JalviewModel.class);
1628 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
1630 // output pretty printed
1631 // jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
1632 jaxbMarshaller.marshal(
1633 new ObjectFactory().createJalviewModel(object), pout);
1635 // jaxbMarshaller.marshal(object, pout);
1636 // marshaller.marshal(object);
1639 } catch (Exception ex)
1641 // TODO: raise error in GUI if marshalling failed.
1642 System.err.println("Error writing Jalview project");
1643 ex.printStackTrace();
1650 * Save any Varna viewers linked to this sequence. Writes an rnaViewer element
1651 * for each viewer, with
1653 * <li>viewer geometry (position, size, split pane divider location)</li>
1654 * <li>index of the selected structure in the viewer (currently shows gapped
1656 * <li>the id of the annotation holding RNA secondary structure</li>
1657 * <li>(currently only one SS is shown per viewer, may be more in future)</li>
1659 * Varna viewer state is also written out (in native Varna XML) to separate
1660 * project jar entries. A separate entry is written for each RNA structure
1661 * displayed, with the naming convention
1663 * <li>rna_viewId_sequenceId_annotationId_[gapped|trimmed]</li>
1671 * @param storeDataset
1673 protected void saveRnaViewers(JarOutputStream jout, JSeq jseq,
1674 final SequenceI jds, List<String> viewIds, AlignmentPanel ap,
1675 boolean storeDataset)
1677 if (Desktop.desktop == null)
1681 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1682 for (int f = frames.length - 1; f > -1; f--)
1684 if (frames[f] instanceof AppVarna)
1686 AppVarna varna = (AppVarna) frames[f];
1688 * link the sequence to every viewer that is showing it and is linked to
1689 * its alignment panel
1691 if (varna.isListeningFor(jds) && ap == varna.getAlignmentPanel())
1693 String viewId = varna.getViewId();
1694 RnaViewer rna = new RnaViewer();
1695 rna.setViewId(viewId);
1696 rna.setTitle(varna.getTitle());
1697 rna.setXpos(varna.getX());
1698 rna.setYpos(varna.getY());
1699 rna.setWidth(varna.getWidth());
1700 rna.setHeight(varna.getHeight());
1701 rna.setDividerLocation(varna.getDividerLocation());
1702 rna.setSelectedRna(varna.getSelectedIndex());
1703 // jseq.addRnaViewer(rna);
1704 jseq.getRnaViewer().add(rna);
1707 * Store each Varna panel's state once in the project per sequence.
1708 * First time through only (storeDataset==false)
1710 // boolean storeSessions = false;
1711 // String sequenceViewId = viewId + seqsToIds.get(jds);
1712 // if (!storeDataset && !viewIds.contains(sequenceViewId))
1714 // viewIds.add(sequenceViewId);
1715 // storeSessions = true;
1717 for (RnaModel model : varna.getModels())
1719 if (model.seq == jds)
1722 * VARNA saves each view (sequence or alignment secondary
1723 * structure, gapped or trimmed) as a separate XML file
1725 String jarEntryName = rnaSessions.get(model);
1726 if (jarEntryName == null)
1729 String varnaStateFile = varna.getStateInfo(model.rna);
1730 jarEntryName = RNA_PREFIX + viewId + "_" + nextCounter();
1731 copyFileToJar(jout, varnaStateFile, jarEntryName);
1732 rnaSessions.put(model, jarEntryName);
1734 SecondaryStructure ss = new SecondaryStructure();
1735 String annotationId = varna.getAnnotation(jds).annotationId;
1736 ss.setAnnotationId(annotationId);
1737 ss.setViewerState(jarEntryName);
1738 ss.setGapped(model.gapped);
1739 ss.setTitle(model.title);
1740 // rna.addSecondaryStructure(ss);
1741 rna.getSecondaryStructure().add(ss);
1750 * Copy the contents of a file to a new entry added to the output jar
1754 * @param jarEntryName
1756 protected void copyFileToJar(JarOutputStream jout, String infilePath,
1757 String jarEntryName)
1759 DataInputStream dis = null;
1762 File file = new File(infilePath);
1763 if (file.exists() && jout != null)
1765 dis = new DataInputStream(new FileInputStream(file));
1766 byte[] data = new byte[(int) file.length()];
1767 dis.readFully(data);
1768 writeJarEntry(jout, jarEntryName, data);
1770 } catch (Exception ex)
1772 ex.printStackTrace();
1780 } catch (IOException e)
1789 * Write the data to a new entry of given name in the output jar file
1792 * @param jarEntryName
1794 * @throws IOException
1796 protected void writeJarEntry(JarOutputStream jout, String jarEntryName,
1797 byte[] data) throws IOException
1801 jarEntryName = jarEntryName.replace('\\','/');
1802 System.out.println("Writing jar entry " + jarEntryName);
1803 jout.putNextEntry(new JarEntry(jarEntryName));
1804 DataOutputStream dout = new DataOutputStream(jout);
1805 dout.write(data, 0, data.length);
1812 * Save the state of a structure viewer
1817 * the archive XML element under which to save the state
1820 * @param matchedFile
1824 protected String saveStructureState(AlignmentPanel ap, SequenceI jds,
1825 Pdbids pdb, PDBEntry entry, List<String> viewIds,
1826 String matchedFile, StructureViewerBase viewFrame)
1828 final AAStructureBindingModel bindingModel = viewFrame.getBinding();
1831 * Look for any bindings for this viewer to the PDB file of interest
1832 * (including part matches excluding chain id)
1834 for (int peid = 0; peid < bindingModel.getPdbCount(); peid++)
1836 final PDBEntry pdbentry = bindingModel.getPdbEntry(peid);
1837 final String pdbId = pdbentry.getId();
1838 if (!pdbId.equals(entry.getId())
1839 && !(entry.getId().length() > 4 && entry.getId().toLowerCase()
1840 .startsWith(pdbId.toLowerCase())))
1843 * not interested in a binding to a different PDB entry here
1847 if (matchedFile == null)
1849 matchedFile = pdbentry.getFile();
1851 else if (!matchedFile.equals(pdbentry.getFile()))
1854 "Probably lost some PDB-Sequence mappings for this structure file (which apparently has same PDB Entry code): "
1855 + pdbentry.getFile());
1859 // can get at it if the ID
1860 // match is ambiguous (e.g.
1863 for (int smap = 0; smap < viewFrame.getBinding()
1864 .getSequence()[peid].length; smap++)
1866 // if (jal.findIndex(jmol.jmb.sequence[peid][smap]) > -1)
1867 if (jds == viewFrame.getBinding().getSequence()[peid][smap])
1869 StructureState state = new StructureState();
1870 state.setVisible(true);
1871 state.setXpos(viewFrame.getX());
1872 state.setYpos(viewFrame.getY());
1873 state.setWidth(viewFrame.getWidth());
1874 state.setHeight(viewFrame.getHeight());
1875 final String viewId = viewFrame.getViewId();
1876 state.setViewId(viewId);
1877 state.setAlignwithAlignPanel(viewFrame.isUsedforaligment(ap));
1878 state.setColourwithAlignPanel(viewFrame.isUsedforcolourby(ap));
1879 state.setColourByJmol(viewFrame.isColouredByViewer());
1880 state.setType(viewFrame.getViewerType().toString());
1881 // pdb.addStructureState(state);
1882 pdb.getStructureState().add(state);
1890 * Populates the AnnotationColourScheme xml for save. This captures the
1891 * settings of the options in the 'Colour by Annotation' dialog.
1894 * @param userColours
1898 private AnnotationColourScheme constructAnnotationColours(
1899 AnnotationColourGradient acg, List<UserColourScheme> userColours,
1902 AnnotationColourScheme ac = new AnnotationColourScheme();
1903 ac.setAboveThreshold(acg.getAboveThreshold());
1904 ac.setThreshold(acg.getAnnotationThreshold());
1905 // 2.10.2 save annotationId (unique) not annotation label
1906 ac.setAnnotation(acg.getAnnotation().annotationId);
1907 if (acg.getBaseColour() instanceof UserColourScheme)
1910 setUserColourScheme(acg.getBaseColour(), userColours, jm));
1915 ColourSchemeProperty.getColourName(acg.getBaseColour()));
1918 ac.setMaxColour(acg.getMaxColour().getRGB());
1919 ac.setMinColour(acg.getMinColour().getRGB());
1920 ac.setPerSequence(acg.isSeqAssociated());
1921 ac.setPredefinedColours(acg.isPredefinedColours());
1925 private void storeAlignmentAnnotation(AlignmentAnnotation[] aa,
1926 IdentityHashMap<SequenceGroup, String> groupRefs,
1927 AlignmentViewport av, Set<String> calcIdSet, boolean storeDS,
1928 SequenceSet vamsasSet)
1931 for (int i = 0; i < aa.length; i++)
1933 Annotation an = new Annotation();
1935 AlignmentAnnotation annotation = aa[i];
1936 if (annotation.annotationId != null)
1938 annotationIds.put(annotation.annotationId, annotation);
1941 an.setId(annotation.annotationId);
1943 an.setVisible(annotation.visible);
1945 an.setDescription(annotation.description);
1947 if (annotation.sequenceRef != null)
1949 // 2.9 JAL-1781 xref on sequence id rather than name
1950 an.setSequenceRef(seqsToIds.get(annotation.sequenceRef));
1952 if (annotation.groupRef != null)
1954 String groupIdr = groupRefs.get(annotation.groupRef);
1955 if (groupIdr == null)
1957 // make a locally unique String
1958 groupRefs.put(annotation.groupRef,
1959 groupIdr = ("" + System.currentTimeMillis()
1960 + annotation.groupRef.getName()
1961 + groupRefs.size()));
1963 an.setGroupRef(groupIdr.toString());
1966 // store all visualization attributes for annotation
1967 an.setGraphHeight(annotation.graphHeight);
1968 an.setCentreColLabels(annotation.centreColLabels);
1969 an.setScaleColLabels(annotation.scaleColLabel);
1970 an.setShowAllColLabels(annotation.showAllColLabels);
1971 an.setBelowAlignment(annotation.belowAlignment);
1973 if (annotation.graph > 0)
1976 an.setGraphType(annotation.graph);
1977 an.setGraphGroup(annotation.graphGroup);
1978 if (annotation.getThreshold() != null)
1980 ThresholdLine line = new ThresholdLine();
1981 line.setLabel(annotation.getThreshold().label);
1982 line.setValue(annotation.getThreshold().value);
1983 line.setColour(annotation.getThreshold().colour.getRGB());
1984 an.setThresholdLine(line);
1992 an.setLabel(annotation.label);
1994 if (annotation == av.getAlignmentQualityAnnot()
1995 || annotation == av.getAlignmentConservationAnnotation()
1996 || annotation == av.getAlignmentConsensusAnnotation()
1997 || annotation.autoCalculated)
1999 // new way of indicating autocalculated annotation -
2000 an.setAutoCalculated(annotation.autoCalculated);
2002 if (annotation.hasScore())
2004 an.setScore(annotation.getScore());
2007 if (annotation.getCalcId() != null)
2009 calcIdSet.add(annotation.getCalcId());
2010 an.setCalcId(annotation.getCalcId());
2012 if (annotation.hasProperties())
2014 for (String pr : annotation.getProperties())
2016 jalview.xml.binding.jalview.Annotation.Property prop = new jalview.xml.binding.jalview.Annotation.Property();
2018 prop.setValue(annotation.getProperty(pr));
2019 // an.addProperty(prop);
2020 an.getProperty().add(prop);
2024 AnnotationElement ae;
2025 if (annotation.annotations != null)
2027 an.setScoreOnly(false);
2028 for (int a = 0; a < annotation.annotations.length; a++)
2030 if ((annotation == null) || (annotation.annotations[a] == null))
2035 ae = new AnnotationElement();
2036 if (annotation.annotations[a].description != null)
2038 ae.setDescription(annotation.annotations[a].description);
2040 if (annotation.annotations[a].displayCharacter != null)
2042 ae.setDisplayCharacter(
2043 annotation.annotations[a].displayCharacter);
2046 if (!Float.isNaN(annotation.annotations[a].value))
2048 ae.setValue(annotation.annotations[a].value);
2052 if (annotation.annotations[a].secondaryStructure > ' ')
2054 ae.setSecondaryStructure(
2055 annotation.annotations[a].secondaryStructure + "");
2058 if (annotation.annotations[a].colour != null
2059 && annotation.annotations[a].colour != java.awt.Color.black)
2061 ae.setColour(annotation.annotations[a].colour.getRGB());
2064 // an.addAnnotationElement(ae);
2065 an.getAnnotationElement().add(ae);
2066 if (annotation.autoCalculated)
2068 // only write one non-null entry into the annotation row -
2069 // sufficient to get the visualization attributes necessary to
2077 an.setScoreOnly(true);
2079 if (!storeDS || (storeDS && !annotation.autoCalculated))
2081 // skip autocalculated annotation - these are only provided for
2083 // vamsasSet.addAnnotation(an);
2084 vamsasSet.getAnnotation().add(an);
2090 private CalcIdParam createCalcIdParam(String calcId, AlignViewport av)
2092 AutoCalcSetting settings = av.getCalcIdSettingsFor(calcId);
2093 if (settings != null)
2095 CalcIdParam vCalcIdParam = new CalcIdParam();
2096 vCalcIdParam.setCalcId(calcId);
2097 // vCalcIdParam.addServiceURL(settings.getServiceURI());
2098 vCalcIdParam.getServiceURL().add(settings.getServiceURI());
2099 // generic URI allowing a third party to resolve another instance of the
2100 // service used for this calculation
2101 for (String url : settings.getServiceURLs())
2103 // vCalcIdParam.addServiceURL(urls);
2104 vCalcIdParam.getServiceURL().add(url);
2106 vCalcIdParam.setVersion("1.0");
2107 if (settings.getPreset() != null)
2109 WsParamSetI setting = settings.getPreset();
2110 vCalcIdParam.setName(setting.getName());
2111 vCalcIdParam.setDescription(setting.getDescription());
2115 vCalcIdParam.setName("");
2116 vCalcIdParam.setDescription("Last used parameters");
2118 // need to be able to recover 1) settings 2) user-defined presets or
2119 // recreate settings from preset 3) predefined settings provided by
2120 // service - or settings that can be transferred (or discarded)
2121 vCalcIdParam.setParameters(
2122 settings.getWsParamFile().replace("\n", "|\\n|"));
2123 vCalcIdParam.setAutoUpdate(settings.isAutoUpdate());
2124 // todo - decide if updateImmediately is needed for any projects.
2126 return vCalcIdParam;
2131 private boolean recoverCalcIdParam(CalcIdParam calcIdParam,
2134 if (calcIdParam.getVersion().equals("1.0"))
2136 final String[] calcIds = calcIdParam.getServiceURL().toArray(new String[0]);
2137 Jws2Instance service = Jws2Discoverer.getDiscoverer()
2138 .getPreferredServiceFor(calcIds);
2139 if (service != null)
2141 WsParamSetI parmSet = null;
2144 parmSet = service.getParamStore().parseServiceParameterFile(
2145 calcIdParam.getName(), calcIdParam.getDescription(),
2147 calcIdParam.getParameters().replace("|\\n|", "\n"));
2148 } catch (IOException x)
2150 warn("Couldn't parse parameter data for "
2151 + calcIdParam.getCalcId(), x);
2154 List<ArgumentI> argList = null;
2155 if (calcIdParam.getName().length() > 0)
2157 parmSet = service.getParamStore()
2158 .getPreset(calcIdParam.getName());
2159 if (parmSet != null)
2161 // TODO : check we have a good match with settings in AACon -
2162 // otherwise we'll need to create a new preset
2167 argList = parmSet.getArguments();
2170 AAConSettings settings = new AAConSettings(
2171 calcIdParam.isAutoUpdate(), service, parmSet, argList);
2172 av.setCalcIdSettingsFor(calcIdParam.getCalcId(), settings,
2173 calcIdParam.isNeedsUpdate());
2178 warn("Cannot resolve a service for the parameters used in this project. Try configuring a JABAWS server.");
2182 throw new Error(MessageManager.formatMessage(
2183 "error.unsupported_version_calcIdparam", new Object[]
2184 { calcIdParam.toString() }));
2188 * External mapping between jalview objects and objects yielding a valid and
2189 * unique object ID string. This is null for normal Jalview project IO, but
2190 * non-null when a jalview project is being read or written as part of a
2193 IdentityHashMap jv2vobj = null;
2196 * Construct a unique ID for jvobj using either existing bindings or if none
2197 * exist, the result of the hashcode call for the object.
2200 * jalview data object
2201 * @return unique ID for referring to jvobj
2203 private String makeHashCode(Object jvobj, String altCode)
2205 if (jv2vobj != null)
2207 Object id = jv2vobj.get(jvobj);
2210 return id.toString();
2212 // check string ID mappings
2213 if (jvids2vobj != null && jvobj instanceof String)
2215 id = jvids2vobj.get(jvobj);
2219 return id.toString();
2221 // give up and warn that something has gone wrong
2222 warn("Cannot find ID for object in external mapping : " + jvobj);
2228 * return local jalview object mapped to ID, if it exists
2232 * @return null or object bound to idcode
2234 private Object retrieveExistingObj(String idcode)
2236 if (idcode != null && vobj2jv != null)
2238 return vobj2jv.get(idcode);
2244 * binding from ID strings from external mapping table to jalview data model
2247 private Hashtable vobj2jv;
2249 private Sequence createVamsasSequence(String id, SequenceI jds)
2251 return createVamsasSequence(true, id, jds, null);
2254 private Sequence createVamsasSequence(boolean recurse, String id,
2255 SequenceI jds, SequenceI parentseq)
2257 Sequence vamsasSeq = new Sequence();
2258 vamsasSeq.setId(id);
2259 vamsasSeq.setName(jds.getName());
2260 vamsasSeq.setSequence(jds.getSequenceAsString());
2261 vamsasSeq.setDescription(jds.getDescription());
2262 jalview.datamodel.DBRefEntry[] dbrefs = null;
2263 if (jds.getDatasetSequence() != null)
2265 vamsasSeq.setDsseqid(seqHash(jds.getDatasetSequence()));
2269 // seqId==dsseqid so we can tell which sequences really are
2270 // dataset sequences only
2271 vamsasSeq.setDsseqid(id);
2272 dbrefs = jds.getDBRefs();
2273 if (parentseq == null)
2280 for (int d = 0; d < dbrefs.length; d++)
2282 DBRef dbref = new DBRef();
2283 dbref.setSource(dbrefs[d].getSource());
2284 dbref.setVersion(dbrefs[d].getVersion());
2285 dbref.setAccessionId(dbrefs[d].getAccessionId());
2286 if (dbrefs[d].hasMap())
2288 Mapping mp = createVamsasMapping(dbrefs[d].getMap(), parentseq,
2290 dbref.setMapping(mp);
2292 // vamsasSeq.addDBRef(dbref);
2293 vamsasSeq.getDBRef().add(dbref);
2299 private Mapping createVamsasMapping(jalview.datamodel.Mapping jmp,
2300 SequenceI parentseq, SequenceI jds, boolean recurse)
2303 if (jmp.getMap() != null)
2307 jalview.util.MapList mlst = jmp.getMap();
2308 List<int[]> r = mlst.getFromRanges();
2309 for (int[] range : r)
2311 MapListFrom mfrom = new MapListFrom();
2312 mfrom.setStart(range[0]);
2313 mfrom.setEnd(range[1]);
2314 // mp.addMapListFrom(mfrom);
2315 mp.getMapListFrom().add(mfrom);
2317 r = mlst.getToRanges();
2318 for (int[] range : r)
2320 MapListTo mto = new MapListTo();
2321 mto.setStart(range[0]);
2322 mto.setEnd(range[1]);
2323 // mp.addMapListTo(mto);
2324 mp.getMapListTo().add(mto);
2326 mp.setMapFromUnit(BigInteger.valueOf(mlst.getFromRatio()));
2327 mp.setMapToUnit(BigInteger.valueOf(mlst.getToRatio()));
2328 if (jmp.getTo() != null)
2330 // MappingChoice mpc = new MappingChoice();
2332 // check/create ID for the sequence referenced by getTo()
2335 SequenceI ps = null;
2336 if (parentseq != jmp.getTo()
2337 && parentseq.getDatasetSequence() != jmp.getTo())
2339 // chaining dbref rather than a handshaking one
2340 jmpid = seqHash(ps = jmp.getTo());
2344 jmpid = seqHash(ps = parentseq);
2346 // mpc.setDseqFor(jmpid);
2347 mp.setDseqFor(jmpid);
2348 if (!seqRefIds.containsKey(jmpid))
2350 jalview.bin.Cache.log.debug("creatign new DseqFor ID");
2351 seqRefIds.put(jmpid, ps);
2355 jalview.bin.Cache.log.debug("reusing DseqFor ID");
2358 // mp.setMappingChoice(mpc);
2364 String setUserColourScheme(jalview.schemes.ColourSchemeI cs,
2365 List<UserColourScheme> userColours, JalviewModel jm)
2368 jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs;
2369 boolean newucs = false;
2370 if (!userColours.contains(ucs))
2372 userColours.add(ucs);
2375 id = "ucs" + userColours.indexOf(ucs);
2378 // actually create the scheme's entry in the XML model
2379 java.awt.Color[] colours = ucs.getColours();
2380 UserColours uc = new UserColours();
2381 // UserColourScheme jbucs = new UserColourScheme();
2382 JalviewUserColours jbucs = new JalviewUserColours();
2384 for (int i = 0; i < colours.length; i++)
2386 Colour col = new Colour();
2387 col.setName(ResidueProperties.aa[i]);
2388 col.setRGB(jalview.util.Format.getHexString(colours[i]));
2389 // jbucs.addColour(col);
2390 jbucs.getColour().add(col);
2392 if (ucs.getLowerCaseColours() != null)
2394 colours = ucs.getLowerCaseColours();
2395 for (int i = 0; i < colours.length; i++)
2397 Colour col = new Colour();
2398 col.setName(ResidueProperties.aa[i].toLowerCase());
2399 col.setRGB(jalview.util.Format.getHexString(colours[i]));
2400 // jbucs.addColour(col);
2401 jbucs.getColour().add(col);
2406 uc.setUserColourScheme(jbucs);
2407 // jm.addUserColours(uc);
2408 jm.getUserColours().add(uc);
2414 jalview.schemes.UserColourScheme getUserColourScheme(
2415 JalviewModel jm, String id)
2417 List<UserColours> uc = jm.getUserColours();
2418 UserColours colours = null;
2420 for (int i = 0; i < uc.length; i++)
2422 if (uc[i].getId().equals(id))
2429 for (UserColours c : uc)
2431 if (c.getId().equals(id))
2438 java.awt.Color[] newColours = new java.awt.Color[24];
2440 for (int i = 0; i < 24; i++)
2442 newColours[i] = new java.awt.Color(Integer.parseInt(
2443 // colours.getUserColourScheme().getColour(i).getRGB(), 16));
2444 colours.getUserColourScheme().getColour().get(i).getRGB(),
2448 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
2451 if (colours.getUserColourScheme().getColour().size()/*Count()*/ > 24)
2453 newColours = new java.awt.Color[23];
2454 for (int i = 0; i < 23; i++)
2456 newColours[i] = new java.awt.Color(Integer.parseInt(
2457 colours.getUserColourScheme().getColour().get(i + 24)
2461 ucs.setLowerCaseColours(newColours);
2468 * contains last error message (if any) encountered by XML loader.
2470 String errorMessage = null;
2473 * flag to control whether the Jalview2XML_V1 parser should be deferred to if
2474 * exceptions are raised during project XML parsing
2476 public boolean attemptversion1parse = false;
2479 * Load a jalview project archive from a jar file
2482 * - HTTP URL or filename
2484 public AlignFrame loadJalviewAlign(final Object file)
2487 jalview.gui.AlignFrame af = null;
2491 // create list to store references for any new Jmol viewers created
2492 newStructureViewers = new Vector<>();
2493 // UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING
2494 // Workaround is to make sure caller implements the JarInputStreamProvider
2496 // so we can re-open the jar input stream for each entry.
2498 jarInputStreamProvider jprovider = createjarInputStreamProvider(file);
2499 af = loadJalviewAlign(jprovider);
2502 af.setMenusForViewport();
2504 } catch (MalformedURLException e)
2506 errorMessage = "Invalid URL format for '" + file + "'";
2512 SwingUtilities.invokeAndWait(new Runnable()
2517 setLoadingFinishedForNewStructureViewers();
2520 } catch (Exception x)
2522 System.err.println("Error loading alignment: " + x.getMessage());
2528 @SuppressWarnings("unused")
2529 private jarInputStreamProvider createjarInputStreamProvider(final Object ofile) throws MalformedURLException {
2531 // BH 2018 allow for bytes already attached to File object
2533 String file = (ofile instanceof File ? ((File) ofile).getCanonicalPath() : ofile.toString());
2534 byte[] bytes = /** @j2sNative ofile._bytes || */
2537 errorMessage = null;
2538 uniqueSetSuffix = null;
2540 viewportsAdded.clear();
2541 frefedSequence = null;
2543 if (file.startsWith("http://")) {
2544 url = new URL(file);
2546 final URL _url = url;
2547 return new jarInputStreamProvider() {
2550 public JarInputStream getJarInputStream() throws IOException {
2551 if (bytes != null) {
2552 // System.out.println("Jalview2XML: opening byte jarInputStream for bytes.length=" + bytes.length);
2553 return new JarInputStream(new ByteArrayInputStream(bytes));
2556 // System.out.println("Jalview2XML: opening url jarInputStream for " + _url);
2557 return new JarInputStream(_url.openStream());
2559 // System.out.println("Jalview2XML: opening file jarInputStream for " + file);
2560 return new JarInputStream(new FileInputStream(file));
2565 public String getFilename() {
2569 } catch (IOException e) {
2570 e.printStackTrace();
2576 * Recover jalview session from a jalview project archive. Caller may
2577 * initialise uniqueSetSuffix, seqRefIds, viewportsAdded and frefedSequence
2578 * themselves. Any null fields will be initialised with default values,
2579 * non-null fields are left alone.
2584 public AlignFrame loadJalviewAlign(final jarInputStreamProvider jprovider)
2586 errorMessage = null;
2587 if (uniqueSetSuffix == null)
2589 uniqueSetSuffix = System.currentTimeMillis() % 100000 + "";
2591 if (seqRefIds == null)
2595 AlignFrame af = null, _af = null;
2596 IdentityHashMap<AlignmentI, AlignmentI> importedDatasets = new IdentityHashMap<>();
2597 Map<String, AlignFrame> gatherToThisFrame = new HashMap<>();
2598 final String file = jprovider.getFilename();
2601 JarInputStream jin = null;
2602 JarEntry jarentry = null;
2607 jin = jprovider.getJarInputStream();
2608 for (int i = 0; i < entryCount; i++)
2610 jarentry = jin.getNextJarEntry();
2613 if (jarentry != null && jarentry.getName().endsWith(".xml"))
2615 JAXBContext jc = JAXBContext
2616 .newInstance("jalview.xml.binding.jalview");
2617 XMLStreamReader streamReader = XMLInputFactory.newInstance()
2618 .createXMLStreamReader(jin);
2619 javax.xml.bind.Unmarshaller um = jc.createUnmarshaller();
2620 JAXBElement<JalviewModel> jbe = um
2621 .unmarshal(streamReader, JalviewModel.class);
2622 JalviewModel object = jbe.getValue();
2624 if (true) // !skipViewport(object))
2626 _af = loadFromObject(object, file, true, jprovider);
2627 if (_af != null && object.getViewport().size() > 0)
2628 // getJalviewModelSequence().getViewportCount() > 0)
2632 // store a reference to the first view
2635 if (_af.getViewport().isGatherViewsHere())
2637 // if this is a gathered view, keep its reference since
2638 // after gathering views, only this frame will remain
2640 gatherToThisFrame.put(_af.getViewport().getSequenceSetId(),
2643 // Save dataset to register mappings once all resolved
2644 importedDatasets.put(
2645 af.getViewport().getAlignment().getDataset(),
2646 af.getViewport().getAlignment().getDataset());
2651 else if (jarentry != null)
2653 // Some other file here.
2656 } while (jarentry != null);
2657 resolveFrefedSequences();
2658 } catch (IOException ex)
2660 ex.printStackTrace();
2661 errorMessage = "Couldn't locate Jalview XML file : " + file;
2663 "Exception whilst loading jalview XML file : " + ex + "\n");
2664 } catch (Exception ex)
2666 System.err.println("Parsing as Jalview Version 2 file failed.");
2667 ex.printStackTrace(System.err);
2668 if (attemptversion1parse)
2670 // Is Version 1 Jar file?
2673 af = new Jalview2XML_V1(raiseGUI).LoadJalviewAlign(jprovider);
2674 } catch (Exception ex2)
2676 System.err.println("Exception whilst loading as jalviewXMLV1:");
2677 ex2.printStackTrace();
2681 if (Desktop.instance != null)
2683 Desktop.instance.stopLoading();
2687 System.out.println("Successfully loaded archive file");
2690 ex.printStackTrace();
2693 "Exception whilst loading jalview XML file : " + ex + "\n");
2694 } catch (OutOfMemoryError e)
2696 // Don't use the OOM Window here
2697 errorMessage = "Out of memory loading jalview XML file";
2698 System.err.println("Out of memory whilst loading jalview XML file");
2699 e.printStackTrace();
2703 * Regather multiple views (with the same sequence set id) to the frame (if
2704 * any) that is flagged as the one to gather to, i.e. convert them to tabbed
2705 * views instead of separate frames. Note this doesn't restore a state where
2706 * some expanded views in turn have tabbed views - the last "first tab" read
2707 * in will play the role of gatherer for all.
2709 for (AlignFrame fr : gatherToThisFrame.values())
2711 Desktop.instance.gatherViews(fr);
2714 restoreSplitFrames();
2715 for (AlignmentI ds : importedDatasets.keySet())
2717 if (ds.getCodonFrames() != null)
2719 StructureSelectionManager
2720 .getStructureSelectionManager(Desktop.instance)
2721 .registerMappings(ds.getCodonFrames());
2724 if (errorMessage != null)
2729 if (Desktop.instance != null)
2731 Desktop.instance.stopLoading();
2738 * Try to reconstruct and display SplitFrame windows, where each contains
2739 * complementary dna and protein alignments. Done by pairing up AlignFrame
2740 * objects (created earlier) which have complementary viewport ids associated.
2742 protected void restoreSplitFrames()
2744 List<SplitFrame> gatherTo = new ArrayList<>();
2745 List<AlignFrame> addedToSplitFrames = new ArrayList<>();
2746 Map<String, AlignFrame> dna = new HashMap<>();
2749 * Identify the DNA alignments
2751 for (Entry<Viewport, AlignFrame> candidate : splitFrameCandidates
2754 AlignFrame af = candidate.getValue();
2755 if (af.getViewport().getAlignment().isNucleotide())
2757 dna.put(candidate.getKey().getId(), af);
2762 * Try to match up the protein complements
2764 for (Entry<Viewport, AlignFrame> candidate : splitFrameCandidates
2767 AlignFrame af = candidate.getValue();
2768 if (!af.getViewport().getAlignment().isNucleotide())
2770 String complementId = candidate.getKey().getComplementId();
2771 // only non-null complements should be in the Map
2772 if (complementId != null && dna.containsKey(complementId))
2774 final AlignFrame dnaFrame = dna.get(complementId);
2775 SplitFrame sf = createSplitFrame(dnaFrame, af);
2776 addedToSplitFrames.add(dnaFrame);
2777 addedToSplitFrames.add(af);
2778 dnaFrame.setMenusForViewport();
2779 af.setMenusForViewport();
2780 if (af.getViewport().isGatherViewsHere())
2789 * Open any that we failed to pair up (which shouldn't happen!) as
2790 * standalone AlignFrame's.
2792 for (Entry<Viewport, AlignFrame> candidate : splitFrameCandidates
2795 AlignFrame af = candidate.getValue();
2796 if (!addedToSplitFrames.contains(af))
2798 Viewport view = candidate.getKey();
2799 Desktop.addInternalFrame(af, view.getTitle(),
2800 safeInt(view.getWidth()), safeInt(view.getHeight()));
2801 af.setMenusForViewport();
2802 System.err.println("Failed to restore view " + view.getTitle()
2803 + " to split frame");
2808 * Gather back into tabbed views as flagged.
2810 for (SplitFrame sf : gatherTo)
2812 Desktop.instance.gatherViews(sf);
2815 splitFrameCandidates.clear();
2819 * Construct and display one SplitFrame holding DNA and protein alignments.
2822 * @param proteinFrame
2825 protected SplitFrame createSplitFrame(AlignFrame dnaFrame,
2826 AlignFrame proteinFrame)
2828 SplitFrame splitFrame = new SplitFrame(dnaFrame, proteinFrame);
2829 String title = MessageManager.getString("label.linked_view_title");
2830 int width = (int) dnaFrame.getBounds().getWidth();
2831 int height = (int) (dnaFrame.getBounds().getHeight()
2832 + proteinFrame.getBounds().getHeight() + 50);
2835 * SplitFrame location is saved to both enclosed frames
2837 splitFrame.setLocation(dnaFrame.getX(), dnaFrame.getY());
2838 Desktop.addInternalFrame(splitFrame, title, width, height);
2841 * And compute cDNA consensus (couldn't do earlier with consensus as
2842 * mappings were not yet present)
2844 proteinFrame.getViewport().alignmentChanged(proteinFrame.alignPanel);
2850 * check errorMessage for a valid error message and raise an error box in the
2851 * GUI or write the current errorMessage to stderr and then clear the error
2854 protected void reportErrors()
2856 reportErrors(false);
2859 protected void reportErrors(final boolean saving)
2861 if (errorMessage != null)
2863 final String finalErrorMessage = errorMessage;
2866 javax.swing.SwingUtilities.invokeLater(new Runnable()
2871 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
2873 "Error " + (saving ? "saving" : "loading")
2875 JvOptionPane.WARNING_MESSAGE);
2881 System.err.println("Problem loading Jalview file: " + errorMessage);
2884 errorMessage = null;
2887 Map<String, String> alreadyLoadedPDB = new HashMap<>();
2890 * when set, local views will be updated from view stored in JalviewXML
2891 * Currently (28th Sep 2008) things will go horribly wrong in vamsas document
2892 * sync if this is set to true.
2894 private final boolean updateLocalViews = false;
2897 * Returns the path to a temporary file holding the PDB file for the given PDB
2898 * id. The first time of asking, searches for a file of that name in the
2899 * Jalview project jar, and copies it to a new temporary file. Any repeat
2900 * requests just return the path to the file previously created.
2906 String loadPDBFile(jarInputStreamProvider jprovider, String pdbId,
2909 if (alreadyLoadedPDB.containsKey(pdbId))
2911 return alreadyLoadedPDB.get(pdbId).toString();
2914 String tempFile = copyJarEntry(jprovider, pdbId, "jalview_pdb",
2916 if (tempFile != null)
2918 alreadyLoadedPDB.put(pdbId, tempFile);
2924 * Copies the jar entry of given name to a new temporary file and returns the
2925 * path to the file, or null if the entry is not found.
2928 * @param jarEntryName
2930 * a prefix for the temporary file name, must be at least three
2933 * null or original file - so new file can be given the same suffix
2937 protected String copyJarEntry(jarInputStreamProvider jprovider,
2938 String jarEntryName, String prefix, String origFile)
2940 BufferedReader in = null;
2941 PrintWriter out = null;
2942 String suffix = ".tmp";
2943 if (origFile == null)
2945 origFile = jarEntryName;
2947 int sfpos = origFile.lastIndexOf(".");
2948 if (sfpos > -1 && sfpos < (origFile.length() - 3))
2950 suffix = "." + origFile.substring(sfpos + 1);
2954 JarInputStream jin = jprovider.getJarInputStream();
2956 * if (jprovider.startsWith("http://")) { jin = new JarInputStream(new
2957 * URL(jprovider).openStream()); } else { jin = new JarInputStream(new
2958 * FileInputStream(jprovider)); }
2961 JarEntry entry = null;
2964 entry = jin.getNextJarEntry();
2965 } while (entry != null && !entry.getName().equals(jarEntryName));
2968 in = new BufferedReader(new InputStreamReader(jin, UTF_8));
2969 File outFile = File.createTempFile(prefix, suffix);
2970 outFile.deleteOnExit();
2971 out = new PrintWriter(new FileOutputStream(outFile));
2974 while ((data = in.readLine()) != null)
2979 String t = outFile.getAbsolutePath();
2984 warn("Couldn't find entry in Jalview Jar for " + jarEntryName);
2986 } catch (Exception ex)
2988 ex.printStackTrace();
2996 } catch (IOException e)
3010 private class JvAnnotRow
3012 public JvAnnotRow(int i, AlignmentAnnotation jaa)
3019 * persisted version of annotation row from which to take vis properties
3021 public jalview.datamodel.AlignmentAnnotation template;
3024 * original position of the annotation row in the alignment
3030 * Load alignment frame from jalview XML DOM object
3032 * @param jalviewModel
3035 * filename source string
3036 * @param loadTreesAndStructures
3037 * when false only create Viewport
3039 * data source provider
3040 * @return alignment frame created from view stored in DOM
3042 AlignFrame loadFromObject(JalviewModel jalviewModel, String file,
3043 boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
3045 SequenceSet vamsasSet = jalviewModel.getVamsasModel().getSequenceSet().get(0);
3046 List<Sequence> vamsasSeqs = vamsasSet.getSequence();
3048 // JalviewModelSequence jms = object.getJalviewModelSequence();
3050 // Viewport view = (jms.getViewportCount() > 0) ? jms.getViewport(0)
3052 Viewport view = (jalviewModel.getViewport().size() > 0)
3053 ? jalviewModel.getViewport().get(0)
3056 // ////////////////////////////////
3059 List<SequenceI> hiddenSeqs = null;
3061 List<SequenceI> tmpseqs = new ArrayList<>();
3063 boolean multipleView = false;
3064 SequenceI referenceseqForView = null;
3065 // JSeq[] jseqs = object.getJalviewModelSequence().getJSeq();
3066 List<JSeq> jseqs = jalviewModel.getJSeq();
3067 int vi = 0; // counter in vamsasSeq array
3068 for (int i = 0; i < jseqs.size(); i++)
3070 JSeq jseq = jseqs.get(i);
3071 String seqId = jseq.getId();
3073 SequenceI tmpSeq = seqRefIds.get(seqId);
3076 if (!incompleteSeqs.containsKey(seqId))
3078 // may not need this check, but keep it for at least 2.9,1 release
3079 if (tmpSeq.getStart() != jseq.getStart()
3080 || tmpSeq.getEnd() != jseq.getEnd())
3083 "Warning JAL-2154 regression: updating start/end for sequence "
3084 + tmpSeq.toString() + " to " + jseq);
3089 incompleteSeqs.remove(seqId);
3091 if (vamsasSeqs.size() > vi
3092 && vamsasSeqs.get(vi).getId().equals(seqId))
3094 // most likely we are reading a dataset XML document so
3095 // update from vamsasSeq section of XML for this sequence
3096 tmpSeq.setName(vamsasSeqs.get(vi).getName());
3097 tmpSeq.setDescription(vamsasSeqs.get(vi).getDescription());
3098 tmpSeq.setSequence(vamsasSeqs.get(vi).getSequence());
3103 // reading multiple views, so vamsasSeq set is a subset of JSeq
3104 multipleView = true;
3106 tmpSeq.setStart(jseq.getStart());
3107 tmpSeq.setEnd(jseq.getEnd());
3108 tmpseqs.add(tmpSeq);
3112 Sequence vamsasSeq = vamsasSeqs.get(vi);
3113 tmpSeq = new jalview.datamodel.Sequence(vamsasSeq.getName(),
3114 vamsasSeq.getSequence());
3115 tmpSeq.setDescription(vamsasSeq.getDescription());
3116 tmpSeq.setStart(jseq.getStart());
3117 tmpSeq.setEnd(jseq.getEnd());
3118 tmpSeq.setVamsasId(uniqueSetSuffix + seqId);
3119 seqRefIds.put(vamsasSeq.getId(), tmpSeq);
3120 tmpseqs.add(tmpSeq);
3124 if (safeBoolean(jseq.isViewreference()))
3126 referenceseqForView = tmpseqs.get(tmpseqs.size() - 1);
3129 if (jseq.isHidden() != null && jseq.isHidden().booleanValue())
3131 if (hiddenSeqs == null)
3133 hiddenSeqs = new ArrayList<>();
3136 hiddenSeqs.add(tmpSeq);
3141 // Create the alignment object from the sequence set
3142 // ///////////////////////////////
3143 SequenceI[] orderedSeqs = tmpseqs
3144 .toArray(new SequenceI[tmpseqs.size()]);
3146 AlignmentI al = null;
3147 // so we must create or recover the dataset alignment before going further
3148 // ///////////////////////////////
3149 if (vamsasSet.getDatasetId() == null || vamsasSet.getDatasetId() == "")
3151 // older jalview projects do not have a dataset - so creat alignment and
3153 al = new Alignment(orderedSeqs);
3154 al.setDataset(null);
3158 boolean isdsal = jalviewModel.getViewport().isEmpty();
3161 // we are importing a dataset record, so
3162 // recover reference to an alignment already materialsed as dataset
3163 al = getDatasetFor(vamsasSet.getDatasetId());
3167 // materialse the alignment
3168 al = new Alignment(orderedSeqs);
3172 addDatasetRef(vamsasSet.getDatasetId(), al);
3175 // finally, verify all data in vamsasSet is actually present in al
3176 // passing on flag indicating if it is actually a stored dataset
3177 recoverDatasetFor(vamsasSet, al, isdsal);
3180 if (referenceseqForView != null)
3182 al.setSeqrep(referenceseqForView);
3184 // / Add the alignment properties
3185 for (int i = 0; i < vamsasSet.getSequenceSetProperties().size(); i++)
3187 SequenceSetProperties ssp = vamsasSet.getSequenceSetProperties()
3189 al.setProperty(ssp.getKey(), ssp.getValue());
3192 // ///////////////////////////////
3194 Hashtable pdbloaded = new Hashtable(); // TODO nothing writes to this??
3197 // load sequence features, database references and any associated PDB
3198 // structures for the alignment
3200 // prior to 2.10, this part would only be executed the first time a
3201 // sequence was encountered, but not afterwards.
3202 // now, for 2.10 projects, this is also done if the xml doc includes
3203 // dataset sequences not actually present in any particular view.
3205 for (int i = 0; i < vamsasSeqs.size(); i++)
3207 JSeq jseq = jseqs.get(i);
3208 if (jseq.getFeatures().size() > 0)
3210 List<Feature> features = jseq.getFeatures();
3211 for (int f = 0; f < features.size(); f++)
3213 Feature feat = features.get(f);
3214 SequenceFeature sf = new SequenceFeature(feat.getType(),
3215 feat.getDescription(), feat.getBegin(), feat.getEnd(),
3216 safeFloat(feat.getScore()), feat.getFeatureGroup());
3217 sf.setStatus(feat.getStatus());
3220 * load any feature attributes - include map-valued attributes
3222 Map<String, Map<String, String>> mapAttributes = new HashMap<>();
3223 for (int od = 0; od < feat.getOtherData().size(); od++)
3225 OtherData keyValue = feat.getOtherData().get(od);
3226 String attributeName = keyValue.getKey();
3227 String attributeValue = keyValue.getValue();
3228 if (attributeName.startsWith("LINK"))
3230 sf.addLink(attributeValue);
3234 String subAttribute = keyValue.getKey2();
3235 if (subAttribute == null)
3237 // simple string-valued attribute
3238 sf.setValue(attributeName, attributeValue);
3242 // attribute 'key' has sub-attribute 'key2'
3243 if (!mapAttributes.containsKey(attributeName))
3245 mapAttributes.put(attributeName, new HashMap<>());
3247 mapAttributes.get(attributeName).put(subAttribute,
3252 for (Entry<String, Map<String, String>> mapAttribute : mapAttributes
3255 sf.setValue(mapAttribute.getKey(), mapAttribute.getValue());
3258 // adds feature to datasequence's feature set (since Jalview 2.10)
3259 al.getSequenceAt(i).addSequenceFeature(sf);
3262 if (vamsasSeqs.get(i).getDBRef().size() > 0)
3264 // adds dbrefs to datasequence's set (since Jalview 2.10)
3266 al.getSequenceAt(i).getDatasetSequence() == null
3267 ? al.getSequenceAt(i)
3268 : al.getSequenceAt(i).getDatasetSequence(),
3271 if (jseq.getPdbids().size() > 0)
3273 List<Pdbids> ids = jseq.getPdbids();
3274 for (int p = 0; p < ids.size(); p++)
3276 Pdbids pdbid = ids.get(p);
3277 jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
3278 entry.setId(pdbid.getId());
3279 if (pdbid.getType() != null)
3281 if (PDBEntry.Type.getType(pdbid.getType()) != null)
3283 entry.setType(PDBEntry.Type.getType(pdbid.getType()));
3287 entry.setType(PDBEntry.Type.FILE);
3290 // jprovider is null when executing 'New View'
3291 if (pdbid.getFile() != null && jprovider != null)
3293 if (!pdbloaded.containsKey(pdbid.getFile()))
3295 entry.setFile(loadPDBFile(jprovider, pdbid.getId(),
3300 entry.setFile(pdbloaded.get(pdbid.getId()).toString());
3304 if (pdbid.getPdbentryItem() != null)
3306 for (PdbentryItem item : pdbid.getPdbentryItem())
3308 for (Property pr : item.getProperty())
3310 entry.setProperty(pr.getName(), pr.getValue());
3315 for (Property prop : pdbid.getProperty())
3317 entry.setProperty(prop.getName(), prop.getValue());
3319 StructureSelectionManager
3320 .getStructureSelectionManager(Desktop.instance)
3321 .registerPDBEntry(entry);
3322 // adds PDBEntry to datasequence's set (since Jalview 2.10)
3323 if (al.getSequenceAt(i).getDatasetSequence() != null)
3325 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
3329 al.getSequenceAt(i).addPDBId(entry);
3334 } // end !multipleview
3336 // ///////////////////////////////
3337 // LOAD SEQUENCE MAPPINGS
3339 if (vamsasSet.getAlcodonFrame().size() > 0)
3341 // TODO Potentially this should only be done once for all views of an
3343 List<AlcodonFrame> alc = vamsasSet.getAlcodonFrame();
3344 for (int i = 0; i < alc.size(); i++)
3346 AlignedCodonFrame cf = new AlignedCodonFrame();
3347 if (alc.get(i).getAlcodMap().size() > 0)
3349 List<AlcodMap> maps = alc.get(i).getAlcodMap();
3350 for (int m = 0; m < maps.size(); m++)
3352 AlcodMap map = maps.get(m);
3353 SequenceI dnaseq = seqRefIds.get(map.getDnasq());
3355 jalview.datamodel.Mapping mapping = null;
3356 // attach to dna sequence reference.
3357 if (map.getMapping() != null)
3359 mapping = addMapping(map.getMapping());
3360 if (dnaseq != null && mapping.getTo() != null)
3362 cf.addMap(dnaseq, mapping.getTo(), mapping.getMap());
3368 newAlcodMapRef(map.getDnasq(), cf, mapping));
3372 al.addCodonFrame(cf);
3377 // ////////////////////////////////
3379 List<JvAnnotRow> autoAlan = new ArrayList<>();
3382 * store any annotations which forward reference a group's ID
3384 Map<String, List<AlignmentAnnotation>> groupAnnotRefs = new Hashtable<>();
3386 if (vamsasSet.getAnnotation().size()/*Count()*/ > 0)
3388 List<Annotation> an = vamsasSet.getAnnotation();
3390 for (int i = 0; i < an.size(); i++)
3392 Annotation annotation = an.get(i);
3395 * test if annotation is automatically calculated for this view only
3397 boolean autoForView = false;
3398 if (annotation.getLabel().equals("Quality")
3399 || annotation.getLabel().equals("Conservation")
3400 || annotation.getLabel().equals("Consensus"))
3402 // Kludge for pre 2.5 projects which lacked the autocalculated flag
3404 // JAXB has no has() test; schema defaults value to false
3405 // if (!annotation.hasAutoCalculated())
3407 // annotation.setAutoCalculated(true);
3410 if (autoForView || annotation.isAutoCalculated())
3412 // remove ID - we don't recover annotation from other views for
3413 // view-specific annotation
3414 annotation.setId(null);
3417 // set visibility for other annotation in this view
3418 String annotationId = annotation.getId();
3419 if (annotationId != null && annotationIds.containsKey(annotationId))
3421 AlignmentAnnotation jda = annotationIds.get(annotationId);
3422 // in principle Visible should always be true for annotation displayed
3423 // in multiple views
3424 if (annotation.isVisible() != null)
3426 jda.visible = annotation.isVisible();
3429 al.addAnnotation(jda);
3433 // Construct new annotation from model.
3434 List<AnnotationElement> ae = annotation.getAnnotationElement();
3435 jalview.datamodel.Annotation[] anot = null;
3436 java.awt.Color firstColour = null;
3438 if (!annotation.isScoreOnly())
3440 anot = new jalview.datamodel.Annotation[al.getWidth()];
3441 for (int aa = 0; aa < ae.size() && aa < anot.length; aa++)
3443 AnnotationElement annElement = ae.get(aa);
3444 anpos = annElement.getPosition();
3446 if (anpos >= anot.length)
3451 float value = safeFloat(annElement.getValue());
3452 anot[anpos] = new jalview.datamodel.Annotation(
3453 annElement.getDisplayCharacter(),
3454 annElement.getDescription(),
3455 (annElement.getSecondaryStructure() == null
3456 || annElement.getSecondaryStructure()
3460 .getSecondaryStructure()
3463 anot[anpos].colour = new Color(safeInt(annElement.getColour()));
3464 if (firstColour == null)
3466 firstColour = anot[anpos].colour;
3470 jalview.datamodel.AlignmentAnnotation jaa = null;
3472 if (annotation.isGraph())
3474 float llim = 0, hlim = 0;
3475 // if (autoForView || an[i].isAutoCalculated()) {
3478 jaa = new jalview.datamodel.AlignmentAnnotation(
3479 annotation.getLabel(), annotation.getDescription(), anot,
3480 llim, hlim, safeInt(annotation.getGraphType()));
3482 jaa.graphGroup = safeInt(annotation.getGraphGroup());
3483 jaa._linecolour = firstColour;
3484 if (annotation.getThresholdLine() != null)
3486 jaa.setThreshold(new jalview.datamodel.GraphLine(
3487 safeFloat(annotation.getThresholdLine().getValue()),
3488 annotation.getThresholdLine().getLabel(),
3489 new java.awt.Color(safeInt(
3490 annotation.getThresholdLine().getColour()))));
3492 if (autoForView || annotation.isAutoCalculated())
3494 // Hardwire the symbol display line to ensure that labels for
3495 // histograms are displayed
3501 jaa = new jalview.datamodel.AlignmentAnnotation(
3502 annotation.getLabel(), annotation.getDescription(), anot);
3503 jaa._linecolour = firstColour;
3505 // register new annotation
3506 if (annotation.getId() != null)
3508 annotationIds.put(annotation.getId(), jaa);
3509 jaa.annotationId = annotation.getId();
3511 // recover sequence association
3512 String sequenceRef = annotation.getSequenceRef();
3513 if (sequenceRef != null)
3515 // from 2.9 sequenceRef is to sequence id (JAL-1781)
3516 SequenceI sequence = seqRefIds.get(sequenceRef);
3517 if (sequence == null)
3519 // in pre-2.9 projects sequence ref is to sequence name
3520 sequence = al.findName(sequenceRef);
3522 if (sequence != null)
3524 jaa.createSequenceMapping(sequence, 1, true);
3525 sequence.addAlignmentAnnotation(jaa);
3528 // and make a note of any group association
3529 if (annotation.getGroupRef() != null
3530 && annotation.getGroupRef().length() > 0)
3532 List<jalview.datamodel.AlignmentAnnotation> aal = groupAnnotRefs
3533 .get(annotation.getGroupRef());
3536 aal = new ArrayList<>();
3537 groupAnnotRefs.put(annotation.getGroupRef(), aal);
3542 if (annotation.getScore() != null)
3544 jaa.setScore(annotation.getScore().doubleValue());
3546 if (annotation.isVisible() != null)
3548 jaa.visible = annotation.isVisible().booleanValue();
3551 if (annotation.isCentreColLabels() != null)
3553 jaa.centreColLabels = annotation.isCentreColLabels()
3557 if (annotation.isScaleColLabels() != null)
3559 jaa.scaleColLabel = annotation.isScaleColLabels().booleanValue();
3561 if (annotation.isAutoCalculated())
3563 // newer files have an 'autoCalculated' flag and store calculation
3564 // state in viewport properties
3565 jaa.autoCalculated = true; // means annotation will be marked for
3566 // update at end of load.
3568 if (annotation.getGraphHeight() != null)
3570 jaa.graphHeight = annotation.getGraphHeight().intValue();
3572 jaa.belowAlignment = annotation.isBelowAlignment();
3573 jaa.setCalcId(annotation.getCalcId());
3574 if (annotation.getProperty().size() > 0)
3576 for (Annotation.Property prop : annotation
3579 jaa.setProperty(prop.getName(), prop.getValue());
3582 if (jaa.autoCalculated)
3584 autoAlan.add(new JvAnnotRow(i, jaa));
3587 // if (!autoForView)
3589 // add autocalculated group annotation and any user created annotation
3591 al.addAnnotation(jaa);
3595 // ///////////////////////
3597 // Create alignment markup and styles for this view
3598 if (jalviewModel.getJGroup().size() > 0)
3600 List<JGroup> groups = jalviewModel.getJGroup();
3601 boolean addAnnotSchemeGroup = false;
3602 for (int i = 0; i < groups.size(); i++)
3604 JGroup jGroup = groups.get(i);
3605 ColourSchemeI cs = null;
3606 if (jGroup.getColour() != null)
3608 if (jGroup.getColour().startsWith("ucs"))
3610 cs = getUserColourScheme(jalviewModel, jGroup.getColour());
3612 else if (jGroup.getColour().equals("AnnotationColourGradient")
3613 && jGroup.getAnnotationColours() != null)
3615 addAnnotSchemeGroup = true;
3619 cs = ColourSchemeProperty.getColourScheme(al,
3620 jGroup.getColour());
3623 int pidThreshold = safeInt(jGroup.getPidThreshold());
3625 Vector<SequenceI> seqs = new Vector<>();
3627 for (int s = 0; s < jGroup.getSeq().size(); s++)
3629 String seqId = jGroup.getSeq().get(s);
3630 SequenceI ts = seqRefIds.get(seqId);
3634 seqs.addElement(ts);
3638 if (seqs.size() < 1)
3643 SequenceGroup sg = new SequenceGroup(seqs, jGroup.getName(), cs,
3644 safeBoolean(jGroup.isDisplayBoxes()),
3645 safeBoolean(jGroup.isDisplayText()),
3646 safeBoolean(jGroup.isColourText()),
3647 safeInt(jGroup.getStart()), safeInt(jGroup.getEnd()));
3648 sg.getGroupColourScheme().setThreshold(pidThreshold, true);
3649 sg.getGroupColourScheme()
3650 .setConservationInc(safeInt(jGroup.getConsThreshold()));
3651 sg.setOutlineColour(new Color(safeInt(jGroup.getOutlineColour())));
3653 sg.textColour = new Color(safeInt(jGroup.getTextCol1()));
3654 sg.textColour2 = new Color(safeInt(jGroup.getTextCol2()));
3655 sg.setShowNonconserved(safeBoolean(jGroup.isShowUnconserved()));
3656 sg.thresholdTextColour = safeInt(jGroup.getTextColThreshold());
3657 // attributes with a default in the schema are never null
3658 sg.setShowConsensusHistogram(jGroup.isShowConsensusHistogram());
3659 sg.setshowSequenceLogo(jGroup.isShowSequenceLogo());
3660 sg.setNormaliseSequenceLogo(jGroup.isNormaliseSequenceLogo());
3661 sg.setIgnoreGapsConsensus(jGroup.isIgnoreGapsinConsensus());
3662 if (jGroup.getConsThreshold() != null
3663 && jGroup.getConsThreshold().intValue() != 0)
3665 Conservation c = new Conservation("All", sg.getSequences(null), 0,
3668 c.verdict(false, 25);
3669 sg.cs.setConservation(c);
3672 if (jGroup.getId() != null && groupAnnotRefs.size() > 0)
3674 // re-instate unique group/annotation row reference
3675 List<AlignmentAnnotation> jaal = groupAnnotRefs
3676 .get(jGroup.getId());
3679 for (AlignmentAnnotation jaa : jaal)
3682 if (jaa.autoCalculated)
3684 // match up and try to set group autocalc alignment row for this
3686 if (jaa.label.startsWith("Consensus for "))
3688 sg.setConsensus(jaa);
3690 // match up and try to set group autocalc alignment row for this
3692 if (jaa.label.startsWith("Conservation for "))
3694 sg.setConservationRow(jaa);
3701 if (addAnnotSchemeGroup)
3703 // reconstruct the annotation colourscheme
3704 sg.setColourScheme(constructAnnotationColour(
3705 jGroup.getAnnotationColours(), null, al, jalviewModel, false));
3711 // only dataset in this model, so just return.
3714 // ///////////////////////////////
3717 // If we just load in the same jar file again, the sequenceSetId
3718 // will be the same, and we end up with multiple references
3719 // to the same sequenceSet. We must modify this id on load
3720 // so that each load of the file gives a unique id
3721 String uniqueSeqSetId = view.getSequenceSetId() + uniqueSetSuffix;
3722 String viewId = (view.getId() == null ? null
3723 : view.getId() + uniqueSetSuffix);
3724 AlignFrame af = null;
3725 AlignViewport av = null;
3726 // now check to see if we really need to create a new viewport.
3727 if (multipleView && viewportsAdded.size() == 0)
3729 // We recovered an alignment for which a viewport already exists.
3730 // TODO: fix up any settings necessary for overlaying stored state onto
3731 // state recovered from another document. (may not be necessary).
3732 // we may need a binding from a viewport in memory to one recovered from
3734 // and then recover its containing af to allow the settings to be applied.
3735 // TODO: fix for vamsas demo
3737 "About to recover a viewport for existing alignment: Sequence set ID is "
3739 Object seqsetobj = retrieveExistingObj(uniqueSeqSetId);
3740 if (seqsetobj != null)
3742 if (seqsetobj instanceof String)
3744 uniqueSeqSetId = (String) seqsetobj;
3746 "Recovered extant sequence set ID mapping for ID : New Sequence set ID is "
3752 "Warning : Collision between sequence set ID string and existing jalview object mapping.");
3758 * indicate that annotation colours are applied across all groups (pre
3759 * Jalview 2.8.1 behaviour)
3761 boolean doGroupAnnColour = Jalview2XML.isVersionStringLaterThan("2.8.1",
3762 jalviewModel.getVersion());
3764 AlignmentPanel ap = null;
3765 boolean isnewview = true;
3768 // Check to see if this alignment already has a view id == viewId
3769 jalview.gui.AlignmentPanel views[] = Desktop
3770 .getAlignmentPanels(uniqueSeqSetId);
3771 if (views != null && views.length > 0)
3773 for (int v = 0; v < views.length; v++)
3775 if (views[v].av.getViewId().equalsIgnoreCase(viewId))
3777 // recover the existing alignpanel, alignframe, viewport
3778 af = views[v].alignFrame;
3781 // TODO: could even skip resetting view settings if we don't want to
3782 // change the local settings from other jalview processes
3791 af = loadViewport(file, jseqs, hiddenSeqs, al, jalviewModel, view,
3792 uniqueSeqSetId, viewId, autoAlan);
3793 av = af.getViewport();
3798 * Load any trees, PDB structures and viewers
3800 * Not done if flag is false (when this method is used for New View)
3802 if (loadTreesAndStructures)
3804 loadTrees(jalviewModel, view, af, av, ap);
3805 loadPDBStructures(jprovider, jseqs, af, ap);
3806 loadRnaViewers(jprovider, jseqs, ap);
3808 // and finally return.
3813 * Instantiate and link any saved RNA (Varna) viewers. The state of the Varna
3814 * panel is restored from separate jar entries, two (gapped and trimmed) per
3815 * sequence and secondary structure.
3817 * Currently each viewer shows just one sequence and structure (gapped and
3818 * trimmed), however this method is designed to support multiple sequences or
3819 * structures in viewers if wanted in future.
3825 private void loadRnaViewers(jarInputStreamProvider jprovider,
3826 List<JSeq> jseqs, AlignmentPanel ap)
3829 * scan the sequences for references to viewers; create each one the first
3830 * time it is referenced, add Rna models to existing viewers
3832 for (JSeq jseq : jseqs)
3834 for (int i = 0; i < jseq.getRnaViewer().size(); i++)
3836 RnaViewer viewer = jseq.getRnaViewer().get(i);
3837 AppVarna appVarna = findOrCreateVarnaViewer(viewer, uniqueSetSuffix,
3840 for (int j = 0; j < viewer.getSecondaryStructure().size(); j++)
3842 SecondaryStructure ss = viewer.getSecondaryStructure().get(j);
3843 SequenceI seq = seqRefIds.get(jseq.getId());
3844 AlignmentAnnotation ann = this.annotationIds
3845 .get(ss.getAnnotationId());
3848 * add the structure to the Varna display (with session state copied
3849 * from the jar to a temporary file)
3851 boolean gapped = safeBoolean(ss.isGapped());
3852 String rnaTitle = ss.getTitle();
3853 String sessionState = ss.getViewerState();
3854 String tempStateFile = copyJarEntry(jprovider, sessionState,
3856 RnaModel rna = new RnaModel(rnaTitle, ann, seq, null, gapped);
3857 appVarna.addModelSession(rna, rnaTitle, tempStateFile);
3859 appVarna.setInitialSelection(safeInt(viewer.getSelectedRna()));
3865 * Locate and return an already instantiated matching AppVarna, or create one
3869 * @param viewIdSuffix
3873 protected AppVarna findOrCreateVarnaViewer(RnaViewer viewer,
3874 String viewIdSuffix, AlignmentPanel ap)
3877 * on each load a suffix is appended to the saved viewId, to avoid conflicts
3878 * if load is repeated
3880 String postLoadId = viewer.getViewId() + viewIdSuffix;
3881 for (JInternalFrame frame : getAllFrames())
3883 if (frame instanceof AppVarna)
3885 AppVarna varna = (AppVarna) frame;
3886 if (postLoadId.equals(varna.getViewId()))
3888 // this viewer is already instantiated
3889 // could in future here add ap as another 'parent' of the
3890 // AppVarna window; currently just 1-to-many
3897 * viewer not found - make it
3899 RnaViewerModel model = new RnaViewerModel(postLoadId, viewer.getTitle(),
3900 safeInt(viewer.getXpos()), safeInt(viewer.getYpos()),
3901 safeInt(viewer.getWidth()), safeInt(viewer.getHeight()),
3902 safeInt(viewer.getDividerLocation()));
3903 AppVarna varna = new AppVarna(model, ap);
3909 * Load any saved trees
3917 protected void loadTrees(JalviewModel jm, Viewport view,
3918 AlignFrame af, AlignViewport av, AlignmentPanel ap)
3920 // TODO result of automated refactoring - are all these parameters needed?
3923 for (int t = 0; t < jm.getTree().size(); t++)
3926 Tree tree = jm.getTree().get(t);
3928 TreePanel tp = (TreePanel) retrieveExistingObj(tree.getId());
3931 tp = af.showNewickTree(new NewickFile(tree.getNewick()),
3932 tree.getTitle(), safeInt(tree.getWidth()),
3933 safeInt(tree.getHeight()), safeInt(tree.getXpos()),
3934 safeInt(tree.getYpos()));
3935 if (tree.getId() != null)
3937 // perhaps bind the tree id to something ?
3942 // update local tree attributes ?
3943 // TODO: should check if tp has been manipulated by user - if so its
3944 // settings shouldn't be modified
3945 tp.setTitle(tree.getTitle());
3946 tp.setBounds(new Rectangle(safeInt(tree.getXpos()),
3947 safeInt(tree.getYpos()), safeInt(tree.getWidth()),
3948 safeInt(tree.getHeight())));
3949 tp.setViewport(av); // af.viewport;
3950 // TODO: verify 'associate with all views' works still
3951 tp.getTreeCanvas().setViewport(av); // af.viewport;
3952 tp.getTreeCanvas().setAssociatedPanel(ap); // af.alignPanel;
3957 warn("There was a problem recovering stored Newick tree: \n"
3958 + tree.getNewick());
3962 tp.fitToWindow.setState(safeBoolean(tree.isFitToWindow()));
3963 tp.fitToWindow_actionPerformed(null);
3965 if (tree.getFontName() != null)
3968 new Font(tree.getFontName(), safeInt(tree.getFontStyle()),
3969 safeInt(tree.getFontSize())));
3974 new Font(view.getFontName(), safeInt(view.getFontStyle()),
3975 safeInt(view.getFontSize())));
3978 tp.showPlaceholders(safeBoolean(tree.isMarkUnlinked()));
3979 tp.showBootstrap(safeBoolean(tree.isShowBootstrap()));
3980 tp.showDistances(safeBoolean(tree.isShowDistances()));
3982 tp.getTreeCanvas().setThreshold(safeFloat(tree.getThreshold()));
3984 if (safeBoolean(tree.isCurrentTree()))
3986 af.getViewport().setCurrentTree(tp.getTree());
3990 } catch (Exception ex)
3992 ex.printStackTrace();
3997 * Load and link any saved structure viewers.
4004 protected void loadPDBStructures(jarInputStreamProvider jprovider,
4005 List<JSeq> jseqs, AlignFrame af, AlignmentPanel ap)
4008 * Run through all PDB ids on the alignment, and collect mappings between
4009 * distinct view ids and all sequences referring to that view.
4011 Map<String, StructureViewerModel> structureViewers = new LinkedHashMap<>();
4013 for (int i = 0; i < jseqs.size(); i++)
4015 JSeq jseq = jseqs.get(i);
4016 if (jseq.getPdbids().size() > 0)
4018 List<Pdbids> ids = jseq.getPdbids();
4019 for (int p = 0; p < ids.size(); p++)
4021 Pdbids pdbid = ids.get(p);
4022 final int structureStateCount = pdbid.getStructureState().size();
4023 for (int s = 0; s < structureStateCount; s++)
4025 // check to see if we haven't already created this structure view
4026 final StructureState structureState = pdbid
4027 .getStructureState().get(s);
4028 String sviewid = (structureState.getViewId() == null) ? null
4029 : structureState.getViewId() + uniqueSetSuffix;
4030 jalview.datamodel.PDBEntry jpdb = new jalview.datamodel.PDBEntry();
4031 // Originally : pdbid.getFile()
4032 // : TODO: verify external PDB file recovery still works in normal
4033 // jalview project load
4035 loadPDBFile(jprovider, pdbid.getId(), pdbid.getFile()));
4036 jpdb.setId(pdbid.getId());
4038 int x = safeInt(structureState.getXpos());
4039 int y = safeInt(structureState.getYpos());
4040 int width = safeInt(structureState.getWidth());
4041 int height = safeInt(structureState.getHeight());
4043 // Probably don't need to do this anymore...
4044 // Desktop.desktop.getComponentAt(x, y);
4045 // TODO: NOW: check that this recovers the PDB file correctly.
4046 String pdbFile = loadPDBFile(jprovider, pdbid.getId(),
4048 jalview.datamodel.SequenceI seq = seqRefIds
4049 .get(jseq.getId() + "");
4050 if (sviewid == null)
4052 sviewid = "_jalview_pre2_4_" + x + "," + y + "," + width + ","
4055 if (!structureViewers.containsKey(sviewid))
4057 structureViewers.put(sviewid,
4058 new StructureViewerModel(x, y, width, height, false,
4059 false, true, structureState.getViewId(),
4060 structureState.getType()));
4061 // Legacy pre-2.7 conversion JAL-823 :
4062 // do not assume any view has to be linked for colour by
4066 // assemble String[] { pdb files }, String[] { id for each
4067 // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
4068 // seqs_file 2}, boolean[] {
4069 // linkAlignPanel,superposeWithAlignpanel}} from hash
4070 StructureViewerModel jmoldat = structureViewers.get(sviewid);
4071 jmoldat.setAlignWithPanel(jmoldat.isAlignWithPanel()
4072 || structureState.isAlignwithAlignPanel());
4075 * Default colour by linked panel to false if not specified (e.g.
4076 * for pre-2.7 projects)
4078 boolean colourWithAlignPanel = jmoldat.isColourWithAlignPanel();
4079 colourWithAlignPanel |= structureState.isColourwithAlignPanel();
4080 jmoldat.setColourWithAlignPanel(colourWithAlignPanel);
4083 * Default colour by viewer to true if not specified (e.g. for
4086 boolean colourByViewer = jmoldat.isColourByViewer();
4087 colourByViewer &= structureState.isColourByJmol();
4088 jmoldat.setColourByViewer(colourByViewer);
4090 if (jmoldat.getStateData().length() < structureState
4091 .getValue()/*Content()*/.length())
4093 jmoldat.setStateData(structureState.getValue());// Content());
4095 if (pdbid.getFile() != null)
4097 File mapkey = new File(pdbid.getFile());
4098 StructureData seqstrmaps = jmoldat.getFileData().get(mapkey);
4099 if (seqstrmaps == null)
4101 jmoldat.getFileData().put(mapkey,
4102 seqstrmaps = jmoldat.new StructureData(pdbFile,
4105 if (!seqstrmaps.getSeqList().contains(seq))
4107 seqstrmaps.getSeqList().add(seq);
4113 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");
4120 // Instantiate the associated structure views
4121 for (Entry<String, StructureViewerModel> entry : structureViewers
4126 createOrLinkStructureViewer(entry, af, ap, jprovider);
4127 } catch (Exception e)
4130 "Error loading structure viewer: " + e.getMessage());
4131 // failed - try the next one
4143 protected void createOrLinkStructureViewer(
4144 Entry<String, StructureViewerModel> viewerData, AlignFrame af,
4145 AlignmentPanel ap, jarInputStreamProvider jprovider)
4147 final StructureViewerModel stateData = viewerData.getValue();
4150 * Search for any viewer windows already open from other alignment views
4151 * that exactly match the stored structure state
4153 StructureViewerBase comp = findMatchingViewer(viewerData);
4157 linkStructureViewer(ap, comp, stateData);
4162 * From 2.9: stateData.type contains JMOL or CHIMERA, data is in jar entry
4163 * "viewer_"+stateData.viewId
4165 if (ViewerType.CHIMERA.toString().equals(stateData.getType()))
4167 createChimeraViewer(viewerData, af, jprovider);
4172 * else Jmol (if pre-2.9, stateData contains JMOL state string)
4174 createJmolViewer(viewerData, af, jprovider);
4179 * Create a new Chimera viewer.
4185 protected void createChimeraViewer(
4186 Entry<String, StructureViewerModel> viewerData, AlignFrame af,
4187 jarInputStreamProvider jprovider)
4189 StructureViewerModel data = viewerData.getValue();
4190 String chimeraSessionFile = data.getStateData();
4193 * Copy Chimera session from jar entry "viewer_"+viewId to a temporary file
4195 * NB this is the 'saved' viewId as in the project file XML, _not_ the
4196 * 'uniquified' sviewid used to reconstruct the viewer here
4198 String viewerJarEntryName = getViewerJarEntryName(data.getViewId());
4199 chimeraSessionFile = copyJarEntry(jprovider, viewerJarEntryName,
4202 Set<Entry<File, StructureData>> fileData = data.getFileData()
4204 List<PDBEntry> pdbs = new ArrayList<>();
4205 List<SequenceI[]> allseqs = new ArrayList<>();
4206 for (Entry<File, StructureData> pdb : fileData)
4208 String filePath = pdb.getValue().getFilePath();
4209 String pdbId = pdb.getValue().getPdbId();
4210 // pdbs.add(new PDBEntry(filePath, pdbId));
4211 pdbs.add(new PDBEntry(pdbId, null, PDBEntry.Type.PDB, filePath));
4212 final List<SequenceI> seqList = pdb.getValue().getSeqList();
4213 SequenceI[] seqs = seqList.toArray(new SequenceI[seqList.size()]);
4217 boolean colourByChimera = data.isColourByViewer();
4218 boolean colourBySequence = data.isColourWithAlignPanel();
4220 // TODO use StructureViewer as a factory here, see JAL-1761
4221 final PDBEntry[] pdbArray = pdbs.toArray(new PDBEntry[pdbs.size()]);
4222 final SequenceI[][] seqsArray = allseqs
4223 .toArray(new SequenceI[allseqs.size()][]);
4224 String newViewId = viewerData.getKey();
4226 ChimeraViewFrame cvf = new ChimeraViewFrame(chimeraSessionFile,
4227 af.alignPanel, pdbArray, seqsArray, colourByChimera,
4228 colourBySequence, newViewId);
4229 cvf.setSize(data.getWidth(), data.getHeight());
4230 cvf.setLocation(data.getX(), data.getY());
4234 * Create a new Jmol window. First parse the Jmol state to translate filenames
4235 * loaded into the view, and record the order in which files are shown in the
4236 * Jmol view, so we can add the sequence mappings in same order.
4242 protected void createJmolViewer(
4243 final Entry<String, StructureViewerModel> viewerData,
4244 AlignFrame af, jarInputStreamProvider jprovider)
4246 final StructureViewerModel svattrib = viewerData.getValue();
4247 String state = svattrib.getStateData();
4250 * Pre-2.9: state element value is the Jmol state string
4252 * 2.9+: @type is "JMOL", state data is in a Jar file member named "viewer_"
4255 if (ViewerType.JMOL.toString().equals(svattrib.getType()))
4257 state = readJarEntry(jprovider,
4258 getViewerJarEntryName(svattrib.getViewId()));
4261 List<String> pdbfilenames = new ArrayList<>();
4262 List<SequenceI[]> seqmaps = new ArrayList<>();
4263 List<String> pdbids = new ArrayList<>();
4264 StringBuilder newFileLoc = new StringBuilder(64);
4265 int cp = 0, ncp, ecp;
4266 Map<File, StructureData> oldFiles = svattrib.getFileData();
4267 while ((ncp = state.indexOf("load ", cp)) > -1)
4271 // look for next filename in load statement
4272 newFileLoc.append(state.substring(cp,
4273 ncp = (state.indexOf("\"", ncp + 1) + 1)));
4274 String oldfilenam = state.substring(ncp,
4275 ecp = state.indexOf("\"", ncp));
4276 // recover the new mapping data for this old filename
4277 // have to normalize filename - since Jmol and jalview do
4279 // translation differently.
4280 StructureData filedat = oldFiles.get(new File(oldfilenam));
4281 if (filedat == null)
4283 String reformatedOldFilename = oldfilenam.replaceAll("/", "\\\\");
4284 filedat = oldFiles.get(new File(reformatedOldFilename));
4286 newFileLoc.append(Platform.escapeString(filedat.getFilePath()));
4287 pdbfilenames.add(filedat.getFilePath());
4288 pdbids.add(filedat.getPdbId());
4289 seqmaps.add(filedat.getSeqList().toArray(new SequenceI[0]));
4290 newFileLoc.append("\"");
4291 cp = ecp + 1; // advance beyond last \" and set cursor so we can
4292 // look for next file statement.
4293 } while ((ncp = state.indexOf("/*file*/", cp)) > -1);
4297 // just append rest of state
4298 newFileLoc.append(state.substring(cp));
4302 System.err.print("Ignoring incomplete Jmol state for PDB ids: ");
4303 newFileLoc = new StringBuilder(state);
4304 newFileLoc.append("; load append ");
4305 for (File id : oldFiles.keySet())
4307 // add this and any other pdb files that should be present in
4309 StructureData filedat = oldFiles.get(id);
4310 newFileLoc.append(filedat.getFilePath());
4311 pdbfilenames.add(filedat.getFilePath());
4312 pdbids.add(filedat.getPdbId());
4313 seqmaps.add(filedat.getSeqList().toArray(new SequenceI[0]));
4314 newFileLoc.append(" \"");
4315 newFileLoc.append(filedat.getFilePath());
4316 newFileLoc.append("\"");
4319 newFileLoc.append(";");
4322 if (newFileLoc.length() == 0)
4326 int histbug = newFileLoc.indexOf("history = ");
4330 * change "history = [true|false];" to "history = [1|0];"
4333 int diff = histbug == -1 ? -1 : newFileLoc.indexOf(";", histbug);
4334 String val = (diff == -1) ? null
4335 : newFileLoc.substring(histbug, diff);
4336 if (val != null && val.length() >= 4)
4338 if (val.contains("e")) // eh? what can it be?
4340 if (val.trim().equals("true"))
4348 newFileLoc.replace(histbug, diff, val);
4353 final String[] pdbf = pdbfilenames
4354 .toArray(new String[pdbfilenames.size()]);
4355 final String[] id = pdbids.toArray(new String[pdbids.size()]);
4356 final SequenceI[][] sq = seqmaps
4357 .toArray(new SequenceI[seqmaps.size()][]);
4358 final String fileloc = newFileLoc.toString();
4359 final String sviewid = viewerData.getKey();
4360 final AlignFrame alf = af;
4361 final Rectangle rect = new Rectangle(svattrib.getX(), svattrib.getY(),
4362 svattrib.getWidth(), svattrib.getHeight());
4365 javax.swing.SwingUtilities.invokeAndWait(new Runnable()
4370 JalviewStructureDisplayI sview = null;
4373 sview = new StructureViewer(
4374 alf.alignPanel.getStructureSelectionManager())
4375 .createView(StructureViewer.ViewerType.JMOL,
4376 pdbf, id, sq, alf.alignPanel, svattrib,
4377 fileloc, rect, sviewid);
4378 addNewStructureViewer(sview);
4379 } catch (OutOfMemoryError ex)
4381 new OOMWarning("restoring structure view for PDB id " + id,
4382 (OutOfMemoryError) ex.getCause());
4383 if (sview != null && sview.isVisible())
4385 sview.closeViewer(false);
4386 sview.setVisible(false);
4392 } catch (InvocationTargetException ex)
4394 warn("Unexpected error when opening Jmol view.", ex);
4396 } catch (InterruptedException e)
4398 // e.printStackTrace();
4404 * Generates a name for the entry in the project jar file to hold state
4405 * information for a structure viewer
4410 protected String getViewerJarEntryName(String viewId)
4412 return VIEWER_PREFIX + viewId;
4416 * Returns any open frame that matches given structure viewer data. The match
4417 * is based on the unique viewId, or (for older project versions) the frame's
4423 protected StructureViewerBase findMatchingViewer(
4424 Entry<String, StructureViewerModel> viewerData)
4426 final String sviewid = viewerData.getKey();
4427 final StructureViewerModel svattrib = viewerData.getValue();
4428 StructureViewerBase comp = null;
4429 JInternalFrame[] frames = getAllFrames();
4430 for (JInternalFrame frame : frames)
4432 if (frame instanceof StructureViewerBase)
4435 * Post jalview 2.4 schema includes structure view id
4437 if (sviewid != null && ((StructureViewerBase) frame).getViewId()
4440 comp = (StructureViewerBase) frame;
4441 break; // break added in 2.9
4444 * Otherwise test for matching position and size of viewer frame
4446 else if (frame.getX() == svattrib.getX()
4447 && frame.getY() == svattrib.getY()
4448 && frame.getHeight() == svattrib.getHeight()
4449 && frame.getWidth() == svattrib.getWidth())
4451 comp = (StructureViewerBase) frame;
4452 // no break in faint hope of an exact match on viewId
4460 * Link an AlignmentPanel to an existing structure viewer.
4465 * @param useinViewerSuperpos
4466 * @param usetoColourbyseq
4467 * @param viewerColouring
4469 protected void linkStructureViewer(AlignmentPanel ap,
4470 StructureViewerBase viewer, StructureViewerModel stateData)
4472 // NOTE: if the jalview project is part of a shared session then
4473 // view synchronization should/could be done here.
4475 final boolean useinViewerSuperpos = stateData.isAlignWithPanel();
4476 final boolean usetoColourbyseq = stateData.isColourWithAlignPanel();
4477 final boolean viewerColouring = stateData.isColourByViewer();
4478 Map<File, StructureData> oldFiles = stateData.getFileData();
4481 * Add mapping for sequences in this view to an already open viewer
4483 final AAStructureBindingModel binding = viewer.getBinding();
4484 for (File id : oldFiles.keySet())
4486 // add this and any other pdb files that should be present in the
4488 StructureData filedat = oldFiles.get(id);
4489 String pdbFile = filedat.getFilePath();
4490 SequenceI[] seq = filedat.getSeqList().toArray(new SequenceI[0]);
4491 binding.getSsm().setMapping(seq, null, pdbFile, DataSourceType.FILE,
4493 binding.addSequenceForStructFile(pdbFile, seq);
4495 // and add the AlignmentPanel's reference to the view panel
4496 viewer.addAlignmentPanel(ap);
4497 if (useinViewerSuperpos)
4499 viewer.useAlignmentPanelForSuperposition(ap);
4503 viewer.excludeAlignmentPanelForSuperposition(ap);
4505 if (usetoColourbyseq)
4507 viewer.useAlignmentPanelForColourbyseq(ap, !viewerColouring);
4511 viewer.excludeAlignmentPanelForColourbyseq(ap);
4516 * Get all frames within the Desktop.
4520 protected JInternalFrame[] getAllFrames()
4522 JInternalFrame[] frames = null;
4523 // TODO is this necessary - is it safe - risk of hanging?
4528 frames = Desktop.desktop.getAllFrames();
4529 } catch (ArrayIndexOutOfBoundsException e)
4531 // occasional No such child exceptions are thrown here...
4535 } catch (InterruptedException f)
4539 } while (frames == null);
4544 * Answers true if 'version' is equal to or later than 'supported', where each
4545 * is formatted as major/minor versions like "2.8.3" or "2.3.4b1" for bugfix
4546 * changes. Development and test values for 'version' are leniently treated
4550 * - minimum version we are comparing against
4552 * - version of data being processsed
4555 public static boolean isVersionStringLaterThan(String supported,
4558 if (supported == null || version == null
4559 || version.equalsIgnoreCase("DEVELOPMENT BUILD")
4560 || version.equalsIgnoreCase("Test")
4561 || version.equalsIgnoreCase("AUTOMATED BUILD"))
4563 System.err.println("Assuming project file with "
4564 + (version == null ? "null" : version)
4565 + " is compatible with Jalview version " + supported);
4570 return StringUtils.compareVersions(version, supported, "b") >= 0;
4574 Vector<JalviewStructureDisplayI> newStructureViewers = null;
4576 protected void addNewStructureViewer(JalviewStructureDisplayI sview)
4578 if (newStructureViewers != null)
4580 sview.getBinding().setFinishedLoadingFromArchive(false);
4581 newStructureViewers.add(sview);
4585 protected void setLoadingFinishedForNewStructureViewers()
4587 if (newStructureViewers != null)
4589 for (JalviewStructureDisplayI sview : newStructureViewers)
4591 sview.getBinding().setFinishedLoadingFromArchive(true);
4593 newStructureViewers.clear();
4594 newStructureViewers = null;
4598 AlignFrame loadViewport(String file, List<JSeq> JSEQ,
4599 List<SequenceI> hiddenSeqs, AlignmentI al,
4600 JalviewModel jm, Viewport view, String uniqueSeqSetId,
4601 String viewId, List<JvAnnotRow> autoAlan)
4603 AlignFrame af = null;
4604 af = new AlignFrame(al, safeInt(view.getWidth()),
4605 safeInt(view.getHeight()), uniqueSeqSetId, viewId)
4609 // protected void processKeyEvent(java.awt.event.KeyEvent e) {
4610 // System.out.println("Jalview2XML AF " + e);
4611 // super.processKeyEvent(e);
4618 af.setFileName(file, FileFormat.Jalview);
4620 final AlignViewport viewport = af.getViewport();
4621 for (int i = 0; i < JSEQ.size(); i++)
4623 int colour = safeInt(JSEQ.get(i).getColour());
4624 viewport.setSequenceColour(viewport.getAlignment().getSequenceAt(i),
4630 viewport.setColourByReferenceSeq(true);
4631 viewport.setDisplayReferenceSeq(true);
4634 viewport.setGatherViewsHere(safeBoolean(view.isGatheredViews()));
4636 if (view.getSequenceSetId() != null)
4638 AlignmentViewport av = viewportsAdded.get(uniqueSeqSetId);
4640 viewport.setSequenceSetId(uniqueSeqSetId);
4643 // propagate shared settings to this new view
4644 viewport.setHistoryList(av.getHistoryList());
4645 viewport.setRedoList(av.getRedoList());
4649 viewportsAdded.put(uniqueSeqSetId, viewport);
4651 // TODO: check if this method can be called repeatedly without
4652 // side-effects if alignpanel already registered.
4653 PaintRefresher.Register(af.alignPanel, uniqueSeqSetId);
4655 // apply Hidden regions to view.
4656 if (hiddenSeqs != null)
4658 for (int s = 0; s < JSEQ.size(); s++)
4660 SequenceGroup hidden = new SequenceGroup();
4661 boolean isRepresentative = false;
4662 for (int r = 0; r < JSEQ.get(s).getHiddenSequences().size(); r++)
4664 isRepresentative = true;
4665 SequenceI sequenceToHide = al
4666 .getSequenceAt(JSEQ.get(s).getHiddenSequences().get(r));
4667 hidden.addSequence(sequenceToHide, false);
4668 // remove from hiddenSeqs list so we don't try to hide it twice
4669 hiddenSeqs.remove(sequenceToHide);
4671 if (isRepresentative)
4673 SequenceI representativeSequence = al.getSequenceAt(s);
4674 hidden.addSequence(representativeSequence, false);
4675 viewport.hideRepSequences(representativeSequence, hidden);
4679 SequenceI[] hseqs = hiddenSeqs
4680 .toArray(new SequenceI[hiddenSeqs.size()]);
4681 viewport.hideSequence(hseqs);
4684 // recover view properties and display parameters
4686 viewport.setShowAnnotation(safeBoolean(view.isShowAnnotation()));
4687 viewport.setAbovePIDThreshold(safeBoolean(view.isPidSelected()));
4688 final int pidThreshold = safeInt(view.getPidThreshold());
4689 viewport.setThreshold(pidThreshold);
4691 viewport.setColourText(safeBoolean(view.isShowColourText()));
4694 .setConservationSelected(
4695 safeBoolean(view.isConservationSelected()));
4696 viewport.setIncrement(safeInt(view.getConsThreshold()));
4697 viewport.setShowJVSuffix(safeBoolean(view.isShowFullId()));
4698 viewport.setRightAlignIds(safeBoolean(view.isRightAlignIds()));
4699 viewport.setFont(new Font(view.getFontName(),
4700 safeInt(view.getFontStyle()), safeInt(view.getFontSize())),
4702 ViewStyleI vs = viewport.getViewStyle();
4703 vs.setScaleProteinAsCdna(view.isScaleProteinAsCdna());
4704 viewport.setViewStyle(vs);
4705 // TODO: allow custom charWidth/Heights to be restored by updating them
4706 // after setting font - which means set above to false
4707 viewport.setRenderGaps(safeBoolean(view.isRenderGaps()));
4708 viewport.setWrapAlignment(safeBoolean(view.isWrapAlignment()));
4709 viewport.setShowAnnotation(safeBoolean(view.isShowAnnotation()));
4711 viewport.setShowBoxes(safeBoolean(view.isShowBoxes()));
4713 viewport.setShowText(safeBoolean(view.isShowText()));
4715 viewport.setTextColour(new Color(safeInt(view.getTextCol1())));
4716 viewport.setTextColour2(new Color(safeInt(view.getTextCol2())));
4717 viewport.setThresholdTextColour(safeInt(view.getTextColThreshold()));
4718 viewport.setShowUnconserved(view.isShowUnconserved());
4719 viewport.getRanges().setStartRes(safeInt(view.getStartRes()));
4721 if (view.getViewName() != null)
4723 viewport.setViewName(view.getViewName());
4724 af.setInitialTabVisible();
4726 af.setBounds(safeInt(view.getXpos()), safeInt(view.getYpos()),
4727 safeInt(view.getWidth()), safeInt(view.getHeight()));
4728 // startSeq set in af.alignPanel.updateLayout below
4729 af.alignPanel.updateLayout();
4730 ColourSchemeI cs = null;
4731 // apply colourschemes
4732 if (view.getBgColour() != null)
4734 if (view.getBgColour().startsWith("ucs"))
4736 cs = getUserColourScheme(jm, view.getBgColour());
4738 else if (view.getBgColour().startsWith("Annotation"))
4740 AnnotationColourScheme viewAnnColour = view.getAnnotationColours();
4741 cs = constructAnnotationColour(viewAnnColour, af, al, jm, true);
4748 cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour());
4752 viewport.setGlobalColourScheme(cs);
4753 viewport.getResidueShading().setThreshold(pidThreshold,
4754 view.isIgnoreGapsinConsensus());
4755 viewport.getResidueShading()
4756 .setConsensus(viewport.getSequenceConsensusHash());
4757 viewport.setColourAppliesToAllGroups(false);
4759 if (safeBoolean(view.isConservationSelected()) && cs != null)
4761 viewport.getResidueShading()
4762 .setConservationInc(safeInt(view.getConsThreshold()));
4765 af.changeColour(cs);
4767 viewport.setColourAppliesToAllGroups(true);
4770 .setShowSequenceFeatures(
4771 safeBoolean(view.isShowSequenceFeatures()));
4773 viewport.setCentreColumnLabels(view.isCentreColumnLabels());
4774 viewport.setIgnoreGapsConsensus(view.isIgnoreGapsinConsensus(), null);
4775 viewport.setFollowHighlight(view.isFollowHighlight());
4776 viewport.followSelection = view.isFollowSelection();
4777 viewport.setShowConsensusHistogram(view.isShowConsensusHistogram());
4778 viewport.setShowSequenceLogo(view.isShowSequenceLogo());
4779 viewport.setNormaliseSequenceLogo(view.isNormaliseSequenceLogo());
4780 viewport.setShowDBRefs(safeBoolean(view.isShowDbRefTooltip()));
4781 viewport.setShowNPFeats(safeBoolean(view.isShowNPfeatureTooltip()));
4782 viewport.setShowGroupConsensus(view.isShowGroupConsensus());
4783 viewport.setShowGroupConservation(view.isShowGroupConservation());
4785 // recover feature settings
4786 if (jm.getFeatureSettings() != null)
4788 FeatureRenderer fr = af.alignPanel.getSeqPanel().seqCanvas
4789 .getFeatureRenderer();
4790 FeaturesDisplayed fdi;
4791 viewport.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
4792 String[] renderOrder = new String[jm.getFeatureSettings()
4793 .getSetting().size()];
4794 Map<String, FeatureColourI> featureColours = new Hashtable<>();
4795 Map<String, Float> featureOrder = new Hashtable<>();
4797 for (int fs = 0; fs < jm.getFeatureSettings()
4798 .getSetting().size(); fs++)
4800 Setting setting = jm.getFeatureSettings().getSetting().get(fs);
4801 String featureType = setting.getType();
4804 * restore feature filters (if any)
4806 jalview.xml.binding.jalview.FeatureMatcherSet filters = setting
4808 if (filters != null)
4810 FeatureMatcherSetI filter = Jalview2XML
4811 .parseFilter(featureType, filters);
4812 if (!filter.isEmpty())
4814 fr.setFeatureFilter(featureType, filter);
4819 * restore feature colour scheme
4821 Color maxColour = new Color(setting.getColour());
4822 if (setting.getMincolour() != null)
4825 * minColour is always set unless a simple colour
4826 * (including for colour by label though it doesn't use it)
4828 Color minColour = new Color(setting.getMincolour().intValue());
4829 Color noValueColour = minColour;
4830 NoValueColour noColour = setting.getNoValueColour();
4831 if (noColour == NoValueColour.NONE)
4833 noValueColour = null;
4835 else if (noColour == NoValueColour.MAX)
4837 noValueColour = maxColour;
4839 float min = safeFloat(safeFloat(setting.getMin()));
4840 float max = setting.getMax() == null ? 1f
4841 : setting.getMax().floatValue();
4842 FeatureColourI gc = new FeatureColour(minColour, maxColour,
4843 noValueColour, min, max);
4844 if (setting.getAttributeName().size() > 0)
4846 gc.setAttributeName(setting.getAttributeName().toArray(
4847 new String[setting.getAttributeName().size()]));
4849 if (setting.getThreshold() != null)
4851 gc.setThreshold(setting.getThreshold().floatValue());
4852 int threshstate = safeInt(setting.getThreshstate());
4853 // -1 = None, 0 = Below, 1 = Above threshold
4854 if (threshstate == 0)
4856 gc.setBelowThreshold(true);
4858 else if (threshstate == 1)
4860 gc.setAboveThreshold(true);
4863 gc.setAutoScaled(true); // default
4864 if (setting.isAutoScale() != null)
4866 gc.setAutoScaled(setting.isAutoScale());
4868 if (setting.isColourByLabel() != null)
4870 gc.setColourByLabel(setting.isColourByLabel());
4872 // and put in the feature colour table.
4873 featureColours.put(featureType, gc);
4877 featureColours.put(featureType,
4878 new FeatureColour(maxColour));
4880 renderOrder[fs] = featureType;
4881 if (setting.getOrder() != null)
4883 featureOrder.put(featureType, setting.getOrder().floatValue());
4887 featureOrder.put(featureType, new Float(
4888 fs / jm.getFeatureSettings().getSetting().size()));
4890 if (safeBoolean(setting.isDisplay()))
4892 fdi.setVisible(featureType);
4895 Map<String, Boolean> fgtable = new Hashtable<>();
4896 for (int gs = 0; gs < jm.getFeatureSettings().getGroup().size(); gs++)
4898 Group grp = jm.getFeatureSettings().getGroup().get(gs);
4899 fgtable.put(grp.getName(), new Boolean(grp.isDisplay()));
4901 // FeatureRendererSettings frs = new FeatureRendererSettings(renderOrder,
4902 // fgtable, featureColours, jms.getFeatureSettings().hasTransparency() ?
4903 // jms.getFeatureSettings().getTransparency() : 0.0, featureOrder);
4904 FeatureRendererSettings frs = new FeatureRendererSettings(renderOrder,
4905 fgtable, featureColours, 1.0f, featureOrder);
4906 fr.transferSettings(frs);
4909 if (view.getHiddenColumns().size() > 0)
4911 for (int c = 0; c < view.getHiddenColumns().size(); c++)
4913 final HiddenColumns hc = view.getHiddenColumns().get(c);
4914 viewport.hideColumns(safeInt(hc.getStart()),
4915 safeInt(hc.getEnd()) /* +1 */);
4918 if (view.getCalcIdParam() != null)
4920 for (CalcIdParam calcIdParam : view.getCalcIdParam())
4922 if (calcIdParam != null)
4924 if (recoverCalcIdParam(calcIdParam, viewport))
4929 warn("Couldn't recover parameters for "
4930 + calcIdParam.getCalcId());
4935 af.setMenusFromViewport(viewport);
4936 af.setTitle(view.getTitle());
4937 // TODO: we don't need to do this if the viewport is aready visible.
4939 * Add the AlignFrame to the desktop (it may be 'gathered' later), unless it
4940 * has a 'cdna/protein complement' view, in which case save it in order to
4941 * populate a SplitFrame once all views have been read in.
4943 String complementaryViewId = view.getComplementId();
4944 if (complementaryViewId == null)
4946 Desktop.addInternalFrame(af, view.getTitle(),
4947 safeInt(view.getWidth()), safeInt(view.getHeight()));
4948 // recompute any autoannotation
4949 af.alignPanel.updateAnnotation(false, true);
4950 reorderAutoannotation(af, al, autoAlan);
4951 af.alignPanel.alignmentChanged();
4955 splitFrameCandidates.put(view, af);
4961 * Reads saved data to restore Colour by Annotation settings
4963 * @param viewAnnColour
4967 * @param checkGroupAnnColour
4970 private ColourSchemeI constructAnnotationColour(
4971 AnnotationColourScheme viewAnnColour, AlignFrame af,
4972 AlignmentI al, JalviewModel model, boolean checkGroupAnnColour)
4974 boolean propagateAnnColour = false;
4975 AlignmentI annAlignment = af != null ? af.getViewport().getAlignment()
4977 if (checkGroupAnnColour && al.getGroups() != null
4978 && al.getGroups().size() > 0)
4980 // pre 2.8.1 behaviour
4981 // check to see if we should transfer annotation colours
4982 propagateAnnColour = true;
4983 for (SequenceGroup sg : al.getGroups())
4985 if (sg.getColourScheme() instanceof AnnotationColourGradient)
4987 propagateAnnColour = false;
4993 * 2.10.2- : saved annotationId is AlignmentAnnotation.annotationId
4995 String annotationId = viewAnnColour.getAnnotation();
4996 AlignmentAnnotation matchedAnnotation = annotationIds.get(annotationId);
4999 * pre 2.10.2: saved annotationId is AlignmentAnnotation.label
5001 if (matchedAnnotation == null
5002 && annAlignment.getAlignmentAnnotation() != null)
5004 for (int i = 0; i < annAlignment.getAlignmentAnnotation().length; i++)
5007 .equals(annAlignment.getAlignmentAnnotation()[i].label))
5009 matchedAnnotation = annAlignment.getAlignmentAnnotation()[i];
5014 if (matchedAnnotation == null)
5016 System.err.println("Failed to match annotation colour scheme for "
5020 if (matchedAnnotation.getThreshold() == null)
5022 matchedAnnotation.setThreshold(
5023 new GraphLine(safeFloat(viewAnnColour.getThreshold()),
5024 "Threshold", Color.black));
5027 AnnotationColourGradient cs = null;
5028 if (viewAnnColour.getColourScheme().equals("None"))
5030 cs = new AnnotationColourGradient(matchedAnnotation,
5031 new Color(safeInt(viewAnnColour.getMinColour())),
5032 new Color(safeInt(viewAnnColour.getMaxColour())),
5033 safeInt(viewAnnColour.getAboveThreshold()));
5035 else if (viewAnnColour.getColourScheme().startsWith("ucs"))
5037 cs = new AnnotationColourGradient(matchedAnnotation,
5038 getUserColourScheme(model, viewAnnColour.getColourScheme()),
5039 safeInt(viewAnnColour.getAboveThreshold()));
5043 cs = new AnnotationColourGradient(matchedAnnotation,
5044 ColourSchemeProperty.getColourScheme(al,
5045 viewAnnColour.getColourScheme()),
5046 safeInt(viewAnnColour.getAboveThreshold()));
5049 boolean perSequenceOnly = safeBoolean(viewAnnColour.isPerSequence());
5050 boolean useOriginalColours = safeBoolean(
5051 viewAnnColour.isPredefinedColours());
5052 cs.setSeqAssociated(perSequenceOnly);
5053 cs.setPredefinedColours(useOriginalColours);
5055 if (propagateAnnColour && al.getGroups() != null)
5057 // Also use these settings for all the groups
5058 for (int g = 0; g < al.getGroups().size(); g++)
5060 SequenceGroup sg = al.getGroups().get(g);
5061 if (sg.getGroupColourScheme() == null)
5066 AnnotationColourGradient groupScheme = new AnnotationColourGradient(
5067 matchedAnnotation, sg.getColourScheme(),
5068 safeInt(viewAnnColour.getAboveThreshold()));
5069 sg.setColourScheme(groupScheme);
5070 groupScheme.setSeqAssociated(perSequenceOnly);
5071 groupScheme.setPredefinedColours(useOriginalColours);
5077 private void reorderAutoannotation(AlignFrame af, AlignmentI al,
5078 List<JvAnnotRow> autoAlan)
5080 // copy over visualization settings for autocalculated annotation in the
5082 if (al.getAlignmentAnnotation() != null)
5085 * Kludge for magic autoannotation names (see JAL-811)
5087 String[] magicNames = new String[] { "Consensus", "Quality",
5089 JvAnnotRow nullAnnot = new JvAnnotRow(-1, null);
5090 Hashtable<String, JvAnnotRow> visan = new Hashtable<>();
5091 for (String nm : magicNames)
5093 visan.put(nm, nullAnnot);
5095 for (JvAnnotRow auan : autoAlan)
5097 visan.put(auan.template.label
5098 + (auan.template.getCalcId() == null ? ""
5099 : "\t" + auan.template.getCalcId()),
5102 int hSize = al.getAlignmentAnnotation().length;
5103 List<JvAnnotRow> reorder = new ArrayList<>();
5104 // work through any autoCalculated annotation already on the view
5105 // removing it if it should be placed in a different location on the
5106 // annotation panel.
5107 List<String> remains = new ArrayList<>(visan.keySet());
5108 for (int h = 0; h < hSize; h++)
5110 jalview.datamodel.AlignmentAnnotation jalan = al
5111 .getAlignmentAnnotation()[h];
5112 if (jalan.autoCalculated)
5115 JvAnnotRow valan = visan.get(k = jalan.label);
5116 if (jalan.getCalcId() != null)
5118 valan = visan.get(k = jalan.label + "\t" + jalan.getCalcId());
5123 // delete the auto calculated row from the alignment
5124 al.deleteAnnotation(jalan, false);
5128 if (valan != nullAnnot)
5130 if (jalan != valan.template)
5132 // newly created autoannotation row instance
5133 // so keep a reference to the visible annotation row
5134 // and copy over all relevant attributes
5135 if (valan.template.graphHeight >= 0)
5138 jalan.graphHeight = valan.template.graphHeight;
5140 jalan.visible = valan.template.visible;
5142 reorder.add(new JvAnnotRow(valan.order, jalan));
5147 // Add any (possibly stale) autocalculated rows that were not appended to
5148 // the view during construction
5149 for (String other : remains)
5151 JvAnnotRow othera = visan.get(other);
5152 if (othera != nullAnnot && othera.template.getCalcId() != null
5153 && othera.template.getCalcId().length() > 0)
5155 reorder.add(othera);
5158 // now put the automatic annotation in its correct place
5159 int s = 0, srt[] = new int[reorder.size()];
5160 JvAnnotRow[] rws = new JvAnnotRow[reorder.size()];
5161 for (JvAnnotRow jvar : reorder)
5164 srt[s++] = jvar.order;
5167 jalview.util.QuickSort.sort(srt, rws);
5168 // and re-insert the annotation at its correct position
5169 for (JvAnnotRow jvar : rws)
5171 al.addAnnotation(jvar.template, jvar.order);
5173 af.alignPanel.adjustAnnotationHeight();
5177 Hashtable skipList = null;
5180 * TODO remove this method
5183 * @return AlignFrame bound to sequenceSetId from view, if one exists. private
5184 * AlignFrame getSkippedFrame(Viewport view) { if (skipList==null) {
5185 * throw new Error("Implementation Error. No skipList defined for this
5186 * Jalview2XML instance."); } return (AlignFrame)
5187 * skipList.get(view.getSequenceSetId()); }
5191 * Check if the Jalview view contained in object should be skipped or not.
5194 * @return true if view's sequenceSetId is a key in skipList
5196 private boolean skipViewport(JalviewModel object)
5198 if (skipList == null)
5202 String id = object.getViewport().get(0).getSequenceSetId();
5203 if (skipList.containsKey(id))
5205 if (Cache.log != null && Cache.log.isDebugEnabled())
5207 Cache.log.debug("Skipping seuqence set id " + id);
5214 public void addToSkipList(AlignFrame af)
5216 if (skipList == null)
5218 skipList = new Hashtable();
5220 skipList.put(af.getViewport().getSequenceSetId(), af);
5223 public void clearSkipList()
5225 if (skipList != null)
5232 private void recoverDatasetFor(SequenceSet vamsasSet, AlignmentI al,
5233 boolean ignoreUnrefed)
5235 jalview.datamodel.AlignmentI ds = getDatasetFor(
5236 vamsasSet.getDatasetId());
5237 Vector dseqs = null;
5240 // create a list of new dataset sequences
5241 dseqs = new Vector();
5243 for (int i = 0, iSize = vamsasSet.getSequence().size(); i < iSize; i++)
5245 Sequence vamsasSeq = vamsasSet.getSequence().get(i);
5246 ensureJalviewDatasetSequence(vamsasSeq, ds, dseqs, ignoreUnrefed, i);
5248 // create a new dataset
5251 SequenceI[] dsseqs = new SequenceI[dseqs.size()];
5252 dseqs.copyInto(dsseqs);
5253 ds = new jalview.datamodel.Alignment(dsseqs);
5254 debug("Created new dataset " + vamsasSet.getDatasetId()
5255 + " for alignment " + System.identityHashCode(al));
5256 addDatasetRef(vamsasSet.getDatasetId(), ds);
5258 // set the dataset for the newly imported alignment.
5259 if (al.getDataset() == null && !ignoreUnrefed)
5268 * sequence definition to create/merge dataset sequence for
5272 * vector to add new dataset sequence to
5273 * @param ignoreUnrefed
5274 * - when true, don't create new sequences from vamsasSeq if it's id
5275 * doesn't already have an asssociated Jalview sequence.
5277 * - used to reorder the sequence in the alignment according to the
5278 * vamsasSeq array ordering, to preserve ordering of dataset
5280 private void ensureJalviewDatasetSequence(Sequence vamsasSeq,
5281 AlignmentI ds, Vector dseqs, boolean ignoreUnrefed, int vseqpos)
5283 // JBP TODO: Check this is called for AlCodonFrames to support recovery of
5285 SequenceI sq = seqRefIds.get(vamsasSeq.getId());
5286 boolean reorder = false;
5287 SequenceI dsq = null;
5288 if (sq != null && sq.getDatasetSequence() != null)
5290 dsq = sq.getDatasetSequence();
5296 if (sq == null && ignoreUnrefed)
5300 String sqid = vamsasSeq.getDsseqid();
5303 // need to create or add a new dataset sequence reference to this sequence
5306 dsq = seqRefIds.get(sqid);
5311 // make a new dataset sequence
5312 dsq = sq.createDatasetSequence();
5315 // make up a new dataset reference for this sequence
5316 sqid = seqHash(dsq);
5318 dsq.setVamsasId(uniqueSetSuffix + sqid);
5319 seqRefIds.put(sqid, dsq);
5324 dseqs.addElement(dsq);
5329 ds.addSequence(dsq);
5335 { // make this dataset sequence sq's dataset sequence
5336 sq.setDatasetSequence(dsq);
5337 // and update the current dataset alignment
5342 if (!dseqs.contains(dsq))
5349 if (ds.findIndex(dsq) < 0)
5351 ds.addSequence(dsq);
5358 // TODO: refactor this as a merge dataset sequence function
5359 // now check that sq (the dataset sequence) sequence really is the union of
5360 // all references to it
5361 // boolean pre = sq.getStart() < dsq.getStart();
5362 // boolean post = sq.getEnd() > dsq.getEnd();
5366 // StringBuffer sb = new StringBuffer();
5367 String newres = jalview.analysis.AlignSeq.extractGaps(
5368 jalview.util.Comparison.GapChars, sq.getSequenceAsString());
5369 if (!newres.equalsIgnoreCase(dsq.getSequenceAsString())
5370 && newres.length() > dsq.getLength())
5372 // Update with the longer sequence.
5376 * if (pre) { sb.insert(0, newres .substring(0, dsq.getStart() -
5377 * sq.getStart())); dsq.setStart(sq.getStart()); } if (post) {
5378 * sb.append(newres.substring(newres.length() - sq.getEnd() -
5379 * dsq.getEnd())); dsq.setEnd(sq.getEnd()); }
5381 dsq.setSequence(newres);
5383 // TODO: merges will never happen if we 'know' we have the real dataset
5384 // sequence - this should be detected when id==dssid
5386 "DEBUG Notice: Merged dataset sequence (if you see this often, post at http://issues.jalview.org/browse/JAL-1474)"); // ("
5387 // + (pre ? "prepended" : "") + " "
5388 // + (post ? "appended" : ""));
5393 // sequence refs are identical. We may need to update the existing dataset
5394 // alignment with this one, though.
5395 if (ds != null && dseqs == null)
5397 int opos = ds.findIndex(dsq);
5398 SequenceI tseq = null;
5399 if (opos != -1 && vseqpos != opos)
5401 // remove from old position
5402 ds.deleteSequence(dsq);
5404 if (vseqpos < ds.getHeight())
5406 if (vseqpos != opos)
5408 // save sequence at destination position
5409 tseq = ds.getSequenceAt(vseqpos);
5410 ds.replaceSequenceAt(vseqpos, dsq);
5411 ds.addSequence(tseq);
5416 ds.addSequence(dsq);
5423 * TODO use AlignmentI here and in related methods - needs
5424 * AlignmentI.getDataset() changed to return AlignmentI instead of Alignment
5426 Hashtable<String, AlignmentI> datasetIds = null;
5428 IdentityHashMap<AlignmentI, String> dataset2Ids = null;
5430 private AlignmentI getDatasetFor(String datasetId)
5432 if (datasetIds == null)
5434 datasetIds = new Hashtable<>();
5437 if (datasetIds.containsKey(datasetId))
5439 return datasetIds.get(datasetId);
5444 private void addDatasetRef(String datasetId, AlignmentI dataset)
5446 if (datasetIds == null)
5448 datasetIds = new Hashtable<>();
5450 datasetIds.put(datasetId, dataset);
5454 * make a new dataset ID for this jalview dataset alignment
5459 private String getDatasetIdRef(AlignmentI dataset)
5461 if (dataset.getDataset() != null)
5463 warn("Serious issue! Dataset Object passed to getDatasetIdRef is not a Jalview DATASET alignment...");
5465 String datasetId = makeHashCode(dataset, null);
5466 if (datasetId == null)
5468 // make a new datasetId and record it
5469 if (dataset2Ids == null)
5471 dataset2Ids = new IdentityHashMap<>();
5475 datasetId = dataset2Ids.get(dataset);
5477 if (datasetId == null)
5479 datasetId = "ds" + dataset2Ids.size() + 1;
5480 dataset2Ids.put(dataset, datasetId);
5486 private void addDBRefs(SequenceI datasetSequence, Sequence sequence)
5488 for (int d = 0; d < sequence.getDBRef().size(); d++)
5490 DBRef dr = sequence.getDBRef().get(d);
5491 jalview.datamodel.DBRefEntry entry = new jalview.datamodel.DBRefEntry(
5492 dr.getSource(), dr.getVersion(), dr.getAccessionId());
5493 if (dr.getMapping() != null)
5495 entry.setMap(addMapping(dr.getMapping()));
5497 datasetSequence.addDBRef(entry);
5501 private jalview.datamodel.Mapping addMapping(Mapping m)
5503 SequenceI dsto = null;
5504 // Mapping m = dr.getMapping();
5505 int fr[] = new int[m.getMapListFrom().size() * 2];
5506 Iterator<MapListFrom> from = m.getMapListFrom().iterator();// enumerateMapListFrom();
5507 for (int _i = 0; from.hasNext(); _i += 2)
5509 MapListFrom mf = from.next();
5510 fr[_i] = mf.getStart();
5511 fr[_i + 1] = mf.getEnd();
5513 int fto[] = new int[m.getMapListTo().size() * 2];
5514 Iterator<MapListTo> to = m.getMapListTo().iterator();// enumerateMapListTo();
5515 for (int _i = 0; to.hasNext(); _i += 2)
5517 MapListTo mf = to.next();
5518 fto[_i] = mf.getStart();
5519 fto[_i + 1] = mf.getEnd();
5521 jalview.datamodel.Mapping jmap = new jalview.datamodel.Mapping(dsto, fr,
5522 fto, m.getMapFromUnit().intValue(),
5523 m.getMapToUnit().intValue());
5524 // if (m.getMappingChoice() != null)
5526 // MappingChoice mc = m.getMappingChoice();
5527 if (m.getDseqFor() != null)
5529 String dsfor = m.getDseqFor();
5530 if (seqRefIds.containsKey(dsfor))
5535 jmap.setTo(seqRefIds.get(dsfor));
5539 frefedSequence.add(newMappingRef(dsfor, jmap));
5545 * local sequence definition
5547 Sequence ms = m.getSequence();
5548 SequenceI djs = null;
5549 String sqid = ms.getDsseqid();
5550 if (sqid != null && sqid.length() > 0)
5553 * recover dataset sequence
5555 djs = seqRefIds.get(sqid);
5560 "Warning - making up dataset sequence id for DbRef sequence map reference");
5561 sqid = ((Object) ms).toString(); // make up a new hascode for
5562 // undefined dataset sequence hash
5563 // (unlikely to happen)
5569 * make a new dataset sequence and add it to refIds hash
5571 djs = new jalview.datamodel.Sequence(ms.getName(),
5573 djs.setStart(jmap.getMap().getToLowest());
5574 djs.setEnd(jmap.getMap().getToHighest());
5575 djs.setVamsasId(uniqueSetSuffix + sqid);
5577 incompleteSeqs.put(sqid, djs);
5578 seqRefIds.put(sqid, djs);
5581 jalview.bin.Cache.log.debug("about to recurse on addDBRefs.");
5590 * Provides a 'copy' of an alignment view (on action New View) by 'saving' the
5591 * view as XML (but not to file), and then reloading it
5596 public AlignmentPanel copyAlignPanel(AlignmentPanel ap)
5599 JalviewModel jm = saveState(ap, null, null, null);
5601 uniqueSetSuffix = "";
5602 // jm.getJalviewModelSequence().getViewport(0).setId(null);
5603 jm.getViewport().get(0).setId(null);
5604 // we don't overwrite the view we just copied
5606 if (this.frefedSequence == null)
5608 frefedSequence = new Vector<>();
5611 viewportsAdded.clear();
5613 AlignFrame af = loadFromObject(jm, null, false, null);
5614 af.getAlignPanels().clear();
5615 af.closeMenuItem_actionPerformed(true);
5618 * if(ap.av.getAlignment().getAlignmentAnnotation()!=null) { for(int i=0;
5619 * i<ap.av.getAlignment().getAlignmentAnnotation().length; i++) {
5620 * if(!ap.av.getAlignment().getAlignmentAnnotation()[i].autoCalculated) {
5621 * af.alignPanel.av.getAlignment().getAlignmentAnnotation()[i] =
5622 * ap.av.getAlignment().getAlignmentAnnotation()[i]; } } }
5625 return af.alignPanel;
5628 private Hashtable jvids2vobj;
5630 private void warn(String msg)
5635 private void warn(String msg, Exception e)
5637 if (Cache.log != null)
5641 Cache.log.warn(msg, e);
5645 Cache.log.warn(msg);
5650 System.err.println("Warning: " + msg);
5653 e.printStackTrace();
5658 private void debug(String string)
5660 debug(string, null);
5663 private void debug(String msg, Exception e)
5665 if (Cache.log != null)
5669 Cache.log.debug(msg, e);
5673 Cache.log.debug(msg);
5678 System.err.println("Warning: " + msg);
5681 e.printStackTrace();
5687 * set the object to ID mapping tables used to write/recover objects and XML
5688 * ID strings for the jalview project. If external tables are provided then
5689 * finalize and clearSeqRefs will not clear the tables when the Jalview2XML
5690 * object goes out of scope. - also populates the datasetIds hashtable with
5691 * alignment objects containing dataset sequences
5694 * Map from ID strings to jalview datamodel
5696 * Map from jalview datamodel to ID strings
5700 public void setObjectMappingTables(Hashtable vobj2jv,
5701 IdentityHashMap jv2vobj)
5703 this.jv2vobj = jv2vobj;
5704 this.vobj2jv = vobj2jv;
5705 Iterator ds = jv2vobj.keySet().iterator();
5707 while (ds.hasNext())
5709 Object jvobj = ds.next();
5710 id = jv2vobj.get(jvobj).toString();
5711 if (jvobj instanceof jalview.datamodel.Alignment)
5713 if (((jalview.datamodel.Alignment) jvobj).getDataset() == null)
5715 addDatasetRef(id, (jalview.datamodel.Alignment) jvobj);
5718 else if (jvobj instanceof jalview.datamodel.Sequence)
5720 // register sequence object so the XML parser can recover it.
5721 if (seqRefIds == null)
5723 seqRefIds = new HashMap<>();
5725 if (seqsToIds == null)
5727 seqsToIds = new IdentityHashMap<>();
5729 seqRefIds.put(jv2vobj.get(jvobj).toString(), (SequenceI) jvobj);
5730 seqsToIds.put((SequenceI) jvobj, id);
5732 else if (jvobj instanceof jalview.datamodel.AlignmentAnnotation)
5735 AlignmentAnnotation jvann = (AlignmentAnnotation) jvobj;
5736 annotationIds.put(anid = jv2vobj.get(jvobj).toString(), jvann);
5737 if (jvann.annotationId == null)
5739 jvann.annotationId = anid;
5741 if (!jvann.annotationId.equals(anid))
5743 // TODO verify that this is the correct behaviour
5744 this.warn("Overriding Annotation ID for " + anid
5745 + " from different id : " + jvann.annotationId);
5746 jvann.annotationId = anid;
5749 else if (jvobj instanceof String)
5751 if (jvids2vobj == null)
5753 jvids2vobj = new Hashtable();
5754 jvids2vobj.put(jvobj, jv2vobj.get(jvobj).toString());
5759 Cache.log.debug("Ignoring " + jvobj.getClass() + " (ID = " + id);
5765 * set the uniqueSetSuffix used to prefix/suffix object IDs for jalview
5766 * objects created from the project archive. If string is null (default for
5767 * construction) then suffix will be set automatically.
5771 public void setUniqueSetSuffix(String string)
5773 uniqueSetSuffix = string;
5778 * uses skipList2 as the skipList for skipping views on sequence sets
5779 * associated with keys in the skipList
5783 public void setSkipList(Hashtable skipList2)
5785 skipList = skipList2;
5789 * Reads the jar entry of given name and returns its contents, or null if the
5790 * entry is not found.
5793 * @param jarEntryName
5796 protected String readJarEntry(jarInputStreamProvider jprovider,
5797 String jarEntryName)
5799 String result = null;
5800 BufferedReader in = null;
5805 * Reopen the jar input stream and traverse its entries to find a matching
5808 JarInputStream jin = jprovider.getJarInputStream();
5809 JarEntry entry = null;
5812 entry = jin.getNextJarEntry();
5813 } while (entry != null && !entry.getName().equals(jarEntryName));
5817 StringBuilder out = new StringBuilder(256);
5818 in = new BufferedReader(new InputStreamReader(jin, UTF_8));
5821 while ((data = in.readLine()) != null)
5825 result = out.toString();
5829 warn("Couldn't find entry in Jalview Jar for " + jarEntryName);
5831 } catch (Exception ex)
5833 ex.printStackTrace();
5841 } catch (IOException e)
5852 * Returns an incrementing counter (0, 1, 2...)
5856 private synchronized int nextCounter()
5862 * Populates an XML model of the feature colour scheme for one feature type
5864 * @param featureType
5868 public static Colour marshalColour(
5869 String featureType, FeatureColourI fcol)
5871 Colour col = new Colour();
5872 if (fcol.isSimpleColour())
5874 col.setRGB(Format.getHexString(fcol.getColour()));
5878 col.setRGB(Format.getHexString(fcol.getMaxColour()));
5879 col.setMin(fcol.getMin());
5880 col.setMax(fcol.getMax());
5881 col.setMinRGB(jalview.util.Format.getHexString(fcol.getMinColour()));
5882 col.setAutoScale(fcol.isAutoScaled());
5883 col.setThreshold(fcol.getThreshold());
5884 col.setColourByLabel(fcol.isColourByLabel());
5885 col.setThreshType(fcol.isAboveThreshold() ? ThresholdType.ABOVE
5886 : (fcol.isBelowThreshold() ? ThresholdType.BELOW
5887 : ThresholdType.NONE));
5888 if (fcol.isColourByAttribute())
5890 final String[] attName = fcol.getAttributeName();
5891 col.getAttributeName().add(attName[0]);
5892 if (attName.length > 1)
5894 col.getAttributeName().add(attName[1]);
5897 Color noColour = fcol.getNoColour();
5898 if (noColour == null)
5900 col.setNoValueColour(NoValueColour.NONE);
5902 else if (noColour == fcol.getMaxColour())
5904 col.setNoValueColour(NoValueColour.MAX);
5908 col.setNoValueColour(NoValueColour.MIN);
5911 col.setName(featureType);
5916 * Populates an XML model of the feature filter(s) for one feature type
5918 * @param firstMatcher
5919 * the first (or only) match condition)
5921 * remaining match conditions (if any)
5923 * if true, conditions are and-ed, else or-ed
5925 public static jalview.xml.binding.jalview.FeatureMatcherSet marshalFilter(
5926 FeatureMatcherI firstMatcher, Iterator<FeatureMatcherI> filters,
5929 jalview.xml.binding.jalview.FeatureMatcherSet result = new jalview.xml.binding.jalview.FeatureMatcherSet();
5931 if (filters.hasNext())
5936 CompoundMatcher compound = new CompoundMatcher();
5937 compound.setAnd(and);
5938 jalview.xml.binding.jalview.FeatureMatcherSet matcher1 = marshalFilter(
5939 firstMatcher, Collections.emptyIterator(), and);
5940 // compound.addMatcherSet(matcher1);
5941 compound.getMatcherSet().add(matcher1);
5942 FeatureMatcherI nextMatcher = filters.next();
5943 jalview.xml.binding.jalview.FeatureMatcherSet matcher2 = marshalFilter(
5944 nextMatcher, filters, and);
5945 // compound.addMatcherSet(matcher2);
5946 compound.getMatcherSet().add(matcher2);
5947 result.setCompoundMatcher(compound);
5952 * single condition matcher
5954 // MatchCondition matcherModel = new MatchCondition();
5955 jalview.xml.binding.jalview.FeatureMatcher matcherModel = new jalview.xml.binding.jalview.FeatureMatcher();
5956 matcherModel.setCondition(
5957 firstMatcher.getMatcher().getCondition().getStableName());
5958 matcherModel.setValue(firstMatcher.getMatcher().getPattern());
5959 if (firstMatcher.isByAttribute())
5961 matcherModel.setBy(FilterBy.BY_ATTRIBUTE);
5962 // matcherModel.setAttributeName(firstMatcher.getAttribute());
5963 String[] attName = firstMatcher.getAttribute();
5964 matcherModel.getAttributeName().add(attName[0]); // attribute
5965 if (attName.length > 1)
5967 matcherModel.getAttributeName().add(attName[1]); // sub-attribute
5970 else if (firstMatcher.isByLabel())
5972 matcherModel.setBy(FilterBy.BY_LABEL);
5974 else if (firstMatcher.isByScore())
5976 matcherModel.setBy(FilterBy.BY_SCORE);
5978 result.setMatchCondition(matcherModel);
5985 * Loads one XML model of a feature filter to a Jalview object
5987 * @param featureType
5988 * @param matcherSetModel
5991 public static FeatureMatcherSetI parseFilter(
5993 jalview.xml.binding.jalview.FeatureMatcherSet matcherSetModel)
5995 FeatureMatcherSetI result = new FeatureMatcherSet();
5998 parseFilterConditions(result, matcherSetModel, true);
5999 } catch (IllegalStateException e)
6001 // mixing AND and OR conditions perhaps
6003 String.format("Error reading filter conditions for '%s': %s",
6004 featureType, e.getMessage()));
6005 // return as much as was parsed up to the error
6012 * Adds feature match conditions to matcherSet as unmarshalled from XML
6013 * (possibly recursively for compound conditions)
6016 * @param matcherSetModel
6018 * if true, multiple conditions are AND-ed, else they are OR-ed
6019 * @throws IllegalStateException
6020 * if AND and OR conditions are mixed
6022 protected static void parseFilterConditions(
6023 FeatureMatcherSetI matcherSet,
6024 jalview.xml.binding.jalview.FeatureMatcherSet matcherSetModel,
6027 jalview.xml.binding.jalview.FeatureMatcher mc = matcherSetModel
6028 .getMatchCondition();
6034 FilterBy filterBy = mc.getBy();
6035 Condition cond = Condition.fromString(mc.getCondition());
6036 String pattern = mc.getValue();
6037 FeatureMatcherI matchCondition = null;
6038 if (filterBy == FilterBy.BY_LABEL)
6040 matchCondition = FeatureMatcher.byLabel(cond, pattern);
6042 else if (filterBy == FilterBy.BY_SCORE)
6044 matchCondition = FeatureMatcher.byScore(cond, pattern);
6047 else if (filterBy == FilterBy.BY_ATTRIBUTE)
6049 final List<String> attributeName = mc.getAttributeName();
6050 String[] attNames = attributeName
6051 .toArray(new String[attributeName.size()]);
6052 matchCondition = FeatureMatcher.byAttribute(cond, pattern,
6057 * note this throws IllegalStateException if AND-ing to a
6058 * previously OR-ed compound condition, or vice versa
6062 matcherSet.and(matchCondition);
6066 matcherSet.or(matchCondition);
6072 * compound condition
6074 List<jalview.xml.binding.jalview.FeatureMatcherSet> matchers = matcherSetModel
6075 .getCompoundMatcher().getMatcherSet();
6076 boolean anded = matcherSetModel.getCompoundMatcher().isAnd();
6077 if (matchers.size() == 2)
6079 parseFilterConditions(matcherSet, matchers.get(0), anded);
6080 parseFilterConditions(matcherSet, matchers.get(1), anded);
6084 System.err.println("Malformed compound filter condition");
6090 * Loads one XML model of a feature colour to a Jalview object
6092 * @param colourModel
6095 public static FeatureColourI parseColour(Colour colourModel)
6097 FeatureColourI colour = null;
6099 if (colourModel.getMax() != null)
6101 Color mincol = null;
6102 Color maxcol = null;
6103 Color noValueColour = null;
6107 mincol = new Color(Integer.parseInt(colourModel.getMinRGB(), 16));
6108 maxcol = new Color(Integer.parseInt(colourModel.getRGB(), 16));
6109 } catch (Exception e)
6111 Cache.log.warn("Couldn't parse out graduated feature color.", e);
6114 NoValueColour noCol = colourModel.getNoValueColour();
6115 if (noCol == NoValueColour.MIN)
6117 noValueColour = mincol;
6119 else if (noCol == NoValueColour.MAX)
6121 noValueColour = maxcol;
6124 colour = new FeatureColour(mincol, maxcol, noValueColour,
6125 safeFloat(colourModel.getMin()),
6126 safeFloat(colourModel.getMax()));
6127 final List<String> attributeName = colourModel.getAttributeName();
6128 String[] attributes = attributeName
6129 .toArray(new String[attributeName.size()]);
6130 if (attributes != null && attributes.length > 0)
6132 colour.setAttributeName(attributes);
6134 if (colourModel.isAutoScale() != null)
6136 colour.setAutoScaled(colourModel.isAutoScale().booleanValue());
6138 if (colourModel.isColourByLabel() != null)
6140 colour.setColourByLabel(
6141 colourModel.isColourByLabel().booleanValue());
6143 if (colourModel.getThreshold() != null)
6145 colour.setThreshold(colourModel.getThreshold().floatValue());
6147 ThresholdType ttyp = colourModel.getThreshType();
6148 if (ttyp == ThresholdType.ABOVE)
6150 colour.setAboveThreshold(true);
6152 else if (ttyp == ThresholdType.BELOW)
6154 colour.setBelowThreshold(true);
6159 Color color = new Color(Integer.parseInt(colourModel.getRGB(), 16));
6160 colour = new FeatureColour(color);