*/
package jalview.gui;
-import java.awt.Rectangle;
-import java.io.BufferedReader;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.Vector;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
-import java.util.jar.JarOutputStream;
-
-import javax.swing.JInternalFrame;
-import javax.swing.JOptionPane;
-import javax.swing.SwingUtilities;
-
-import org.exolab.castor.xml.Marshaller;
-import org.exolab.castor.xml.Unmarshaller;
-
+import jalview.api.FeatureColourI;
+import jalview.api.ViewStyleI;
import jalview.api.structures.JalviewStructureDisplayI;
import jalview.bin.Cache;
import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.PDBEntry;
+import jalview.datamodel.RnaViewerModel;
+import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.datamodel.StructureViewerModel;
import jalview.datamodel.StructureViewerModel.StructureData;
+import jalview.ext.varna.RnaModel;
import jalview.gui.StructureViewer.ViewerType;
import jalview.schemabinding.version2.AlcodMap;
import jalview.schemabinding.version2.AlcodonFrame;
import jalview.schemabinding.version2.PdbentryItem;
import jalview.schemabinding.version2.Pdbids;
import jalview.schemabinding.version2.Property;
+import jalview.schemabinding.version2.RnaViewer;
+import jalview.schemabinding.version2.SecondaryStructure;
import jalview.schemabinding.version2.Sequence;
import jalview.schemabinding.version2.SequenceSet;
import jalview.schemabinding.version2.SequenceSetProperties;
import jalview.schemes.AnnotationColourGradient;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.GraduatedColor;
+import jalview.schemes.FeatureColour;
import jalview.schemes.ResidueColourScheme;
import jalview.schemes.ResidueProperties;
import jalview.schemes.UserColourScheme;
import jalview.structures.models.AAStructureBindingModel;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.StringUtils;
import jalview.util.jarInputStreamProvider;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
import jalview.ws.params.AutoCalcSetting;
import jalview.ws.params.WsParamSetI;
+import java.awt.Color;
+import java.awt.Rectangle;
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.Vector;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+
+import javax.swing.JInternalFrame;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+
+import org.exolab.castor.xml.Marshaller;
+import org.exolab.castor.xml.Unmarshaller;
+
/**
* Write out the current jalview desktop state as a Jalview XML stream.
*
*/
public class Jalview2XML
{
+ private static final String VIEWER_PREFIX = "viewer_";
+
+ private static final String RNA_PREFIX = "rna_";
+
private static final String UTF_8 = "UTF-8";
+ // use this with nextCounter() to make unique names for entities
+ private int counter = 0;
+
/*
* SequenceI reference -> XML ID string in jalview XML. Populated as XML reps
* of sequence objects are created.
*/
Map<String, SequenceI> seqRefIds = null;
- Vector frefedSequence = null;
+ Map<String, SequenceI> incompleteSeqs = null;
+
+ List<SeqFref> frefedSequence = null;
boolean raiseGUI = true; // whether errors are raised in dialog boxes or not
*/
private Map<Viewport, AlignFrame> splitFrameCandidates = new HashMap<Viewport, AlignFrame>();
+ /*
+ * Map from displayed rna structure models to their saved session state jar
+ * entry names
+ */
+ private Map<RnaModel, String> rnaSessions = new HashMap<RnaModel, String>();
+
/**
* create/return unique hash string for sq
*
{
seqsToIds.clear();
}
+ if (incompleteSeqs != null)
+ {
+ incompleteSeqs.clear();
+ }
// seqRefIds = null;
// seqsToIds = null;
}
{
seqRefIds = new HashMap<String, SequenceI>();
}
+ if (incompleteSeqs == null)
+ {
+ incompleteSeqs = new HashMap<String, SequenceI>();
+ }
+ if (frefedSequence == null)
+ {
+ frefedSequence = new ArrayList<SeqFref>();
+ }
}
public Jalview2XML()
this.raiseGUI = raiseGUI;
}
- public void resolveFrefedSequences()
+ /**
+ * base class for resolving forward references to sequences by their ID
+ *
+ * @author jprocter
+ *
+ */
+ abstract class SeqFref
{
- if (frefedSequence.size() > 0)
+ String sref;
+
+ String type;
+
+ public SeqFref(String _sref, String type)
+ {
+ sref = _sref;
+ this.type = type;
+ }
+
+ public String getSref()
+ {
+ return sref;
+ }
+
+ public SequenceI getSrefSeq()
+ {
+ return seqRefIds.get(sref);
+ }
+
+ public boolean isResolvable()
{
- int r = 0, rSize = frefedSequence.size();
- while (r < rSize)
+ return seqRefIds.get(sref) != null;
+ }
+
+ public SequenceI getSrefDatasetSeq()
+ {
+ SequenceI sq = seqRefIds.get(sref);
+ if (sq != null)
{
- Object[] ref = (Object[]) frefedSequence.elementAt(r);
- if (ref != null)
+ while (sq.getDatasetSequence() != null)
{
- String sref = (String) ref[0];
- if (seqRefIds.containsKey(sref))
- {
- if (ref[1] instanceof jalview.datamodel.Mapping)
- {
- SequenceI seq = seqRefIds.get(sref);
- while (seq.getDatasetSequence() != null)
- {
- seq = seq.getDatasetSequence();
- }
- ((jalview.datamodel.Mapping) ref[1]).setTo(seq);
- }
- else
- {
- if (ref[1] instanceof jalview.datamodel.AlignedCodonFrame)
- {
- SequenceI seq = seqRefIds.get(sref);
- while (seq.getDatasetSequence() != null)
- {
- seq = seq.getDatasetSequence();
- }
- if (ref[2] != null
- && ref[2] instanceof jalview.datamodel.Mapping)
- {
- jalview.datamodel.Mapping mp = (jalview.datamodel.Mapping) ref[2];
- ((jalview.datamodel.AlignedCodonFrame) ref[1]).addMap(
- seq, mp.getTo(), mp.getMap());
- }
- else
- {
- System.err
- .println("IMPLEMENTATION ERROR: Unimplemented forward sequence references for AlcodonFrames involving "
- + ref[2].getClass() + " type objects.");
- }
- }
- else
- {
- System.err
- .println("IMPLEMENTATION ERROR: Unimplemented forward sequence references for "
- + ref[1].getClass() + " type objects.");
- }
- }
- frefedSequence.remove(r);
- rSize--;
- }
- else
+ sq = sq.getDatasetSequence();
+ }
+ }
+ return sq;
+ }
+ /**
+ * @return true if the forward reference was fully resolved
+ */
+ abstract boolean resolve();
+
+ @Override
+ public String toString()
+ {
+ return type + " reference to " + sref;
+ }
+ }
+
+ /**
+ * create forward reference for a mapping
+ *
+ * @param sref
+ * @param _jmap
+ * @return
+ */
+ public SeqFref newMappingRef(final String sref,
+ final jalview.datamodel.Mapping _jmap)
+ {
+ SeqFref fref = new SeqFref(sref, "Mapping")
+ {
+ public jalview.datamodel.Mapping jmap = _jmap;
+
+ @Override
+ boolean resolve()
+ {
+ SequenceI seq = getSrefDatasetSeq();
+ if (seq == null)
+ {
+ return false;
+ }
+ jmap.setTo(seq);
+ return true;
+ }
+ };
+ return fref;
+ }
+
+ public SeqFref newAlcodMapRef(final String sref,
+ final AlignedCodonFrame _cf, final jalview.datamodel.Mapping _jmap)
+ {
+
+ SeqFref fref = new SeqFref(sref, "Codon Frame")
+ {
+ AlignedCodonFrame cf = _cf;
+
+ public jalview.datamodel.Mapping mp = _jmap;
+
+ @Override
+ boolean resolve()
+ {
+ SequenceI seq = getSrefDatasetSeq();
+ if (seq == null)
+ {
+ return false;
+ }
+ cf.addMap(seq, mp.getTo(), mp.getMap());
+ return true;
+ }
+ };
+ return fref;
+ }
+
+ public void resolveFrefedSequences()
+ {
+ Iterator<SeqFref> nextFref=frefedSequence.iterator();
+ int toresolve=frefedSequence.size();
+ int unresolved=0,failedtoresolve=0;
+ while (nextFref.hasNext()) {
+ SeqFref ref = nextFref.next();
+ if (ref.isResolvable())
+ {
+ try {
+ if (ref.resolve())
{
- System.err
- .println("IMPLEMENTATION WARNING: Unresolved forward reference for hash string "
- + ref[0]
- + " with objecttype "
- + ref[1].getClass());
- r++;
+ nextFref.remove();
+ } else {
+ failedtoresolve++;
}
- }
- else
+ } catch (Exception x) {
+ System.err.println("IMPLEMENTATION ERROR: Failed to resolve forward reference for sequence "+ref.getSref());
+ x.printStackTrace();
+ failedtoresolve++;
+ }
+ } else {
+ unresolved++;
+ }
+ }
+ if (unresolved>0)
+ {
+ System.err.println("Jalview Project Import: There were " + unresolved
+ + " forward references left unresolved on the stack.");
+ }
+ if (failedtoresolve>0)
+ {
+ System.err.println("SERIOUS! " + failedtoresolve
+ + " resolvable forward references failed to resolve.");
+ }
+ if (incompleteSeqs != null && incompleteSeqs.size() > 0)
+ {
+ System.err.println("Jalview Project Import: There are "
+ + incompleteSeqs.size()
+ + " sequences which may have incomplete metadata.");
+ if (incompleteSeqs.size() < 10)
+ {
+ for (SequenceI s : incompleteSeqs.values())
{
- // empty reference
- frefedSequence.remove(r);
- rSize--;
+ System.err.println(s.toString());
}
}
+ else
+ {
+ System.err
+ .println("Too many to report. Skipping output of incomplete sequences.");
+ }
}
}
*/
public void saveState(JarOutputStream jout)
{
- AlignFrame[] frames = Desktop.getAlignFrames(); // Desktop.desktop.getAllFrames();
+ AlignFrame[] frames = Desktop.getAlignFrames();
if (frames == null)
{
return;
}
+ saveAllFrames(Arrays.asList(frames), jout);
+ }
+ /**
+ * core method for storing state for a set of AlignFrames.
+ *
+ * @param frames
+ * - frames involving all data to be exported (including containing
+ * splitframes)
+ * @param jout
+ * - project output stream
+ */
+ private void saveAllFrames(List<AlignFrame> frames, JarOutputStream jout)
+ {
Hashtable<String, AlignFrame> dsses = new Hashtable<String, AlignFrame>();
+ /*
+ * ensure cached data is clear before starting
+ */
+ // todo tidy up seqRefIds, seqsToIds initialisation / reset
+ rnaSessions.clear();
+ splitFrameCandidates.clear();
+
try
{
// //////////////////////////////////////////////////
List<String> shortNames = new ArrayList<String>();
+ List<String> viewIds = new ArrayList<String>();
// REVERSE ORDER
- for (int i = frames.length - 1; i > -1; i--)
+ for (int i = frames.size() - 1; i > -1; i--)
{
- AlignFrame af = frames[i];
+ AlignFrame af = frames.get(i);
// skip ?
if (skipList != null
&& skipList
fileName = fileName + ".xml";
}
- saveState(apanel, fileName, jout);
+ saveState(apanel, fileName, jout, viewIds);
String dssid = getDatasetIdRef(af.getViewport().getAlignment()
.getDataset());
{
try
{
- int ap = 0;
- int apSize = af.alignPanels.size();
FileOutputStream fos = new FileOutputStream(jarFile);
JarOutputStream jout = new JarOutputStream(fos);
- Hashtable<String, AlignFrame> dsses = new Hashtable<String, AlignFrame>();
- for (AlignmentPanel apanel : af.alignPanels)
+ List<AlignFrame> frames = new ArrayList<AlignFrame>();
+
+ // resolve splitframes
+ if (af.getViewport().getCodingComplement() != null)
{
- String jfileName = apSize == 1 ? fileName : fileName + ap;
- ap++;
- if (!jfileName.endsWith(".xml"))
- {
- jfileName = jfileName + ".xml";
- }
- saveState(apanel, jfileName, jout);
- String dssid = getDatasetIdRef(af.getViewport().getAlignment()
- .getDataset());
- if (!dsses.containsKey(dssid))
- {
- dsses.put(dssid, af);
- }
+ frames = ((SplitFrame) af.getSplitViewContainer()).getAlignFrames();
}
- writeDatasetFor(dsses, fileName, jout);
+ else
+ {
+ frames.add(af);
+ }
+ saveAllFrames(frames, jout);
try
{
jout.flush();
{
jfileName = jfileName + ".xml";
}
- saveState(_af.alignPanel, jfileName, true, jout);
+ saveState(_af.alignPanel, jfileName, true, jout, null);
}
}
* name of alignment panel written to output stream
* @param jout
* jar output stream
+ * @param viewIds
* @param out
* jar entry name
*/
public JalviewModel saveState(AlignmentPanel ap, String fileName,
- JarOutputStream jout)
+ JarOutputStream jout, List<String> viewIds)
{
- return saveState(ap, fileName, false, jout);
+ return saveState(ap, fileName, false, jout, viewIds);
}
/**
* jar entry name
*/
public JalviewModel saveState(AlignmentPanel ap, String fileName,
- boolean storeDS, JarOutputStream jout)
+ boolean storeDS, JarOutputStream jout, List<String> viewIds)
{
+ if (viewIds == null)
+ {
+ viewIds = new ArrayList<String>();
+ }
+
initSeqRefs();
- List<String> viewIds = new ArrayList<String>();
+
List<UserColourScheme> userColours = new ArrayList<UserColourScheme>();
AlignViewport av = ap.av;
object.setVersion(jalview.bin.Cache.getDefault("VERSION",
"Development Build"));
- jalview.datamodel.AlignmentI jal = av.getAlignment();
+ /**
+ * rjal is full height alignment, jal is actual alignment with full metadata
+ * but excludes hidden sequences.
+ */
+ jalview.datamodel.AlignmentI rjal = av.getAlignment(), jal = rjal;
if (av.hasHiddenRows())
{
- jal = jal.getHiddenSequences().getFullAlignment();
+ rjal = jal.getHiddenSequences().getFullAlignment();
}
SequenceSet vamsasSet = new SequenceSet();
{
// switch jal and the dataset
jal = jal.getDataset();
+ rjal = jal;
}
}
if (jal.getProperties() != null)
Set<String> calcIdSet = new HashSet<String>();
// SAVE SEQUENCES
- String id = "";
- jalview.datamodel.SequenceI jds, jdatasq;
- for (int i = 0; i < jal.getHeight(); i++)
+ for (final SequenceI jds : rjal.getSequences())
{
- jds = jal.getSequenceAt(i);
- jdatasq = jds.getDatasetSequence() == null ? jds : jds
- .getDatasetSequence();
- id = seqHash(jds);
+ final SequenceI jdatasq = jds.getDatasetSequence() == null ? jds
+ : jds.getDatasetSequence();
+ String id = seqHash(jds);
if (seqRefIds.get(id) != null)
{
// Store any sequences this sequence represents
if (av.hasHiddenRows())
{
+ // use rjal, contains the full height alignment
jseq.setHidden(av.getAlignment().getHiddenSequences()
.isHidden(jds));
- if (av.isHiddenRepSequence(jal.getSequenceAt(i)))
+ if (av.isHiddenRepSequence(jds))
{
jalview.datamodel.SequenceI[] reps = av
- .getRepresentedSequences(jal.getSequenceAt(i))
- .getSequencesInOrder(jal);
+ .getRepresentedSequences(jds)
+ .getSequencesInOrder(rjal);
for (int h = 0; h < reps.length; h++)
{
- if (reps[h] != jal.getSequenceAt(i))
+ if (reps[h] != jds)
{
- jseq.addHiddenSequences(jal.findIndex(reps[h]));
+ jseq.addHiddenSequences(rjal.findIndex(reps[h]));
}
}
}
}
+ // mark sequence as reference - if it is the reference for this view
+ if (jal.hasSeqrep())
+ {
+ jseq.setViewreference(jds == jal.getSeqrep());
+ }
}
+ // TODO: omit sequence features from each alignment view's XML dump if we
+ // are storing dataset
if (jds.getSequenceFeatures() != null)
{
- jalview.datamodel.SequenceFeature[] sf = jds
- .getSequenceFeatures();
+ jalview.datamodel.SequenceFeature[] sf = jds.getSequenceFeatures();
int index = 0;
while (index < sf.length)
{
if (sf[index].otherDetails != null)
{
String key;
- Enumeration keys = sf[index].otherDetails.keys();
- while (keys.hasMoreElements())
+ Iterator<String> keys = sf[index].otherDetails.keySet()
+ .iterator();
+ while (keys.hasNext())
{
- key = keys.nextElement().toString();
+ key = keys.next();
OtherData keyValue = new OtherData();
keyValue.setKey(key);
keyValue.setValue(sf[index].otherDetails.get(key).toString());
}
}
- if (jdatasq.getPDBId() != null)
+ if (jdatasq.getAllPDBEntries() != null)
{
- Enumeration en = jdatasq.getPDBId().elements();
+ Enumeration en = jdatasq.getAllPDBEntries().elements();
while (en.hasMoreElements())
{
Pdbids pdb = new Pdbids();
matchedFile = saveStructureState(ap, jds, pdb, entry,
viewIds, matchedFile, viewFrame);
/*
- * Only store each structure viewer's state once in each XML
- * document. First time through only (storeDS==false)
+ * Only store each structure viewer's state once in the project
+ * jar. First time through only (storeDS==false)
*/
String viewId = viewFrame.getViewId();
if (!storeDS && !viewIds.contains(viewId))
viewIds.add(viewId);
try
{
+ String viewerState = viewFrame.getStateInfo();
writeJarEntry(jout, getViewerJarEntryName(viewId),
- viewFrame.getStateInfo().getBytes());
+ viewerState.getBytes());
} catch (IOException e)
{
System.err.println("Error saving viewer state: "
}
}
+ saveRnaViewers(jout, jseq, jds, viewIds, ap, storeDS);
+
jms.addJSeq(jseq);
}
jal = av.getAlignment();
}
// SAVE MAPPINGS
- if (jal.getCodonFrames() != null)
+ // FOR DATASET
+ if (storeDS && jal.getCodonFrames() != null)
{
- Set<AlignedCodonFrame> jac = jal.getCodonFrames();
+ List<AlignedCodonFrame> jac = jal.getCodonFrames();
for (AlignedCodonFrame acf : jac)
{
AlcodonFrame alc = new AlcodonFrame();
- vamsasSet.addAlcodonFrame(alc);
if (acf.getProtMappings() != null
&& acf.getProtMappings().length > 0)
{
+ boolean hasMap = false;
SequenceI[] dnas = acf.getdnaSeqs();
jalview.datamodel.Mapping[] pmaps = acf.getProtMappings();
for (int m = 0; m < pmaps.length; m++)
alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null,
false));
alc.addAlcodMap(alcmap);
+ hasMap = true;
+ }
+ if (hasMap)
+ {
+ vamsasSet.addAlcodonFrame(alc);
}
}
-
-// {
-// AlcodonFrame alc = new AlcodonFrame();
-// vamsasSet.addAlcodonFrame(alc);
-// for (int p = 0; p < acf.aaWidth; p++)
-// {
-// Alcodon cmap = new Alcodon();
-// if (acf.codons[p] != null)
-// {
-// // Null codons indicate a gapped column in the translated peptide
-// // alignment.
-// cmap.setPos1(acf.codons[p][0]);
-// cmap.setPos2(acf.codons[p][1]);
-// cmap.setPos3(acf.codons[p][2]);
-// }
-// alc.addAlcodon(cmap);
-// }
-// if (acf.getProtMappings() != null
-// && acf.getProtMappings().length > 0)
-// {
-// SequenceI[] dnas = acf.getdnaSeqs();
-// jalview.datamodel.Mapping[] pmaps = acf.getProtMappings();
-// for (int m = 0; m < pmaps.length; m++)
-// {
-// AlcodMap alcmap = new AlcodMap();
-// alcmap.setDnasq(seqHash(dnas[m]));
-// alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null,
-// false));
-// alc.addAlcodMap(alcmap);
-// }
-// }
+ // TODO: delete this ? dead code from 2.8.3->2.9 ?
+ // {
+ // AlcodonFrame alc = new AlcodonFrame();
+ // vamsasSet.addAlcodonFrame(alc);
+ // for (int p = 0; p < acf.aaWidth; p++)
+ // {
+ // Alcodon cmap = new Alcodon();
+ // if (acf.codons[p] != null)
+ // {
+ // // Null codons indicate a gapped column in the translated peptide
+ // // alignment.
+ // cmap.setPos1(acf.codons[p][0]);
+ // cmap.setPos2(acf.codons[p][1]);
+ // cmap.setPos3(acf.codons[p][2]);
+ // }
+ // alc.addAlcodon(cmap);
+ // }
+ // if (acf.getProtMappings() != null
+ // && acf.getProtMappings().length > 0)
+ // {
+ // SequenceI[] dnas = acf.getdnaSeqs();
+ // jalview.datamodel.Mapping[] pmaps = acf.getProtMappings();
+ // for (int m = 0; m < pmaps.length; m++)
+ // {
+ // AlcodMap alcmap = new AlcodMap();
+ // alcmap.setDnasq(seqHash(dnas[m]));
+ // alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null,
+ // false));
+ // alc.addAlcodMap(alcmap);
+ // }
+ // }
}
}
}
}
- /*
- * Save associated Varna panels
- */
- if (Desktop.desktop != null)
- {
- for (JInternalFrame frame : Desktop.desktop.getAllFrames())
- {
- if (frame instanceof AppVarna)
- {
- AppVarna vp = (AppVarna) frame;
- if (vp.ap == ap)
- {
- // save Varna state
- }
- }
- }
- }
-
// SAVE ANNOTATIONS
/**
* store forward refs from an annotationRow to any groups
*/
- IdentityHashMap groupRefs = new IdentityHashMap();
+ IdentityHashMap<SequenceGroup, String> groupRefs = new IdentityHashMap<SequenceGroup, String>();
if (storeDS)
{
for (SequenceI sq : jal.getSequences())
{
// Store annotation on dataset sequences only
- jalview.datamodel.AlignmentAnnotation[] aa = sq.getAnnotation();
+ AlignmentAnnotation[] aa = sq.getAnnotation();
if (aa != null && aa.length > 0)
{
storeAlignmentAnnotation(aa, groupRefs, av, calcIdSet, storeDS,
if (jal.getAlignmentAnnotation() != null)
{
// Store the annotation shown on the alignment.
- jalview.datamodel.AlignmentAnnotation[] aa = jal
- .getAlignmentAnnotation();
+ AlignmentAnnotation[] aa = jal.getAlignmentAnnotation();
storeAlignmentAnnotation(aa, groupRefs, av, calcIdSet, storeDS,
vamsasSet);
}
int i = -1;
for (jalview.datamodel.SequenceGroup sg : jal.getGroups())
{
- groups[++i] = new JGroup();
+ JGroup jGroup = new JGroup();
+ groups[++i] = jGroup;
- groups[i].setStart(sg.getStartRes());
- groups[i].setEnd(sg.getEndRes());
- groups[i].setName(sg.getName());
+ jGroup.setStart(sg.getStartRes());
+ jGroup.setEnd(sg.getEndRes());
+ jGroup.setName(sg.getName());
if (groupRefs.containsKey(sg))
{
- // group has references so set it's ID field
- groups[i].setId(groupRefs.get(sg).toString());
+ // group has references so set its ID field
+ jGroup.setId(groupRefs.get(sg));
}
if (sg.cs != null)
{
if (sg.cs.conservationApplied())
{
- groups[i].setConsThreshold(sg.cs.getConservationInc());
+ jGroup.setConsThreshold(sg.cs.getConservationInc());
if (sg.cs instanceof jalview.schemes.UserColourScheme)
{
- groups[i].setColour(setUserColourScheme(sg.cs, userColours,
- jms));
+ jGroup.setColour(setUserColourScheme(sg.cs, userColours, jms));
}
else
{
- groups[i]
- .setColour(ColourSchemeProperty.getColourName(sg.cs));
+ jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs));
}
}
else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient)
{
- groups[i].setColour("AnnotationColourGradient");
- groups[i].setAnnotationColours(constructAnnotationColours(
+ jGroup.setColour("AnnotationColourGradient");
+ jGroup.setAnnotationColours(constructAnnotationColours(
(jalview.schemes.AnnotationColourGradient) sg.cs,
userColours, jms));
}
else if (sg.cs instanceof jalview.schemes.UserColourScheme)
{
- groups[i]
- .setColour(setUserColourScheme(sg.cs, userColours, jms));
+ jGroup.setColour(setUserColourScheme(sg.cs, userColours, jms));
}
else
{
- groups[i].setColour(ColourSchemeProperty.getColourName(sg.cs));
+ jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs));
}
- groups[i].setPidThreshold(sg.cs.getThreshold());
+ jGroup.setPidThreshold(sg.cs.getThreshold());
}
- groups[i].setOutlineColour(sg.getOutlineColour().getRGB());
- groups[i].setDisplayBoxes(sg.getDisplayBoxes());
- groups[i].setDisplayText(sg.getDisplayText());
- groups[i].setColourText(sg.getColourText());
- groups[i].setTextCol1(sg.textColour.getRGB());
- groups[i].setTextCol2(sg.textColour2.getRGB());
- groups[i].setTextColThreshold(sg.thresholdTextColour);
- groups[i].setShowUnconserved(sg.getShowNonconserved());
- groups[i].setIgnoreGapsinConsensus(sg.getIgnoreGapsConsensus());
- groups[i].setShowConsensusHistogram(sg.isShowConsensusHistogram());
- groups[i].setShowSequenceLogo(sg.isShowSequenceLogo());
- groups[i].setNormaliseSequenceLogo(sg.isNormaliseSequenceLogo());
- for (int s = 0; s < sg.getSize(); s++)
- {
- jalview.datamodel.Sequence seq = (jalview.datamodel.Sequence) sg
- .getSequenceAt(s);
- groups[i].addSeq(seqHash(seq));
+ jGroup.setOutlineColour(sg.getOutlineColour().getRGB());
+ jGroup.setDisplayBoxes(sg.getDisplayBoxes());
+ jGroup.setDisplayText(sg.getDisplayText());
+ jGroup.setColourText(sg.getColourText());
+ jGroup.setTextCol1(sg.textColour.getRGB());
+ jGroup.setTextCol2(sg.textColour2.getRGB());
+ jGroup.setTextColThreshold(sg.thresholdTextColour);
+ jGroup.setShowUnconserved(sg.getShowNonconserved());
+ jGroup.setIgnoreGapsinConsensus(sg.getIgnoreGapsConsensus());
+ jGroup.setShowConsensusHistogram(sg.isShowConsensusHistogram());
+ jGroup.setShowSequenceLogo(sg.isShowSequenceLogo());
+ jGroup.setNormaliseSequenceLogo(sg.isNormaliseSequenceLogo());
+ for (SequenceI seq : sg.getSequences())
+ {
+ jGroup.addSeq(seqHash(seq));
}
}
view.setViewName(av.viewName);
view.setGatheredViews(av.isGatherViewsHere());
- Rectangle position = ap.av.getExplodedGeometry();
- if (position == null)
+ Rectangle size = ap.av.getExplodedGeometry();
+ Rectangle position = size;
+ if (size == null)
{
- position = ap.alignFrame.getBounds();
+ size = ap.alignFrame.getBounds();
+ if (av.getCodingComplement() != null)
+ {
+ position = ((SplitFrame) ap.alignFrame.getSplitViewContainer())
+ .getBounds();
+ }
+ else
+ {
+ position = size;
+ }
}
view.setXpos(position.x);
view.setYpos(position.y);
- view.setWidth(position.width);
- view.setHeight(position.height);
+
+ view.setWidth(size.width);
+ view.setHeight(size.height);
view.setStartRes(av.startRes);
view.setStartSeq(av.startSeq);
view.setFontName(av.font.getName());
view.setFontSize(av.font.getSize());
view.setFontStyle(av.font.getStyle());
+ view.setScaleProteinAsCdna(av.getViewStyle().isScaleProteinAsCdna());
view.setRenderGaps(av.isRenderGaps());
view.setShowAnnotation(av.isShowAnnotation());
view.setShowBoxes(av.getShowBoxes());
.getFeatureRenderer().getRenderOrder()
.toArray(new String[0]);
- Vector settingsAdded = new Vector();
- Object gstyle = null;
- GraduatedColor gcol = null;
+ Vector<String> settingsAdded = new Vector<String>();
if (renderOrder != null)
{
- for (int ro = 0; ro < renderOrder.length; ro++)
+ for (String featureType : renderOrder)
{
- gstyle = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
- .getFeatureStyle(renderOrder[ro]);
+ FeatureColourI fcol = ap.getSeqPanel().seqCanvas
+ .getFeatureRenderer()
+ .getFeatureStyle(featureType);
Setting setting = new Setting();
- setting.setType(renderOrder[ro]);
- if (gstyle instanceof GraduatedColor)
+ setting.setType(featureType);
+ if (!fcol.isSimpleColour())
{
- gcol = (GraduatedColor) gstyle;
- setting.setColour(gcol.getMaxColor().getRGB());
- setting.setMincolour(gcol.getMinColor().getRGB());
- setting.setMin(gcol.getMin());
- setting.setMax(gcol.getMax());
- setting.setColourByLabel(gcol.isColourByLabel());
- setting.setAutoScale(gcol.isAutoScale());
- setting.setThreshold(gcol.getThresh());
- setting.setThreshstate(gcol.getThreshType());
+ setting.setColour(fcol.getMaxColour().getRGB());
+ setting.setMincolour(fcol.getMinColour().getRGB());
+ setting.setMin(fcol.getMin());
+ setting.setMax(fcol.getMax());
+ setting.setColourByLabel(fcol.isColourByLabel());
+ setting.setAutoScale(fcol.isAutoScaled());
+ setting.setThreshold(fcol.getThreshold());
+ // -1 = No threshold, 0 = Below, 1 = Above
+ setting.setThreshstate(fcol.isAboveThreshold() ? 1
+ : (fcol.isBelowThreshold() ? 0 : -1));
}
else
{
- setting.setColour(ap.getSeqPanel().seqCanvas
- .getFeatureRenderer()
- .getColour(renderOrder[ro]).getRGB());
+ setting.setColour(fcol.getColour().getRGB());
}
setting.setDisplay(av.getFeaturesDisplayed().isVisible(
- renderOrder[ro]));
+ featureType));
float rorder = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
- .getOrder(renderOrder[ro]);
+ .getOrder(featureType);
if (rorder > -1)
{
setting.setOrder(rorder);
}
fs.addSetting(setting);
- settingsAdded.addElement(renderOrder[ro]);
+ settingsAdded.addElement(featureType);
}
}
- // Make sure we save none displayed feature settings
- Iterator en = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
- .getFeatureColours().keySet().iterator();
- while (en.hasNext())
- {
- String key = en.next().toString();
- if (settingsAdded.contains(key))
- {
- continue;
- }
-
- Setting setting = new Setting();
- setting.setType(key);
- setting.setColour(ap.getSeqPanel().seqCanvas.getFeatureRenderer()
- .getColour(key).getRGB());
-
- setting.setDisplay(false);
- float rorder = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
- .getOrder(key);
- if (rorder > -1)
- {
- setting.setOrder(rorder);
- }
- fs.addSetting(setting);
- settingsAdded.addElement(key);
- }
// is groups actually supposed to be a map here ?
- en = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
+ Iterator<String> en = ap.getSeqPanel().seqCanvas
+ .getFeatureRenderer()
.getFeatureGroups().iterator();
- Vector groupsAdded = new Vector();
+ Vector<String> groupsAdded = new Vector<String>();
while (en.hasNext())
{
- String grp = en.next().toString();
+ String grp = en.next();
if (groupsAdded.contains(grp))
{
continue;
groupsAdded.addElement(grp);
}
jms.setFeatureSettings(fs);
-
}
if (av.hasHiddenColumns())
// using save and then load
try
{
+ System.out.println("Writing jar entry " + fileName);
JarEntry entry = new JarEntry(fileName);
jout.putNextEntry(entry);
PrintWriter pout = new PrintWriter(new OutputStreamWriter(jout,
}
/**
- * Copy the contents of a file to a new file added to the output jar
+ * Save any Varna viewers linked to this sequence. Writes an rnaViewer element
+ * for each viewer, with
+ * <ul>
+ * <li>viewer geometry (position, size, split pane divider location)</li>
+ * <li>index of the selected structure in the viewer (currently shows gapped
+ * or ungapped)</li>
+ * <li>the id of the annotation holding RNA secondary structure</li>
+ * <li>(currently only one SS is shown per viewer, may be more in future)</li>
+ * </ul>
+ * Varna viewer state is also written out (in native Varna XML) to separate
+ * project jar entries. A separate entry is written for each RNA structure
+ * displayed, with the naming convention
+ * <ul>
+ * <li>rna_viewId_sequenceId_annotationId_[gapped|trimmed]</li>
+ * </ul>
+ *
+ * @param jout
+ * @param jseq
+ * @param jds
+ * @param viewIds
+ * @param ap
+ * @param storeDataset
+ */
+ protected void saveRnaViewers(JarOutputStream jout, JSeq jseq,
+ final SequenceI jds, List<String> viewIds, AlignmentPanel ap,
+ boolean storeDataset)
+ {
+ if (Desktop.desktop == null)
+ {
+ return;
+ }
+ JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+ for (int f = frames.length - 1; f > -1; f--)
+ {
+ if (frames[f] instanceof AppVarna)
+ {
+ AppVarna varna = (AppVarna) frames[f];
+ /*
+ * link the sequence to every viewer that is showing it and is linked to
+ * its alignment panel
+ */
+ if (varna.isListeningFor(jds) && ap == varna.getAlignmentPanel())
+ {
+ String viewId = varna.getViewId();
+ RnaViewer rna = new RnaViewer();
+ rna.setViewId(viewId);
+ rna.setTitle(varna.getTitle());
+ rna.setXpos(varna.getX());
+ rna.setYpos(varna.getY());
+ rna.setWidth(varna.getWidth());
+ rna.setHeight(varna.getHeight());
+ rna.setDividerLocation(varna.getDividerLocation());
+ rna.setSelectedRna(varna.getSelectedIndex());
+ jseq.addRnaViewer(rna);
+
+ /*
+ * Store each Varna panel's state once in the project per sequence.
+ * First time through only (storeDataset==false)
+ */
+ // boolean storeSessions = false;
+ // String sequenceViewId = viewId + seqsToIds.get(jds);
+ // if (!storeDataset && !viewIds.contains(sequenceViewId))
+ // {
+ // viewIds.add(sequenceViewId);
+ // storeSessions = true;
+ // }
+ for (RnaModel model : varna.getModels())
+ {
+ if (model.seq == jds)
+ {
+ /*
+ * VARNA saves each view (sequence or alignment secondary
+ * structure, gapped or trimmed) as a separate XML file
+ */
+ String jarEntryName = rnaSessions.get(model);
+ if (jarEntryName == null)
+ {
+
+ String varnaStateFile = varna.getStateInfo(model.rna);
+ jarEntryName = RNA_PREFIX + viewId + "_" + nextCounter();
+ copyFileToJar(jout, varnaStateFile, jarEntryName);
+ rnaSessions.put(model, jarEntryName);
+ }
+ SecondaryStructure ss = new SecondaryStructure();
+ String annotationId = varna.getAnnotation(jds).annotationId;
+ ss.setAnnotationId(annotationId);
+ ss.setViewerState(jarEntryName);
+ ss.setGapped(model.gapped);
+ ss.setTitle(model.title);
+ rna.addSecondaryStructure(ss);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Copy the contents of a file to a new entry added to the output jar
*
* @param jout
* @param infilePath
- * @param jarfileName
+ * @param jarEntryName
*/
protected void copyFileToJar(JarOutputStream jout, String infilePath,
- String jarfileName)
+ String jarEntryName)
{
DataInputStream dis = null;
try
dis = new DataInputStream(new FileInputStream(file));
byte[] data = new byte[(int) file.length()];
dis.readFully(data);
- writeJarEntry(jout, jarfileName, data);
+ writeJarEntry(jout, jarEntryName, data);
}
} catch (Exception ex)
{
* Write the data to a new entry of given name in the output jar file
*
* @param jout
- * @param jarfileName
+ * @param jarEntryName
* @param data
* @throws IOException
*/
- protected void writeJarEntry(JarOutputStream jout, String jarfileName,
+ protected void writeJarEntry(JarOutputStream jout, String jarEntryName,
byte[] data) throws IOException
{
if (jout != null)
{
- jout.putNextEntry(new JarEntry(jarfileName));
+ System.out.println("Writing jar entry " + jarEntryName);
+ jout.putNextEntry(new JarEntry(jarEntryName));
DataOutputStream dout = new DataOutputStream(jout);
dout.write(data, 0, data.length);
dout.flush();
}
private void storeAlignmentAnnotation(AlignmentAnnotation[] aa,
- IdentityHashMap groupRefs, AlignmentViewport av,
- Set<String> calcIdSet, boolean storeDS, SequenceSet vamsasSet)
+ IdentityHashMap<SequenceGroup, String> groupRefs,
+ AlignmentViewport av, Set<String> calcIdSet, boolean storeDS,
+ SequenceSet vamsasSet)
{
for (int i = 0; i < aa.length; i++)
{
Annotation an = new Annotation();
- if (aa[i].annotationId != null)
+ AlignmentAnnotation annotation = aa[i];
+ if (annotation.annotationId != null)
{
- annotationIds.put(aa[i].annotationId, aa[i]);
+ annotationIds.put(annotation.annotationId, annotation);
}
- an.setId(aa[i].annotationId);
+ an.setId(annotation.annotationId);
- an.setVisible(aa[i].visible);
+ an.setVisible(annotation.visible);
- an.setDescription(aa[i].description);
+ an.setDescription(annotation.description);
- if (aa[i].sequenceRef != null)
+ if (annotation.sequenceRef != null)
{
- // TODO later annotation sequenceRef should be the XML ID of the
- // sequence rather than its display name
- an.setSequenceRef(aa[i].sequenceRef.getName());
+ // 2.9 JAL-1781 xref on sequence id rather than name
+ an.setSequenceRef(seqsToIds.get(annotation.sequenceRef));
}
- if (aa[i].groupRef != null)
+ if (annotation.groupRef != null)
{
- Object groupIdr = groupRefs.get(aa[i].groupRef);
+ String groupIdr = groupRefs.get(annotation.groupRef);
if (groupIdr == null)
{
// make a locally unique String
- groupRefs.put(aa[i].groupRef,
+ groupRefs.put(
+ annotation.groupRef,
groupIdr = ("" + System.currentTimeMillis()
- + aa[i].groupRef.getName() + groupRefs.size()));
+ + annotation.groupRef.getName() + groupRefs
+ .size()));
}
an.setGroupRef(groupIdr.toString());
}
// store all visualization attributes for annotation
- an.setGraphHeight(aa[i].graphHeight);
- an.setCentreColLabels(aa[i].centreColLabels);
- an.setScaleColLabels(aa[i].scaleColLabel);
- an.setShowAllColLabels(aa[i].showAllColLabels);
- an.setBelowAlignment(aa[i].belowAlignment);
+ an.setGraphHeight(annotation.graphHeight);
+ an.setCentreColLabels(annotation.centreColLabels);
+ an.setScaleColLabels(annotation.scaleColLabel);
+ an.setShowAllColLabels(annotation.showAllColLabels);
+ an.setBelowAlignment(annotation.belowAlignment);
- if (aa[i].graph > 0)
+ if (annotation.graph > 0)
{
an.setGraph(true);
- an.setGraphType(aa[i].graph);
- an.setGraphGroup(aa[i].graphGroup);
- if (aa[i].getThreshold() != null)
+ an.setGraphType(annotation.graph);
+ an.setGraphGroup(annotation.graphGroup);
+ if (annotation.getThreshold() != null)
{
ThresholdLine line = new ThresholdLine();
- line.setLabel(aa[i].getThreshold().label);
- line.setValue(aa[i].getThreshold().value);
- line.setColour(aa[i].getThreshold().colour.getRGB());
+ line.setLabel(annotation.getThreshold().label);
+ line.setValue(annotation.getThreshold().value);
+ line.setColour(annotation.getThreshold().colour.getRGB());
an.setThresholdLine(line);
}
}
an.setGraph(false);
}
- an.setLabel(aa[i].label);
+ an.setLabel(annotation.label);
- if (aa[i] == av.getAlignmentQualityAnnot()
- || aa[i] == av.getAlignmentConservationAnnotation()
- || aa[i] == av.getAlignmentConsensusAnnotation()
- || aa[i].autoCalculated)
+ if (annotation == av.getAlignmentQualityAnnot()
+ || annotation == av.getAlignmentConservationAnnotation()
+ || annotation == av.getAlignmentConsensusAnnotation()
+ || annotation.autoCalculated)
{
// new way of indicating autocalculated annotation -
- an.setAutoCalculated(aa[i].autoCalculated);
+ an.setAutoCalculated(annotation.autoCalculated);
}
- if (aa[i].hasScore())
+ if (annotation.hasScore())
{
- an.setScore(aa[i].getScore());
+ an.setScore(annotation.getScore());
}
- if (aa[i].getCalcId() != null)
+ if (annotation.getCalcId() != null)
{
- calcIdSet.add(aa[i].getCalcId());
- an.setCalcId(aa[i].getCalcId());
+ calcIdSet.add(annotation.getCalcId());
+ an.setCalcId(annotation.getCalcId());
}
- if (aa[i].hasProperties())
+ if (annotation.hasProperties())
{
- for (String pr : aa[i].getProperties())
+ for (String pr : annotation.getProperties())
{
Property prop = new Property();
prop.setName(pr);
- prop.setValue(aa[i].getProperty(pr));
+ prop.setValue(annotation.getProperty(pr));
an.addProperty(prop);
}
}
AnnotationElement ae;
- if (aa[i].annotations != null)
+ if (annotation.annotations != null)
{
an.setScoreOnly(false);
- for (int a = 0; a < aa[i].annotations.length; a++)
+ for (int a = 0; a < annotation.annotations.length; a++)
{
- if ((aa[i] == null) || (aa[i].annotations[a] == null))
+ if ((annotation == null) || (annotation.annotations[a] == null))
{
continue;
}
ae = new AnnotationElement();
- if (aa[i].annotations[a].description != null)
+ if (annotation.annotations[a].description != null)
{
- ae.setDescription(aa[i].annotations[a].description);
+ ae.setDescription(annotation.annotations[a].description);
}
- if (aa[i].annotations[a].displayCharacter != null)
+ if (annotation.annotations[a].displayCharacter != null)
{
- ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter);
+ ae.setDisplayCharacter(annotation.annotations[a].displayCharacter);
}
- if (!Float.isNaN(aa[i].annotations[a].value))
+ if (!Float.isNaN(annotation.annotations[a].value))
{
- ae.setValue(aa[i].annotations[a].value);
+ ae.setValue(annotation.annotations[a].value);
}
ae.setPosition(a);
- if (aa[i].annotations[a].secondaryStructure > ' ')
+ if (annotation.annotations[a].secondaryStructure > ' ')
{
- ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure
+ ae.setSecondaryStructure(annotation.annotations[a].secondaryStructure
+ "");
}
- if (aa[i].annotations[a].colour != null
- && aa[i].annotations[a].colour != java.awt.Color.black)
+ if (annotation.annotations[a].colour != null
+ && annotation.annotations[a].colour != java.awt.Color.black)
{
- ae.setColour(aa[i].annotations[a].colour.getRGB());
+ ae.setColour(annotation.annotations[a].colour.getRGB());
}
an.addAnnotationElement(ae);
- if (aa[i].autoCalculated)
+ if (annotation.autoCalculated)
{
// only write one non-null entry into the annotation row -
// sufficient to get the visualization attributes necessary to
{
an.setScoreOnly(true);
}
- if (!storeDS || (storeDS && !aa[i].autoCalculated))
+ if (!storeDS || (storeDS && !annotation.autoCalculated))
{
// skip autocalculated annotation - these are only provided for
// alignments
}
}
throw new Error(MessageManager.formatMessage(
- "error.unsupported_version_calcIdparam", new Object[]
- { calcIdParam.toString() }));
+ "error.unsupported_version_calcIdparam",
+ new Object[] { calcIdParam.toString() }));
}
/**
if (jds.getDatasetSequence() != null)
{
vamsasSeq.setDsseqid(seqHash(jds.getDatasetSequence()));
- if (jds.getDatasetSequence().getDBRef() != null)
- {
- dbrefs = jds.getDatasetSequence().getDBRef();
- }
}
else
{
- vamsasSeq.setDsseqid(id); // so we can tell which sequences really are
+ // seqId==dsseqid so we can tell which sequences really are
// dataset sequences only
- dbrefs = jds.getDBRef();
+ vamsasSeq.setDsseqid(id);
+ dbrefs = jds.getDBRefs();
+ if (parentseq == null)
+ {
+ parentseq = jds;
+ }
}
if (dbrefs != null)
{
if (jmp.getTo() != null)
{
MappingChoice mpc = new MappingChoice();
- if (recurse
- && (parentseq != jmp.getTo() || parentseq
- .getDatasetSequence() != jmp.getTo()))
+
+ // check/create ID for the sequence referenced by getTo()
+
+ String jmpid = "";
+ SequenceI ps = null;
+ if (parentseq != jmp.getTo()
+ && parentseq.getDatasetSequence() != jmp.getTo())
{
- mpc.setSequence(createVamsasSequence(false, seqHash(jmp.getTo()),
- jmp.getTo(), jds));
+ // chaining dbref rather than a handshaking one
+ jmpid = seqHash(ps = jmp.getTo());
}
else
{
- String jmpid = "";
- SequenceI ps = null;
- if (parentseq != jmp.getTo()
- && parentseq.getDatasetSequence() != jmp.getTo())
- {
- // chaining dbref rather than a handshaking one
- jmpid = seqHash(ps = jmp.getTo());
- }
- else
- {
- jmpid = seqHash(ps = parentseq);
- }
- mpc.setDseqFor(jmpid);
- if (!seqRefIds.containsKey(mpc.getDseqFor()))
- {
- jalview.bin.Cache.log.debug("creatign new DseqFor ID");
- seqRefIds.put(mpc.getDseqFor(), ps);
- }
- else
- {
- jalview.bin.Cache.log.debug("reusing DseqFor ID");
- }
+ jmpid = seqHash(ps = parentseq);
+ }
+ mpc.setDseqFor(jmpid);
+ if (!seqRefIds.containsKey(mpc.getDseqFor()))
+ {
+ jalview.bin.Cache.log.debug("creatign new DseqFor ID");
+ seqRefIds.put(mpc.getDseqFor(), ps);
}
+ else
+ {
+ jalview.bin.Cache.log.debug("reusing DseqFor ID");
+ }
+
mp.setMappingChoice(mpc);
}
}
{
SwingUtilities.invokeAndWait(new Runnable()
{
+ @Override
public void run()
{
setLoadingFinishedForNewStructureViewers();
});
} catch (Exception x)
{
-
+ System.err.println("Error loading alignment: " + x.getMessage());
}
}
return af;
}
if (seqRefIds == null)
{
- seqRefIds = new HashMap<String, SequenceI>();
- }
- if (frefedSequence == null)
- {
- frefedSequence = new Vector();
+ initSeqRefs();
}
-
AlignFrame af = null, _af = null;
+ IdentityHashMap<AlignmentI, AlignmentI> importedDatasets = new IdentityHashMap<AlignmentI, AlignmentI>();
Map<String, AlignFrame> gatherToThisFrame = new HashMap<String, AlignFrame>();
final String file = jprovider.getFilename();
try
if (true) // !skipViewport(object))
{
_af = loadFromObject(object, file, true, jprovider);
- if (object.getJalviewModelSequence().getViewportCount() > 0)
+ if (_af != null
+ && object.getJalviewModelSequence().getViewportCount() > 0)
{
- af = _af;
- if (af.viewport.isGatherViewsHere())
+ if (af == null)
+ {
+ // store a reference to the first view
+ af = _af;
+ }
+ if (_af.viewport.isGatherViewsHere())
{
- gatherToThisFrame.put(af.viewport.getSequenceSetId(), af);
+ // if this is a gathered view, keep its reference since
+ // after gathering views, only this frame will remain
+ af = _af;
+ gatherToThisFrame.put(_af.viewport.getSequenceSetId(), _af);
}
+ // Save dataset to register mappings once all resolved
+ importedDatasets.put(af.viewport.getAlignment().getDataset(),
+ af.viewport.getAlignment().getDataset());
}
}
entryCount++;
}
} while (jarentry != null);
resolveFrefedSequences();
- } catch (java.io.FileNotFoundException ex)
- {
- ex.printStackTrace();
- errorMessage = "Couldn't locate Jalview XML file : " + file;
- System.err.println("Exception whilst loading jalview XML file : "
- + ex + "\n");
- } catch (java.net.UnknownHostException ex)
+ } catch (IOException ex)
{
ex.printStackTrace();
errorMessage = "Couldn't locate Jalview XML file : " + file;
e.printStackTrace();
}
- if (Desktop.instance != null)
- {
- Desktop.instance.stopLoading();
- }
-
/*
* Regather multiple views (with the same sequence set id) to the frame (if
* any) that is flagged as the one to gather to, i.e. convert them to tabbed
}
restoreSplitFrames();
-
+ for (AlignmentI ds : importedDatasets.keySet())
+ {
+ if (ds.getCodonFrames() != null)
+ {
+ StructureSelectionManager.getStructureSelectionManager(
+ Desktop.instance).registerMappings(ds.getCodonFrames());
+ }
+ }
if (errorMessage != null)
{
reportErrors();
}
+
+ if (Desktop.instance != null)
+ {
+ Desktop.instance.stopLoading();
+ }
+
return af;
}
.entrySet())
{
AlignFrame af = candidate.getValue();
- if (!addedToSplitFrames.contains(af)) {
+ if (!addedToSplitFrames.contains(af))
+ {
Viewport view = candidate.getKey();
Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
view.getHeight());
int width = (int) dnaFrame.getBounds().getWidth();
int height = (int) (dnaFrame.getBounds().getHeight()
+ proteinFrame.getBounds().getHeight() + 50);
+
+ /*
+ * SplitFrame location is saved to both enclosed frames
+ */
+ splitFrame.setLocation(dnaFrame.getX(), dnaFrame.getY());
Desktop.addInternalFrame(splitFrame, title, width, height);
/*
// LOAD SEQUENCES
List<SequenceI> hiddenSeqs = null;
- jalview.datamodel.Sequence jseq;
+
List<SequenceI> tmpseqs = new ArrayList<SequenceI>();
boolean multipleView = false;
-
+ SequenceI referenceseqForView = null;
JSeq[] jseqs = object.getJalviewModelSequence().getJSeq();
int vi = 0; // counter in vamsasSeq array
for (int i = 0; i < jseqs.length; i++)
{
String seqId = jseqs[i].getId();
- if (seqRefIds.get(seqId) != null)
+ SequenceI tmpSeq = seqRefIds.get(seqId);
+ if (tmpSeq != null)
{
- tmpseqs.add(seqRefIds.get(seqId));
+ if (!incompleteSeqs.containsKey(seqId))
+ {
+ // may not need this check, but keep it for at least 2.9,1 release
+ if (tmpSeq.getStart()!=jseqs[i].getStart() || tmpSeq.getEnd()!=jseqs[i].getEnd())
+ {
+ System.err
+ .println("Warning JAL-2154 regression: updating start/end for sequence "
+ + tmpSeq.toString());
+ }
+ } else {
+ incompleteSeqs.remove(seqId);
+ }
+ tmpSeq.setStart(jseqs[i].getStart());
+ tmpSeq.setEnd(jseqs[i].getEnd());
+ tmpseqs.add(tmpSeq);
multipleView = true;
}
else
{
- jseq = new jalview.datamodel.Sequence(vamsasSeq[vi].getName(),
+ tmpSeq = new jalview.datamodel.Sequence(vamsasSeq[vi].getName(),
vamsasSeq[vi].getSequence());
- jseq.setDescription(vamsasSeq[vi].getDescription());
- jseq.setStart(jseqs[i].getStart());
- jseq.setEnd(jseqs[i].getEnd());
- jseq.setVamsasId(uniqueSetSuffix + seqId);
- seqRefIds.put(vamsasSeq[vi].getId(), jseq);
- tmpseqs.add(jseq);
+ tmpSeq.setDescription(vamsasSeq[vi].getDescription());
+ tmpSeq.setStart(jseqs[i].getStart());
+ tmpSeq.setEnd(jseqs[i].getEnd());
+ tmpSeq.setVamsasId(uniqueSetSuffix + seqId);
+ seqRefIds.put(vamsasSeq[vi].getId(), tmpSeq);
+ tmpseqs.add(tmpSeq);
vi++;
}
+ if (jseqs[i].hasViewreference() && jseqs[i].getViewreference())
+ {
+ referenceseqForView = tmpseqs.get(tmpseqs.size() - 1);
+ }
+
if (jseqs[i].getHidden())
{
if (hiddenSeqs == null)
hiddenSeqs = new ArrayList<SequenceI>();
}
- hiddenSeqs.add(seqRefIds.get(seqId));
+ hiddenSeqs.add(tmpSeq);
}
-
}
// /
SequenceI[] orderedSeqs = tmpseqs
.toArray(new SequenceI[tmpseqs.size()]);
- Alignment al = new Alignment(orderedSeqs);
-
- // / Add the alignment properties
- for (int i = 0; i < vamsasSet.getSequenceSetPropertiesCount(); i++)
- {
- SequenceSetProperties ssp = vamsasSet.getSequenceSetProperties(i);
- al.setProperty(ssp.getKey(), ssp.getValue());
- }
-
- // /
- // SequenceFeatures are added to the DatasetSequence,
- // so we must create or recover the dataset before loading features
+ AlignmentI al = null;
+ // so we must create or recover the dataset alignment before going further
// ///////////////////////////////
if (vamsasSet.getDatasetId() == null || vamsasSet.getDatasetId() == "")
{
- // older jalview projects do not have a dataset id.
+ // older jalview projects do not have a dataset - so creat alignment and
+ // dataset
+ al = new Alignment(orderedSeqs);
al.setDataset(null);
}
else
{
- // recover dataset - passing on flag indicating if this a 'viewless'
- // sequence set (a.k.a. a stored dataset for the project)
- recoverDatasetFor(vamsasSet, al, object.getJalviewModelSequence()
- .getViewportCount() == 0);
+ boolean isdsal = object.getJalviewModelSequence().getViewportCount() == 0;
+ if (isdsal)
+ {
+ // we are importing a dataset record, so
+ // recover reference to an alignment already materialsed as dataset
+ al = getDatasetFor(vamsasSet.getDatasetId());
+ }
+ if (al == null)
+ {
+ // materialse the alignment
+ al = new Alignment(orderedSeqs);
+ }
+ if (isdsal)
+ {
+ addDatasetRef(vamsasSet.getDatasetId(), al);
+ }
+
+ // finally, verify all data in vamsasSet is actually present in al
+ // passing on flag indicating if it is actually a stored dataset
+ recoverDatasetFor(vamsasSet, al, isdsal);
+ }
+
+ if (referenceseqForView != null)
+ {
+ al.setSeqrep(referenceseqForView);
+ }
+ // / Add the alignment properties
+ for (int i = 0; i < vamsasSet.getSequenceSetPropertiesCount(); i++)
+ {
+ SequenceSetProperties ssp = vamsasSet.getSequenceSetProperties(i);
+ al.setProperty(ssp.getKey(), ssp.getValue());
}
+
// ///////////////////////////////
Hashtable pdbloaded = new Hashtable(); // TODO nothing writes to this??
{
mapping = addMapping(maps[m].getMapping());
}
- if (dnaseq != null)
+ if (dnaseq != null && mapping.getTo() != null)
{
cf.addMap(dnaseq, mapping.getTo(), mapping.getMap());
}
else
{
// defer to later
- frefedSequence.add(new Object[]
- { maps[m].getDnasq(), cf, mapping });
+ frefedSequence.add(newAlcodMapRef(maps[m].getDnasq(), cf,
+ mapping));
}
}
+ al.addCodonFrame(cf);
}
- al.addCodonFrame(cf);
}
}
// ////////////////////////////////
// LOAD ANNOTATIONS
List<JvAnnotRow> autoAlan = new ArrayList<JvAnnotRow>();
- /**
+
+ /*
* store any annotations which forward reference a group's ID
*/
- Hashtable<String, ArrayList<jalview.datamodel.AlignmentAnnotation>> groupAnnotRefs = new Hashtable<String, ArrayList<jalview.datamodel.AlignmentAnnotation>>();
+ Map<String, List<AlignmentAnnotation>> groupAnnotRefs = new Hashtable<String, List<AlignmentAnnotation>>();
if (vamsasSet.getAnnotationCount() > 0)
{
for (int i = 0; i < an.length; i++)
{
+ Annotation annotation = an[i];
+
/**
* test if annotation is automatically calculated for this view only
*/
boolean autoForView = false;
- if (an[i].getLabel().equals("Quality")
- || an[i].getLabel().equals("Conservation")
- || an[i].getLabel().equals("Consensus"))
+ if (annotation.getLabel().equals("Quality")
+ || annotation.getLabel().equals("Conservation")
+ || annotation.getLabel().equals("Consensus"))
{
// Kludge for pre 2.5 projects which lacked the autocalculated flag
autoForView = true;
- if (!an[i].hasAutoCalculated())
+ if (!annotation.hasAutoCalculated())
{
- an[i].setAutoCalculated(true);
+ annotation.setAutoCalculated(true);
}
}
if (autoForView
- || (an[i].hasAutoCalculated() && an[i].isAutoCalculated()))
+ || (annotation.hasAutoCalculated() && annotation
+ .isAutoCalculated()))
{
// remove ID - we don't recover annotation from other views for
// view-specific annotation
- an[i].setId(null);
+ annotation.setId(null);
}
// set visiblity for other annotation in this view
- if (an[i].getId() != null
- && annotationIds.containsKey(an[i].getId()))
+ String annotationId = annotation.getId();
+ if (annotationId != null && annotationIds.containsKey(annotationId))
{
- AlignmentAnnotation jda = annotationIds.get(an[i].getId());
+ AlignmentAnnotation jda = annotationIds.get(annotationId);
// in principle Visible should always be true for annotation displayed
// in multiple views
- if (an[i].hasVisible())
+ if (annotation.hasVisible())
{
- jda.visible = an[i].getVisible();
+ jda.visible = annotation.getVisible();
}
al.addAnnotation(jda);
continue;
}
// Construct new annotation from model.
- AnnotationElement[] ae = an[i].getAnnotationElement();
+ AnnotationElement[] ae = annotation.getAnnotationElement();
jalview.datamodel.Annotation[] anot = null;
java.awt.Color firstColour = null;
int anpos;
- if (!an[i].getScoreOnly())
+ if (!annotation.getScoreOnly())
{
anot = new jalview.datamodel.Annotation[al.getWidth()];
for (int aa = 0; aa < ae.length && aa < anot.length; aa++)
}
jalview.datamodel.AlignmentAnnotation jaa = null;
- if (an[i].getGraph())
+ if (annotation.getGraph())
{
float llim = 0, hlim = 0;
// if (autoForView || an[i].isAutoCalculated()) {
// hlim=11f;
// }
- jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
- an[i].getDescription(), anot, llim, hlim,
- an[i].getGraphType());
+ jaa = new jalview.datamodel.AlignmentAnnotation(
+ annotation.getLabel(), annotation.getDescription(), anot,
+ llim, hlim, annotation.getGraphType());
- jaa.graphGroup = an[i].getGraphGroup();
+ jaa.graphGroup = annotation.getGraphGroup();
jaa._linecolour = firstColour;
- if (an[i].getThresholdLine() != null)
+ if (annotation.getThresholdLine() != null)
{
- jaa.setThreshold(new jalview.datamodel.GraphLine(an[i]
- .getThresholdLine().getValue(), an[i]
+ jaa.setThreshold(new jalview.datamodel.GraphLine(annotation
+ .getThresholdLine().getValue(), annotation
.getThresholdLine().getLabel(), new java.awt.Color(
- an[i].getThresholdLine().getColour())));
+ annotation.getThresholdLine().getColour())));
}
- if (autoForView || an[i].isAutoCalculated())
+ if (autoForView || annotation.isAutoCalculated())
{
// Hardwire the symbol display line to ensure that labels for
// histograms are displayed
jaa.annotationId = an[i].getId();
}
// recover sequence association
- if (an[i].getSequenceRef() != null)
+ String sequenceRef = an[i].getSequenceRef();
+ if (sequenceRef != null)
{
- if (al.findName(an[i].getSequenceRef()) != null)
+ // from 2.9 sequenceRef is to sequence id (JAL-1781)
+ SequenceI sequence = seqRefIds.get(sequenceRef);
+ if (sequence == null)
+ {
+ // in pre-2.9 projects sequence ref is to sequence name
+ sequence = al.findName(sequenceRef);
+ }
+ if (sequence != null)
{
- jaa.createSequenceMapping(al.findName(an[i].getSequenceRef()),
- 1, true);
- al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa);
+ jaa.createSequenceMapping(sequence, 1, true);
+ sequence.addAlignmentAnnotation(jaa);
}
}
// and make a note of any group association
if (an[i].getGroupRef() != null && an[i].getGroupRef().length() > 0)
{
- ArrayList<jalview.datamodel.AlignmentAnnotation> aal = groupAnnotRefs
+ List<jalview.datamodel.AlignmentAnnotation> aal = groupAnnotRefs
.get(an[i].getGroupRef());
if (aal == null)
{
boolean addAnnotSchemeGroup = false;
for (int i = 0; i < groups.length; i++)
{
+ JGroup jGroup = groups[i];
ColourSchemeI cs = null;
-
- if (groups[i].getColour() != null)
+ if (jGroup.getColour() != null)
{
- if (groups[i].getColour().startsWith("ucs"))
+ if (jGroup.getColour().startsWith("ucs"))
{
- cs = getUserColourScheme(jms, groups[i].getColour());
+ cs = getUserColourScheme(jms, jGroup.getColour());
}
- else if (groups[i].getColour().equals("AnnotationColourGradient")
- && groups[i].getAnnotationColours() != null)
+ else if (jGroup.getColour().equals("AnnotationColourGradient")
+ && jGroup.getAnnotationColours() != null)
{
addAnnotSchemeGroup = true;
cs = null;
}
else
{
- cs = ColourSchemeProperty.getColour(al, groups[i].getColour());
+ cs = ColourSchemeProperty.getColour(al, jGroup.getColour());
}
if (cs != null)
{
- cs.setThreshold(groups[i].getPidThreshold(), true);
+ cs.setThreshold(jGroup.getPidThreshold(), true);
}
}
- Vector seqs = new Vector();
+ Vector<SequenceI> seqs = new Vector<SequenceI>();
- for (int s = 0; s < groups[i].getSeqCount(); s++)
+ for (int s = 0; s < jGroup.getSeqCount(); s++)
{
- String seqId = groups[i].getSeq(s) + "";
- jalview.datamodel.SequenceI ts = seqRefIds.get(seqId);
+ String seqId = jGroup.getSeq(s) + "";
+ SequenceI ts = seqRefIds.get(seqId);
if (ts != null)
{
continue;
}
- jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(
- seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(),
- groups[i].getDisplayText(), groups[i].getColourText(),
- groups[i].getStart(), groups[i].getEnd());
+ SequenceGroup sg = new SequenceGroup(seqs, jGroup.getName(), cs,
+ jGroup.getDisplayBoxes(), jGroup.getDisplayText(),
+ jGroup.getColourText(), jGroup.getStart(), jGroup.getEnd());
- sg.setOutlineColour(new java.awt.Color(groups[i].getOutlineColour()));
+ sg.setOutlineColour(new java.awt.Color(jGroup.getOutlineColour()));
- sg.textColour = new java.awt.Color(groups[i].getTextCol1());
- sg.textColour2 = new java.awt.Color(groups[i].getTextCol2());
- sg.setShowNonconserved(groups[i].hasShowUnconserved() ? groups[i]
+ sg.textColour = new java.awt.Color(jGroup.getTextCol1());
+ sg.textColour2 = new java.awt.Color(jGroup.getTextCol2());
+ sg.setShowNonconserved(jGroup.hasShowUnconserved() ? jGroup
.isShowUnconserved() : false);
- sg.thresholdTextColour = groups[i].getTextColThreshold();
- if (groups[i].hasShowConsensusHistogram())
+ sg.thresholdTextColour = jGroup.getTextColThreshold();
+ if (jGroup.hasShowConsensusHistogram())
{
- sg.setShowConsensusHistogram(groups[i].isShowConsensusHistogram());
+ sg.setShowConsensusHistogram(jGroup.isShowConsensusHistogram());
}
;
- if (groups[i].hasShowSequenceLogo())
+ if (jGroup.hasShowSequenceLogo())
{
- sg.setshowSequenceLogo(groups[i].isShowSequenceLogo());
+ sg.setshowSequenceLogo(jGroup.isShowSequenceLogo());
}
- if (groups[i].hasNormaliseSequenceLogo())
+ if (jGroup.hasNormaliseSequenceLogo())
{
- sg.setNormaliseSequenceLogo(groups[i].isNormaliseSequenceLogo());
+ sg.setNormaliseSequenceLogo(jGroup.isNormaliseSequenceLogo());
}
- if (groups[i].hasIgnoreGapsinConsensus())
+ if (jGroup.hasIgnoreGapsinConsensus())
{
- sg.setIgnoreGapsConsensus(groups[i].getIgnoreGapsinConsensus());
+ sg.setIgnoreGapsConsensus(jGroup.getIgnoreGapsinConsensus());
}
- if (groups[i].getConsThreshold() != 0)
+ if (jGroup.getConsThreshold() != 0)
{
jalview.analysis.Conservation c = new jalview.analysis.Conservation(
"All", ResidueProperties.propHash, 3,
sg.cs.setConservation(c);
}
- if (groups[i].getId() != null && groupAnnotRefs.size() > 0)
+ if (jGroup.getId() != null && groupAnnotRefs.size() > 0)
{
// re-instate unique group/annotation row reference
- ArrayList<jalview.datamodel.AlignmentAnnotation> jaal = groupAnnotRefs
- .get(groups[i].getId());
+ List<AlignmentAnnotation> jaal = groupAnnotRefs.get(jGroup
+ .getId());
if (jaal != null)
{
- for (jalview.datamodel.AlignmentAnnotation jaa : jaal)
+ for (AlignmentAnnotation jaa : jaal)
{
jaa.groupRef = sg;
if (jaa.autoCalculated)
if (addAnnotSchemeGroup)
{
// reconstruct the annotation colourscheme
- sg.cs = constructAnnotationColour(
- groups[i].getAnnotationColours(), null, al, jms, false);
+ sg.cs = constructAnnotationColour(jGroup.getAnnotationColours(),
+ null, al, jms, false);
}
}
}
* indicate that annotation colours are applied across all groups (pre
* Jalview 2.8.1 behaviour)
*/
- boolean doGroupAnnColour = isVersionStringLaterThan("2.8.1",
- object.getVersion());
+ boolean doGroupAnnColour = Jalview2XML.isVersionStringLaterThan(
+ "2.8.1", object.getVersion());
AlignmentPanel ap = null;
boolean isnewview = true;
av = af.viewport;
ap = af.alignPanel;
}
- // LOAD TREES
- // /////////////////////////////////////
- if (loadTreesAndStructures && jms.getTreeCount() > 0)
+
+ /*
+ * Load any trees, PDB structures and viewers
+ *
+ * Not done if flag is false (when this method is used for New View)
+ */
+ if (loadTreesAndStructures)
{
- try
+ loadTrees(jms, view, af, av, ap);
+ loadPDBStructures(jprovider, jseqs, af, ap);
+ loadRnaViewers(jprovider, jseqs, ap);
+ }
+ // and finally return.
+ return af;
+ }
+
+ /**
+ * Instantiate and link any saved RNA (Varna) viewers. The state of the Varna
+ * panel is restored from separate jar entries, two (gapped and trimmed) per
+ * sequence and secondary structure.
+ *
+ * Currently each viewer shows just one sequence and structure (gapped and
+ * trimmed), however this method is designed to support multiple sequences or
+ * structures in viewers if wanted in future.
+ *
+ * @param jprovider
+ * @param jseqs
+ * @param ap
+ */
+ private void loadRnaViewers(jarInputStreamProvider jprovider,
+ JSeq[] jseqs, AlignmentPanel ap)
+ {
+ /*
+ * scan the sequences for references to viewers; create each one the first
+ * time it is referenced, add Rna models to existing viewers
+ */
+ for (JSeq jseq : jseqs)
+ {
+ for (int i = 0; i < jseq.getRnaViewerCount(); i++)
{
- for (int t = 0; t < jms.getTreeCount(); t++)
+ RnaViewer viewer = jseq.getRnaViewer(i);
+ AppVarna appVarna = findOrCreateVarnaViewer(viewer,
+ uniqueSetSuffix, ap);
+
+ for (int j = 0; j < viewer.getSecondaryStructureCount(); j++)
{
+ SecondaryStructure ss = viewer.getSecondaryStructure(j);
+ SequenceI seq = seqRefIds.get(jseq.getId());
+ AlignmentAnnotation ann = this.annotationIds.get(ss
+ .getAnnotationId());
- Tree tree = jms.getTree(t);
+ /*
+ * add the structure to the Varna display (with session state copied
+ * from the jar to a temporary file)
+ */
+ boolean gapped = ss.isGapped();
+ String rnaTitle = ss.getTitle();
+ String sessionState = ss.getViewerState();
+ String tempStateFile = copyJarEntry(jprovider, sessionState,
+ "varna");
+ RnaModel rna = new RnaModel(rnaTitle, ann, seq, null, gapped);
+ appVarna.addModelSession(rna, rnaTitle, tempStateFile);
+ }
+ appVarna.setInitialSelection(viewer.getSelectedRna());
+ }
+ }
+ }
- TreePanel tp = (TreePanel) retrieveExistingObj(tree.getId());
- if (tp == null)
- {
- tp = af.ShowNewickTree(
- new jalview.io.NewickFile(tree.getNewick()),
- tree.getTitle(), tree.getWidth(), tree.getHeight(),
- tree.getXpos(), tree.getYpos());
- if (tree.getId() != null)
- {
- // perhaps bind the tree id to something ?
- }
- }
- else
- {
- // update local tree attributes ?
- // TODO: should check if tp has been manipulated by user - if so its
- // settings shouldn't be modified
- tp.setTitle(tree.getTitle());
- tp.setBounds(new Rectangle(tree.getXpos(), tree.getYpos(), tree
- .getWidth(), tree.getHeight()));
- tp.av = av; // af.viewport; // TODO: verify 'associate with all
- // views'
- // works still
- tp.treeCanvas.av = av; // af.viewport;
- tp.treeCanvas.ap = ap; // af.alignPanel;
+ /**
+ * Locate and return an already instantiated matching AppVarna, or create one
+ * if not found
+ *
+ * @param viewer
+ * @param viewIdSuffix
+ * @param ap
+ * @return
+ */
+ protected AppVarna findOrCreateVarnaViewer(RnaViewer viewer,
+ String viewIdSuffix, AlignmentPanel ap)
+ {
+ /*
+ * on each load a suffix is appended to the saved viewId, to avoid conflicts
+ * if load is repeated
+ */
+ String postLoadId = viewer.getViewId() + viewIdSuffix;
+ for (JInternalFrame frame : getAllFrames())
+ {
+ if (frame instanceof AppVarna)
+ {
+ AppVarna varna = (AppVarna) frame;
+ if (postLoadId.equals(varna.getViewId()))
+ {
+ // this viewer is already instantiated
+ // could in future here add ap as another 'parent' of the
+ // AppVarna window; currently just 1-to-many
+ return varna;
+ }
+ }
+ }
- }
- if (tp == null)
- {
- warn("There was a problem recovering stored Newick tree: \n"
- + tree.getNewick());
- continue;
- }
+ /*
+ * viewer not found - make it
+ */
+ RnaViewerModel model = new RnaViewerModel(postLoadId,
+ viewer.getTitle(), viewer.getXpos(), viewer.getYpos(),
+ viewer.getWidth(), viewer.getHeight(),
+ viewer.getDividerLocation());
+ AppVarna varna = new AppVarna(model, ap);
- tp.fitToWindow.setState(tree.getFitToWindow());
- tp.fitToWindow_actionPerformed(null);
+ return varna;
+ }
- if (tree.getFontName() != null)
- {
- tp.setTreeFont(new java.awt.Font(tree.getFontName(), tree
- .getFontStyle(), tree.getFontSize()));
- }
- else
+ /**
+ * Load any saved trees
+ *
+ * @param jms
+ * @param view
+ * @param af
+ * @param av
+ * @param ap
+ */
+ protected void loadTrees(JalviewModelSequence jms, Viewport view,
+ AlignFrame af, AlignViewport av, AlignmentPanel ap)
+ {
+ // TODO result of automated refactoring - are all these parameters needed?
+ try
+ {
+ for (int t = 0; t < jms.getTreeCount(); t++)
+ {
+
+ Tree tree = jms.getTree(t);
+
+ TreePanel tp = (TreePanel) retrieveExistingObj(tree.getId());
+ if (tp == null)
+ {
+ tp = af.ShowNewickTree(
+ new jalview.io.NewickFile(tree.getNewick()),
+ tree.getTitle(), tree.getWidth(), tree.getHeight(),
+ tree.getXpos(), tree.getYpos());
+ if (tree.getId() != null)
{
- tp.setTreeFont(new java.awt.Font(view.getFontName(), view
- .getFontStyle(), tree.getFontSize()));
+ // perhaps bind the tree id to something ?
}
+ }
+ else
+ {
+ // update local tree attributes ?
+ // TODO: should check if tp has been manipulated by user - if so its
+ // settings shouldn't be modified
+ tp.setTitle(tree.getTitle());
+ tp.setBounds(new Rectangle(tree.getXpos(), tree.getYpos(), tree
+ .getWidth(), tree.getHeight()));
+ tp.av = av; // af.viewport; // TODO: verify 'associate with all
+ // views'
+ // works still
+ tp.treeCanvas.av = av; // af.viewport;
+ tp.treeCanvas.ap = ap; // af.alignPanel;
- tp.showPlaceholders(tree.getMarkUnlinked());
- tp.showBootstrap(tree.getShowBootstrap());
- tp.showDistances(tree.getShowDistances());
+ }
+ if (tp == null)
+ {
+ warn("There was a problem recovering stored Newick tree: \n"
+ + tree.getNewick());
+ continue;
+ }
- tp.treeCanvas.threshold = tree.getThreshold();
+ tp.fitToWindow.setState(tree.getFitToWindow());
+ tp.fitToWindow_actionPerformed(null);
- if (tree.getCurrentTree())
- {
- af.viewport.setCurrentTree(tp.getTree());
- }
+ if (tree.getFontName() != null)
+ {
+ tp.setTreeFont(new java.awt.Font(tree.getFontName(), tree
+ .getFontStyle(), tree.getFontSize()));
+ }
+ else
+ {
+ tp.setTreeFont(new java.awt.Font(view.getFontName(), view
+ .getFontStyle(), tree.getFontSize()));
}
- } catch (Exception ex)
- {
- ex.printStackTrace();
+ tp.showPlaceholders(tree.getMarkUnlinked());
+ tp.showBootstrap(tree.getShowBootstrap());
+ tp.showDistances(tree.getShowDistances());
+
+ tp.treeCanvas.threshold = tree.getThreshold();
+
+ if (tree.getCurrentTree())
+ {
+ af.viewport.setCurrentTree(tp.getTree());
+ }
}
- }
- // //LOAD STRUCTURES
- if (loadTreesAndStructures)
+ } catch (Exception ex)
{
- loadStructures(jprovider, jseqs, af, ap);
+ ex.printStackTrace();
}
- // and finally return.
- return af;
}
/**
* @param af
* @param ap
*/
- protected void loadStructures(jarInputStreamProvider jprovider,
+ protected void loadPDBStructures(jarInputStreamProvider jprovider,
JSeq[] jseqs, AlignFrame af, AlignmentPanel ap)
{
/*
* @param af
* @param jprovider
*/
- protected void createChimeraViewer(Entry<String, StructureViewerModel> viewerData,
- AlignFrame af,
+ protected void createChimeraViewer(
+ Entry<String, StructureViewerModel> viewerData, AlignFrame af,
jarInputStreamProvider jprovider)
{
StructureViewerModel data = viewerData.getValue();
- String chimeraSessionFile = data.getStateData();
+ String chimeraSessionFile = data.getStateData();
/*
* Copy Chimera session from jar entry "viewer_"+viewId to a temporary file
*
- * Note this is the 'saved' viewId as in the project file XML, _not_ the
+ * NB this is the 'saved' viewId as in the project file XML, _not_ the
* 'uniquified' sviewid used to reconstruct the viewer here
*/
- chimeraSessionFile = copyJarEntry(jprovider,
- getViewerJarEntryName(data.getViewId()), "chimera");
+ String viewerJarEntryName = getViewerJarEntryName(data.getViewId());
+ chimeraSessionFile = copyJarEntry(jprovider, viewerJarEntryName,
+ "chimera");
Set<Entry<File, StructureData>> fileData = data.getFileData()
.entrySet();
final SequenceI[][] seqsArray = allseqs.toArray(new SequenceI[allseqs
.size()][]);
String newViewId = viewerData.getKey();
- new ChimeraViewFrame(chimeraSessionFile, af.alignPanel, pdbArray,
- seqsArray, colourByChimera, colourBySequence, newViewId);
+
+ ChimeraViewFrame cvf = new ChimeraViewFrame(chimeraSessionFile,
+ af.alignPanel, pdbArray, seqsArray, colourByChimera,
+ colourBySequence, newViewId);
+ cvf.setSize(data.getWidth(), data.getHeight());
+ cvf.setLocation(data.getX(), data.getY());
}
/**
newFileLoc.append(";");
}
- if (newFileLoc.length() > 0)
+ if (newFileLoc.length() == 0)
+ {
+ return;
+ }
+ int histbug = newFileLoc.indexOf("history = ");
+ if (histbug > -1)
{
- int histbug = newFileLoc.indexOf("history = ");
+ /*
+ * change "history = [true|false];" to "history = [1|0];"
+ */
histbug += 10;
int diff = histbug == -1 ? -1 : newFileLoc.indexOf(";", histbug);
String val = (diff == -1) ? null : newFileLoc
.substring(histbug, diff);
if (val != null && val.length() >= 4)
{
- if (val.contains("e"))
+ if (val.contains("e")) // eh? what can it be?
{
if (val.trim().equals("true"))
{
newFileLoc.replace(histbug, diff, val);
}
}
+ }
- final String[] pdbf = pdbfilenames.toArray(new String[pdbfilenames
- .size()]);
- final String[] id = pdbids.toArray(new String[pdbids.size()]);
- final SequenceI[][] sq = seqmaps
- .toArray(new SequenceI[seqmaps.size()][]);
- final String fileloc = newFileLoc.toString();
- final String sviewid = viewerData.getKey();
- final AlignFrame alf = af;
- final Rectangle rect = new Rectangle(svattrib.getX(),
- svattrib.getY(), svattrib.getWidth(), svattrib.getHeight());
- try
+ final String[] pdbf = pdbfilenames.toArray(new String[pdbfilenames
+ .size()]);
+ final String[] id = pdbids.toArray(new String[pdbids.size()]);
+ final SequenceI[][] sq = seqmaps
+ .toArray(new SequenceI[seqmaps.size()][]);
+ final String fileloc = newFileLoc.toString();
+ final String sviewid = viewerData.getKey();
+ final AlignFrame alf = af;
+ final Rectangle rect = new Rectangle(svattrib.getX(), svattrib.getY(),
+ svattrib.getWidth(), svattrib.getHeight());
+ try
+ {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable()
{
- javax.swing.SwingUtilities.invokeAndWait(new Runnable()
+ @Override
+ public void run()
{
- @Override
- public void run()
+ JalviewStructureDisplayI sview = null;
+ try
{
- JalviewStructureDisplayI sview = null;
- try
- {
- sview = new StructureViewer(alf.alignPanel
- .getStructureSelectionManager()).createView(
- StructureViewer.ViewerType.JMOL, pdbf, id, sq,
- alf.alignPanel, svattrib, fileloc, rect, sviewid);
- addNewStructureViewer(sview);
- } catch (OutOfMemoryError ex)
+ sview = new StructureViewer(alf.alignPanel
+ .getStructureSelectionManager()).createView(
+ StructureViewer.ViewerType.JMOL, pdbf, id, sq,
+ alf.alignPanel, svattrib, fileloc, rect, sviewid);
+ addNewStructureViewer(sview);
+ } catch (OutOfMemoryError ex)
+ {
+ new OOMWarning("restoring structure view for PDB id " + id,
+ (OutOfMemoryError) ex.getCause());
+ if (sview != null && sview.isVisible())
{
- new OOMWarning("restoring structure view for PDB id " + id,
- (OutOfMemoryError) ex.getCause());
- if (sview != null && sview.isVisible())
- {
- sview.closeViewer(false);
- sview.setVisible(false);
- sview.dispose();
- }
+ sview.closeViewer(false);
+ sview.setVisible(false);
+ sview.dispose();
}
}
- });
- } catch (InvocationTargetException ex)
- {
- warn("Unexpected error when opening Jmol view.", ex);
+ }
+ });
+ } catch (InvocationTargetException ex)
+ {
+ warn("Unexpected error when opening Jmol view.", ex);
- } catch (InterruptedException e)
- {
- // e.printStackTrace();
- }
+ } catch (InterruptedException e)
+ {
+ // e.printStackTrace();
}
+
}
/**
*/
protected String getViewerJarEntryName(String viewId)
{
- return "viewer_" + viewId;
+ return VIEWER_PREFIX + viewId;
}
/**
}
/**
+ * Answers true if 'version' is equal to or later than 'supported', where each
+ * is formatted as major/minor versions like "2.8.3" or "2.3.4b1" for bugfix
+ * changes. Development and test values for 'version' are leniently treated
+ * i.e. answer true.
*
* @param supported
* - minimum version we are comparing against
* @param version
- * - version of data being processsed.
- * @return true if version is development/null or evaluates to the same or
- * later X.Y.Z (where X,Y,Z are like [0-9]+b?[0-9]*)
+ * - version of data being processsed
+ * @return
*/
- private boolean isVersionStringLaterThan(String supported, String version)
+ public static boolean isVersionStringLaterThan(String supported,
+ String version)
{
- if (version == null || version.equalsIgnoreCase("DEVELOPMENT BUILD")
+ if (supported == null || version == null
+ || version.equalsIgnoreCase("DEVELOPMENT BUILD")
|| version.equalsIgnoreCase("Test")
|| version.equalsIgnoreCase("AUTOMATED BUILD"))
{
}
else
{
- StringTokenizer currentV = new StringTokenizer(supported, "."), fileV = new StringTokenizer(
- version, ".");
- while (currentV.hasMoreTokens() && fileV.hasMoreTokens())
- {
- // convert b to decimal to catch bugfix releases within a series
- String curT = currentV.nextToken().toLowerCase().replace('b', '.');
- String fileT = fileV.nextToken().toLowerCase().replace('b', '.');
- try
- {
- if (Float.valueOf(curT) > Float.valueOf(fileT))
- {
- // current version is newer than the version that wrote the file
- return false;
- }
- } catch (NumberFormatException nfe)
- {
- System.err
- .println("** WARNING: Version comparison failed for tokens ("
- + curT
- + ") and ("
- + fileT
- + ")\n** Current: '"
- + supported + "' and Version: '" + version + "'");
- }
- }
- if (currentV.hasMoreElements())
- {
- // fileV has no minor version but identical series to current
- return false;
- }
+ return StringUtils.compareVersions(version, supported, "b") >= 0;
}
- return true;
}
Vector<JalviewStructureDisplayI> newStructureViewers = null;
}
AlignFrame loadViewport(String file, JSeq[] JSEQ,
- List<SequenceI> hiddenSeqs, Alignment al,
+ List<SequenceI> hiddenSeqs, AlignmentI al,
JalviewModelSequence jms, Viewport view, String uniqueSeqSetId,
String viewId, List<JvAnnotRow> autoAlan)
{
.getSequenceAt(i), new java.awt.Color(JSEQ[i].getColour()));
}
+ if (al.hasSeqrep())
+ {
+ af.getViewport().setColourByReferenceSeq(true);
+ af.getViewport().setDisplayReferenceSeq(true);
+ }
+
af.viewport.setGatherViewsHere(view.getGatheredViews());
if (view.getSequenceSetId() != null)
{
for (int s = 0; s < JSEQ.length; s++)
{
- jalview.datamodel.SequenceGroup hidden = new jalview.datamodel.SequenceGroup();
-
+ SequenceGroup hidden = new SequenceGroup();
+ boolean isRepresentative = false;
for (int r = 0; r < JSEQ[s].getHiddenSequencesCount(); r++)
{
- hidden.addSequence(
- al.getSequenceAt(JSEQ[s].getHiddenSequences(r)), false);
+ isRepresentative = true;
+ SequenceI sequenceToHide = al.getSequenceAt(JSEQ[s]
+ .getHiddenSequences(r));
+ hidden.addSequence(sequenceToHide, false);
+ // remove from hiddenSeqs list so we don't try to hide it twice
+ hiddenSeqs.remove(sequenceToHide);
+ }
+ if (isRepresentative)
+ {
+ SequenceI representativeSequence = al.getSequenceAt(s);
+ hidden.addSequence(representativeSequence, false);
+ af.viewport.hideRepSequences(representativeSequence, hidden);
}
- af.viewport.hideRepSequences(al.getSequenceAt(s), hidden);
}
- // jalview.datamodel.SequenceI[] hseqs = new
- // jalview.datamodel.SequenceI[hiddenSeqs
- // .size()];
- //
- // for (int s = 0; s < hiddenSeqs.size(); s++)
- // {
- // hseqs[s] = (jalview.datamodel.SequenceI) hiddenSeqs.elementAt(s);
- // }
-
SequenceI[] hseqs = hiddenSeqs.toArray(new SequenceI[hiddenSeqs
.size()]);
af.viewport.hideSequence(hseqs);
af.viewport.setFont(
new java.awt.Font(view.getFontName(), view.getFontStyle(), view
.getFontSize()), true);
+ ViewStyleI vs = af.viewport.getViewStyle();
+ vs.setScaleProteinAsCdna(view.isScaleProteinAsCdna());
+ af.viewport.setViewStyle(vs);
// TODO: allow custom charWidth/Heights to be restored by updating them
// after setting font - which means set above to false
af.viewport.setRenderGaps(view.getRenderGaps());
af.viewport.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
String[] renderOrder = new String[jms.getFeatureSettings()
.getSettingCount()];
- Hashtable featureGroups = new Hashtable();
- Hashtable featureColours = new Hashtable();
- Hashtable featureOrder = new Hashtable();
+ Map<String, FeatureColourI> featureColours = new Hashtable<String, FeatureColourI>();
+ Map<String, Float> featureOrder = new Hashtable<String, Float>();
for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++)
{
Setting setting = jms.getFeatureSettings().getSetting(fs);
if (setting.hasMincolour())
{
- GraduatedColor gc = setting.hasMin() ? new GraduatedColor(
- new java.awt.Color(setting.getMincolour()),
- new java.awt.Color(setting.getColour()),
- setting.getMin(), setting.getMax()) : new GraduatedColor(
- new java.awt.Color(setting.getMincolour()),
- new java.awt.Color(setting.getColour()), 0, 1);
+ FeatureColourI gc = setting.hasMin() ? new FeatureColour(
+ new Color(setting.getMincolour()), new Color(
+ setting.getColour()), setting.getMin(),
+ setting.getMax()) : new FeatureColour(new Color(
+ setting.getMincolour()), new Color(setting.getColour()),
+ 0, 1);
if (setting.hasThreshold())
{
- gc.setThresh(setting.getThreshold());
- gc.setThreshType(setting.getThreshstate());
+ gc.setThreshold(setting.getThreshold());
+ int threshstate = setting.getThreshstate();
+ // -1 = None, 0 = Below, 1 = Above threshold
+ if (threshstate == 0)
+ {
+ gc.setBelowThreshold(true);
+ }
+ else if (threshstate == 1)
+ {
+ gc.setAboveThreshold(true);
+ }
}
gc.setAutoScaled(true); // default
if (setting.hasAutoScale())
}
else
{
- featureColours.put(setting.getType(),
- new java.awt.Color(setting.getColour()));
+ featureColours.put(setting.getType(), new FeatureColour(
+ new Color(setting.getColour())));
}
renderOrder[fs] = setting.getType();
if (setting.hasOrder())
fdi.setVisible(setting.getType());
}
}
- Hashtable fgtable = new Hashtable();
+ Map<String, Boolean> fgtable = new Hashtable<String, Boolean>();
for (int gs = 0; gs < jms.getFeatureSettings().getGroupCount(); gs++)
{
Group grp = jms.getFeatureSettings().getGroup(gs);
}
}
af.setMenusFromViewport(af.viewport);
-
+ af.setTitle(view.getTitle());
// TODO: we don't need to do this if the viewport is aready visible.
/*
* Add the AlignFrame to the desktop (it may be 'gathered' later), unless it
}
private ColourSchemeI constructAnnotationColour(
- AnnotationColours viewAnnColour, AlignFrame af, Alignment al,
+ AnnotationColours viewAnnColour, AlignFrame af, AlignmentI al,
JalviewModelSequence jms, boolean checkGroupAnnColour)
{
boolean propagateAnnColour = false;
return cs;
}
- private void reorderAutoannotation(AlignFrame af, Alignment al,
+ private void reorderAutoannotation(AlignFrame af, AlignmentI al,
List<JvAnnotRow> autoAlan)
{
// copy over visualization settings for autocalculated annotation in the
/**
* Kludge for magic autoannotation names (see JAL-811)
*/
- String[] magicNames = new String[]
- { "Consensus", "Quality", "Conservation" };
+ String[] magicNames = new String[] { "Consensus", "Quality",
+ "Conservation" };
JvAnnotRow nullAnnot = new JvAnnotRow(-1, null);
Hashtable<String, JvAnnotRow> visan = new Hashtable<String, JvAnnotRow>();
for (String nm : magicNames)
}
}
- private void recoverDatasetFor(SequenceSet vamsasSet, Alignment al,
+ private void recoverDatasetFor(SequenceSet vamsasSet, AlignmentI al,
boolean ignoreUnrefed)
{
- jalview.datamodel.Alignment ds = getDatasetFor(vamsasSet.getDatasetId());
+ jalview.datamodel.AlignmentI ds = getDatasetFor(vamsasSet
+ .getDatasetId());
Vector dseqs = null;
if (ds == null)
{
}
}
- java.util.Hashtable datasetIds = null;
+ /*
+ * TODO use AlignmentI here and in related methods - needs
+ * AlignmentI.getDataset() changed to return AlignmentI instead of Alignment
+ */
+ Hashtable<String, AlignmentI> datasetIds = null;
- java.util.IdentityHashMap dataset2Ids = null;
+ IdentityHashMap<AlignmentI, String> dataset2Ids = null;
- private Alignment getDatasetFor(String datasetId)
+ private AlignmentI getDatasetFor(String datasetId)
{
if (datasetIds == null)
{
- datasetIds = new Hashtable();
+ datasetIds = new Hashtable<String, AlignmentI>();
return null;
}
if (datasetIds.containsKey(datasetId))
{
- return (Alignment) datasetIds.get(datasetId);
+ return datasetIds.get(datasetId);
}
return null;
}
- private void addDatasetRef(String datasetId, Alignment dataset)
+ private void addDatasetRef(String datasetId, AlignmentI dataset)
{
if (datasetIds == null)
{
- datasetIds = new Hashtable();
+ datasetIds = new Hashtable<String, AlignmentI>();
}
datasetIds.put(datasetId, dataset);
}
* @param dataset
* @return
*/
- private String getDatasetIdRef(jalview.datamodel.Alignment dataset)
+ private String getDatasetIdRef(AlignmentI dataset)
{
if (dataset.getDataset() != null)
{
// make a new datasetId and record it
if (dataset2Ids == null)
{
- dataset2Ids = new IdentityHashMap();
+ dataset2Ids = new IdentityHashMap<AlignmentI, String>();
}
else
{
- datasetId = (String) dataset2Ids.get(dataset);
+ datasetId = dataset2Ids.get(dataset);
}
if (datasetId == null)
{
}
else
{
- frefedSequence.add(new Object[]
- { dsfor, jmap });
+ frefedSequence.add(newMappingRef(dsfor, jmap));
}
}
else
djs.setEnd(jmap.getMap().getToHighest());
djs.setVamsasId(uniqueSetSuffix + sqid);
jmap.setTo(djs);
+ incompleteSeqs.put(sqid, djs);
seqRefIds.put(sqid, djs);
}
boolean keepSeqRefs)
{
initSeqRefs();
- jalview.schemabinding.version2.JalviewModel jm = saveState(ap, null,
- null);
+ JalviewModel jm = saveState(ap, null, null, null);
if (!keepSeqRefs)
{
}
}
}
-
+
return result;
}
+
+ /**
+ * Returns an incrementing counter (0, 1, 2...)
+ *
+ * @return
+ */
+ private synchronized int nextCounter()
+ {
+ return counter++;
+ }
}