package jalview.structures.models;
import jalview.api.AlignmentViewPanel;
-import jalview.api.SequenceRenderer;
+import jalview.api.SequenceRendererI;
import jalview.api.StructureSelectionManagerProvider;
import jalview.api.structures.JalviewStructureDisplayI;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.HiddenColumns;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
+import jalview.gui.AlignmentPanel;
+import jalview.gui.SequenceRenderer;
import jalview.io.DataSourceType;
import jalview.schemes.ColourSchemeI;
import jalview.structure.AtomSpec;
import java.util.BitSet;
import java.util.List;
+import org.springframework.web.filter.ShallowEtagHeaderFilter;
+
/**
*
* A base class to hold common function for protein structure model binding.
extends SequenceStructureBindingModel
implements StructureListener, StructureSelectionManagerProvider
{
+ public enum ColourBy
+ {
+ Sequence, Chain, ChargeAndCysteine, Jalview, Viewer
+ }
+
+ /*
+ * selected colour menu option
+ */
+ private ColourBy colourBy = ColourBy.Sequence;
+ /*
+ * selected colour scheme, if a Jalview colour scheme is selected
+ */
+ private ColourSchemeI colourScheme;
+
+ /*
+ * flag for whether to include feature colouring, if using a Jalview colour
+ * scheme (independently of whether features are shown on alignment)
+ */
+ private boolean showFeatures;
+
private StructureSelectionManager ssm;
/*
* datasource protocol for access to PDBEntrylatest
*/
DataSourceType protocol = null;
-
- protected boolean colourBySequence = true;
-
+
private boolean nucleotide;
private boolean finishedInit = false;
String chain = (chains != null && chains[pe] != null)
? chains[pe][se]
: null;
- SequenceI sq = asq.getDatasetSequence();
+ SequenceI sq = (asq.getDatasetSequence() == null) ? asq
+ : asq.getDatasetSequence();
if (sq.getAllPDBEntries() != null)
{
for (PDBEntry pdbentry : sq.getAllPDBEntries())
}
+ public void setColourBy(ColourBy option)
+ {
+ colourBy = option;
+ }
+
public boolean isColourBySequence()
{
- return colourBySequence;
+ return colourBy == ColourBy.Sequence;
}
-
- public void setColourBySequence(boolean colourBySequence)
+
+ protected boolean isJalviewColourScheme()
{
- this.colourBySequence = colourBySequence;
+ return colourBy == ColourBy.Jalview;
}
protected void addSequenceAndChain(int pe, SequenceI[] seq,
return null;
}
- public abstract void setJalviewColourScheme(ColourSchemeI cs);
+ /**
+ * Sets the selected colour scheme, possibly with reference to the given
+ * alignment view
+ *
+ * @param cs
+ * @param ap
+ * @param showFeats
+ */
+ public void setJalviewColourScheme(ColourSchemeI cs, AlignmentViewPanel ap,
+ boolean showFeats)
+ {
+ colourBy = ColourBy.Jalview;
+ colourScheme = cs;
+ showFeatures = showFeats;
+
+ if (!showFeats && (cs == null || cs.isSimple()))
+ {
+ setSimpleColourScheme(cs);
+ }
+ else
+ {
+ colourBySequence(ap, new SequenceRenderer(ap.getAlignViewport(), cs), showFeatures);
+ }
+ }
/**
+ * Sets a colour scheme which is determined solely by the residue at each
+ * position
+ *
+ * @param cs
+ */
+ protected abstract void setSimpleColourScheme(ColourSchemeI cs);
+
+ /**
* Constructs and sends a command to align structures against a reference
* structure, based on one or more sequence alignments. May optionally return
* an error or warning message for the alignment command.
public abstract void setBackgroundColour(Color col);
protected abstract StructureMappingcommandSet[] getColourBySequenceCommands(
- String[] files, SequenceRenderer sr, AlignmentViewPanel avp);
-
- /**
- * returns the current sequenceRenderer that should be used to colour the
- * structures
- *
- * @param alignment
- *
- * @return
- */
- public abstract SequenceRenderer getSequenceRenderer(
- AlignmentViewPanel alignment);
+ String[] files, SequenceRendererI sr, AlignmentViewPanel avp, boolean showFeatures);
protected abstract void colourBySequence(
StructureMappingcommandSet[] colourBySequenceCommands);
- public abstract void colourByChain();
+ public void colourByChain()
+ {
+ colourBy = ColourBy.Chain;
+ }
+
+ public void colourByCharge()
+ {
+ colourBy = ColourBy.ChargeAndCysteine;
+ }
- public abstract void colourByCharge();
+ public void colourBySequence(AlignmentViewPanel alignmentv, boolean showFeatures)
+ {
+ colourBySequence(alignmentv, alignmentv.getSequenceRenderer(), showFeatures);
+ }
/**
- * colour any structures associated with sequences in the given alignment
- * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
- * if colourBySequence is enabled.
+ * Colours any structures associated with sequences in the given alignment view
+ * using the getFeatureRenderer() and getSequenceRenderer() renderers
*/
- public void colourBySequence(AlignmentViewPanel alignmentv)
+ public void colourBySequence(AlignmentViewPanel alignmentv, SequenceRendererI sr, boolean showFeats)
{
- if (!colourBySequence || !isLoadingFinished())
+ showFeatures = showFeats;
+ if (!isLoadingFinished())
{
return;
}
}
String[] files = getStructureFiles();
- SequenceRenderer sr = getSequenceRenderer(alignmentv);
-
StructureMappingcommandSet[] colourBySequenceCommands = getColourBySequenceCommands(
- files, sr, alignmentv);
+ files, sr, alignmentv, showFeatures);
colourBySequence(colourBySequenceCommands);
}
public abstract jalview.api.FeatureRenderer getFeatureRenderer(
AlignmentViewPanel alignment);
+
+@Override
+public void updateColours(Object source) {
+ AlignmentPanel ap = (AlignmentPanel) source;
+
+ /*
+ * ignore events from panels not used to colour this view
+ */
+ if (!getViewer().isUsedForColourBy(ap))
+ {
+ return;
+ }
+
+ /*
+ * no need to update colours if structure colouring is not
+ * viewport dependent
+ */
+ if (!isColourBySequence() && !isJalviewColourScheme())
+ {
+ return;
+ }
+ if (!showFeatures && (colourScheme == null || colourScheme.isSimple()))
+ {
+ return;
+ }
+
+ if (!isLoadingFromArchive())
+ {
+ if (isColourBySequence())
+ {
+ colourBySequence(ap, new SequenceRenderer(ap.getAlignViewport()),
+ showFeatures);
+ }
+ else
+ {
+ colourBySequence(ap, new SequenceRenderer(ap.getAlignViewport(),
+ colourScheme), showFeatures);
+ }
+ }
+ }
}