();
+ String string;
+ int refN, iadj;
+ // todo: add a 'reference origin column' to set column number relative to
+ for (int i = scalestartx; i < endx; i += 5)
+ {
+ if (((i - refSp) % 10) == 0)
+ {
+ if (refSeq == null)
+ {
+ iadj = av.getColumnSelection().adjustForHiddenColumns(i - 1) + 1;
+ string = String.valueOf(iadj);
+ }
+ else
+ {
+ iadj = av.getColumnSelection().adjustForHiddenColumns(i - 1);
+ refN = refSeq.findPosition(iadj);
+ // TODO show bounds if position is a gap
+ // - ie L--R -> "1L|2R" for
+ // marker
+ if (iadj < refStartI)
+ {
+ string = String.valueOf(iadj - refStartI);
+ }
+ else if (iadj > refEndI)
+ {
+ string = "+" + String.valueOf(iadj - refEndI);
+ }
+ else
+ {
+ string = String.valueOf(refN) + refSeq.getCharAt(iadj);
+ }
+ }
+ marks.add(new ScaleMark(true, i - startx - 1, string));
+ }
+ else
+ {
+ marks.add(new ScaleMark(false, i - startx - 1, null));
+ }
+ }
+ return marks;
+ }
+
+}
diff --git a/src/jalview/renderer/seqfeatures/FeatureRenderer.java b/src/jalview/renderer/seqfeatures/FeatureRenderer.java
index 2276913..b007365 100644
--- a/src/jalview/renderer/seqfeatures/FeatureRenderer.java
+++ b/src/jalview/renderer/seqfeatures/FeatureRenderer.java
@@ -20,6 +20,7 @@
*/
package jalview.renderer.seqfeatures;
+import jalview.api.AlignViewportI;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.viewmodel.seqfeatures.FeatureRendererModel;
@@ -50,6 +51,18 @@ public class FeatureRenderer extends FeatureRendererModel
boolean av_validCharWidth, av_isShowSeqFeatureHeight;
+ private Integer currentColour;
+
+ /**
+ * Constructor given a viewport
+ *
+ * @param viewport
+ */
+ public FeatureRenderer(AlignViewportI viewport)
+ {
+ this.av = viewport;
+ }
+
protected void updateAvConfig()
{
av_charHeight = av.getCharHeight();
@@ -175,8 +188,8 @@ public class FeatureRenderer extends FeatureRendererModel
}
/**
- * This is used by the Molecule Viewer and Overview to get the accurate
- * colourof the rendered sequence
+ * This is used by the Molecule Viewer and Overview to get the accurate colour
+ * of the rendered sequence
*/
public synchronized int findFeatureColour(int initialCol,
final SequenceI seq, int column)
@@ -246,7 +259,7 @@ public class FeatureRenderer extends FeatureRendererModel
}
else
{
- return ((Integer) currentColour).intValue();
+ return currentColour.intValue();
}
}
@@ -390,7 +403,7 @@ public class FeatureRenderer extends FeatureRendererModel
}
- if (transparency != 1.0f && g != null && transparencyAvailable)
+ if (transparency != 1.0f && g != null)
{
Graphics2D g2 = (Graphics2D) g;
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
@@ -398,19 +411,6 @@ public class FeatureRenderer extends FeatureRendererModel
}
}
- boolean transparencyAvailable = true;
-
- protected void setTransparencyAvailable(boolean isTransparencyAvailable)
- {
- transparencyAvailable = isTransparencyAvailable;
- }
-
- @Override
- public boolean isTransparencyAvailable()
- {
- return transparencyAvailable;
- }
-
/**
* Called when alignment in associated view has new/modified features to
* discover and display.
diff --git a/src/jalview/schemabinding/version2/.castor.cdr b/src/jalview/schemabinding/version2/.castor.cdr
index 361fb7c..0a01103 100644
--- a/src/jalview/schemabinding/version2/.castor.cdr
+++ b/src/jalview/schemabinding/version2/.castor.cdr
@@ -1,4 +1,4 @@
-#Thu Sep 03 10:55:37 BST 2015
+#Mon Jun 20 15:44:52 BST 2016
jalview.schemabinding.version2.ThresholdLine=jalview.schemabinding.version2.descriptors.ThresholdLineDescriptor
jalview.schemabinding.version2.SequenceSetProperties=jalview.schemabinding.version2.descriptors.SequenceSetPropertiesDescriptor
jalview.schemabinding.version2.StructureState=jalview.schemabinding.version2.descriptors.StructureStateDescriptor
diff --git a/src/jalview/schemabinding/version2/JSeq.java b/src/jalview/schemabinding/version2/JSeq.java
index 9ca6708..7c6308e 100644
--- a/src/jalview/schemabinding/version2/JSeq.java
+++ b/src/jalview/schemabinding/version2/JSeq.java
@@ -72,6 +72,16 @@ public class JSeq implements java.io.Serializable
private boolean _has_hidden;
/**
+ * Field _viewreference.
+ */
+ private boolean _viewreference;
+
+ /**
+ * keeps track of state for field: _viewreference
+ */
+ private boolean _has_viewreference;
+
+ /**
* Field _featuresList.
*/
private java.util.Vector _featuresList;
@@ -256,6 +266,13 @@ public class JSeq implements java.io.Serializable
}
/**
+ */
+ public void deleteViewreference()
+ {
+ this._has_viewreference = false;
+ }
+
+ /**
* Method enumerateFeatures.
*
* @return an Enumeration over all jalview.schemabinding.version2.Features
@@ -549,6 +566,16 @@ public class JSeq implements java.io.Serializable
}
/**
+ * Returns the value of field 'viewreference'.
+ *
+ * @return the value of field 'Viewreference'.
+ */
+ public boolean getViewreference()
+ {
+ return this._viewreference;
+ }
+
+ /**
* Method hasColour.
*
* @return true if at least one Colour has been added
@@ -589,6 +616,16 @@ public class JSeq implements java.io.Serializable
}
/**
+ * Method hasViewreference.
+ *
+ * @return true if at least one Viewreference has been added
+ */
+ public boolean hasViewreference()
+ {
+ return this._has_viewreference;
+ }
+
+ /**
* Returns the value of field 'hidden'.
*
* @return the value of field 'Hidden'.
@@ -616,6 +653,16 @@ public class JSeq implements java.io.Serializable
}
/**
+ * Returns the value of field 'viewreference'.
+ *
+ * @return the value of field 'Viewreference'.
+ */
+ public boolean isViewreference()
+ {
+ return this._viewreference;
+ }
+
+ /**
*
*
* @param out
@@ -1004,6 +1051,18 @@ public class JSeq implements java.io.Serializable
}
/**
+ * Sets the value of field 'viewreference'.
+ *
+ * @param viewreference
+ * the value of field 'viewreference'.
+ */
+ public void setViewreference(final boolean viewreference)
+ {
+ this._viewreference = viewreference;
+ this._has_viewreference = true;
+ }
+
+ /**
* Method unmarshal.
*
* @param reader
diff --git a/src/jalview/schemabinding/version2/descriptors/AnnotationColoursDescriptor.java b/src/jalview/schemabinding/version2/descriptors/AnnotationColoursDescriptor.java
index 1d2aad3..5739d90 100644
--- a/src/jalview/schemabinding/version2/descriptors/AnnotationColoursDescriptor.java
+++ b/src/jalview/schemabinding/version2/descriptors/AnnotationColoursDescriptor.java
@@ -11,6 +11,8 @@ package jalview.schemabinding.version2.descriptors;
//- Imported classes and packages -/
//---------------------------------/
+import jalview.schemabinding.version2.AnnotationColours;
+
/**
* Class AnnotationColoursDescriptor.
*
diff --git a/src/jalview/schemabinding/version2/descriptors/FeaturesDescriptor.java b/src/jalview/schemabinding/version2/descriptors/FeaturesDescriptor.java
index a7ffaba..107c06d 100644
--- a/src/jalview/schemabinding/version2/descriptors/FeaturesDescriptor.java
+++ b/src/jalview/schemabinding/version2/descriptors/FeaturesDescriptor.java
@@ -11,6 +11,8 @@ package jalview.schemabinding.version2.descriptors;
//- Imported classes and packages -/
//---------------------------------/
+import jalview.schemabinding.version2.Features;
+
/**
* Class FeaturesDescriptor.
*
diff --git a/src/jalview/schemabinding/version2/descriptors/JSeqDescriptor.java b/src/jalview/schemabinding/version2/descriptors/JSeqDescriptor.java
index 0f000bb..28f23b26 100644
--- a/src/jalview/schemabinding/version2/descriptors/JSeqDescriptor.java
+++ b/src/jalview/schemabinding/version2/descriptors/JSeqDescriptor.java
@@ -334,6 +334,61 @@ public class JSeqDescriptor extends
fieldValidator.setValidator(typeValidator);
}
desc.setValidator(fieldValidator);
+ // -- _viewreference
+ desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(
+ java.lang.Boolean.TYPE, "_viewreference", "viewreference",
+ org.exolab.castor.xml.NodeType.Attribute);
+ handler = new org.exolab.castor.xml.XMLFieldHandler()
+ {
+ public java.lang.Object getValue(java.lang.Object object)
+ throws IllegalStateException
+ {
+ JSeq target = (JSeq) object;
+ if (!target.hasViewreference())
+ {
+ return null;
+ }
+ return (target.getViewreference() ? java.lang.Boolean.TRUE
+ : java.lang.Boolean.FALSE);
+ }
+
+ public void setValue(java.lang.Object object, java.lang.Object value)
+ throws IllegalStateException, IllegalArgumentException
+ {
+ try
+ {
+ JSeq target = (JSeq) object;
+ // if null, use delete method for optional primitives
+ if (value == null)
+ {
+ target.deleteViewreference();
+ return;
+ }
+ target.setViewreference(((java.lang.Boolean) value)
+ .booleanValue());
+ } catch (java.lang.Exception ex)
+ {
+ throw new IllegalStateException(ex.toString());
+ }
+ }
+
+ public java.lang.Object newInstance(java.lang.Object parent)
+ {
+ return null;
+ }
+ };
+ desc.setHandler(handler);
+ desc.setMultivalued(false);
+ addFieldDescriptor(desc);
+
+ // -- validation code for: _viewreference
+ fieldValidator = new org.exolab.castor.xml.FieldValidator();
+ { // -- local scope
+ org.exolab.castor.xml.validators.BooleanValidator typeValidator;
+ typeValidator = new org.exolab.castor.xml.validators.BooleanValidator();
+ fieldValidator.setValidator(typeValidator);
+ }
+ desc.setValidator(fieldValidator);
// -- initialize element descriptors
// -- _featuresList
diff --git a/src/jalview/schemabinding/version2/descriptors/JalviewUserColoursDescriptor.java b/src/jalview/schemabinding/version2/descriptors/JalviewUserColoursDescriptor.java
index 77efa7e..d65de13 100644
--- a/src/jalview/schemabinding/version2/descriptors/JalviewUserColoursDescriptor.java
+++ b/src/jalview/schemabinding/version2/descriptors/JalviewUserColoursDescriptor.java
@@ -72,6 +72,7 @@ public class JalviewUserColoursDescriptor extends
desc.setImmutable(true);
handler = new org.exolab.castor.xml.XMLFieldHandler()
{
+ @Override
public java.lang.Object getValue(java.lang.Object object)
throws IllegalStateException
{
@@ -79,6 +80,7 @@ public class JalviewUserColoursDescriptor extends
return target.getSchemeName();
}
+ @Override
public void setValue(java.lang.Object object, java.lang.Object value)
throws IllegalStateException, IllegalArgumentException
{
@@ -92,6 +94,7 @@ public class JalviewUserColoursDescriptor extends
}
}
+ @Override
public java.lang.Object newInstance(java.lang.Object parent)
{
return null;
@@ -119,6 +122,7 @@ public class JalviewUserColoursDescriptor extends
desc.setImmutable(true);
handler = new org.exolab.castor.xml.XMLFieldHandler()
{
+ @Override
public java.lang.Object getValue(java.lang.Object object)
throws IllegalStateException
{
@@ -126,6 +130,7 @@ public class JalviewUserColoursDescriptor extends
return target.getVersion();
}
+ @Override
public void setValue(java.lang.Object object, java.lang.Object value)
throws IllegalStateException, IllegalArgumentException
{
@@ -139,6 +144,7 @@ public class JalviewUserColoursDescriptor extends
}
}
+ @Override
public java.lang.Object newInstance(java.lang.Object parent)
{
return null;
@@ -163,6 +169,7 @@ public class JalviewUserColoursDescriptor extends
org.exolab.castor.xml.NodeType.Element);
handler = new org.exolab.castor.xml.XMLFieldHandler()
{
+ @Override
public java.lang.Object getValue(java.lang.Object object)
throws IllegalStateException
{
@@ -170,6 +177,7 @@ public class JalviewUserColoursDescriptor extends
return target.getColour();
}
+ @Override
public void setValue(java.lang.Object object, java.lang.Object value)
throws IllegalStateException, IllegalArgumentException
{
@@ -183,6 +191,7 @@ public class JalviewUserColoursDescriptor extends
}
}
+ @Override
public void resetValue(Object object) throws IllegalStateException,
IllegalArgumentException
{
@@ -196,6 +205,7 @@ public class JalviewUserColoursDescriptor extends
}
}
+ @Override
public java.lang.Object newInstance(java.lang.Object parent)
{
return new Colour();
@@ -222,6 +232,7 @@ public class JalviewUserColoursDescriptor extends
*
* @return the access mode specified for this class.
*/
+ @Override
public org.exolab.castor.mapping.AccessMode getAccessMode()
{
return null;
@@ -232,6 +243,7 @@ public class JalviewUserColoursDescriptor extends
*
* @return the identity field, null if this class has no identity.
*/
+ @Override
public org.exolab.castor.mapping.FieldDescriptor getIdentity()
{
return super.getIdentity();
@@ -242,6 +254,7 @@ public class JalviewUserColoursDescriptor extends
*
* @return the Java class represented by this descriptor.
*/
+ @Override
public java.lang.Class getJavaClass()
{
return jalview.schemabinding.version2.JalviewUserColours.class;
@@ -252,6 +265,7 @@ public class JalviewUserColoursDescriptor extends
*
* @return the namespace prefix to use when marshaling as XML.
*/
+ @Override
public java.lang.String getNameSpacePrefix()
{
return _nsPrefix;
@@ -262,6 +276,7 @@ public class JalviewUserColoursDescriptor extends
*
* @return the namespace URI used when marshaling and unmarshaling as XML.
*/
+ @Override
public java.lang.String getNameSpaceURI()
{
return _nsURI;
@@ -273,6 +288,7 @@ public class JalviewUserColoursDescriptor extends
* @return a specific validator for the class described by this
* ClassDescriptor.
*/
+ @Override
public org.exolab.castor.xml.TypeValidator getValidator()
{
return this;
@@ -283,6 +299,7 @@ public class JalviewUserColoursDescriptor extends
*
* @return the XML Name for the Class being described.
*/
+ @Override
public java.lang.String getXMLName()
{
return _xmlName;
@@ -294,6 +311,7 @@ public class JalviewUserColoursDescriptor extends
* @return true if XML schema definition of this Class is that of a global
* element or element with anonymous type definition.
*/
+ @Override
public boolean isElementDefinition()
{
return _elementDefinition;
diff --git a/src/jalview/schemabinding/version2/descriptors/UserColourSchemeDescriptor.java b/src/jalview/schemabinding/version2/descriptors/UserColourSchemeDescriptor.java
index ece728a..df9ab07 100644
--- a/src/jalview/schemabinding/version2/descriptors/UserColourSchemeDescriptor.java
+++ b/src/jalview/schemabinding/version2/descriptors/UserColourSchemeDescriptor.java
@@ -11,6 +11,8 @@ package jalview.schemabinding.version2.descriptors;
//- Imported classes and packages -/
//---------------------------------/
+import jalview.schemabinding.version2.UserColourScheme;
+
/**
* Class UserColourSchemeDescriptor.
*
diff --git a/src/jalview/schemabinding/version2/descriptors/VamsasModelDescriptor.java b/src/jalview/schemabinding/version2/descriptors/VamsasModelDescriptor.java
index 86e6992..3e26611 100644
--- a/src/jalview/schemabinding/version2/descriptors/VamsasModelDescriptor.java
+++ b/src/jalview/schemabinding/version2/descriptors/VamsasModelDescriptor.java
@@ -11,6 +11,8 @@ package jalview.schemabinding.version2.descriptors;
//- Imported classes and packages -/
//---------------------------------/
+import jalview.schemabinding.version2.VamsasModel;
+
/**
* Class VamsasModelDescriptor.
*
diff --git a/src/jalview/schemes/Blosum62ColourScheme.java b/src/jalview/schemes/Blosum62ColourScheme.java
index 9d09259..37c31f9 100755
--- a/src/jalview/schemes/Blosum62ColourScheme.java
+++ b/src/jalview/schemes/Blosum62ColourScheme.java
@@ -20,16 +20,19 @@
*/
package jalview.schemes;
-import jalview.analysis.AAFrequency;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
import java.awt.Color;
import java.util.Map;
public class Blosum62ColourScheme extends ResidueColourScheme
{
+ private static final Color LIGHT_BLUE = new Color(204, 204, 255);
+ private static final Color DARK_BLUE = new Color(154, 154, 255);
+
public Blosum62ColourScheme()
{
super();
@@ -52,14 +55,16 @@ public class Blosum62ColourScheme extends ResidueColourScheme
Color currentColour;
- if (!jalview.util.Comparison.isGap(res))
+ if (!Comparison.isGap(res))
{
- String max = (String) consensus[j].get(AAFrequency.MAXRESIDUE);
+ /*
+ * test if this is the consensus (or joint consensus) residue
+ */
+ String max = consensus[j].getModalResidue();
if (max.indexOf(res) > -1)
{
- // TODO use a constant here?
- currentColour = new Color(154, 154, 255);
+ currentColour = DARK_BLUE;
}
else
{
@@ -74,8 +79,7 @@ public class Blosum62ColourScheme extends ResidueColourScheme
if (c > 0)
{
- // TODO use a constant here?
- currentColour = new Color(204, 204, 255);
+ currentColour = LIGHT_BLUE;
}
else
{
diff --git a/src/jalview/schemes/ColourSchemeI.java b/src/jalview/schemes/ColourSchemeI.java
index effdf59..165ece9 100755
--- a/src/jalview/schemes/ColourSchemeI.java
+++ b/src/jalview/schemes/ColourSchemeI.java
@@ -20,6 +20,7 @@
*/
package jalview.schemes;
+import jalview.analysis.Profile;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
@@ -52,7 +53,7 @@ public interface ColourSchemeI
/**
* assign the given consensus profile for the colourscheme
*/
- public void setConsensus(java.util.Hashtable[] h);
+ public void setConsensus(Profile[] hconsensus);
/**
* assign the given conservation to the colourscheme
diff --git a/src/jalview/schemes/FeatureColour.java b/src/jalview/schemes/FeatureColour.java
new file mode 100644
index 0000000..23087a8
--- /dev/null
+++ b/src/jalview/schemes/FeatureColour.java
@@ -0,0 +1,696 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.schemes;
+
+import jalview.api.FeatureColourI;
+import jalview.datamodel.SequenceFeature;
+import jalview.util.Format;
+
+import java.awt.Color;
+import java.util.StringTokenizer;
+
+/**
+ * A class that wraps either a simple colour or a graduated colour
+ */
+public class FeatureColour implements FeatureColourI
+{
+ private static final String BAR = "|";
+
+ final private Color colour;
+
+ final private Color minColour;
+
+ final private Color maxColour;
+
+ private boolean graduatedColour;
+
+ private boolean colourByLabel;
+
+ private float threshold;
+
+ private float base;
+
+ private float range;
+
+ private boolean belowThreshold;
+
+ private boolean aboveThreshold;
+
+ private boolean thresholdIsMinOrMax;
+
+ private boolean isHighToLow;
+
+ private boolean autoScaled;
+
+ final private float minRed;
+
+ final private float minGreen;
+
+ final private float minBlue;
+
+ final private float deltaRed;
+
+ final private float deltaGreen;
+
+ final private float deltaBlue;
+
+ /**
+ * Parses a Jalview features file format colour descriptor
+ * [label|][mincolour|maxcolour
+ * |[absolute|]minvalue|maxvalue|thresholdtype|thresholdvalue] Examples:
+ *
+ * - red
+ * - a28bbb
+ * - 25,125,213
+ * - label
+ * - label|||0.0|0.0|above|12.5
+ * - label|||0.0|0.0|below|12.5
+ * - red|green|12.0|26.0|none
+ * - a28bbb|3eb555|12.0|26.0|above|12.5
+ * - a28bbb|3eb555|abso|12.0|26.0|below|12.5
+ *
+ *
+ * @param descriptor
+ * @return
+ * @throws IllegalArgumentException
+ * if not parseable
+ */
+ public static FeatureColour parseJalviewFeatureColour(String descriptor)
+ {
+ StringTokenizer gcol = new StringTokenizer(descriptor, "|", true);
+ float min = Float.MIN_VALUE;
+ float max = Float.MAX_VALUE;
+ boolean labelColour = false;
+
+ String mincol = gcol.nextToken();
+ if (mincol == "|")
+ {
+ throw new IllegalArgumentException(
+ "Expected either 'label' or a colour specification in the line: "
+ + descriptor);
+ }
+ String maxcol = null;
+ if (mincol.toLowerCase().indexOf("label") == 0)
+ {
+ labelColour = true;
+ mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null);
+ // skip '|'
+ mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null);
+ }
+
+ if (!labelColour && !gcol.hasMoreTokens())
+ {
+ /*
+ * only a simple colour specification - parse it
+ */
+ Color colour = UserColourScheme.getColourFromString(descriptor);
+ if (colour == null)
+ {
+ throw new IllegalArgumentException("Invalid colour descriptor: "
+ + descriptor);
+ }
+ return new FeatureColour(colour);
+ }
+
+ /*
+ * autoScaled == true: colours range over actual score range
+ * autoScaled == false ('abso'): colours range over min/max range
+ */
+ boolean autoScaled = true;
+ String tok = null, minval, maxval;
+ if (mincol != null)
+ {
+ // at least four more tokens
+ if (mincol.equals("|"))
+ {
+ mincol = "";
+ }
+ else
+ {
+ gcol.nextToken(); // skip next '|'
+ }
+ maxcol = gcol.nextToken();
+ if (maxcol.equals("|"))
+ {
+ maxcol = "";
+ }
+ else
+ {
+ gcol.nextToken(); // skip next '|'
+ }
+ tok = gcol.nextToken();
+ gcol.nextToken(); // skip next '|'
+ if (tok.toLowerCase().startsWith("abso"))
+ {
+ minval = gcol.nextToken();
+ gcol.nextToken(); // skip next '|'
+ autoScaled = false;
+ }
+ else
+ {
+ minval = tok;
+ }
+ maxval = gcol.nextToken();
+ if (gcol.hasMoreTokens())
+ {
+ gcol.nextToken(); // skip next '|'
+ }
+ try
+ {
+ if (minval.length() > 0)
+ {
+ min = new Float(minval).floatValue();
+ }
+ } catch (Exception e)
+ {
+ throw new IllegalArgumentException(
+ "Couldn't parse the minimum value for graduated colour ("
+ + descriptor + ")");
+ }
+ try
+ {
+ if (maxval.length() > 0)
+ {
+ max = new Float(maxval).floatValue();
+ }
+ } catch (Exception e)
+ {
+ throw new IllegalArgumentException(
+ "Couldn't parse the maximum value for graduated colour ("
+ + descriptor + ")");
+ }
+ }
+ else
+ {
+ // add in some dummy min/max colours for the label-only
+ // colourscheme.
+ mincol = "FFFFFF";
+ maxcol = "000000";
+ }
+
+ /*
+ * construct the FeatureColour
+ */
+ FeatureColour featureColour;
+ try
+ {
+ featureColour = new FeatureColour(
+ new UserColourScheme(mincol).findColour('A'),
+ new UserColourScheme(maxcol).findColour('A'), min, max);
+ featureColour.setColourByLabel(labelColour);
+ featureColour.setAutoScaled(autoScaled);
+ // add in any additional parameters
+ String ttype = null, tval = null;
+ if (gcol.hasMoreTokens())
+ {
+ // threshold type and possibly a threshold value
+ ttype = gcol.nextToken();
+ if (ttype.toLowerCase().startsWith("below"))
+ {
+ featureColour.setBelowThreshold(true);
+ }
+ else if (ttype.toLowerCase().startsWith("above"))
+ {
+ featureColour.setAboveThreshold(true);
+ }
+ else
+ {
+ if (!ttype.toLowerCase().startsWith("no"))
+ {
+ System.err.println("Ignoring unrecognised threshold type : "
+ + ttype);
+ }
+ }
+ }
+ if (featureColour.hasThreshold())
+ {
+ try
+ {
+ gcol.nextToken();
+ tval = gcol.nextToken();
+ featureColour.setThreshold(new Float(tval).floatValue());
+ } catch (Exception e)
+ {
+ System.err.println("Couldn't parse threshold value as a float: ("
+ + tval + ")");
+ }
+ }
+ if (gcol.hasMoreTokens())
+ {
+ System.err
+ .println("Ignoring additional tokens in parameters in graduated colour specification\n");
+ while (gcol.hasMoreTokens())
+ {
+ System.err.println("|" + gcol.nextToken());
+ }
+ System.err.println("\n");
+ }
+ return featureColour;
+ } catch (Exception e)
+ {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ }
+
+ /**
+ * Default constructor
+ */
+ public FeatureColour()
+ {
+ this((Color) null);
+ }
+
+ /**
+ * Constructor given a simple colour
+ *
+ * @param c
+ */
+ public FeatureColour(Color c)
+ {
+ minColour = Color.WHITE;
+ maxColour = Color.BLACK;
+ minRed = 0f;
+ minGreen = 0f;
+ minBlue = 0f;
+ deltaRed = 0f;
+ deltaGreen = 0f;
+ deltaBlue = 0f;
+ colour = c;
+ }
+
+ /**
+ * Constructor given a colour range and a score range
+ *
+ * @param low
+ * @param high
+ * @param min
+ * @param max
+ */
+ public FeatureColour(Color low, Color high, float min, float max)
+ {
+ graduatedColour = true;
+ colour = null;
+ minColour = low;
+ maxColour = high;
+ threshold = Float.NaN;
+ isHighToLow = min >= max;
+ minRed = low.getRed() / 255f;
+ minGreen = low.getGreen() / 255f;
+ minBlue = low.getBlue() / 255f;
+ deltaRed = (high.getRed() / 255f) - minRed;
+ deltaGreen = (high.getGreen() / 255f) - minGreen;
+ deltaBlue = (high.getBlue() / 255f) - minBlue;
+ if (isHighToLow)
+ {
+ base = max;
+ range = min - max;
+ }
+ else
+ {
+ base = min;
+ range = max - min;
+ }
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param fc
+ */
+ public FeatureColour(FeatureColour fc)
+ {
+ graduatedColour = fc.graduatedColour;
+ colour = fc.colour;
+ minColour = fc.minColour;
+ maxColour = fc.maxColour;
+ minRed = fc.minRed;
+ minGreen = fc.minGreen;
+ minBlue = fc.minBlue;
+ deltaRed = fc.deltaRed;
+ deltaGreen = fc.deltaGreen;
+ deltaBlue = fc.deltaBlue;
+ base = fc.base;
+ range = fc.range;
+ isHighToLow = fc.isHighToLow;
+ setAboveThreshold(fc.isAboveThreshold());
+ setBelowThreshold(fc.isBelowThreshold());
+ setThreshold(fc.getThreshold());
+ setAutoScaled(fc.isAutoScaled());
+ setColourByLabel(fc.isColourByLabel());
+ }
+
+ /**
+ * Copy constructor with new min/max ranges
+ *
+ * @param fc
+ * @param min
+ * @param max
+ */
+ public FeatureColour(FeatureColour fc, float min, float max)
+ {
+ this(fc);
+ graduatedColour = true;
+ updateBounds(min, max);
+ }
+
+ @Override
+ public boolean isGraduatedColour()
+ {
+ return graduatedColour;
+ }
+
+ /**
+ * Sets the 'graduated colour' flag. If true, also sets 'colour by label' to
+ * false.
+ */
+ void setGraduatedColour(boolean b)
+ {
+ graduatedColour = b;
+ if (b)
+ {
+ setColourByLabel(false);
+ }
+ }
+
+ @Override
+ public Color getColour()
+ {
+ return colour;
+ }
+
+ @Override
+ public Color getMinColour()
+ {
+ return minColour;
+ }
+
+ @Override
+ public Color getMaxColour()
+ {
+ return maxColour;
+ }
+
+ @Override
+ public boolean isColourByLabel()
+ {
+ return colourByLabel;
+ }
+
+ /**
+ * Sets the 'colour by label' flag. If true, also sets 'graduated colour' to
+ * false.
+ */
+ @Override
+ public void setColourByLabel(boolean b)
+ {
+ colourByLabel = b;
+ if (b)
+ {
+ setGraduatedColour(false);
+ }
+ }
+
+ @Override
+ public boolean isBelowThreshold()
+ {
+ return belowThreshold;
+ }
+
+ @Override
+ public void setBelowThreshold(boolean b)
+ {
+ belowThreshold = b;
+ if (b)
+ {
+ setAboveThreshold(false);
+ }
+ }
+
+ @Override
+ public boolean isAboveThreshold()
+ {
+ return aboveThreshold;
+ }
+
+ @Override
+ public void setAboveThreshold(boolean b)
+ {
+ aboveThreshold = b;
+ if (b)
+ {
+ setBelowThreshold(false);
+ }
+ }
+
+ @Override
+ public boolean isThresholdMinMax()
+ {
+ return thresholdIsMinOrMax;
+ }
+
+ @Override
+ public void setThresholdMinMax(boolean b)
+ {
+ thresholdIsMinOrMax = b;
+ }
+
+ @Override
+ public float getThreshold()
+ {
+ return threshold;
+ }
+
+ @Override
+ public void setThreshold(float f)
+ {
+ threshold = f;
+ }
+
+ @Override
+ public boolean isAutoScaled()
+ {
+ return autoScaled;
+ }
+
+ @Override
+ public void setAutoScaled(boolean b)
+ {
+ this.autoScaled = b;
+ }
+
+ /**
+ * Updates the base and range appropriately for the given minmax range
+ *
+ * @param min
+ * @param max
+ */
+ @Override
+ public void updateBounds(float min, float max)
+ {
+ if (max < min)
+ {
+ base = max;
+ range = min - max;
+ isHighToLow = true;
+ }
+ else
+ {
+ base = min;
+ range = max - min;
+ isHighToLow = false;
+ }
+ }
+
+ /**
+ * Returns the colour for the given instance of the feature. This may be a
+ * simple colour, a colour generated from the feature description (if
+ * isColourByLabel()), or a colour derived from the feature score (if
+ * isGraduatedColour()).
+ *
+ * @param feature
+ * @return
+ */
+ @Override
+ public Color getColor(SequenceFeature feature)
+ {
+ if (isColourByLabel())
+ {
+ return UserColourScheme
+ .createColourFromName(feature.getDescription());
+ }
+
+ if (!isGraduatedColour())
+ {
+ return getColour();
+ }
+
+ // todo should we check for above/below threshold here?
+ if (range == 0.0)
+ {
+ return getMaxColour();
+ }
+ float scr = feature.getScore();
+ if (Float.isNaN(scr))
+ {
+ return getMinColour();
+ }
+ float scl = (scr - base) / range;
+ if (isHighToLow)
+ {
+ scl = -scl;
+ }
+ if (scl < 0f)
+ {
+ scl = 0f;
+ }
+ if (scl > 1f)
+ {
+ scl = 1f;
+ }
+ return new Color(minRed + scl * deltaRed, minGreen + scl * deltaGreen,
+ minBlue + scl * deltaBlue);
+ }
+
+ /**
+ * Returns the maximum score of the graduated colour range
+ *
+ * @return
+ */
+ @Override
+ public float getMax()
+ {
+ // regenerate the original values passed in to the constructor
+ return (isHighToLow) ? base : (base + range);
+ }
+
+ /**
+ * Returns the minimum score of the graduated colour range
+ *
+ * @return
+ */
+ @Override
+ public float getMin()
+ {
+ // regenerate the original value passed in to the constructor
+ return (isHighToLow) ? (base + range) : base;
+ }
+
+ /**
+ * Answers true if the feature has a simple colour, or is coloured by label,
+ * or has a graduated colour and the score of this feature instance is within
+ * the range to render (if any), i.e. does not lie below or above any
+ * threshold set.
+ *
+ * @param feature
+ * @return
+ */
+ @Override
+ public boolean isColored(SequenceFeature feature)
+ {
+ if (isColourByLabel() || !isGraduatedColour())
+ {
+ return true;
+ }
+
+ float val = feature.getScore();
+ if (Float.isNaN(val))
+ {
+ return true;
+ }
+ if (Float.isNaN(this.threshold))
+ {
+ return true;
+ }
+
+ if (isAboveThreshold() && val <= threshold)
+ {
+ return false;
+ }
+ if (isBelowThreshold() && val >= threshold)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean isSimpleColour()
+ {
+ return (!isColourByLabel() && !isGraduatedColour());
+ }
+
+ @Override
+ public boolean hasThreshold()
+ {
+ return isAboveThreshold() || isBelowThreshold();
+ }
+
+ @Override
+ public String toJalviewFormat(String featureType)
+ {
+ String colourString = null;
+ if (isSimpleColour())
+ {
+ colourString = Format.getHexString(getColour());
+ }
+ else
+ {
+ StringBuilder sb = new StringBuilder(32);
+ if (isColourByLabel())
+ {
+ sb.append("label");
+ if (hasThreshold())
+ {
+ sb.append(BAR).append(BAR).append(BAR);
+ }
+ }
+ if (isGraduatedColour())
+ {
+ sb.append(Format.getHexString(getMinColour())).append(BAR);
+ sb.append(Format.getHexString(getMaxColour())).append(BAR);
+ if (!isAutoScaled())
+ {
+ sb.append("abso").append(BAR);
+ }
+ }
+ if (hasThreshold() || isGraduatedColour())
+ {
+ sb.append(getMin()).append(BAR);
+ sb.append(getMax()).append(BAR);
+ if (isBelowThreshold())
+ {
+ sb.append("below").append(BAR).append(getThreshold());
+ }
+ else if (isAboveThreshold())
+ {
+ sb.append("above").append(BAR).append(getThreshold());
+ }
+ else
+ {
+ sb.append("none");
+ }
+ }
+ colourString = sb.toString();
+ }
+ return String.format("%s\t%s", featureType, colourString);
+ }
+
+}
diff --git a/src/jalview/schemes/FeatureColourAdapter.java b/src/jalview/schemes/FeatureColourAdapter.java
deleted file mode 100644
index a86bee4..0000000
--- a/src/jalview/schemes/FeatureColourAdapter.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package jalview.schemes;
-
-import jalview.api.FeatureColourI;
-
-import java.awt.Color;
-
-/**
- * A convenience class with implementations of FeatureColourI methods. Override
- * methods as required in subclasses.
- */
-public class FeatureColourAdapter implements FeatureColourI
-{
- @Override
- public boolean isGraduatedColour()
- {
- return isColourByLabel() || isAboveThreshold() || isBelowThreshold();
- }
-
- @Override
- public Color getColour()
- {
- return Color.BLACK;
- }
-
- @Override
- public Color getMinColour()
- {
- return Color.WHITE;
- }
-
- @Override
- public Color getMaxColour()
- {
- return Color.BLACK;
- }
-
- @Override
- public boolean isColourByLabel()
- {
- return false;
- }
-
- @Override
- public boolean isBelowThreshold()
- {
- return false;
- }
-
- @Override
- public boolean isAboveThreshold()
- {
- return false;
- }
-
- @Override
- public boolean isThresholdMinMax()
- {
- return false;
- }
-
- @Override
- public float getThreshold()
- {
- return 0f;
- }
-
- @Override
- public boolean isLowToHigh()
- {
- return true;
- }
-
-}
diff --git a/src/jalview/schemes/FeatureSettingsAdapter.java b/src/jalview/schemes/FeatureSettingsAdapter.java
index 699d954..b15e4cf 100644
--- a/src/jalview/schemes/FeatureSettingsAdapter.java
+++ b/src/jalview/schemes/FeatureSettingsAdapter.java
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.schemes;
import jalview.api.FeatureColourI;
diff --git a/src/jalview/schemes/FollowerColourScheme.java b/src/jalview/schemes/FollowerColourScheme.java
index eac467a..0dcf960 100644
--- a/src/jalview/schemes/FollowerColourScheme.java
+++ b/src/jalview/schemes/FollowerColourScheme.java
@@ -21,8 +21,7 @@
package jalview.schemes;
import jalview.analysis.Conservation;
-
-import java.util.Hashtable;
+import jalview.analysis.Profile;
/**
* Colourscheme that takes its colours from some other colourscheme
@@ -41,7 +40,7 @@ public class FollowerColourScheme extends ResidueColourScheme
}
@Override
- public void setConsensus(Hashtable[] consensus)
+ public void setConsensus(Profile[] consensus)
{
if (colourScheme != null)
{
diff --git a/src/jalview/schemes/GraduatedColor.java b/src/jalview/schemes/GraduatedColor.java
deleted file mode 100644
index 2d1c572..0000000
--- a/src/jalview/schemes/GraduatedColor.java
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Jalview. If not, see .
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.schemes;
-
-import jalview.api.FeatureColourI;
-import jalview.datamodel.SequenceFeature;
-
-import java.awt.Color;
-
-/**
- * Value and/or thresholded colour scale used for colouring by annotation and
- * feature score
- *
- * @author JimP
- *
- */
-public class GraduatedColor
-{
- int thresholdState = AnnotationColourGradient.NO_THRESHOLD; // or
- // ABOVE_THRESHOLD
- // or
- // BELOW_THRESHOLD
-
- float lr, lg, lb, dr, dg, db;
-
- /**
- * linear scaling parameters, base, minimum colour threshold, range of linear
- * scale from lower to upper
- */
- float base, range, thrsh;
-
- /**
- * when true, colour from u to u-d rather than u to u+d
- */
- boolean tolow = false;
-
- /**
- * when false, min/max range has been manually set so should not be
- * dynamically adjusted.
- */
- boolean autoScale = true;
-
- /**
- * construct a graduatedColor object from simple parameters
- *
- * @param low
- * @param high
- * @param min
- * @param max
- * color low->high from min->max
- */
- public GraduatedColor(Color low, Color high, float min, float max)
- {
- thrsh = Float.NaN;
- tolow = min >= max;
- lr = low.getRed() / 255f;
- lg = low.getGreen() / 255f;
- lb = low.getBlue() / 255f;
- dr = (high.getRed() / 255f) - lr;
- dg = (high.getGreen() / 255f) - lg;
- db = (high.getBlue() / 255f) - lb;
- if (tolow)
- {
- base = max;
- range = min - max;
- }
- else
- {
- base = min;
- range = max - min;
- }
- }
-
- public GraduatedColor(GraduatedColor oldcs)
- {
- lr = oldcs.lr;
- lg = oldcs.lg;
- lb = oldcs.lb;
- dr = oldcs.dr;
- dg = oldcs.dg;
- db = oldcs.db;
- base = oldcs.base;
- range = oldcs.range;
- tolow = oldcs.tolow;
- thresholdState = oldcs.thresholdState;
- thrsh = oldcs.thrsh;
- autoScale = oldcs.autoScale;
- colourByLabel = oldcs.colourByLabel;
- }
-
- /**
- * make a new gradient from an old one with a different scale range
- *
- * @param oldcs
- * @param min
- * @param max
- */
- public GraduatedColor(GraduatedColor oldcs, float min, float max)
- {
- this(oldcs);
- updateBounds(min, max);
- }
-
- public GraduatedColor(FeatureColourI col)
- {
- setColourByLabel(col.isColourByLabel());
- }
-
- public Color getMinColor()
- {
- return new Color(lr, lg, lb);
- }
-
- public Color getMaxColor()
- {
- return new Color(lr + dr, lg + dg, lb + db);
- }
-
- /**
- *
- * @return true if original min/max scale was from high to low
- */
- public boolean getTolow()
- {
- return tolow;
- }
-
- public void setTolow(boolean tolower)
- {
- tolow = tolower;
- }
-
- public boolean isColored(SequenceFeature feature)
- {
- float val = feature.getScore();
- if (Float.isNaN(val))
- {
- return true;
- }
- if (this.thresholdState == AnnotationColourGradient.NO_THRESHOLD)
- {
- return true;
- }
- if (Float.isNaN(this.thrsh))
- {
- return true;
- }
- boolean rtn = thresholdState == AnnotationColourGradient.ABOVE_THRESHOLD;
- if (val <= thrsh)
- {
- return !rtn; // ? !tolow : tolow;
- }
- else
- {
- return rtn; // ? tolow : !tolow;
- }
- }
-
- /**
- * default implementor of a getColourFromString method. TODO: abstract an
- * interface enabling pluggable colour from string
- */
- private UserColourScheme ucs = null;
-
- private boolean colourByLabel = false;
-
- /**
- *
- * @return true if colourByLabel style is set
- */
- public boolean isColourByLabel()
- {
- return colourByLabel;
- }
-
- /**
- * @param colourByLabel
- * the colourByLabel to set
- */
- public void setColourByLabel(boolean colourByLabel)
- {
- this.colourByLabel = colourByLabel;
- }
-
- public Color findColor(SequenceFeature feature)
- {
- if (colourByLabel)
- {
- // TODO: allow user defined feature label colourschemes. Colour space is
- // {type,regex,%anytype%}x{description string, regex, keyword}
- if (ucs == null)
- {
- ucs = new UserColourScheme();
- }
- return ucs.createColourFromName(feature.getDescription());
- }
- if (range == 0.0)
- {
- return getMaxColor();
- }
- float scr = feature.getScore();
- if (Float.isNaN(scr))
- {
- return getMinColor();
- }
- float scl = (scr - base) / range;
- if (tolow)
- {
- scl = -scl;
- }
- if (scl < 0f)
- {
- scl = 0f;
- }
- if (scl > 1f)
- {
- scl = 1f;
- }
- return new Color(lr + scl * dr, lg + scl * dg, lb + scl * db);
- }
-
- public void setThresh(float value)
- {
- thrsh = value;
- }
-
- public float getThresh()
- {
- return thrsh;
- }
-
- public void setThreshType(int aboveThreshold)
- {
- thresholdState = aboveThreshold;
- }
-
- public int getThreshType()
- {
- return thresholdState;
- }
-
- public float getMax()
- {
- // regenerate the original values passed in to the constructor
- return (tolow) ? base : (base + range);
- }
-
- public float getMin()
- {
- // regenerate the original value passed in to the constructor
- return (tolow) ? (base + range) : base;
- }
-
- public boolean isAutoScale()
- {
- return autoScale;
- }
-
- public void setAutoScaled(boolean autoscale)
- {
- autoScale = autoscale;
- }
-
- /**
- * update the base and range appropriatly for the given minmax range
- *
- * @param a
- * float[] {min,max} array containing minmax range for the associated
- * score values
- */
- public void updateBounds(float min, float max)
- {
- if (max < min)
- {
- base = max;
- range = min - max;
- tolow = true;
- }
- else
- {
- base = min;
- range = max - min;
- tolow = false;
- }
- }
-}
diff --git a/src/jalview/schemes/PIDColourScheme.java b/src/jalview/schemes/PIDColourScheme.java
index 9dd763d..ccc69c2 100755
--- a/src/jalview/schemes/PIDColourScheme.java
+++ b/src/jalview/schemes/PIDColourScheme.java
@@ -20,9 +20,9 @@
*/
package jalview.schemes;
-import jalview.analysis.AAFrequency;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
import java.awt.Color;
@@ -67,20 +67,22 @@ public class PIDColourScheme extends ResidueColourScheme
return Color.white;
}
- if ((Integer
- .parseInt(consensus[j].get(AAFrequency.MAXCOUNT).toString()) != -1)
- && consensus[j].contains(String.valueOf(c)))
+ /*
+ * test whether this is the consensus (or joint consensus) residue
+ */
+ boolean matchesConsensus = consensus[j].getModalResidue().contains(
+ String.valueOf(c));
+ if (matchesConsensus)
{
- sc = ((Float) consensus[j].get(ignoreGaps)).floatValue();
+ sc = consensus[j].getPercentageIdentity(ignoreGaps);
- if (!jalview.util.Comparison.isGap(c))
+ if (!Comparison.isGap(c))
{
for (int i = 0; i < thresholds.length; i++)
{
if (sc > thresholds[i])
{
currentColour = pidColours[i];
-
break;
}
}
diff --git a/src/jalview/schemes/RNAHelicesColour.java b/src/jalview/schemes/RNAHelicesColour.java
index d17f510..9729a83 100644
--- a/src/jalview/schemes/RNAHelicesColour.java
+++ b/src/jalview/schemes/RNAHelicesColour.java
@@ -91,6 +91,10 @@ public class RNAHelicesColour extends ResidueColourScheme
// This loop will find the first rna structure annotation by which to colour
// the sequences.
AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation();
+ if (annotations == null)
+ {
+ return;
+ }
for (int i = 0; i < annotations.length; i++)
{
diff --git a/src/jalview/schemes/RNAHelicesColourChooser.java b/src/jalview/schemes/RNAHelicesColourChooser.java
index 1a13bbe..b1b3c5a 100644
--- a/src/jalview/schemes/RNAHelicesColourChooser.java
+++ b/src/jalview/schemes/RNAHelicesColourChooser.java
@@ -22,6 +22,7 @@ package jalview.schemes;
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
+import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.SequenceGroup;
import java.awt.event.ActionEvent;
@@ -77,16 +78,20 @@ public class RNAHelicesColourChooser
adjusting = true;
Vector list = new Vector();
int index = 1;
- for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
+ AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
+ if (anns != null)
{
- String label = av.getAlignment().getAlignmentAnnotation()[i].label;
- if (!list.contains(label))
+ for (int i = 0; i < anns.length; i++)
{
- list.addElement(label);
- }
- else
- {
- list.addElement(label + "_" + (index++));
+ String label = anns[i].label;
+ if (!list.contains(label))
+ {
+ list.addElement(label);
+ }
+ else
+ {
+ list.addElement(label + "_" + (index++));
+ }
}
}
diff --git a/src/jalview/schemes/ResidueColourScheme.java b/src/jalview/schemes/ResidueColourScheme.java
index bca98cf..a15ca20 100755
--- a/src/jalview/schemes/ResidueColourScheme.java
+++ b/src/jalview/schemes/ResidueColourScheme.java
@@ -20,15 +20,16 @@
*/
package jalview.schemes;
-import jalview.analysis.AAFrequency;
import jalview.analysis.Conservation;
+import jalview.analysis.Profile;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
+import jalview.util.Comparison;
import jalview.util.MessageManager;
import java.awt.Color;
-import java.util.Hashtable;
import java.util.Map;
/**
@@ -48,17 +49,21 @@ public class ResidueColourScheme implements ColourSchemeI
int threshold = 0;
/* Set when threshold colouring to either pid_gaps or pid_nogaps */
- protected String ignoreGaps = AAFrequency.PID_GAPS;
+ protected boolean ignoreGaps = false;
- /** Consenus as a hashtable array */
- Hashtable[] consensus;
+ /*
+ * Consensus data indexed by column
+ */
+ Profile[] consensus;
- /** Conservation string as a char array */
+ /*
+ * Conservation string as a char array
+ */
char[] conservation;
- int conservationLength = 0;
-
- /** DOCUMENT ME!! */
+ /*
+ * The conservation slider percentage setting
+ */
int inc = 30;
/**
@@ -100,6 +105,7 @@ public class ResidueColourScheme implements ColourSchemeI
/**
* Find a colour without an index in a sequence
*/
+ @Override
public Color findColour(char c)
{
return colors == null ? Color.white : colors[symbolIndex[c]];
@@ -133,58 +139,62 @@ public class ResidueColourScheme implements ColourSchemeI
*
* @return Returns the percentage threshold
*/
+ @Override
public int getThreshold()
{
return threshold;
}
/**
- * DOCUMENT ME!
+ * Sets the percentage consensus threshold value, and whether gaps are ignored
+ * in percentage identity calculation
*
- * @param ct
- * DOCUMENT ME!
+ * @param consensusThreshold
+ * @param ignoreGaps
*/
- public void setThreshold(int ct, boolean ignoreGaps)
+ @Override
+ public void setThreshold(int consensusThreshold, boolean ignoreGaps)
{
- threshold = ct;
- if (ignoreGaps)
- {
- this.ignoreGaps = AAFrequency.PID_NOGAPS;
- }
- else
- {
- this.ignoreGaps = AAFrequency.PID_GAPS;
- }
+ threshold = consensusThreshold;
+ this.ignoreGaps = ignoreGaps;
}
/**
- * DOCUMENT ME!
+ * Answers true if there is a consensus profile for the specified column, and
+ * the given residue matches the consensus (or joint consensus) residue for
+ * the column, and the percentage identity for the profile is equal to or
+ * greater than the current threshold; else answers false. The percentage
+ * calculation depends on whether or not we are ignoring gapped sequences.
*
- * @param s
- * DOCUMENT ME!
- * @param j
- * DOCUMENT ME!
+ * @param residue
+ * @param column
+ * (index into consensus profiles)
*
- * @return DOCUMENT ME!
+ * @return
+ * @see #setThreshold(int, boolean)
*/
- public boolean aboveThreshold(char c, int j)
+ public boolean aboveThreshold(char residue, int column)
{
- if ('a' <= c && c <= 'z')
+ if ('a' <= residue && residue <= 'z')
{
// TO UPPERCASE !!!
// Faster than toUpperCase
- c -= ('a' - 'A');
+ residue -= ('a' - 'A');
}
- if (consensus == null || consensus.length < j || consensus[j] == null)
+ if (consensus == null || consensus.length < column
+ || consensus[column] == null)
{
return false;
}
- if ((((Integer) consensus[j].get(AAFrequency.MAXCOUNT)).intValue() != -1)
- && consensus[j].contains(String.valueOf(c)))
+ /*
+ * test whether this is the consensus (or joint consensus) residue
+ */
+ if (consensus[column].getModalResidue().contains(
+ String.valueOf(residue)))
{
- if (((Float) consensus[j].get(ignoreGaps)).floatValue() >= threshold)
+ if (consensus[column].getPercentageIdentity(ignoreGaps) >= threshold)
{
return true;
}
@@ -193,6 +203,7 @@ public class ResidueColourScheme implements ColourSchemeI
return false;
}
+ @Override
public boolean conservationApplied()
{
return conservationColouring;
@@ -204,11 +215,13 @@ public class ResidueColourScheme implements ColourSchemeI
conservationColouring = conservationApplied;
}
+ @Override
public void setConservationInc(int i)
{
inc = i;
}
+ @Override
public int getConservationInc()
{
return inc;
@@ -220,7 +233,8 @@ public class ResidueColourScheme implements ColourSchemeI
* @param consensus
* DOCUMENT ME!
*/
- public void setConsensus(Hashtable[] consensus)
+ @Override
+ public void setConsensus(Profile[] consensus)
{
if (consensus == null)
{
@@ -230,6 +244,7 @@ public class ResidueColourScheme implements ColourSchemeI
this.consensus = consensus;
}
+ @Override
public void setConservation(Conservation cons)
{
if (cons == null)
@@ -240,73 +255,70 @@ public class ResidueColourScheme implements ColourSchemeI
else
{
conservationColouring = true;
- int i, iSize = cons.getConsSequence().getLength();
+ int iSize = cons.getConsSequence().getLength();
conservation = new char[iSize];
- for (i = 0; i < iSize; i++)
+ for (int i = 0; i < iSize; i++)
{
conservation[i] = cons.getConsSequence().getCharAt(i);
}
- conservationLength = conservation.length;
}
}
/**
- * DOCUMENT ME!
+ * Applies a combination of column conservation score, and conservation
+ * percentage slider, to 'bleach' out the residue colours towards white.
+ *
+ * If a column is fully conserved (identical residues, conservation score 11,
+ * shown as *), or all 10 physico-chemical properties are conserved
+ * (conservation score 10, shown as +), then the colour is left unchanged.
+ *
+ * Otherwise a 'bleaching' factor is computed and applied to the colour. This
+ * is designed to fade colours for scores of 0-9 completely to white at slider
+ * positions ranging from 18% - 100% respectively.
*
- * @param s
- * DOCUMENT ME!
- * @param i
- * DOCUMENT ME!
+ * @param currentColour
+ * @param column
*
- * @return DOCUMENT ME!
+ * @return bleached (or unmodified) colour
*/
-
- Color applyConservation(Color currentColour, int i)
+ Color applyConservation(Color currentColour, int column)
{
+ if (conservation == null || conservation.length <= column)
+ {
+ return currentColour;
+ }
+ char conservationScore = conservation[column];
+
+ /*
+ * if residues are fully conserved (* or 11), or all properties
+ * are conserved (+ or 10), leave colour unchanged
+ */
+ if (conservationScore == '*' || conservationScore == '+'
+ || conservationScore == (char) 10
+ || conservationScore == (char) 11)
+ {
+ return currentColour;
+ }
- if ((conservationLength > i) && (conservation[i] != '*')
- && (conservation[i] != '+'))
+ if (Comparison.isGap(conservationScore))
{
- if (jalview.util.Comparison.isGap(conservation[i]))
- {
- currentColour = Color.white;
- }
- else
- {
- float t = 11 - (conservation[i] - '0');
- if (t == 0)
- {
- return Color.white;
- }
-
- int red = currentColour.getRed();
- int green = currentColour.getGreen();
- int blue = currentColour.getBlue();
-
- int dr = 255 - red;
- int dg = 255 - green;
- int db = 255 - blue;
-
- dr *= t / 10f;
- dg *= t / 10f;
- db *= t / 10f;
-
- red += (inc / 20f) * dr;
- green += (inc / 20f) * dg;
- blue += (inc / 20f) * db;
-
- if (red > 255 || green > 255 || blue > 255)
- {
- currentColour = Color.white;
- }
- else
- {
- currentColour = new Color(red, green, blue);
- }
- }
+ return Color.white;
}
- return currentColour;
+
+ /*
+ * convert score 0-9 to a bleaching factor 1.1 - 0.2
+ */
+ float bleachFactor = (11 - (conservationScore - '0')) / 10f;
+
+ /*
+ * scale this up by 0-5 (percentage slider / 20)
+ * as a result, scores of: 0 1 2 3 4 5 6 7 8 9
+ * fade to white at slider value: 18 20 22 25 29 33 40 50 67 100%
+ */
+ bleachFactor *= (inc / 20f);
+
+ return ColorUtils.bleachColour(currentColour, bleachFactor);
}
@Override
diff --git a/src/jalview/schemes/ResidueProperties.java b/src/jalview/schemes/ResidueProperties.java
index 2aa24a1..90a7952 100755
--- a/src/jalview/schemes/ResidueProperties.java
+++ b/src/jalview/schemes/ResidueProperties.java
@@ -26,6 +26,7 @@ import jalview.api.analysis.ScoreModelI;
import java.awt.Color;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
@@ -223,36 +224,36 @@ public class ResidueProperties
static
{
- aa3Hash.put("ALA", new Integer(0));
- aa3Hash.put("ARG", new Integer(1));
- aa3Hash.put("ASN", new Integer(2));
- aa3Hash.put("ASP", new Integer(3)); // D
- aa3Hash.put("CYS", new Integer(4));
- aa3Hash.put("GLN", new Integer(5)); // Q
- aa3Hash.put("GLU", new Integer(6)); // E
- aa3Hash.put("GLY", new Integer(7));
- aa3Hash.put("HIS", new Integer(8));
- aa3Hash.put("ILE", new Integer(9));
- aa3Hash.put("LEU", new Integer(10));
- aa3Hash.put("LYS", new Integer(11));
- aa3Hash.put("MET", new Integer(12));
- aa3Hash.put("PHE", new Integer(13));
- aa3Hash.put("PRO", new Integer(14));
- aa3Hash.put("SER", new Integer(15));
- aa3Hash.put("THR", new Integer(16));
- aa3Hash.put("TRP", new Integer(17));
- aa3Hash.put("TYR", new Integer(18));
- aa3Hash.put("VAL", new Integer(19));
+ aa3Hash.put("ALA", Integer.valueOf(0));
+ aa3Hash.put("ARG", Integer.valueOf(1));
+ aa3Hash.put("ASN", Integer.valueOf(2));
+ aa3Hash.put("ASP", Integer.valueOf(3)); // D
+ aa3Hash.put("CYS", Integer.valueOf(4));
+ aa3Hash.put("GLN", Integer.valueOf(5)); // Q
+ aa3Hash.put("GLU", Integer.valueOf(6)); // E
+ aa3Hash.put("GLY", Integer.valueOf(7));
+ aa3Hash.put("HIS", Integer.valueOf(8));
+ aa3Hash.put("ILE", Integer.valueOf(9));
+ aa3Hash.put("LEU", Integer.valueOf(10));
+ aa3Hash.put("LYS", Integer.valueOf(11));
+ aa3Hash.put("MET", Integer.valueOf(12));
+ aa3Hash.put("PHE", Integer.valueOf(13));
+ aa3Hash.put("PRO", Integer.valueOf(14));
+ aa3Hash.put("SER", Integer.valueOf(15));
+ aa3Hash.put("THR", Integer.valueOf(16));
+ aa3Hash.put("TRP", Integer.valueOf(17));
+ aa3Hash.put("TYR", Integer.valueOf(18));
+ aa3Hash.put("VAL", Integer.valueOf(19));
// IUB Nomenclature for ambiguous peptides
- aa3Hash.put("ASX", new Integer(20)); // "B";
- aa3Hash.put("GLX", new Integer(21)); // Z
- aa3Hash.put("XAA", new Integer(22)); // X unknown
- aa3Hash.put("-", new Integer(23));
- aa3Hash.put("*", new Integer(23));
- aa3Hash.put(".", new Integer(23));
- aa3Hash.put(" ", new Integer(23));
- aa3Hash.put("Gap", new Integer(23));
- aa3Hash.put("UR3", new Integer(24));
+ aa3Hash.put("ASX", Integer.valueOf(20)); // "B";
+ aa3Hash.put("GLX", Integer.valueOf(21)); // Z
+ aa3Hash.put("XAA", Integer.valueOf(22)); // X unknown
+ aa3Hash.put("-", Integer.valueOf(23));
+ aa3Hash.put("*", Integer.valueOf(23));
+ aa3Hash.put(".", Integer.valueOf(23));
+ aa3Hash.put(" ", Integer.valueOf(23));
+ aa3Hash.put("Gap", Integer.valueOf(23));
+ aa3Hash.put("UR3", Integer.valueOf(24));
}
static
@@ -305,24 +306,24 @@ public class ResidueProperties
public static final Color midBlue = new Color(100, 100, 255);
- public static final Vector scaleColours = new Vector();
-
- static
- {
- scaleColours.addElement(new Color(114, 0, 147));
- scaleColours.addElement(new Color(156, 0, 98));
- scaleColours.addElement(new Color(190, 0, 0));
- scaleColours.addElement(Color.red);
- scaleColours.addElement(new Color(255, 125, 0));
- scaleColours.addElement(Color.orange);
- scaleColours.addElement(new Color(255, 194, 85));
- scaleColours.addElement(Color.yellow);
- scaleColours.addElement(new Color(255, 255, 181));
- scaleColours.addElement(Color.white);
- }
-
- public static final Color[] taylor = { new Color(204, 255, 0), // A
- // Greenish-yellowy-yellow
+ // not currently in use
+ // public static final Vector scaleColours = new Vector();
+ // static
+ // {
+ // scaleColours.addElement(new Color(114, 0, 147));
+ // scaleColours.addElement(new Color(156, 0, 98));
+ // scaleColours.addElement(new Color(190, 0, 0));
+ // scaleColours.addElement(Color.red);
+ // scaleColours.addElement(new Color(255, 125, 0));
+ // scaleColours.addElement(Color.orange);
+ // scaleColours.addElement(new Color(255, 194, 85));
+ // scaleColours.addElement(Color.yellow);
+ // scaleColours.addElement(new Color(255, 255, 181));
+ // scaleColours.addElement(Color.white);
+ // }
+
+ public static final Color[] taylor = { new Color(204, 255, 0),
+ // A Greenish-yellowy-yellow
new Color(0, 0, 255), // R Blueish-bluey-blue
new Color(204, 0, 255), // N Blueish-reddy-blue
new Color(255, 0, 0), // D Reddish-reddy-red
@@ -572,21 +573,21 @@ public class ResidueProperties
{ -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
-8, -8, -8, -8, -8, -8, 1 }, };
- public static final Hashtable ssHash = new Hashtable(); // stores the number
- // value of the aa
-
- static
- {
- ssHash.put("H", Color.magenta);
- ssHash.put("E", Color.yellow);
- ssHash.put("-", Color.white);
- ssHash.put(".", Color.white);
- ssHash.put("S", Color.cyan);
- ssHash.put("T", Color.blue);
- ssHash.put("G", Color.pink);
- ssHash.put("I", Color.pink);
- ssHash.put("B", Color.yellow);
- }
+ // not currently used
+ // public static final Map ssHash = new Hashtable();
+ // static
+ // {
+ // ssHash.put("H", Color.magenta);
+ // ssHash.put("E", Color.yellow);
+ // ssHash.put("-", Color.white);
+ // ssHash.put(".", Color.white);
+ // ssHash.put("S", Color.cyan);
+ // ssHash.put("T", Color.blue);
+ // ssHash.put("G", Color.pink);
+ // ssHash.put("I", Color.pink);
+ // ssHash.put("B", Color.yellow);
+ // }
/*
* new Color(60, 136, 238), // U Color.white, // I Color.white, // X
@@ -618,7 +619,6 @@ public class ResidueProperties
scoreMatrices.put("BLOSUM62", new ScoreMatrix("BLOSUM62", BLOSUM62, 0));
scoreMatrices.put("PAM250", new ScoreMatrix("PAM250", PAM250, 0));
scoreMatrices.put("DNA", new ScoreMatrix("DNA", DNA, 1));
-
}
public static final Color[] pidColours = { midBlue,
@@ -628,77 +628,10 @@ public class ResidueProperties
public static final float[] pidThresholds = { 80, 60, 40, };
- public static Map> codonHash = new HashMap>();
-
- private static List Lys = new ArrayList();
-
- private static List Asn = new ArrayList();
-
- private static List Gln = new ArrayList();
-
- private static List His = new ArrayList();
-
- private static List Glu = new ArrayList();
-
- private static List Asp = new ArrayList();
-
- private static List Tyr = new ArrayList();
-
- private static List Thr = new ArrayList();
-
- private static List Pro = new ArrayList();
-
- private static List Ala = new ArrayList();
-
- private static List Ser = new ArrayList();
-
- private static List Arg = new ArrayList();
-
- private static List Gly = new ArrayList();
-
- private static List Trp = new ArrayList();
-
- private static List Cys = new ArrayList();
-
- private static List Ile = new ArrayList();
-
- private static List Met = new ArrayList();
-
- private static List Leu = new ArrayList();
-
- private static List Val = new ArrayList();
-
- private static List Phe = new ArrayList();
-
- public static List STOP = new ArrayList();
+ public static List STOP = Arrays.asList("TGA", "TAA", "TAG");
public static String START = "ATG";
- static
- {
- codonHash.put("K", Lys);
- codonHash.put("N", Asn);
- codonHash.put("Q", Gln);
- codonHash.put("H", His);
- codonHash.put("E", Glu);
- codonHash.put("D", Asp);
- codonHash.put("Y", Tyr);
- codonHash.put("T", Thr);
- codonHash.put("P", Pro);
- codonHash.put("A", Ala);
- codonHash.put("S", Ser);
- codonHash.put("R", Arg);
- codonHash.put("G", Gly);
- codonHash.put("W", Trp);
- codonHash.put("C", Cys);
- codonHash.put("I", Ile);
- codonHash.put("M", Met);
- codonHash.put("L", Leu);
- codonHash.put("V", Val);
- codonHash.put("F", Phe);
- codonHash.put("STOP", STOP);
- }
-
/**
* Nucleotide Ambiguity Codes
*/
@@ -885,7 +818,6 @@ public class ResidueProperties
// make all codons for this combination
char allres[][] = new char[tpos.length][];
String _acodon = "";
- char _anuc;
for (ipos = 0; ipos < tpos.length; ipos++)
{
if (acodon[ipos].length == 0 || tpos[ipos] < 0)
@@ -951,379 +883,294 @@ public class ResidueProperties
}
}
}
-
- }
-
- static
- {
- Lys.add("AAA");
- Lys.add("AAG");
- Asn.add("AAC");
- Asn.add("AAT");
-
- Gln.add("CAA");
- Gln.add("CAG");
- His.add("CAC");
- His.add("CAT");
-
- Glu.add("GAA");
- Glu.add("GAG");
- Asp.add("GAC");
- Asp.add("GAT");
-
- Tyr.add("TAC");
- Tyr.add("TAT");
-
- Thr.add("ACA");
- Thr.add("ACG");
- Thr.add("ACC");
- Thr.add("ACT");
-
- Pro.add("CCA");
- Pro.add("CCG");
- Pro.add("CCC");
- Pro.add("CCT");
-
- Ala.add("GCA");
- Ala.add("GCG");
- Ala.add("GCC");
- Ala.add("GCT");
-
- Ser.add("TCA");
- Ser.add("TCG");
- Ser.add("TCC");
- Ser.add("TCT");
- Ser.add("AGC");
- Ser.add("AGT");
-
- Arg.add("AGA");
- Arg.add("AGG");
- Arg.add("CGA");
- Arg.add("CGG");
- Arg.add("CGC");
- Arg.add("CGT");
-
- Gly.add("GGA");
- Gly.add("GGG");
- Gly.add("GGC");
- Gly.add("GGT");
-
- STOP.add("TGA");
- STOP.add("TAA");
- STOP.add("TAG");
-
- Trp.add("TGG");
-
- Cys.add("TGC");
- Cys.add("TGT");
-
- Ile.add("ATA");
- Ile.add("ATC");
- Ile.add("ATT");
-
- Met.add("ATG");
-
- Leu.add("CTA");
- Leu.add("CTG");
- Leu.add("CTC");
- Leu.add("CTT");
- Leu.add("TTA");
- Leu.add("TTG");
-
- Val.add("GTA");
- Val.add("GTG");
- Val.add("GTC");
- Val.add("GTT");
-
- Phe.add("TTC");
- Phe.add("TTT");
}
// Stores residue codes/names and colours and other things
- public static Hashtable propHash = new Hashtable();
+ public static Map> propHash = new Hashtable>();
- public static Hashtable hydrophobic = new Hashtable();
+ public static Map hydrophobic = new Hashtable();
- public static Hashtable polar = new Hashtable();
+ public static Map polar = new Hashtable();
- public static Hashtable small = new Hashtable();
+ public static Map small = new Hashtable();
- public static Hashtable positive = new Hashtable();
+ public static Map positive = new Hashtable();
- public static Hashtable negative = new Hashtable();
+ public static Map negative = new Hashtable();
- public static Hashtable charged = new Hashtable();
+ public static Map charged = new Hashtable();
- public static Hashtable aromatic = new Hashtable();
+ public static Map aromatic = new Hashtable();
- public static Hashtable aliphatic = new Hashtable();
+ public static Map aliphatic = new Hashtable();
- public static Hashtable tiny = new Hashtable();
+ public static Map tiny = new Hashtable();
- public static Hashtable proline = new Hashtable();
+ public static Map proline = new Hashtable();
static
{
- hydrophobic.put("I", new Integer(1));
- hydrophobic.put("L", new Integer(1));
- hydrophobic.put("V", new Integer(1));
- hydrophobic.put("C", new Integer(1));
- hydrophobic.put("A", new Integer(1));
- hydrophobic.put("G", new Integer(1));
- hydrophobic.put("M", new Integer(1));
- hydrophobic.put("F", new Integer(1));
- hydrophobic.put("Y", new Integer(1));
- hydrophobic.put("W", new Integer(1));
- hydrophobic.put("H", new Integer(1));
- hydrophobic.put("K", new Integer(1));
- hydrophobic.put("X", new Integer(1));
- hydrophobic.put("-", new Integer(1));
- hydrophobic.put("*", new Integer(1));
- hydrophobic.put("R", new Integer(0));
- hydrophobic.put("E", new Integer(0));
- hydrophobic.put("Q", new Integer(0));
- hydrophobic.put("D", new Integer(0));
- hydrophobic.put("N", new Integer(0));
- hydrophobic.put("S", new Integer(0));
- hydrophobic.put("T", new Integer(0));
- hydrophobic.put("P", new Integer(0));
+ hydrophobic.put("I", Integer.valueOf(1));
+ hydrophobic.put("L", Integer.valueOf(1));
+ hydrophobic.put("V", Integer.valueOf(1));
+ hydrophobic.put("C", Integer.valueOf(1));
+ hydrophobic.put("A", Integer.valueOf(1));
+ hydrophobic.put("G", Integer.valueOf(1));
+ hydrophobic.put("M", Integer.valueOf(1));
+ hydrophobic.put("F", Integer.valueOf(1));
+ hydrophobic.put("Y", Integer.valueOf(1));
+ hydrophobic.put("W", Integer.valueOf(1));
+ hydrophobic.put("H", Integer.valueOf(1));
+ hydrophobic.put("K", Integer.valueOf(1));
+ hydrophobic.put("X", Integer.valueOf(1));
+ hydrophobic.put("-", Integer.valueOf(1));
+ hydrophobic.put("*", Integer.valueOf(1));
+ hydrophobic.put("R", Integer.valueOf(0));
+ hydrophobic.put("E", Integer.valueOf(0));
+ hydrophobic.put("Q", Integer.valueOf(0));
+ hydrophobic.put("D", Integer.valueOf(0));
+ hydrophobic.put("N", Integer.valueOf(0));
+ hydrophobic.put("S", Integer.valueOf(0));
+ hydrophobic.put("T", Integer.valueOf(0));
+ hydrophobic.put("P", Integer.valueOf(0));
}
static
{
- polar.put("Y", new Integer(1));
- polar.put("W", new Integer(1));
- polar.put("H", new Integer(1));
- polar.put("K", new Integer(1));
- polar.put("R", new Integer(1));
- polar.put("E", new Integer(1));
- polar.put("Q", new Integer(1));
- polar.put("D", new Integer(1));
- polar.put("N", new Integer(1));
- polar.put("S", new Integer(1));
- polar.put("T", new Integer(1));
- polar.put("X", new Integer(1));
- polar.put("-", new Integer(1));
- polar.put("*", new Integer(1));
- polar.put("I", new Integer(0));
- polar.put("L", new Integer(0));
- polar.put("V", new Integer(0));
- polar.put("C", new Integer(0));
- polar.put("A", new Integer(0));
- polar.put("G", new Integer(0));
- polar.put("M", new Integer(0));
- polar.put("F", new Integer(0));
- polar.put("P", new Integer(0));
+ polar.put("Y", Integer.valueOf(1));
+ polar.put("W", Integer.valueOf(1));
+ polar.put("H", Integer.valueOf(1));
+ polar.put("K", Integer.valueOf(1));
+ polar.put("R", Integer.valueOf(1));
+ polar.put("E", Integer.valueOf(1));
+ polar.put("Q", Integer.valueOf(1));
+ polar.put("D", Integer.valueOf(1));
+ polar.put("N", Integer.valueOf(1));
+ polar.put("S", Integer.valueOf(1));
+ polar.put("T", Integer.valueOf(1));
+ polar.put("X", Integer.valueOf(1));
+ polar.put("-", Integer.valueOf(1));
+ polar.put("*", Integer.valueOf(1));
+ polar.put("I", Integer.valueOf(0));
+ polar.put("L", Integer.valueOf(0));
+ polar.put("V", Integer.valueOf(0));
+ polar.put("C", Integer.valueOf(0));
+ polar.put("A", Integer.valueOf(0));
+ polar.put("G", Integer.valueOf(0));
+ polar.put("M", Integer.valueOf(0));
+ polar.put("F", Integer.valueOf(0));
+ polar.put("P", Integer.valueOf(0));
}
static
{
- small.put("I", new Integer(0));
- small.put("L", new Integer(0));
- small.put("V", new Integer(1));
- small.put("C", new Integer(1));
- small.put("A", new Integer(1));
- small.put("G", new Integer(1));
- small.put("M", new Integer(0));
- small.put("F", new Integer(0));
- small.put("Y", new Integer(0));
- small.put("W", new Integer(0));
- small.put("H", new Integer(0));
- small.put("K", new Integer(0));
- small.put("R", new Integer(0));
- small.put("E", new Integer(0));
- small.put("Q", new Integer(0));
- small.put("D", new Integer(1));
- small.put("N", new Integer(1));
- small.put("S", new Integer(1));
- small.put("T", new Integer(1));
- small.put("P", new Integer(1));
- small.put("-", new Integer(1));
- small.put("*", new Integer(1));
+ small.put("I", Integer.valueOf(0));
+ small.put("L", Integer.valueOf(0));
+ small.put("V", Integer.valueOf(1));
+ small.put("C", Integer.valueOf(1));
+ small.put("A", Integer.valueOf(1));
+ small.put("G", Integer.valueOf(1));
+ small.put("M", Integer.valueOf(0));
+ small.put("F", Integer.valueOf(0));
+ small.put("Y", Integer.valueOf(0));
+ small.put("W", Integer.valueOf(0));
+ small.put("H", Integer.valueOf(0));
+ small.put("K", Integer.valueOf(0));
+ small.put("R", Integer.valueOf(0));
+ small.put("E", Integer.valueOf(0));
+ small.put("Q", Integer.valueOf(0));
+ small.put("D", Integer.valueOf(1));
+ small.put("N", Integer.valueOf(1));
+ small.put("S", Integer.valueOf(1));
+ small.put("T", Integer.valueOf(1));
+ small.put("P", Integer.valueOf(1));
+ small.put("-", Integer.valueOf(1));
+ small.put("*", Integer.valueOf(1));
}
static
{
- positive.put("I", new Integer(0));
- positive.put("L", new Integer(0));
- positive.put("V", new Integer(0));
- positive.put("C", new Integer(0));
- positive.put("A", new Integer(0));
- positive.put("G", new Integer(0));
- positive.put("M", new Integer(0));
- positive.put("F", new Integer(0));
- positive.put("Y", new Integer(0));
- positive.put("W", new Integer(0));
- positive.put("H", new Integer(1));
- positive.put("K", new Integer(1));
- positive.put("R", new Integer(1));
- positive.put("E", new Integer(0));
- positive.put("Q", new Integer(0));
- positive.put("D", new Integer(0));
- positive.put("N", new Integer(0));
- positive.put("S", new Integer(0));
- positive.put("T", new Integer(0));
- positive.put("P", new Integer(0));
- positive.put("-", new Integer(1));
- positive.put("*", new Integer(1));
+ positive.put("I", Integer.valueOf(0));
+ positive.put("L", Integer.valueOf(0));
+ positive.put("V", Integer.valueOf(0));
+ positive.put("C", Integer.valueOf(0));
+ positive.put("A", Integer.valueOf(0));
+ positive.put("G", Integer.valueOf(0));
+ positive.put("M", Integer.valueOf(0));
+ positive.put("F", Integer.valueOf(0));
+ positive.put("Y", Integer.valueOf(0));
+ positive.put("W", Integer.valueOf(0));
+ positive.put("H", Integer.valueOf(1));
+ positive.put("K", Integer.valueOf(1));
+ positive.put("R", Integer.valueOf(1));
+ positive.put("E", Integer.valueOf(0));
+ positive.put("Q", Integer.valueOf(0));
+ positive.put("D", Integer.valueOf(0));
+ positive.put("N", Integer.valueOf(0));
+ positive.put("S", Integer.valueOf(0));
+ positive.put("T", Integer.valueOf(0));
+ positive.put("P", Integer.valueOf(0));
+ positive.put("-", Integer.valueOf(1));
+ positive.put("*", Integer.valueOf(1));
}
static
{
- negative.put("I", new Integer(0));
- negative.put("L", new Integer(0));
- negative.put("V", new Integer(0));
- negative.put("C", new Integer(0));
- negative.put("A", new Integer(0));
- negative.put("G", new Integer(0));
- negative.put("M", new Integer(0));
- negative.put("F", new Integer(0));
- negative.put("Y", new Integer(0));
- negative.put("W", new Integer(0));
- negative.put("H", new Integer(0));
- negative.put("K", new Integer(0));
- negative.put("R", new Integer(0));
- negative.put("E", new Integer(1));
- negative.put("Q", new Integer(0));
- negative.put("D", new Integer(1));
- negative.put("N", new Integer(0));
- negative.put("S", new Integer(0));
- negative.put("T", new Integer(0));
- negative.put("P", new Integer(0));
- negative.put("-", new Integer(1));
- negative.put("*", new Integer(1));
+ negative.put("I", Integer.valueOf(0));
+ negative.put("L", Integer.valueOf(0));
+ negative.put("V", Integer.valueOf(0));
+ negative.put("C", Integer.valueOf(0));
+ negative.put("A", Integer.valueOf(0));
+ negative.put("G", Integer.valueOf(0));
+ negative.put("M", Integer.valueOf(0));
+ negative.put("F", Integer.valueOf(0));
+ negative.put("Y", Integer.valueOf(0));
+ negative.put("W", Integer.valueOf(0));
+ negative.put("H", Integer.valueOf(0));
+ negative.put("K", Integer.valueOf(0));
+ negative.put("R", Integer.valueOf(0));
+ negative.put("E", Integer.valueOf(1));
+ negative.put("Q", Integer.valueOf(0));
+ negative.put("D", Integer.valueOf(1));
+ negative.put("N", Integer.valueOf(0));
+ negative.put("S", Integer.valueOf(0));
+ negative.put("T", Integer.valueOf(0));
+ negative.put("P", Integer.valueOf(0));
+ negative.put("-", Integer.valueOf(1));
+ negative.put("*", Integer.valueOf(1));
}
static
{
- charged.put("I", new Integer(0));
- charged.put("L", new Integer(0));
- charged.put("V", new Integer(0));
- charged.put("C", new Integer(0));
- charged.put("A", new Integer(0));
- charged.put("G", new Integer(0));
- charged.put("M", new Integer(0));
- charged.put("F", new Integer(0));
- charged.put("Y", new Integer(0));
- charged.put("W", new Integer(0));
- charged.put("H", new Integer(1));
- charged.put("K", new Integer(1));
- charged.put("R", new Integer(1));
- charged.put("E", new Integer(1));
- charged.put("Q", new Integer(0));
- charged.put("D", new Integer(1));
- charged.put("N", new Integer(0)); // Asparagine is polar but not charged.
- // Alternative would be charged and
- // negative (in basic form)?
- charged.put("S", new Integer(0));
- charged.put("T", new Integer(0));
- charged.put("P", new Integer(0));
- charged.put("-", new Integer(1));
- charged.put("*", new Integer(1));
+ charged.put("I", Integer.valueOf(0));
+ charged.put("L", Integer.valueOf(0));
+ charged.put("V", Integer.valueOf(0));
+ charged.put("C", Integer.valueOf(0));
+ charged.put("A", Integer.valueOf(0));
+ charged.put("G", Integer.valueOf(0));
+ charged.put("M", Integer.valueOf(0));
+ charged.put("F", Integer.valueOf(0));
+ charged.put("Y", Integer.valueOf(0));
+ charged.put("W", Integer.valueOf(0));
+ charged.put("H", Integer.valueOf(1));
+ charged.put("K", Integer.valueOf(1));
+ charged.put("R", Integer.valueOf(1));
+ charged.put("E", Integer.valueOf(1));
+ charged.put("Q", Integer.valueOf(0));
+ charged.put("D", Integer.valueOf(1));
+ charged.put("N", Integer.valueOf(0)); // Asparagine is polar but not
+ // charged.
+ // Alternative would be charged and
+ // negative (in basic form)?
+ charged.put("S", Integer.valueOf(0));
+ charged.put("T", Integer.valueOf(0));
+ charged.put("P", Integer.valueOf(0));
+ charged.put("-", Integer.valueOf(1));
+ charged.put("*", Integer.valueOf(1));
}
static
{
- aromatic.put("I", new Integer(0));
- aromatic.put("L", new Integer(0));
- aromatic.put("V", new Integer(0));
- aromatic.put("C", new Integer(0));
- aromatic.put("A", new Integer(0));
- aromatic.put("G", new Integer(0));
- aromatic.put("M", new Integer(0));
- aromatic.put("F", new Integer(1));
- aromatic.put("Y", new Integer(1));
- aromatic.put("W", new Integer(1));
- aromatic.put("H", new Integer(1));
- aromatic.put("K", new Integer(0));
- aromatic.put("R", new Integer(0));
- aromatic.put("E", new Integer(0));
- aromatic.put("Q", new Integer(0));
- aromatic.put("D", new Integer(0));
- aromatic.put("N", new Integer(0));
- aromatic.put("S", new Integer(0));
- aromatic.put("T", new Integer(0));
- aromatic.put("P", new Integer(0));
- aromatic.put("-", new Integer(1));
- aromatic.put("*", new Integer(1));
+ aromatic.put("I", Integer.valueOf(0));
+ aromatic.put("L", Integer.valueOf(0));
+ aromatic.put("V", Integer.valueOf(0));
+ aromatic.put("C", Integer.valueOf(0));
+ aromatic.put("A", Integer.valueOf(0));
+ aromatic.put("G", Integer.valueOf(0));
+ aromatic.put("M", Integer.valueOf(0));
+ aromatic.put("F", Integer.valueOf(1));
+ aromatic.put("Y", Integer.valueOf(1));
+ aromatic.put("W", Integer.valueOf(1));
+ aromatic.put("H", Integer.valueOf(1));
+ aromatic.put("K", Integer.valueOf(0));
+ aromatic.put("R", Integer.valueOf(0));
+ aromatic.put("E", Integer.valueOf(0));
+ aromatic.put("Q", Integer.valueOf(0));
+ aromatic.put("D", Integer.valueOf(0));
+ aromatic.put("N", Integer.valueOf(0));
+ aromatic.put("S", Integer.valueOf(0));
+ aromatic.put("T", Integer.valueOf(0));
+ aromatic.put("P", Integer.valueOf(0));
+ aromatic.put("-", Integer.valueOf(1));
+ aromatic.put("*", Integer.valueOf(1));
}
static
{
- aliphatic.put("I", new Integer(1));
- aliphatic.put("L", new Integer(1));
- aliphatic.put("V", new Integer(1));
- aliphatic.put("C", new Integer(0));
- aliphatic.put("A", new Integer(0));
- aliphatic.put("G", new Integer(0));
- aliphatic.put("M", new Integer(0));
- aliphatic.put("F", new Integer(0));
- aliphatic.put("Y", new Integer(0));
- aliphatic.put("W", new Integer(0));
- aliphatic.put("H", new Integer(0));
- aliphatic.put("K", new Integer(0));
- aliphatic.put("R", new Integer(0));
- aliphatic.put("E", new Integer(0));
- aliphatic.put("Q", new Integer(0));
- aliphatic.put("D", new Integer(0));
- aliphatic.put("N", new Integer(0));
- aliphatic.put("S", new Integer(0));
- aliphatic.put("T", new Integer(0));
- aliphatic.put("P", new Integer(0));
- aliphatic.put("-", new Integer(1));
- aliphatic.put("*", new Integer(1));
+ aliphatic.put("I", Integer.valueOf(1));
+ aliphatic.put("L", Integer.valueOf(1));
+ aliphatic.put("V", Integer.valueOf(1));
+ aliphatic.put("C", Integer.valueOf(0));
+ aliphatic.put("A", Integer.valueOf(0));
+ aliphatic.put("G", Integer.valueOf(0));
+ aliphatic.put("M", Integer.valueOf(0));
+ aliphatic.put("F", Integer.valueOf(0));
+ aliphatic.put("Y", Integer.valueOf(0));
+ aliphatic.put("W", Integer.valueOf(0));
+ aliphatic.put("H", Integer.valueOf(0));
+ aliphatic.put("K", Integer.valueOf(0));
+ aliphatic.put("R", Integer.valueOf(0));
+ aliphatic.put("E", Integer.valueOf(0));
+ aliphatic.put("Q", Integer.valueOf(0));
+ aliphatic.put("D", Integer.valueOf(0));
+ aliphatic.put("N", Integer.valueOf(0));
+ aliphatic.put("S", Integer.valueOf(0));
+ aliphatic.put("T", Integer.valueOf(0));
+ aliphatic.put("P", Integer.valueOf(0));
+ aliphatic.put("-", Integer.valueOf(1));
+ aliphatic.put("*", Integer.valueOf(1));
}
static
{
- tiny.put("I", new Integer(0));
- tiny.put("L", new Integer(0));
- tiny.put("V", new Integer(0));
- tiny.put("C", new Integer(0));
- tiny.put("A", new Integer(1));
- tiny.put("G", new Integer(1));
- tiny.put("M", new Integer(0));
- tiny.put("F", new Integer(0));
- tiny.put("Y", new Integer(0));
- tiny.put("W", new Integer(0));
- tiny.put("H", new Integer(0));
- tiny.put("K", new Integer(0));
- tiny.put("R", new Integer(0));
- tiny.put("E", new Integer(0));
- tiny.put("Q", new Integer(0));
- tiny.put("D", new Integer(0));
- tiny.put("N", new Integer(0));
- tiny.put("S", new Integer(1));
- tiny.put("T", new Integer(0));
- tiny.put("P", new Integer(0));
- tiny.put("-", new Integer(1));
- tiny.put("*", new Integer(1));
+ tiny.put("I", Integer.valueOf(0));
+ tiny.put("L", Integer.valueOf(0));
+ tiny.put("V", Integer.valueOf(0));
+ tiny.put("C", Integer.valueOf(0));
+ tiny.put("A", Integer.valueOf(1));
+ tiny.put("G", Integer.valueOf(1));
+ tiny.put("M", Integer.valueOf(0));
+ tiny.put("F", Integer.valueOf(0));
+ tiny.put("Y", Integer.valueOf(0));
+ tiny.put("W", Integer.valueOf(0));
+ tiny.put("H", Integer.valueOf(0));
+ tiny.put("K", Integer.valueOf(0));
+ tiny.put("R", Integer.valueOf(0));
+ tiny.put("E", Integer.valueOf(0));
+ tiny.put("Q", Integer.valueOf(0));
+ tiny.put("D", Integer.valueOf(0));
+ tiny.put("N", Integer.valueOf(0));
+ tiny.put("S", Integer.valueOf(1));
+ tiny.put("T", Integer.valueOf(0));
+ tiny.put("P", Integer.valueOf(0));
+ tiny.put("-", Integer.valueOf(1));
+ tiny.put("*", Integer.valueOf(1));
}
static
{
- proline.put("I", new Integer(0));
- proline.put("L", new Integer(0));
- proline.put("V", new Integer(0));
- proline.put("C", new Integer(0));
- proline.put("A", new Integer(0));
- proline.put("G", new Integer(0));
- proline.put("M", new Integer(0));
- proline.put("F", new Integer(0));
- proline.put("Y", new Integer(0));
- proline.put("W", new Integer(0));
- proline.put("H", new Integer(0));
- proline.put("K", new Integer(0));
- proline.put("R", new Integer(0));
- proline.put("E", new Integer(0));
- proline.put("Q", new Integer(0));
- proline.put("D", new Integer(0));
- proline.put("N", new Integer(0));
- proline.put("S", new Integer(0));
- proline.put("T", new Integer(0));
- proline.put("P", new Integer(1));
- proline.put("-", new Integer(1));
- proline.put("*", new Integer(1));
+ proline.put("I", Integer.valueOf(0));
+ proline.put("L", Integer.valueOf(0));
+ proline.put("V", Integer.valueOf(0));
+ proline.put("C", Integer.valueOf(0));
+ proline.put("A", Integer.valueOf(0));
+ proline.put("G", Integer.valueOf(0));
+ proline.put("M", Integer.valueOf(0));
+ proline.put("F", Integer.valueOf(0));
+ proline.put("Y", Integer.valueOf(0));
+ proline.put("W", Integer.valueOf(0));
+ proline.put("H", Integer.valueOf(0));
+ proline.put("K", Integer.valueOf(0));
+ proline.put("R", Integer.valueOf(0));
+ proline.put("E", Integer.valueOf(0));
+ proline.put("Q", Integer.valueOf(0));
+ proline.put("D", Integer.valueOf(0));
+ proline.put("N", Integer.valueOf(0));
+ proline.put("S", Integer.valueOf(0));
+ proline.put("T", Integer.valueOf(0));
+ proline.put("P", Integer.valueOf(1));
+ proline.put("-", Integer.valueOf(1));
+ proline.put("*", Integer.valueOf(1));
}
static
@@ -1368,11 +1215,9 @@ public class ResidueProperties
propMatrixF[i][j] = 0;
propMatrixPos[i][j] = 0;
propMatrixEpos[i][j] = 0;
- for (Enumeration en = propHash.keys(); en.hasMoreElements();)
+ for (String ph : propHash.keySet())
{
- String ph = en.nextElement();
- Map pph = (Map) propHash
- .get(ph);
+ Map pph = propHash.get(ph);
if (pph.get(ic) != null && pph.get(jc) != null)
{
int icp = pph.get(ic).intValue(), jcp = pph.get(jc).intValue();
@@ -1470,22 +1315,8 @@ public class ResidueProperties
return pog;
}
- public static Vector getCodons(String res)
- {
- if (codonHash.containsKey(res))
- {
- return (Vector) codonHash.get(res);
- }
-
- return null;
- }
-
public static String codonTranslate(String lccodon)
{
- if (false)
- {
- return _codonTranslate(lccodon);
- }
String cdn = codonHash2.get(lccodon.toUpperCase());
if ("*".equals(cdn))
{
@@ -1494,25 +1325,6 @@ public class ResidueProperties
return cdn;
}
- public static String _codonTranslate(String lccodon)
- {
- String codon = lccodon.toUpperCase();
- // all base ambiguity codes yield an 'X' amino acid residue
- if (codon.indexOf('X') > -1 || codon.indexOf('N') > -1)
- {
- return "X";
- }
- for (String key : codonHash.keySet())
- {
- if (codonHash.get(key).contains(codon))
- {
- return key;
- }
- }
-
- return null;
- }
-
public static int[][] getDefaultPeptideMatrix()
{
return ResidueProperties.getBLOSUM62();
@@ -1560,10 +1372,10 @@ public class ResidueProperties
return pog;
}
- public static Hashtable toDssp3State;
+ public static Hashtable toDssp3State;
static
{
- toDssp3State = new Hashtable();
+ toDssp3State = new Hashtable();
toDssp3State.put("H", "H");
toDssp3State.put("E", "E");
toDssp3State.put("C", " ");
@@ -1593,7 +1405,7 @@ public class ResidueProperties
String ssc = ssstring.substring(i, i + 1);
if (toDssp3State.containsKey(ssc))
{
- ss.append((String) toDssp3State.get(ssc));
+ ss.append(toDssp3State.get(ssc));
}
else
{
@@ -1603,87 +1415,6 @@ public class ResidueProperties
return ss.toString();
}
- /**
- * Used by getRNASecStrucState
- *
- */
- public static Hashtable toRNAssState;
-
- public static boolean RNAcloseParen[] = new boolean[255];
- static
- {
- toRNAssState = new Hashtable();
- toRNAssState.put(")", "(");
- toRNAssState.put("(", "(");
- toRNAssState.put("]", "[");
- toRNAssState.put("[", "[");
- toRNAssState.put("{", "{");
- toRNAssState.put("}", "{");
- toRNAssState.put(">", ">");
- toRNAssState.put("<", ">");
- toRNAssState.put("A", "A");
- toRNAssState.put("a", "A");
- toRNAssState.put("B", "B");
- toRNAssState.put("b", "B");
- toRNAssState.put("C", "C");
- toRNAssState.put("c", "C");
- toRNAssState.put("D", "D");
- toRNAssState.put("d", "D");
- toRNAssState.put("E", "E");
- toRNAssState.put("e", "E");
- toRNAssState.put("F", "F");
- toRNAssState.put("f", "F");
- toRNAssState.put("G", "G");
- toRNAssState.put("g", "G");
- toRNAssState.put("H", "H");
- toRNAssState.put("h", "H");
- toRNAssState.put("I", "I");
- toRNAssState.put("i", "I");
- toRNAssState.put("J", "J");
- toRNAssState.put("j", "J");
- toRNAssState.put("K", "K");
- toRNAssState.put("k", "K");
- toRNAssState.put("L", "L");
- toRNAssState.put("l", "L");
- toRNAssState.put("M", "M");
- toRNAssState.put("m", "M");
- toRNAssState.put("N", "N");
- toRNAssState.put("n", "N");
- toRNAssState.put("O", "O");
- toRNAssState.put("o", "O");
- toRNAssState.put("P", "P");
- toRNAssState.put("p", "P");
- toRNAssState.put("Q", "Q");
- toRNAssState.put("q", "Q");
- toRNAssState.put("R", "R");
- toRNAssState.put("r", "R");
- toRNAssState.put("S", "S");
- toRNAssState.put("s", "S");
- toRNAssState.put("T", "T");
- toRNAssState.put("t", "T");
- toRNAssState.put("U", "U");
- toRNAssState.put("u", "U");
- toRNAssState.put("V", "V");
- toRNAssState.put("v", "V");
- toRNAssState.put("W", "W");
- toRNAssState.put("w", "W");
- toRNAssState.put("X", "X");
- toRNAssState.put("x", "X");
- toRNAssState.put("Y", "Y");
- toRNAssState.put("y", "Y");
- toRNAssState.put("Z", "Z");
- toRNAssState.put("z", "Z");
- for (int p = 0; p < RNAcloseParen.length; p++)
- {
- RNAcloseParen[p] = false;
- }
- for (String k : toRNAssState.keySet())
- {
- RNAcloseParen[k.charAt(0)] = k.charAt(0) != toRNAssState.get(k)
- .charAt(0);
- }
- }
-
static
{
modifications.put("MSE", "MET"); // Selenomethionine
@@ -3002,85 +2733,47 @@ public class ResidueProperties
}
- public static String getCanonicalAminoAcid(String aa)
- {
- String canonical = modifications.get(aa);
- return canonical == null ? aa : canonical;
- }
-
- /**
- * translate to RNA secondary structure representation
- *
- * @param ssstring
- * @return ssstring as a RNA-state secondary structure assignment.
- */
- public static String getRNASecStrucState(String ssstring)
- {
- if (ssstring == null)
- {
- return null;
- }
- StringBuffer ss = new StringBuffer();
- for (int i = 0; i < ssstring.length(); i++)
- {
- String ssc = ssstring.substring(i, i + 1);
- if (toRNAssState.containsKey(ssc))
- {
- // valid ss character - so return it
- ss.append(ssc); // (String) toRNAssState.get(ssc));
- }
- else
- {
- ss.append(" ");
- }
- }
- return ss.toString();
- }
-
- public static boolean isCloseParenRNA(char dc)
+ public static String getCanonicalAminoAcid(String aA)
{
- return RNAcloseParen[dc];
+ String canonical = modifications.get(aA);
+ return canonical == null ? aA : canonical;
}
// main method generates perl representation of residue property hash
// / cut here
public static void main(String[] args)
{
- Hashtable aa = new Hashtable();
+ Hashtable> aaProps = new Hashtable>();
System.out.println("my %aa = {");
// invert property hashes
- Enumeration prop = propHash.keys();
- while (prop.hasMoreElements())
+ for (String pname : propHash.keySet())
{
- String pname = (String) prop.nextElement();
- Hashtable phash = (Hashtable) propHash.get(pname);
- Enumeration res = phash.keys();
- while (res.hasMoreElements())
+ Map phash = propHash.get(pname);
+ for (String rname : phash.keySet())
{
- String rname = (String) res.nextElement();
- Vector aprops = (Vector) aa.get(rname);
+ Vector aprops = aaProps.get(rname);
if (aprops == null)
{
- aprops = new Vector();
- aa.put(rname, aprops);
+ aprops = new Vector();
+ aaProps.put(rname, aprops);
}
- Integer hasprop = (Integer) phash.get(rname);
+ Integer hasprop = phash.get(rname);
if (hasprop.intValue() == 1)
{
aprops.addElement(pname);
}
}
}
- Enumeration res = aa.keys();
+ Enumeration res = aaProps.keys();
while (res.hasMoreElements())
{
- String rname = (String) res.nextElement();
+ String rname = res.nextElement();
System.out.print("'" + rname + "' => [");
- Enumeration props = ((Vector) aa.get(rname)).elements();
+ Enumeration props = aaProps.get(rname).elements();
while (props.hasMoreElements())
{
- System.out.print("'" + (String) props.nextElement() + "'");
+ System.out.print("'" + props.nextElement() + "'");
if (props.hasMoreElements())
{
System.out.println(", ");
@@ -3096,15 +2789,15 @@ public class ResidueProperties
/**
* Returns a list of residue characters for the specified inputs
*
- * @param nucleotide
+ * @param forNucleotide
* @param includeAmbiguous
* @return
*/
- public static List getResidues(boolean nucleotide,
+ public static List getResidues(boolean forNucleotide,
boolean includeAmbiguous)
{
List result = new ArrayList();
- if (nucleotide)
+ if (forNucleotide)
{
for (String nuc : nucleotideName.keySet())
{
diff --git a/src/jalview/schemes/TCoffeeColourScheme.java b/src/jalview/schemes/TCoffeeColourScheme.java
index 62f3a2e..2be51c2 100644
--- a/src/jalview/schemes/TCoffeeColourScheme.java
+++ b/src/jalview/schemes/TCoffeeColourScheme.java
@@ -86,6 +86,10 @@ public class TCoffeeColourScheme extends ResidueColourScheme
seqMap = new IdentityHashMap();
AnnotatedCollectionI alcontext = alignment instanceof AlignmentI ? alignment
: alignment.getContext();
+ if (alcontext == null)
+ {
+ return;
+ }
int w = 0;
for (AlignmentAnnotation al : alcontext
.findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE))
diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java
index b1e4d58..9ae14ca 100755
--- a/src/jalview/schemes/UserColourScheme.java
+++ b/src/jalview/schemes/UserColourScheme.java
@@ -101,6 +101,10 @@ public class UserColourScheme extends ResidueColourScheme
public static Color getColourFromString(String colour)
{
+ if (colour == null)
+ {
+ return null;
+ }
colour = colour.trim();
Color col = null;
@@ -136,7 +140,7 @@ public class UserColourScheme extends ResidueColourScheme
}
- public Color createColourFromName(String name)
+ public static Color createColourFromName(String name)
{
int r, g, b;
diff --git a/src/jalview/structure/StructureImportSettings.java b/src/jalview/structure/StructureImportSettings.java
new file mode 100644
index 0000000..6254b43
--- /dev/null
+++ b/src/jalview/structure/StructureImportSettings.java
@@ -0,0 +1,153 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.structure;
+
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.PDBEntry.Type;
+
+/**
+ * bean holding settings for structure IO. TODO: tests for validation of values
+ * TODO: tests for race conditions (all fields are static, is that correct ?)
+ *
+ * @author tcofoegbu
+ *
+ */
+public class StructureImportSettings
+{
+ /**
+ * set to true to add derived sequence annotations (temp factor read from
+ * file, or computed secondary structure) to the alignment
+ */
+ private static boolean visibleChainAnnotation = false;
+
+ /**
+ * Set true to predict secondary structure (using JMol for protein, Annotate3D
+ * for RNA)
+ */
+ private static boolean processSecStr = false;
+
+ /**
+ * Set true (with predictSecondaryStructure=true) to predict secondary
+ * structure using an external service (currently Annotate3D for RNA only)
+ */
+ private static boolean externalSecondaryStructure = false;
+
+ private static boolean showSeqFeatures = true;
+
+ public enum StructureParser
+ {
+ JMOL_PARSER, JALVIEW_PARSER
+ }
+
+ /**
+ * Determines the default file format for structure files to be downloaded
+ * from the PDB sequence fetcher. Possible options include: PDB|mmCIF
+ */
+ private static PDBEntry.Type defaultStructureFileFormat = Type.PDB;
+
+ /**
+ * Determines the parser used for parsing PDB format file. Possible options
+ * are : JMolParser|JalveiwParser
+ */
+ private static StructureParser defaultPDBFileParser = StructureParser.JMOL_PARSER;
+
+ public static void addSettings(boolean addAlignmentAnnotations,
+ boolean processSecStr, boolean externalSecStr)
+ {
+ StructureImportSettings.visibleChainAnnotation = addAlignmentAnnotations;
+ StructureImportSettings.processSecStr = processSecStr;
+ StructureImportSettings.externalSecondaryStructure = externalSecStr;
+ StructureImportSettings.showSeqFeatures = true;
+ }
+
+ public static boolean isVisibleChainAnnotation()
+ {
+ return visibleChainAnnotation;
+ }
+
+ public static void setVisibleChainAnnotation(
+ boolean visibleChainAnnotation)
+ {
+ StructureImportSettings.visibleChainAnnotation = visibleChainAnnotation;
+ }
+
+ public static boolean isProcessSecondaryStructure()
+ {
+ return processSecStr;
+ }
+
+ public static void setProcessSecondaryStructure(
+ boolean processSecondaryStructure)
+ {
+ StructureImportSettings.processSecStr = processSecondaryStructure;
+ }
+
+ public static boolean isExternalSecondaryStructure()
+ {
+ return externalSecondaryStructure;
+ }
+
+ public static void setExternalSecondaryStructure(
+ boolean externalSecondaryStructure)
+ {
+ StructureImportSettings.externalSecondaryStructure = externalSecondaryStructure;
+ }
+
+ public static boolean isShowSeqFeatures()
+ {
+ return showSeqFeatures;
+ }
+
+ public static void setShowSeqFeatures(boolean showSeqFeatures)
+ {
+ StructureImportSettings.showSeqFeatures = showSeqFeatures;
+ }
+
+ public static String getDefaultStructureFileFormat()
+ {
+ return defaultStructureFileFormat.toString();
+ }
+
+ public static void setDefaultStructureFileFormat(
+ String defaultStructureFileFormat)
+ {
+ StructureImportSettings.defaultStructureFileFormat = PDBEntry.Type
+ .valueOf(defaultStructureFileFormat.toUpperCase());
+ }
+
+ public static String getDefaultPDBFileParser()
+ {
+ return defaultPDBFileParser.toString();
+ }
+
+ public static void setDefaultPDBFileParser(
+ StructureParser defaultPDBFileParser)
+ {
+ StructureImportSettings.defaultPDBFileParser = defaultPDBFileParser;
+ }
+
+ public static void setDefaultPDBFileParser(String defaultPDBFileParser)
+ {
+ StructureImportSettings.defaultPDBFileParser = StructureParser
+ .valueOf(defaultPDBFileParser.toUpperCase());
+ }
+
+}
diff --git a/src/jalview/structure/StructureMapping.java b/src/jalview/structure/StructureMapping.java
index 3fcb5e9..78634e0 100644
--- a/src/jalview/structure/StructureMapping.java
+++ b/src/jalview/structure/StructureMapping.java
@@ -159,4 +159,14 @@ public class StructureMapping
}
return ala_copy;
}
+
+ public String getMappingDetailsOutput()
+ {
+ return mappingDetails;
+ }
+
+ public HashMap getMapping()
+ {
+ return mapping;
+ }
}
diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java
index a5d9736..7e691be 100644
--- a/src/jalview/structure/StructureSelectionManager.java
+++ b/src/jalview/structure/StructureSelectionManager.java
@@ -32,6 +32,7 @@ import jalview.datamodel.Annotation;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SearchResults;
import jalview.datamodel.SequenceI;
+import jalview.ext.jmol.JmolParser;
import jalview.gui.IProgressIndicator;
import jalview.io.AppletFormatAdapter;
import jalview.io.StructureFile;
@@ -326,7 +327,6 @@ public class StructureSelectionManager
return setMapping(true, sequence, targetChains, pdbFile, protocol);
}
-
/**
* create sequence structure mappings between each sequence and the given
* pdbFile (retrieved via the given protocol).
@@ -347,8 +347,7 @@ public class StructureSelectionManager
*/
synchronized public StructureFile setMapping(boolean forStructureView,
SequenceI[] sequenceArray, String[] targetChainIds,
- String pdbFile,
- String protocol)
+ String pdbFile, String protocol)
{
/*
* There will be better ways of doing this in the future, for now we'll use
@@ -384,23 +383,16 @@ public class StructureSelectionManager
boolean isMapUsingSIFTs = SiftsSettings.isMapWithSifts();
try
{
-
- if (pdbFile != null && isCIFFile(pdbFile))
- {
- pdb = new jalview.ext.jmol.JmolParser(addTempFacAnnot, parseSecStr,
- secStructServices, pdbFile, protocol);
- }
- else
- {
- pdb = new PDBfile(addTempFacAnnot, parseSecStr, secStructServices,
- pdbFile, protocol);
- }
+ pdb = new JmolParser(pdbFile, protocol);
if (pdb.getId() != null && pdb.getId().trim().length() > 0
&& AppletFormatAdapter.FILE.equals(protocol))
{
registerPDBFile(pdb.getId().trim(), pdbFile);
}
+ // if PDBId is unavailable then skip SIFTS mapping execution path
+ isMapUsingSIFTs = pdb.isPPDBIdAvailable();
+
} catch (Exception ex)
{
ex.printStackTrace();
@@ -424,6 +416,12 @@ public class StructureSelectionManager
{
boolean infChain = true;
final SequenceI seq = sequenceArray[s];
+ SequenceI ds = seq;
+ while (ds.getDatasetSequence() != null)
+ {
+ ds = ds.getDatasetSequence();
+ }
+
if (targetChainIds != null && targetChainIds[s] != null)
{
infChain = false;
@@ -498,34 +496,88 @@ public class StructureSelectionManager
}
ArrayList seqToStrucMapping = new ArrayList();
- if (isMapUsingSIFTs)
+ if (isMapUsingSIFTs && seq.isProtein())
{
setProgressBar(null);
- setProgressBar("Obtaining mapping with SIFTS");
+ setProgressBar(MessageManager
+ .getString("status.obtaining_mapping_with_sifts"));
jalview.datamodel.Mapping sqmpping = maxAlignseq
.getMappingFromS1(false);
if (targetChainId != null && !targetChainId.trim().isEmpty())
{
- StructureMapping mapping = getStructureMapping(seq, pdbFile,
- targetChainId, pdb, maxChain, sqmpping, maxAlignseq);
- seqToStrucMapping.add(mapping);
+ StructureMapping siftsMapping;
+ try
+ {
+ siftsMapping = getStructureMapping(seq, pdbFile, targetChainId,
+ pdb, maxChain, sqmpping, maxAlignseq);
+ seqToStrucMapping.add(siftsMapping);
+ maxChain.makeExactMapping(maxAlignseq, seq);
+ maxChain.transferRESNUMFeatures(seq, null);// FIXME: is this
+ // "IEA:SIFTS" ?
+ maxChain.transferResidueAnnotation(siftsMapping, sqmpping);
+ ds.addPDBId(maxChain.sequence.getAllPDBEntries().get(0));
+
+ } catch (SiftsException e)
+ {
+ // fall back to NW alignment
+ System.err.println(e.getMessage());
+ StructureMapping nwMapping = getNWMappings(seq, pdbFile,
+ targetChainId, maxChain, pdb, maxAlignseq);
+ seqToStrucMapping.add(nwMapping);
+ maxChain.makeExactMapping(maxAlignseq, seq);
+ maxChain.transferRESNUMFeatures(seq, null); // FIXME: is this
+ // "IEA:Jalview" ?
+ maxChain.transferResidueAnnotation(nwMapping, sqmpping);
+ ds.addPDBId(maxChain.sequence.getAllPDBEntries().get(0));
+ }
}
else
{
+ ArrayList foundSiftsMappings = new ArrayList();
for (PDBChain chain : pdb.getChains())
{
- StructureMapping mapping = getStructureMapping(seq, pdbFile,
- chain.id, pdb, chain, sqmpping, maxAlignseq);
- seqToStrucMapping.add(mapping);
+ try
+ {
+ StructureMapping siftsMapping = getStructureMapping(seq,
+ pdbFile, chain.id, pdb, chain, sqmpping, maxAlignseq);
+ foundSiftsMappings.add(siftsMapping);
+ } catch (SiftsException e)
+ {
+ System.err.println(e.getMessage());
+ }
+ }
+ if (!foundSiftsMappings.isEmpty())
+ {
+ seqToStrucMapping.addAll(foundSiftsMappings);
+ maxChain.makeExactMapping(maxAlignseq, seq);
+ maxChain.transferRESNUMFeatures(seq, null);// FIXME: is this
+ // "IEA:SIFTS" ?
+ maxChain.transferResidueAnnotation(foundSiftsMappings.get(0),
+ sqmpping);
+ ds.addPDBId(sqmpping.getTo().getAllPDBEntries().get(0));
+ }
+ else
+ {
+ StructureMapping nwMapping = getNWMappings(seq, pdbFile,
+ maxChainId, maxChain, pdb, maxAlignseq);
+ seqToStrucMapping.add(nwMapping);
+ maxChain.transferRESNUMFeatures(seq, null); // FIXME: is this
+ // "IEA:Jalview" ?
+ maxChain.transferResidueAnnotation(nwMapping, sqmpping);
+ ds.addPDBId(maxChain.sequence.getAllPDBEntries().get(0));
}
}
}
else
{
setProgressBar(null);
- setProgressBar("Obtaining mapping with NW alignment");
- seqToStrucMapping.add(getNWMappings(seq, pdbFile, maxChainId,
- maxChain, pdb, maxAlignseq));
+ setProgressBar(MessageManager
+ .getString("status.obtaining_mapping_with_nw_alignment"));
+ StructureMapping nwMapping = getNWMappings(seq, pdbFile,
+ maxChainId, maxChain, pdb, maxAlignseq);
+ seqToStrucMapping.add(nwMapping);
+ ds.addPDBId(maxChain.sequence.getAllPDBEntries().get(0));
+
}
if (forStructureView)
@@ -543,41 +595,42 @@ public class StructureSelectionManager
return "cif".equalsIgnoreCase(fileExt);
}
+ /**
+ * retrieve a mapping for seq from SIFTs using associated DBRefEntry for
+ * uniprot or PDB
+ *
+ * @param seq
+ * @param pdbFile
+ * @param targetChainId
+ * @param pdb
+ * @param maxChain
+ * @param sqmpping
+ * @param maxAlignseq
+ * @return
+ * @throws SiftsException
+ */
private StructureMapping getStructureMapping(SequenceI seq,
String pdbFile, String targetChainId, StructureFile pdb,
PDBChain maxChain, jalview.datamodel.Mapping sqmpping,
- AlignSeq maxAlignseq)
+ AlignSeq maxAlignseq) throws SiftsException
{
- String maxChainId = targetChainId;
+ StructureMapping curChainMapping = siftsClient
+ .getSiftsStructureMapping(seq, pdbFile, targetChainId);
try
{
- StructureMapping curChainMapping = siftsClient
- .getSiftsStructureMapping(seq, pdbFile, targetChainId);
- try
- {
PDBChain chain = pdb.findChain(targetChainId);
if (chain != null)
{
chain.transferResidueAnnotation(curChainMapping, sqmpping);
}
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- return curChainMapping;
- } catch (SiftsException e)
+ } catch (Exception e)
{
- System.err.println(e.getMessage());
- System.err.println(">>> Now switching mapping with NW alignment...");
- setProgressBar(null);
- setProgressBar(">>> Now switching mapping with NW alignment...");
- return getNWMappings(seq, pdbFile, maxChainId, maxChain, pdb,
- maxAlignseq);
+ e.printStackTrace();
}
+ return curChainMapping;
}
- private StructureMapping getNWMappings(SequenceI seq,
- String pdbFile,
+ private StructureMapping getNWMappings(SequenceI seq, String pdbFile,
String maxChainId, PDBChain maxChain, StructureFile pdb,
AlignSeq maxAlignseq)
{
diff --git a/src/jalview/structure/StructureViewSettings.java b/src/jalview/structure/StructureViewSettings.java
deleted file mode 100644
index 2fcb3e5..0000000
--- a/src/jalview/structure/StructureViewSettings.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package jalview.structure;
-
-public class StructureViewSettings
-{
- private String dbRefType;
-
- /**
- * set to true to add derived sequence annotations (temp factor read from
- * file, or computed secondary structure) to the alignment
- */
- private static boolean visibleChainAnnotation = false;
-
- /**
- * Set true to predict secondary structure (using JMol for protein, Annotate3D
- * for RNA)
- */
- private static boolean predictSecStr = false;
-
- /**
- * Set true (with predictSecondaryStructure=true) to predict secondary
- * structure using an external service (currently Annotate3D for RNA only)
- */
- private static boolean externalSecondaryStructure = false;
-
- private static boolean showSeqFeatures = true;
-
- public static void addSettings(boolean addAlignmentAnnotations,
- boolean predictSecStr, boolean externalSecStr)
- {
- StructureViewSettings.visibleChainAnnotation = addAlignmentAnnotations;
- StructureViewSettings.predictSecStr = predictSecStr;
- StructureViewSettings.externalSecondaryStructure = externalSecStr;
- StructureViewSettings.showSeqFeatures = true;
- }
-
- public static boolean isVisibleChainAnnotation()
- {
- return visibleChainAnnotation;
- }
-
- public static void setVisibleChainAnnotation(
- boolean visibleChainAnnotation)
- {
- StructureViewSettings.visibleChainAnnotation = visibleChainAnnotation;
- }
-
- public static boolean isPredictSecondaryStructure()
- {
- return predictSecStr;
- }
-
- public static void setPredictSecondaryStructure(
- boolean predictSecondaryStructure)
- {
- StructureViewSettings.predictSecStr = predictSecondaryStructure;
- }
-
- public static boolean isExternalSecondaryStructure()
- {
- return externalSecondaryStructure;
- }
-
- public static void setExternalSecondaryStructure(
- boolean externalSecondaryStructure)
- {
- StructureViewSettings.externalSecondaryStructure = externalSecondaryStructure;
- }
-
- public static boolean isShowSeqFeatures()
- {
- return showSeqFeatures;
- }
-
- public static void setShowSeqFeatures(boolean showSeqFeatures)
- {
- StructureViewSettings.showSeqFeatures = showSeqFeatures;
- }
-
-}
diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java
index 42fbfa9..b00f1bc 100644
--- a/src/jalview/structures/models/AAStructureBindingModel.java
+++ b/src/jalview/structures/models/AAStructureBindingModel.java
@@ -51,6 +51,10 @@ public abstract class AAStructureBindingModel extends
private StructureSelectionManager ssm;
+ /*
+ * distinct PDB entries (pdb files) associated
+ * with sequences
+ */
private PDBEntry[] pdbEntry;
/*
@@ -75,6 +79,11 @@ public abstract class AAStructureBindingModel extends
private boolean finishedInit = false;
/**
+ * current set of model filenames loaded in the Jmol instance
+ */
+ protected String[] modelFileNames = null;
+
+ /**
* Data bean class to simplify parameterisation in superposeStructures
*/
protected class SuperposeData
@@ -239,24 +248,21 @@ public abstract class AAStructureBindingModel extends
// TODO: give a more informative title when multiple structures are
// displayed.
StringBuilder title = new StringBuilder(64);
- final PDBEntry pdbEntry = getPdbEntry(0);
+ final PDBEntry pdbe = getPdbEntry(0);
title.append(viewerName + " view for " + getSequence()[0][0].getName()
- + ":" + pdbEntry.getId());
+ + ":" + pdbe.getId());
if (verbose)
{
- if (pdbEntry.getProperty() != null)
+ String method = (String) pdbe.getProperty("method");
+ if (method != null)
{
- if (pdbEntry.getProperty().get("method") != null)
- {
- title.append(" Method: ");
- title.append(pdbEntry.getProperty().get("method"));
- }
- if (pdbEntry.getProperty().get("chains") != null)
- {
- title.append(" Chain:");
- title.append(pdbEntry.getProperty().get("chains"));
- }
+ title.append(" Method: ").append(method);
+ }
+ String chain = (String) pdbe.getProperty("chains");
+ if (chain != null)
+ {
+ title.append(" Chain:").append(chain);
}
}
return title.toString();
@@ -521,6 +527,10 @@ public abstract class AAStructureBindingModel extends
{
int refStructure = -1;
String[] files = getPdbFile();
+ if (files == null)
+ {
+ return -1;
+ }
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
{
StructureMapping[] mappings = getSsm().getMapping(files[pdbfnum]);
@@ -565,7 +575,11 @@ public abstract class AAStructureBindingModel extends
}
structures[pdbfnum].pdbId = mapping.getPdbId();
structures[pdbfnum].isRna = theSequence.getRNA() != null;
- // move on to next pdb file
+
+ /*
+ * move on to next pdb file (ignore sequences for other chains
+ * for the same structure)
+ */
s = seqCountForPdbFile;
break;
}
@@ -598,6 +612,10 @@ public abstract class AAStructureBindingModel extends
for (String file : files)
{
notLoaded = file;
+ if (file == null)
+ {
+ continue;
+ }
try
{
StructureMapping[] sm = getSsm().getMapping(file);
diff --git a/src/jalview/util/ArrayUtils.java b/src/jalview/util/ArrayUtils.java
index 92085c3..c05dac5 100644
--- a/src/jalview/util/ArrayUtils.java
+++ b/src/jalview/util/ArrayUtils.java
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.util;
public class ArrayUtils
diff --git a/src/jalview/util/CaseInsensitiveString.java b/src/jalview/util/CaseInsensitiveString.java
new file mode 100644
index 0000000..b66e80d
--- /dev/null
+++ b/src/jalview/util/CaseInsensitiveString.java
@@ -0,0 +1,77 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.util;
+
+/**
+ * A class to wrap a case insensitive string. For use in collections where we
+ * want to preserve case, but do not want to duplicate upper and lower case
+ * variants
+ */
+public final class CaseInsensitiveString
+{
+ String value;
+
+ public CaseInsensitiveString(String s)
+ {
+ this.value = s;
+ }
+
+ @Override
+ public String toString()
+ {
+ return value;
+ }
+
+ /**
+ * Answers true if the object compared to is a CaseInsensitiveString wrapping
+ * the same string value (ignoring case), or if both wrap a null value, else
+ * false
+ */
+ @Override
+ public boolean equals(Object o)
+ {
+ if (o == null)
+ {
+ return false;
+ }
+ if (!(o instanceof CaseInsensitiveString))
+ {
+ return false;
+ }
+ CaseInsensitiveString obj = (CaseInsensitiveString) o;
+ if (value == null)
+ {
+ return obj.value == null;
+ }
+ return value.equalsIgnoreCase(obj.value);
+ }
+
+ /**
+ * hashCode overriden to guarantee that 'equal' objects have the same hash
+ * code
+ */
+ @Override
+ public int hashCode()
+ {
+ return value == null ? super.hashCode() : value.toUpperCase()
+ .hashCode();
+ }
+}
diff --git a/src/jalview/util/ColorUtils.java b/src/jalview/util/ColorUtils.java
index b8cd563..525bfdb 100644
--- a/src/jalview/util/ColorUtils.java
+++ b/src/jalview/util/ColorUtils.java
@@ -103,4 +103,92 @@ public class ColorUtils
return col == null ? null : col.brighter().brighter().brighter();
}
+ /**
+ * Returns a color between minColour and maxColour; the RGB values are in
+ * proportion to where 'value' lies between minValue and maxValue
+ *
+ * @param value
+ * @param minValue
+ * @param minColour
+ * @param maxValue
+ * @param maxColour
+ * @return
+ */
+ public static Color getGraduatedColour(float value, float minValue,
+ Color minColour, float maxValue, Color maxColour)
+ {
+ if (minValue == maxValue)
+ {
+ return minColour;
+ }
+ if (value < minValue)
+ {
+ value = minValue;
+ }
+ if (value > maxValue)
+ {
+ value = maxValue;
+ }
+
+ /*
+ * prop = proportion of the way value is from minValue to maxValue
+ */
+ float prop = (value - minValue) / (maxValue - minValue);
+ float r = minColour.getRed() + prop
+ * (maxColour.getRed() - minColour.getRed());
+ float g = minColour.getGreen() + prop
+ * (maxColour.getGreen() - minColour.getGreen());
+ float b = minColour.getBlue() + prop
+ * (maxColour.getBlue() - minColour.getBlue());
+ return new Color(r / 255, g / 255, b / 255);
+ }
+
+ /**
+ * 'Fades' the given colour towards white by the specified proportion. A
+ * factor of 1 or more results in White, a factor of 0 leaves the colour
+ * unchanged, and a factor between 0 and 1 results in a proportionate change
+ * of RGB values towards (255, 255, 255).
+ *
+ * A negative bleachFactor can be specified to darken the colour towards Black
+ * (0, 0, 0).
+ *
+ * @param colour
+ * @param bleachFactor
+ * @return
+ */
+ public static Color bleachColour(Color colour, float bleachFactor)
+ {
+ if (bleachFactor >= 1f)
+ {
+ return Color.WHITE;
+ }
+ if (bleachFactor <= -1f)
+ {
+ return Color.BLACK;
+ }
+ if (bleachFactor == 0f)
+ {
+ return colour;
+ }
+
+ int red = colour.getRed();
+ int green = colour.getGreen();
+ int blue = colour.getBlue();
+
+ if (bleachFactor > 0)
+ {
+ red += (255 - red) * bleachFactor;
+ green += (255 - green) * bleachFactor;
+ blue += (255 - blue) * bleachFactor;
+ return new Color(red, green, blue);
+ }
+ else
+ {
+ float factor = 1 + bleachFactor;
+ red *= factor;
+ green *= factor;
+ blue *= factor;
+ return new Color(red, green, blue);
+ }
+ }
}
diff --git a/src/jalview/util/Comparison.java b/src/jalview/util/Comparison.java
index 8902e2c..0beb45b 100644
--- a/src/jalview/util/Comparison.java
+++ b/src/jalview/util/Comparison.java
@@ -249,6 +249,18 @@ public class Comparison
}
/**
+ * Overloaded method signature to test whether a single sequence is nucleotide
+ * (that is, more than 85% CGTA)
+ *
+ * @param seq
+ * @return
+ */
+ public static final boolean isNucleotide(SequenceI seq)
+ {
+ return isNucleotide(new SequenceI[] { seq });
+ }
+
+ /**
* Answers true if more than 85% of the sequence residues (ignoring gaps) are
* A, G, C, T or U, else false. This is just a heuristic guess and may give a
* wrong answer (as AGCT are also amino acid codes).
@@ -286,7 +298,7 @@ public class Comparison
* @param letters
* @return
*/
- public static final boolean areNucleotide(char[][] letters)
+ static final boolean areNucleotide(char[][] letters)
{
int ntCount = 0;
int aaCount = 0;
@@ -300,16 +312,11 @@ public class Comparison
// to save a lengthy calculation
for (char c : seq)
{
- if ('a' <= c && c <= 'z')
- {
- c -= TO_UPPER_CASE;
- }
-
- if (c == 'A' || c == 'G' || c == 'C' || c == 'T' || c == 'U')
+ if (isNucleotide(c))
{
ntCount++;
}
- else if (!Comparison.isGap(c))
+ else if (!isGap(c))
{
aaCount++;
}
@@ -332,6 +339,59 @@ public class Comparison
}
/**
+ * Answers true if the character is one of aAcCgGtTuU
+ *
+ * @param c
+ * @return
+ */
+ public static boolean isNucleotide(char c)
+ {
+ if ('a' <= c && c <= 'z')
+ {
+ c -= TO_UPPER_CASE;
+ }
+
+ switch (c)
+ {
+ case 'A':
+ case 'C':
+ case 'G':
+ case 'T':
+ case 'U':
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Answers true if every character in the string is one of aAcCgGtTuU, or
+ * (optionally) a gap character (dot, dash, space), else false
+ *
+ * @param s
+ * @param allowGaps
+ * @return
+ */
+ public static boolean isNucleotideSequence(String s, boolean allowGaps)
+ {
+ if (s == null)
+ {
+ return false;
+ }
+ for (int i = 0; i < s.length(); i++)
+ {
+ char c = s.charAt(i);
+ if (!isNucleotide(c))
+ {
+ if (!allowGaps || !isGap(c))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
* Convenience overload of isNucleotide
*
* @param seqs
diff --git a/src/jalview/util/DBRefUtils.java b/src/jalview/util/DBRefUtils.java
index 424d40b..e6aa472 100755
--- a/src/jalview/util/DBRefUtils.java
+++ b/src/jalview/util/DBRefUtils.java
@@ -26,11 +26,12 @@ import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import com.stevesoft.pat.Regex;
@@ -59,6 +60,18 @@ public class DBRefUtils
canonicalSourceNameLookup.put("pdb", DBRefSource.PDB);
canonicalSourceNameLookup.put("ensembl", DBRefSource.ENSEMBL);
+ // Ensembl Gn and Tr are for Ensembl genomic and transcript IDs as served
+ // from ENA.
+ canonicalSourceNameLookup.put("ensembl-tr", DBRefSource.ENSEMBL);
+ canonicalSourceNameLookup.put("ensembl-gn", DBRefSource.ENSEMBL);
+
+ // Make sure we have lowercase entries for all canonical string lookups
+ Set keys = canonicalSourceNameLookup.keySet();
+ for (String k : keys)
+ {
+ canonicalSourceNameLookup.put(k.toLowerCase(),
+ canonicalSourceNameLookup.get(k));
+ }
dasCoordinateSystemsLookup.put("pdbresnum", DBRefSource.PDB);
dasCoordinateSystemsLookup.put("uniprot", DBRefSource.UNIPROT);
@@ -67,11 +80,14 @@ public class DBRefUtils
}
/**
+ * Returns those DBRefEntry objects whose source identifier (once converted to
+ * Jalview's canonical form) is in the list of sources to search for. Returns
+ * null if no matches found.
*
* @param dbrefs
- * array of DBRef objects to search
+ * DBRefEntry objects to search
* @param sources
- * String[] array of source DBRef IDs to retrieve
+ * array of sources to select
* @return
*/
public static DBRefEntry[] selectRefs(DBRefEntry[] dbrefs,
@@ -148,8 +164,8 @@ public class DBRefUtils
}
/**
- * Returns an array of those references that match the given entry, or null if
- * no matches. Currently uses a comparator which matches if
+ * Returns a (possibly empty) list of those references that match the given
+ * entry. Currently uses a comparator which matches if
*
* - database sources are the same
* - accession ids are the same
@@ -162,34 +178,35 @@ public class DBRefUtils
* pattern to match
* @return
*/
- public static DBRefEntry[] searchRefs(DBRefEntry[] ref, DBRefEntry entry)
+ public static List searchRefs(DBRefEntry[] ref,
+ DBRefEntry entry)
{
return searchRefs(ref, entry,
matchDbAndIdAndEitherMapOrEquivalentMapList);
}
/**
- * Returns an array of those references that match the given accession id
+ * Returns a list of those references that match the given accession id
*
* - database sources are the same
* - accession ids are the same
* - both have no mapping, or the mappings are the same
*
*
- * @param ref
+ * @param refs
* Set of references to search
- * @param entry
- * pattern to match
+ * @param accId
+ * accession id to match
* @return
*/
- public static DBRefEntry[] searchRefs(DBRefEntry[] ref, String accId)
+ public static List searchRefs(DBRefEntry[] refs, String accId)
{
- return searchRefs(ref, new DBRefEntry("", "", accId), matchId);
+ return searchRefs(refs, new DBRefEntry("", "", accId), matchId);
}
/**
- * Returns an array of those references that match the given entry, according
- * to the given comparator. Returns null if no matches.
+ * Returns a (possibly empty) list of those references that match the given
+ * entry, according to the given comparator.
*
* @param refs
* an array of database references to search
@@ -198,14 +215,14 @@ public class DBRefUtils
* @param comparator
* @return
*/
- static DBRefEntry[] searchRefs(DBRefEntry[] refs, DBRefEntry entry,
+ static List searchRefs(DBRefEntry[] refs, DBRefEntry entry,
DbRefComp comparator)
{
+ List rfs = new ArrayList();
if (refs == null || entry == null)
{
- return null;
+ return rfs;
}
- List rfs = new ArrayList();
for (int i = 0; i < refs.length; i++)
{
if (comparator.matches(entry, refs[i]))
@@ -213,7 +230,7 @@ public class DBRefUtils
rfs.add(refs[i]);
}
}
- return rfs.size() == 0 ? null : rfs.toArray(new DBRefEntry[rfs.size()]);
+ return rfs;
}
interface DbRefComp
@@ -231,7 +248,8 @@ public class DBRefUtils
public boolean matches(DBRefEntry refa, DBRefEntry refb)
{
if (refa.getSource() == null
- || refb.getSource().equals(refa.getSource()))
+ || DBRefUtils.getCanonicalName(refb.getSource()).equals(
+ DBRefUtils.getCanonicalName(refa.getSource())))
{
if (refa.getVersion() == null
|| refb.getVersion().equals(refa.getVersion()))
@@ -262,7 +280,7 @@ public class DBRefUtils
@Override
public boolean matches(DBRefEntry refa, DBRefEntry refb)
{
- if (nullOrEqual(refa.getSource(), refb.getSource())
+ if (nullOrEqualSource(refa.getSource(), refb.getSource())
&& nullOrEqual(refa.getVersion(), refb.getVersion())
&& nullOrEqual(refa.getAccessionId(), refb.getAccessionId())
&& nullOrEqual(refa.getMap(), refb.getMap()))
@@ -283,8 +301,10 @@ public class DBRefUtils
@Override
public boolean matches(DBRefEntry refa, DBRefEntry refb)
{
- if (refa.getSource() != null && refb.getSource() != null
- && refb.getSource().equals(refa.getSource()))
+ if (refa.getSource() != null
+ && refb.getSource() != null
+ && DBRefUtils.getCanonicalName(refb.getSource()).equals(
+ DBRefUtils.getCanonicalName(refa.getSource())))
{
// We dont care about version
if (refa.getAccessionId() != null && refb.getAccessionId() != null
@@ -314,8 +334,10 @@ public class DBRefUtils
@Override
public boolean matches(DBRefEntry refa, DBRefEntry refb)
{
- if (refa.getSource() != null && refb.getSource() != null
- && refb.getSource().equals(refa.getSource()))
+ if (refa.getSource() != null
+ && refb.getSource() != null
+ && DBRefUtils.getCanonicalName(refb.getSource()).equals(
+ DBRefUtils.getCanonicalName(refa.getSource())))
{
// We dont care about version
if (refa.getAccessionId() != null && refb.getAccessionId() != null
@@ -350,8 +372,10 @@ public class DBRefUtils
@Override
public boolean matches(DBRefEntry refa, DBRefEntry refb)
{
- if (refa.getSource() != null && refb.getSource() != null
- && refb.getSource().equals(refa.getSource()))
+ if (refa.getSource() != null
+ && refb.getSource() != null
+ && DBRefUtils.getCanonicalName(refb.getSource()).equals(
+ DBRefUtils.getCanonicalName(refa.getSource())))
{
// We dont care about version
// if ((refa.getVersion()==null || refb.getVersion()==null)
@@ -380,21 +404,24 @@ public class DBRefUtils
};
/**
- * accession ID and DB must be identical. Version is ignored. No map on either
- * or map but no maplist on either or maplist of map on a is equivalent to the
- * maplist of map on b.
+ * accession ID and DB must be identical, or null on a. Version is ignored. No
+ * map on either or map but no maplist on either or maplist of map on a is
+ * equivalent to the maplist of map on b.
*/
public static DbRefComp matchDbAndIdAndEitherMapOrEquivalentMapList = new DbRefComp()
{
@Override
public boolean matches(DBRefEntry refa, DBRefEntry refb)
{
- if (refa.getSource() != null && refb.getSource() != null
- && refb.getSource().equals(refa.getSource()))
+ if (refa.getSource() != null
+ && refb.getSource() != null
+ && DBRefUtils.getCanonicalName(refb.getSource()).equals(
+ DBRefUtils.getCanonicalName(refa.getSource())))
{
// We dont care about version
- if (refa.getAccessionId() != null && refb.getAccessionId() != null
- && refb.getAccessionId().equals(refa.getAccessionId()))
+
+ if (refa.getAccessionId() == null
+ || refa.getAccessionId().equals(refb.getAccessionId()))
{
if (refa.getMap() == null || refb.getMap() == null)
{
@@ -406,7 +433,7 @@ public class DBRefUtils
|| (refb.getMap().getMap() != null
&& refa.getMap().getMap() != null && (refb
.getMap().getMap().equals(refa.getMap().getMap()))))
- { // getMap().getMap().containsEither(false,refa.getMap().getMap())
+ {
return true;
}
}
@@ -480,9 +507,7 @@ public class DBRefUtils
PDBEntry pdbr = new PDBEntry();
pdbr.setId(pdbid);
pdbr.setType(PDBEntry.Type.PDB);
- pdbr.setProperty(new Hashtable());
pdbr.setChainCode(chaincode);
- // pdbr.getProperty().put("CHAIN", chaincode);
seq.addPDBId(pdbr);
}
else
@@ -516,7 +541,196 @@ public class DBRefUtils
{
return true;
}
- return (o1 == null ? o2.equals(o1) : o1.equals(o2));
+ return o1.equals(o2);
+ }
+
+ /**
+ * canonicalise source string before comparing. null is always wildcard
+ *
+ * @param o1
+ * - null or source string to compare
+ * @param o2
+ * - null or source string to compare
+ * @return true if either o1 or o2 are null, or o1 equals o2 under
+ * DBRefUtils.getCanonicalName
+ * (o1).equals(DBRefUtils.getCanonicalName(o2))
+ */
+ public static boolean nullOrEqualSource(String o1, String o2)
+ {
+ if (o1 == null || o2 == null)
+ {
+ return true;
+ }
+ return DBRefUtils.getCanonicalName(o1).equals(
+ DBRefUtils.getCanonicalName(o2));
+ }
+
+ /**
+ * Selects just the DNA or protein references from a set of references
+ *
+ * @param selectDna
+ * if true, select references to 'standard' DNA databases, else to
+ * 'standard' peptide databases
+ * @param refs
+ * a set of references to select from
+ * @return
+ */
+ public static DBRefEntry[] selectDbRefs(boolean selectDna,
+ DBRefEntry[] refs)
+ {
+ return selectRefs(refs, selectDna ? DBRefSource.DNACODINGDBS
+ : DBRefSource.PROTEINDBS);
+ // could attempt to find other cross
+ // refs here - ie PDB xrefs
+ // (not dna, not protein seq)
+ }
+
+ /**
+ * Returns the (possibly empty) list of those supplied dbrefs which have the
+ * specified source database, with a case-insensitive match of source name
+ *
+ * @param dbRefs
+ * @param source
+ * @return
+ */
+ public static List searchRefsForSource(DBRefEntry[] dbRefs,
+ String source)
+ {
+ List matches = new ArrayList();
+ if (dbRefs != null && source != null)
+ {
+ for (DBRefEntry dbref : dbRefs)
+ {
+ if (source.equalsIgnoreCase(dbref.getSource()))
+ {
+ matches.add(dbref);
+ }
+ }
+ }
+ return matches;
+ }
+
+ /**
+ * promote direct database references to primary for nucleotide or protein
+ * sequences if they have an appropriate primary ref
+ *
+ *
+ * Seq Type |
+ * Primary DB |
+ * Direct which will be promoted |
+ *
+ *
+ * peptides |
+ * Ensembl |
+ * Uniprot |
+ *
+ *
+ * peptides |
+ * Ensembl |
+ * Uniprot |
+ *
+ *
+ * dna |
+ * Ensembl |
+ * ENA |
+ *
+ *
+ *
+ * @param sequence
+ */
+ public static void ensurePrimaries(SequenceI sequence)
+ {
+ List pr = sequence.getPrimaryDBRefs();
+ if (pr.size() == 0)
+ {
+ // nothing to do
+ return;
+ }
+ List selfs = new ArrayList();
+ {
+ DBRefEntry[] selfArray = selectDbRefs(!sequence.isProtein(),
+ sequence.getDBRefs());
+ if (selfArray == null || selfArray.length == 0)
+ {
+ // nothing to do
+ return;
+ }
+ selfs.addAll(Arrays.asList(selfArray));
+ }
+
+ // filter non-primary refs
+ for (DBRefEntry p : pr)
+ {
+ while (selfs.contains(p))
+ {
+ selfs.remove(p);
+ }
+ }
+ List toPromote = new ArrayList();
+
+ for (DBRefEntry p : pr)
+ {
+ List promType = new ArrayList();
+ if (sequence.isProtein())
+ {
+ switch (getCanonicalName(p.getSource()))
+ {
+ case DBRefSource.UNIPROT:
+ // case DBRefSource.UNIPROTKB:
+ // case DBRefSource.UP_NAME:
+ // search for and promote ensembl
+ promType.add(DBRefSource.ENSEMBL);
+ break;
+ case DBRefSource.ENSEMBL:
+ // search for and promote Uniprot
+ promType.add(DBRefSource.UNIPROT);
+ break;
+ }
+ }
+ else
+ {
+ // TODO: promote transcript refs
+ }
+
+ // collate candidates and promote them
+ DBRefEntry[] candidates = selectRefs(
+ selfs.toArray(new DBRefEntry[0]),
+ promType.toArray(new String[0]));
+ if (candidates != null)
+ {
+ for (DBRefEntry cand : candidates)
+ {
+ if (cand.hasMap())
+ {
+ if (cand.getMap().getTo() != null
+ && cand.getMap().getTo() != sequence)
+ {
+ // can't promote refs with mappings to other sequences
+ continue;
+ }
+ if (cand.getMap().getMap().getFromLowest() != sequence
+ .getStart()
+ && cand.getMap().getMap().getFromHighest() != sequence
+ .getEnd())
+ {
+ // can't promote refs with mappings from a region of this sequence
+ // - eg CDS
+ continue;
+ }
+ }
+ // and promote
+ cand.setVersion(p.getVersion() + " (promoted)");
+ selfs.remove(cand);
+ toPromote.add(cand);
+ if (!cand.isPrimaryCandidate())
+ {
+ System.out.println("Warning: Couldn't promote dbref "
+ + cand.toString() + " for sequence "
+ + sequence.toString());
+ }
+ }
+ }
+ }
}
}
diff --git a/src/jalview/util/DnaUtils.java b/src/jalview/util/DnaUtils.java
new file mode 100644
index 0000000..284ec10
--- /dev/null
+++ b/src/jalview/util/DnaUtils.java
@@ -0,0 +1,153 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.util;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class DnaUtils
+{
+
+ /**
+ * Parses an ENA/GenBank format location specifier and returns a list of
+ * [start, end] ranges. Throws an exception if not able to parse.
+ *
+ * Currently we do not parse "order()" specifiers, or indeterminate ranges of
+ * the format "<start..end" or "start..>end" or "start.end" or
+ * "start^end"
+ *
+ * @param location
+ * @return
+ * @throws ParseException
+ * if unable to parse the location (the exception message is the
+ * location specifier being parsed); we use ParseException in
+ * preference to the unchecked IllegalArgumentException
+ * @see http://www.insdc.org/files/feature_table.html#3.4
+ */
+ public static List parseLocation(String location)
+ throws ParseException
+ {
+ if (location.startsWith("join("))
+ {
+ return parseJoin(location);
+ }
+ else if (location.startsWith("complement("))
+ {
+ return parseComplement(location);
+ }
+ if (location.startsWith("order("))
+ {
+ throw new ParseException(location, 0);
+ }
+
+ /*
+ * try to parse m..n (or simply m)
+ */
+ String[] range = location.split("\\.\\.");
+ if (range.length == 1 || range.length == 2)
+ {
+ try
+ {
+ int start = Integer.valueOf(range[0]);
+ int end = range.length == 1 ? start : Integer.valueOf(range[1]);
+ return Collections.singletonList(new int[] { start, end });
+ } catch (NumberFormatException e)
+ {
+ /*
+ * could be a location like <1..888 or 1..>888
+ */
+ throw new ParseException(location, 0);
+ }
+ }
+ else
+ {
+ /*
+ * could be a location like 102.110 or 123^124
+ */
+ throw new ParseException(location, 0);
+ }
+ }
+
+ /**
+ * Parses a complement(locationSpec) into a list of start-end ranges
+ *
+ * @param location
+ * @return
+ * @throws ParseException
+ */
+ static List parseComplement(String location) throws ParseException
+ {
+ /*
+ * take what is inside complement()
+ */
+ if (!location.endsWith(")"))
+ {
+ throw new ParseException(location, 0);
+ }
+ String toComplement = location.substring("complement(".length(),
+ location.length() - 1);
+ List ranges = parseLocation(toComplement);
+
+ /*
+ * reverse the order and direction of ranges
+ */
+ Collections.reverse(ranges);
+ for (int[] range : ranges)
+ {
+ int temp = range[0];
+ range[0] = range[1];
+ range[1] = temp;
+ }
+ return ranges;
+ }
+
+ /**
+ * Parses a join(loc1,loc2,...,locn) into a list of start-end ranges
+ *
+ * @param location
+ * @return
+ * @throws ParseException
+ */
+ static List parseJoin(String location) throws ParseException
+ {
+ List ranges = new ArrayList();
+
+ /*
+ * take what is inside join()
+ */
+ if (!location.endsWith(")"))
+ {
+ throw new ParseException(location, 0);
+ }
+ String joinedLocs = location.substring("join(".length(),
+ location.length() - 1);
+ String[] locations = joinedLocs.split(",");
+ for (String loc : locations)
+ {
+ List range = parseLocation(loc);
+ ranges.addAll(range);
+ }
+ return ranges;
+ }
+
+}
diff --git a/src/jalview/util/Format.java b/src/jalview/util/Format.java
index d14e4ad..7121985 100755
--- a/src/jalview/util/Format.java
+++ b/src/jalview/util/Format.java
@@ -947,4 +947,29 @@ public class Format
{
return formatString;
}
+
+ /**
+ * Bespoke method to format percentage float value to the specified number of
+ * decimal places. Avoids use of general-purpose format parsers as a
+ * processing hotspot.
+ *
+ * @param sb
+ * @param value
+ * @param dp
+ */
+ public static void appendPercentage(StringBuilder sb, float value, int dp)
+ {
+ sb.append((int) value);
+ if (dp > 0)
+ {
+ sb.append(".");
+ while (dp > 0)
+ {
+ value = value - (int) value;
+ value *= 10;
+ sb.append((int) value);
+ dp--;
+ }
+ }
+ }
}
diff --git a/src/jalview/util/HttpUtils.java b/src/jalview/util/HttpUtils.java
index 991a20a..a5a9460 100644
--- a/src/jalview/util/HttpUtils.java
+++ b/src/jalview/util/HttpUtils.java
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
*
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
- ******************************************************************************/
+ */
package jalview.util;
import java.io.IOException;
diff --git a/src/jalview/util/ImageMaker.java b/src/jalview/util/ImageMaker.java
index b7aa4ca..9532230 100755
--- a/src/jalview/util/ImageMaker.java
+++ b/src/jalview/util/ImageMaker.java
@@ -54,11 +54,17 @@ public class ImageMaker
TYPE type;
+ private IProgressIndicator pIndicator;
+
+ private long pSessionId;
+
+ private boolean headless;
+
public enum TYPE
{
- EPS("EPS", MessageManager.getString("label.eps_file"), getEPSChooser()), PNG(
- "PNG", MessageManager.getString("label.png_image"),
- getPNGChooser()), SVG("SVG", "SVG", getSVGChooser());
+ EPS("EPS", MessageManager.getString("label.eps_file"), getEPSChooser()),
+ PNG("PNG", MessageManager.getString("label.png_image"), getPNGChooser()),
+ SVG("SVG", "SVG", getSVGChooser());
private JalviewFileChooser chooser;
@@ -94,17 +100,14 @@ public class ImageMaker
int height, File file, String fileTitle,
IProgressIndicator pIndicator, long pSessionId, boolean headless)
{
+ this.pIndicator = pIndicator;
this.type = type;
-
+ this.pSessionId = pSessionId;
+ this.headless = headless;
if (file == null)
{
- if (pIndicator != null && !headless)
- {
- pIndicator.setProgressBar(
- MessageManager.formatMessage(
- "status.waiting_for_user_to_select_output_file",
- type.name), pSessionId);
- }
+ setProgressMessage(MessageManager.formatMessage(
+ "status.waiting_for_user_to_select_output_file", type.name));
JalviewFileChooser chooser;
chooser = type.getChooser();
chooser.setFileView(new jalview.io.JalviewFileView());
@@ -120,12 +123,8 @@ public class ImageMaker
}
else
{
- if (pIndicator != null && !headless)
- {
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "status.cancelled_image_export_operation", type.name),
- pSessionId);
- }
+ setProgressMessage(MessageManager.formatMessage(
+ "status.cancelled_image_export_operation", type.name));
}
}
@@ -134,6 +133,9 @@ public class ImageMaker
try
{
out = new FileOutputStream(file);
+ setProgressMessage(null);
+ setProgressMessage(MessageManager.formatMessage(
+ "status.exporting_alignment_as_x_file", type.getName()));
if (type == TYPE.SVG)
{
setupSVG(width, height, fileTitle);
@@ -146,19 +148,13 @@ public class ImageMaker
{
setupPNG(width, height);
}
- if (pIndicator != null && !headless)
- {
- pIndicator.setProgressBar(
-MessageManager.formatMessage(
- "status.export_complete", type.getName()),
- pSessionId);
- }
+
} catch (Exception ex)
{
System.out.println("Error creating " + type.getName() + " file.");
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "info.error_creating_file", type.getName()), pSessionId);
+ setProgressMessage(MessageManager.formatMessage(
+ "info.error_creating_file", type.getName()));
}
}
}
@@ -214,6 +210,8 @@ MessageManager.formatMessage(
if (renderStyle == null || eps.cancelled)
{
+ setProgressMessage(MessageManager.formatMessage(
+ "status.cancelled_image_export_operation", "EPS"));
return;
}
}
@@ -233,6 +231,8 @@ MessageManager.formatMessage(
pg.setAccurateTextMode(accurateText);
graphics = pg;
+ setProgressMessage(MessageManager.formatMessage(
+ "status.export_complete", type.getName()));
} catch (Exception ex)
{
}
@@ -245,6 +245,8 @@ MessageManager.formatMessage(
Graphics2D ig2 = (Graphics2D) graphics;
ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
+ setProgressMessage(MessageManager.formatMessage(
+ "status.export_complete", type.getName()));
}
@@ -268,16 +270,20 @@ MessageManager.formatMessage(
if (renderStyle == null || svgOption.cancelled)
{
+ setProgressMessage(MessageManager.formatMessage(
+ "status.cancelled_image_export_operation", "SVG"));
return;
}
}
- if (renderStyle.equalsIgnoreCase("lineart"))
+ if (renderStyle.equalsIgnoreCase("Lineart"))
{
ig2.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE,
SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR);
}
+ setProgressMessage(MessageManager.formatMessage(
+ "status.export_complete", type.getName()));
graphics = g2;
}
@@ -307,6 +313,14 @@ MessageManager.formatMessage(
"Encapsulated Postscript");
}
+ private void setProgressMessage(String message)
+ {
+ if (pIndicator != null && !headless)
+ {
+ pIndicator.setProgressBar(message, pSessionId);
+ }
+ }
+
static JalviewFileChooser getSVGChooser()
{
if (Jalview.isHeadlessMode())
diff --git a/src/jalview/util/LinkedIdentityHashSet.java b/src/jalview/util/LinkedIdentityHashSet.java
new file mode 100644
index 0000000..bce540f
--- /dev/null
+++ b/src/jalview/util/LinkedIdentityHashSet.java
@@ -0,0 +1,143 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.util;
+
+import java.util.AbstractSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+
+/**
+ * Order preserving Set based on System.identityHashCode() for an object, which
+ * also supports Object->index lookup.
+ *
+ * @author Jim Procter (2016) based on Evgeniy Dorofeev's response: via
+ * https://stackoverflow.com/questions/17276658/linkedidentityhashset
+ *
+ */
+public class LinkedIdentityHashSet extends AbstractSet
+{
+ LinkedHashMap set = new LinkedHashMap();
+
+ static class IdentityWrapper
+ {
+ Object obj;
+
+ public int p;
+
+ IdentityWrapper(Object obj, int p)
+ {
+ this.obj = obj;
+ this.p = p;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return this.obj == obj;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return System.identityHashCode(obj);
+ }
+ }
+
+ @Override
+ public boolean add(E e)
+ {
+ IdentityWrapper el = (new IdentityWrapper(e, set.size()));
+ // Map.putIfAbsent() from Java 8
+ // return set.putIfAbsent(el, el) == null;
+ return putIfAbsent(el, el) == null;
+ }
+
+ /**
+ * If the specified key is not already associated with a value (or is mapped
+ * to null) associates it with the given value and returns null, else returns
+ * the current value.
+ *
+ * Method added for Java 7 (can remove for Java 8)
+ *
+ * @param key
+ * @param value
+ * @return
+ * @see https
+ * ://docs.oracle.com/javase/8/docs/api/java/util/Map.html#putIfAbsent
+ * -K-V-
+ */
+ private IdentityWrapper putIfAbsent(IdentityWrapper key,
+ IdentityWrapper value)
+ {
+ IdentityWrapper v = set.get(key);
+ if (v == null)
+ {
+ v = set.put(key, value);
+ }
+ return v;
+ }
+
+ @Override
+ public Iterator iterator()
+ {
+ return new Iterator()
+ {
+ final Iterator se = set.keySet().iterator();
+
+ @Override
+ public boolean hasNext()
+ {
+ return se.hasNext();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public E next()
+ {
+ return (E) se.next().obj;
+ }
+
+ @Override
+ public void remove()
+ {
+ // Java 8 default behaviour
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ @Override
+ public int size()
+ {
+ return set.size();
+ }
+
+ /**
+ * Lookup the index for e in the set
+ *
+ * @param e
+ * @return position of e in the set when it was added.
+ */
+ public int indexOf(E e)
+ {
+ return set.get(e).p;
+ }
+}
diff --git a/src/jalview/util/MapList.java b/src/jalview/util/MapList.java
index e51442c..58abdc3 100644
--- a/src/jalview/util/MapList.java
+++ b/src/jalview/util/MapList.java
@@ -88,8 +88,6 @@ public class MapList
@Override
public boolean equals(Object o)
{
- // TODO should also override hashCode to ensure equal objects have equal
- // hashcodes
if (o == null || !(o instanceof MapList))
{
return false;
@@ -112,6 +110,19 @@ public class MapList
}
/**
+ * Returns a hashcode made from the fromRatio, toRatio, and from/to ranges
+ */
+ @Override
+ public int hashCode()
+ {
+ int hashCode = 31 * fromRatio;
+ hashCode = 31 * hashCode + toRatio;
+ hashCode = 31 * hashCode + fromShifts.toArray().hashCode();
+ hashCode = 31 * hashCode + toShifts.toArray().hashCode();
+ return hashCode;
+ }
+
+ /**
* Returns the 'from' ranges as {[start1, end1], [start2, end2], ...}
*
* @return
@@ -215,7 +226,7 @@ public class MapList
{
/*
* note lowest and highest values - bearing in mind the
- * direction may be revesed
+ * direction may be reversed
*/
fromLowest = Math.min(fromLowest, Math.min(from[i], from[i + 1]));
fromHighest = Math.max(fromHighest, Math.max(from[i], from[i + 1]));
@@ -331,7 +342,8 @@ public class MapList
*/
public static List coalesceRanges(final List ranges)
{
- if (ranges == null || ranges.size() < 2) {
+ if (ranges == null || ranges.size() < 2)
+ {
return ranges;
}
@@ -342,7 +354,7 @@ public class MapList
lastRange = new int[] { lastRange[0], lastRange[1] };
merged.add(lastRange);
boolean first = true;
-
+
for (final int[] range : ranges)
{
if (first)
@@ -376,7 +388,8 @@ public class MapList
* if next range is in the same direction as last and contiguous,
* just update the end position of the last range
*/
- boolean sameDirection = range[1] == range[0] || direction == lastDirection;
+ boolean sameDirection = range[1] == range[0]
+ || direction == lastDirection;
boolean extending = range[0] == lastRange[1] + lastDirection;
boolean overlapping = (lastDirection == 1 && range[0] >= lastRange[0] && range[0] <= lastRange[1])
|| (lastDirection == -1 && range[0] <= lastRange[0] && range[0] >= lastRange[1]);
@@ -393,7 +406,7 @@ public class MapList
lastDirection = (range[1] == range[0]) ? lastDirection : direction;
}
}
-
+
return changed ? merged : ranges;
}
@@ -992,6 +1005,10 @@ public class MapList
*/
public void addMapList(MapList map)
{
+ if (this.equals(map))
+ {
+ return;
+ }
this.fromLowest = Math.min(fromLowest, map.fromLowest);
this.toLowest = Math.min(toLowest, map.toLowest);
this.fromHighest = Math.max(fromHighest, map.fromHighest);
@@ -1087,4 +1104,15 @@ public class MapList
}
return forwardStrand;
}
+
+ /**
+ *
+ * @return true if from, or to is a three to 1 mapping
+ */
+ public boolean isTripletMap()
+ {
+ return (toRatio == 3 && fromRatio == 1)
+ || (fromRatio == 3 && toRatio == 1);
+ }
+
}
diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java
index ae4e55d..1fe452d 100644
--- a/src/jalview/util/MappingUtils.java
+++ b/src/jalview/util/MappingUtils.java
@@ -374,7 +374,8 @@ public final class MappingUtils
/*
* Found a sequence mapping. Locate the start/end mapped residues.
*/
- List mapping = Arrays.asList(new AlignedCodonFrame[] { acf });
+ List mapping = Arrays
+ .asList(new AlignedCodonFrame[] { acf });
SearchResults sr = buildSearchResults(selected,
startResiduePos, mapping);
for (Match m : sr.getResults())
@@ -555,9 +556,9 @@ public final class MappingUtils
* @param fromGapChar
*/
protected static void mapHiddenColumns(int[] hidden,
- List mappings,
- ColumnSelection mappedColumns, List fromSequences,
- List toSequences, char fromGapChar)
+ List mappings, ColumnSelection mappedColumns,
+ List fromSequences, List toSequences,
+ char fromGapChar)
{
for (int col = hidden[0]; col <= hidden[1]; col++)
{
@@ -589,9 +590,9 @@ public final class MappingUtils
* @param fromGapChar
*/
protected static void mapColumn(int col,
- List mappings,
- ColumnSelection mappedColumns, List fromSequences,
- List toSequences, char fromGapChar)
+ List mappings, ColumnSelection mappedColumns,
+ List fromSequences, List toSequences,
+ char fromGapChar)
{
int[] mappedTo = findMappedColumns(col, mappings, fromSequences,
toSequences, fromGapChar);
@@ -646,8 +647,7 @@ public final class MappingUtils
* Get the residue position and find the mapped position.
*/
int residuePos = fromSeq.findPosition(col);
- SearchResults sr = buildSearchResults(fromSeq, residuePos,
- mappings);
+ SearchResults sr = buildSearchResults(fromSeq, residuePos, mappings);
for (Match m : sr.getResults())
{
int mappedStartResidue = m.getStart();
@@ -754,6 +754,23 @@ public final class MappingUtils
public static List findMappingsForSequence(
SequenceI sequence, List mappings)
{
+ return findMappingsForSequenceAndOthers(sequence, mappings, null);
+ }
+
+ /**
+ * Returns a list of any mappings that are from or to the given (aligned or
+ * dataset) sequence, optionally limited to mappings involving one of a given
+ * list of sequences.
+ *
+ * @param sequence
+ * @param mappings
+ * @param filterList
+ * @return
+ */
+ public static List findMappingsForSequenceAndOthers(
+ SequenceI sequence, List mappings,
+ List filterList)
+ {
List result = new ArrayList();
if (sequence == null || mappings == null)
{
@@ -763,7 +780,31 @@ public final class MappingUtils
{
if (mapping.involvesSequence(sequence))
{
- result.add(mapping);
+ if (filterList != null)
+ {
+ for (SequenceI otherseq : filterList)
+ {
+ SequenceI otherDataset = otherseq.getDatasetSequence();
+ if (otherseq == sequence
+ || otherseq == sequence.getDatasetSequence()
+ || (otherDataset != null && (otherDataset == sequence || otherDataset == sequence
+ .getDatasetSequence())))
+ {
+ // skip sequences in subset which directly relate to sequence
+ continue;
+ }
+ if (mapping.involvesSequence(otherseq))
+ {
+ // selected a mapping contained in subselect alignment
+ result.add(mapping);
+ break;
+ }
+ }
+ }
+ else
+ {
+ result.add(mapping);
+ }
}
}
return result;
@@ -852,7 +893,7 @@ public final class MappingUtils
{
return ranges;
}
-
+
int[] copy = Arrays.copyOf(ranges, ranges.length);
int sxpos = -1;
int cdspos = 0;
@@ -880,7 +921,7 @@ public final class MappingUtils
break;
}
}
-
+
if (sxpos > 0)
{
/*
diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java
index b812feb..3fb384f 100644
--- a/src/jalview/util/Platform.java
+++ b/src/jalview/util/Platform.java
@@ -20,6 +20,9 @@
*/
package jalview.util;
+import java.awt.Toolkit;
+import java.awt.event.MouseEvent;
+
/**
* System platform information used by Applet and Application
*
@@ -74,4 +77,24 @@ public class Platform
f.append(file.substring(lastp));
return f.toString();
}
+
+ /**
+ * Answers true if the mouse event has Meta-down (Command key on Mac) or
+ * Ctrl-down (on other o/s). Note this answers _false_ if the Ctrl key is
+ * pressed instead of the Meta/Cmd key on Mac. To test for Ctrl-click on Mac,
+ * you can use e.isPopupTrigger().
+ *
+ * @param e
+ * @return
+ */
+ public static boolean isControlDown(MouseEvent e)
+ {
+ if (isAMac())
+ {
+ return (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() & e
+ .getModifiers()) != 0;
+ // could we use e.isMetaDown() here?
+ }
+ return e.isControlDown();
+ }
}
diff --git a/src/jalview/util/QuickSort.java b/src/jalview/util/QuickSort.java
index c1ef153..62fd56e 100755
--- a/src/jalview/util/QuickSort.java
+++ b/src/jalview/util/QuickSort.java
@@ -670,7 +670,7 @@ public class QuickSort
final int length = arr.length;
Integer[] indices = makeIndexArray(length);
Arrays.sort(indices, new IntComparator(arr, ascending));
-
+
/*
* Copy the array values as per the sorted indices
*/
@@ -681,7 +681,7 @@ public class QuickSort
sortedInts[i] = arr[indices[i]];
sortedObjects[i] = s[indices[i]];
}
-
+
/*
* And copy the sorted values back into the arrays
*/
@@ -707,7 +707,7 @@ public class QuickSort
final int length = arr.length;
Integer[] indices = makeIndexArray(length);
Arrays.sort(indices, new ExternalComparator(arr, ascending));
-
+
/*
* Copy the array values as per the sorted indices
*/
@@ -718,7 +718,7 @@ public class QuickSort
sortedStrings[i] = arr[indices[i]];
sortedObjects[i] = s[indices[i]];
}
-
+
/*
* And copy the sorted values back into the arrays
*/
@@ -743,7 +743,7 @@ public class QuickSort
final int length = arr.length;
Integer[] indices = makeIndexArray(length);
Arrays.sort(indices, new DoubleComparator(arr, ascending));
-
+
/*
* Copy the array values as per the sorted indices
*/
@@ -754,7 +754,7 @@ public class QuickSort
sortedDoubles[i] = arr[indices[i]];
sortedObjects[i] = s[indices[i]];
}
-
+
/*
* And copy the sorted values back into the arrays
*/
diff --git a/src/jalview/util/SparseCount.java b/src/jalview/util/SparseCount.java
new file mode 100644
index 0000000..e6b45f2
--- /dev/null
+++ b/src/jalview/util/SparseCount.java
@@ -0,0 +1,154 @@
+package jalview.util;
+
+import jalview.ext.android.SparseIntArray;
+import jalview.ext.android.SparseShortArray;
+
+/**
+ * A class to count occurrences of characters with minimal memory footprint.
+ * Sparse arrays of short values are used to hold the counts, with automatic
+ * promotion to arrays of int if any count exceeds the maximum value for a
+ * short.
+ *
+ * @author gmcarstairs
+ *
+ */
+public class SparseCount
+{
+ private static final int DEFAULT_PROFILE_SIZE = 2;
+
+ /*
+ * array of keys (chars) and values (counts)
+ * held either as shorts or (if shorts overflow) as ints
+ */
+ private SparseShortArray shortProfile;
+
+ private SparseIntArray intProfile;
+
+ /*
+ * flag is set true after short overflow occurs
+ */
+ private boolean useInts;
+
+ /**
+ * Constructor which initially creates a new sparse array of short values to
+ * hold counts.
+ *
+ * @param profileSize
+ */
+ public SparseCount(int profileSize)
+ {
+ this.shortProfile = new SparseShortArray(profileSize);
+ }
+
+ /**
+ * Constructor which allocates an initial count array for only two distinct
+ * values (the array will grow if needed)
+ */
+ public SparseCount()
+ {
+ this(DEFAULT_PROFILE_SIZE);
+ }
+
+ /**
+ * Adds the given value for the given key (or sets the initial value), and
+ * returns the new value
+ *
+ * @param key
+ * @param value
+ */
+ public int add(int key, int value)
+ {
+ int newValue = 0;
+ if (useInts)
+ {
+ newValue = intProfile.add(key, value);
+ }
+ else
+ {
+ try {
+ newValue = shortProfile.add(key, value);
+ } catch (ArithmeticException e) {
+ handleOverflow();
+ newValue = intProfile.add(key, value);
+ }
+ }
+ return newValue;
+ }
+
+ /**
+ * Switch from counting shorts to counting ints
+ */
+ synchronized void handleOverflow()
+ {
+ int size = shortProfile.size();
+ intProfile = new SparseIntArray(size);
+ for (int i = 0; i < size; i++)
+ {
+ short key = shortProfile.keyAt(i);
+ short value = shortProfile.valueAt(i);
+ intProfile.put(key, value);
+ }
+ shortProfile = null;
+ useInts = true;
+ }
+
+ /**
+ * Returns the size of the profile (number of distinct items counted)
+ *
+ * @return
+ */
+ public int size()
+ {
+ return useInts ? intProfile.size() : shortProfile.size();
+ }
+
+ /**
+ * Returns the value for the key (zero if no such key)
+ *
+ * @param key
+ * @return
+ */
+ public int get(int key)
+ {
+ return useInts ? intProfile.get(key) : shortProfile.get(key);
+ }
+
+ /**
+ * Sets the value for the given key
+ *
+ * @param key
+ * @param value
+ */
+ public void put(int key, int value)
+ {
+ if (useInts)
+ {
+ intProfile.put(key, value);
+ }
+ else
+ {
+ shortProfile.put(key, value);
+ }
+ }
+
+ public int keyAt(int k)
+ {
+ return useInts ? intProfile.keyAt(k) : shortProfile.keyAt(k);
+ }
+
+ public int valueAt(int k)
+ {
+ return useInts ? intProfile.valueAt(k) : shortProfile.valueAt(k);
+ }
+
+ /**
+ * Answers true if this object wraps arrays of int values, false if using
+ * short values
+ *
+ * @return
+ */
+ boolean isUsingInt()
+ {
+ return useInts;
+ }
+}
diff --git a/src/jalview/util/StringUtils.java b/src/jalview/util/StringUtils.java
index 6044655..b5ab40d 100644
--- a/src/jalview/util/StringUtils.java
+++ b/src/jalview/util/StringUtils.java
@@ -248,7 +248,7 @@ public class StringUtils
}
return "" + separator;
}
-
+
/**
* Converts a list to a string with a delimiter before each term except the
* first. Returns an empty string given a null or zero-length argument. This
@@ -299,4 +299,108 @@ public class StringUtils
}
return result;
}
+
+ /**
+ * Compares two versions formatted as e.g. "3.4.5" and returns -1, 0 or 1 as
+ * the first version precedes, is equal to, or follows the second
+ *
+ * @param v1
+ * @param v2
+ * @return
+ */
+ public static int compareVersions(String v1, String v2)
+ {
+ return compareVersions(v1, v2, null);
+ }
+
+ /**
+ * Compares two versions formatted as e.g. "3.4.5b1" and returns -1, 0 or 1 as
+ * the first version precedes, is equal to, or follows the second
+ *
+ * @param v1
+ * @param v2
+ * @param pointSeparator
+ * a string used to delimit point increments in sub-tokens of the
+ * version
+ * @return
+ */
+ public static int compareVersions(String v1, String v2,
+ String pointSeparator)
+ {
+ if (v1 == null || v2 == null)
+ {
+ return 0;
+ }
+ String[] toks1 = v1.split("\\.");
+ String[] toks2 = v2.split("\\.");
+ int i = 0;
+ for (; i < toks1.length; i++)
+ {
+ if (i >= toks2.length)
+ {
+ /*
+ * extra tokens in v1
+ */
+ return 1;
+ }
+ String tok1 = toks1[i];
+ String tok2 = toks2[i];
+ if (pointSeparator != null)
+ {
+ /*
+ * convert e.g. 5b2 into decimal 5.2 for comparison purposes
+ */
+ tok1 = tok1.replace(pointSeparator, ".");
+ tok2 = tok2.replace(pointSeparator, ".");
+ }
+ try
+ {
+ float f1 = Float.valueOf(tok1);
+ float f2 = Float.valueOf(tok2);
+ int comp = Float.compare(f1, f2);
+ if (comp != 0)
+ {
+ return comp;
+ }
+ } catch (NumberFormatException e)
+ {
+ System.err.println("Invalid version format found: "
+ + e.getMessage());
+ return 0;
+ }
+ }
+
+ if (i < toks2.length)
+ {
+ /*
+ * extra tokens in v2
+ */
+ return -1;
+ }
+
+ /*
+ * same length, all tokens match
+ */
+ return 0;
+ }
+
+ /**
+ * Converts the string to all lower-case except the first character which is
+ * upper-cased
+ *
+ * @param s
+ * @return
+ */
+ public static String toSentenceCase(String s)
+ {
+ if (s == null)
+ {
+ return s;
+ }
+ if (s.length() <= 1)
+ {
+ return s.toUpperCase();
+ }
+ return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
+ }
}
diff --git a/src/jalview/util/UrlConstants.java b/src/jalview/util/UrlConstants.java
new file mode 100644
index 0000000..ce6d980
--- /dev/null
+++ b/src/jalview/util/UrlConstants.java
@@ -0,0 +1,60 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.util;
+
+/**
+ * A class to hold constants relating to Url links used in Jalview
+ */
+public class UrlConstants
+{
+
+ /*
+ * Sequence ID string
+ */
+ public static final String SEQUENCE_ID = "SEQUENCE_ID";
+
+ /*
+ * Sequence Name string
+ */
+ public static final String SEQUENCE_NAME = "SEQUENCE_NAME";
+
+ /*
+ * Default sequence URL link string for EMBL-EBI search
+ */
+ public static final String EMBLEBI_STRING = "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_NAME$";
+
+ /*
+ * Default sequence URL link string for EMBL-EBI search
+ */
+ public static final String OLD_EMBLEBI_STRING = "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$";
+
+ /*
+ * Default sequence URL link string for SRS
+ */
+ public static final String SRS_STRING = "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry";
+
+ /*
+ * not instantiable
+ */
+ private UrlConstants()
+ {
+ }
+}
diff --git a/src/jalview/util/UrlLink.java b/src/jalview/util/UrlLink.java
index 4297090..872f432 100644
--- a/src/jalview/util/UrlLink.java
+++ b/src/jalview/util/UrlLink.java
@@ -20,6 +20,9 @@
*/
package jalview.util;
+import static jalview.util.UrlConstants.SEQUENCE_ID;
+import static jalview.util.UrlConstants.SEQUENCE_NAME;
+
import java.util.Vector;
public class UrlLink
@@ -37,6 +40,8 @@ public class UrlLink
private boolean dynamic = false;
+ private boolean uses_seq_id = false;
+
private String invalidMessage = null;
/**
@@ -48,81 +53,40 @@ public class UrlLink
*/
public UrlLink(String link)
{
- int sep = link.indexOf("|"), psqid = link.indexOf("$SEQUENCE_ID");
+ int sep = link.indexOf("|");
+ int psqid = link.indexOf("$" + SEQUENCE_ID);
+ int nsqid = link.indexOf("$" + SEQUENCE_NAME);
if (psqid > -1)
{
dynamic = true;
- int p = sep;
- do
- {
- sep = p;
- p = link.indexOf("|", sep + 1);
- } while (p > sep && p < psqid);
- // Assuming that the URL itself does not contain any '|' symbols
- // sep now contains last pipe symbol position prior to any regex symbols
- label = link.substring(0, sep);
- if (label.indexOf("|") > -1)
- {
- // | terminated database name / www target at start of Label
- target = label.substring(0, label.indexOf("|"));
- }
- else if (label.indexOf(" ") > 2)
- {
- // space separated Label - matches database name
- target = label.substring(0, label.indexOf(" "));
- }
- else
- {
- target = label;
- }
- // Parse URL : Whole URL string first
- url_prefix = link.substring(sep + 1, psqid);
- if (link.indexOf("$SEQUENCE_ID=/") == psqid
- && (p = link.indexOf("/=$", psqid + 14)) > psqid + 14)
- {
- // Extract Regex and suffix
- url_suffix = link.substring(p + 3);
- regexReplace = link.substring(psqid + 14, p);
- try
- {
- com.stevesoft.pat.Regex rg = com.stevesoft.pat.Regex.perlCode("/"
- + regexReplace + "/");
- if (rg == null)
- {
- invalidMessage = "Invalid Regular Expression : '"
- + regexReplace + "'\n";
- }
- } catch (Exception e)
- {
- invalidMessage = "Invalid Regular Expression : '" + regexReplace
- + "'\n";
- }
- }
- else
- {
- regexReplace = null;
- // verify format is really correct.
- if (link.indexOf("$SEQUENCE_ID$") == psqid)
- {
- url_suffix = link.substring(psqid + 13);
- regexReplace = null;
- }
- else
- {
- invalidMessage = "Warning: invalid regex structure for URL link : "
- + link;
- }
- }
+ uses_seq_id = true;
+
+ sep = parseTargetAndLabel(sep, psqid, link);
+
+ parseUrl(link, SEQUENCE_ID, psqid, sep);
+ }
+ else if (nsqid > -1)
+ {
+ dynamic = true;
+ sep = parseTargetAndLabel(sep, nsqid, link);
+
+ parseUrl(link, SEQUENCE_NAME, nsqid, sep);
}
else
{
target = link.substring(0, sep);
- label = link.substring(0, sep = link.lastIndexOf("|"));
+ sep = link.lastIndexOf("|");
+ label = link.substring(0, sep);
url_prefix = link.substring(sep + 1);
regexReplace = null; // implies we trim any prefix if necessary //
// regexReplace=".*\\|?(.*)";
url_suffix = null;
}
+
+ label = label.trim();
+ target = target.trim();
+ target = target.toUpperCase(); // DBRefEntry uppercases DB names
+ // NB getCanonicalName might be better but does not currently change case
}
/**
@@ -295,15 +259,122 @@ public class UrlLink
}
}
+ @Override
public String toString()
{
+ String var = (uses_seq_id ? SEQUENCE_ID : SEQUENCE_NAME);
+
return label
+ "|"
+ url_prefix
- + (dynamic ? ("$SEQUENCE_ID" + ((regexReplace != null) ? "="
+ + (dynamic ? ("$" + var + ((regexReplace != null) ? "="
+ regexReplace + "=$" : "$")) : "")
+ ((url_suffix == null) ? "" : url_suffix);
+ }
+
+ /**
+ *
+ * @param firstSep
+ * Location of first occurrence of separator in link string
+ * @param psqid
+ * Position of sequence id or name in link string
+ * @param link
+ * Link string containing database name and url
+ * @return Position of last separator symbol prior to any regex symbols
+ */
+ protected int parseTargetAndLabel(int firstSep, int psqid, String link)
+ {
+ int p = firstSep;
+ int sep = firstSep;
+ do
+ {
+ sep = p;
+ p = link.indexOf("|", sep + 1);
+ } while (p > sep && p < psqid);
+ // Assuming that the URL itself does not contain any '|' symbols
+ // sep now contains last pipe symbol position prior to any regex symbols
+ label = link.substring(0, sep);
+ if (label.indexOf("|") > -1)
+ {
+ // | terminated database name / www target at start of Label
+ target = label.substring(0, label.indexOf("|"));
+ }
+ else if (label.indexOf(" ") > 2)
+ {
+ // space separated Label - matches database name
+ target = label.substring(0, label.indexOf(" "));
+ }
+ else
+ {
+ target = label;
+ }
+ return sep;
+ }
+
+ /**
+ * Parse the URL part of the link string
+ *
+ * @param link
+ * Link string containing database name and url
+ * @param varName
+ * Name of variable in url string (e.g. SEQUENCE_ID, SEQUENCE_NAME)
+ * @param sqidPos
+ * Position of id or name in link string
+ * @param sep
+ * Position of separator in link string
+ */
+ protected void parseUrl(String link, String varName, int sqidPos, int sep)
+ {
+ url_prefix = link.substring(sep + 1, sqidPos);
+
+ // delimiter at start of regex: e.g. $SEQUENCE_ID=/
+ String startDelimiter = "$" + varName + "=/";
+ // delimiter at end of regex: /=$
+ String endDelimiter = "/=$";
+
+ int startLength = startDelimiter.length();
+
+ // Parse URL : Whole URL string first
+ int p = link.indexOf(endDelimiter, sqidPos + startLength);
+
+ if (link.indexOf(startDelimiter) == sqidPos
+ && (p > sqidPos + startLength))
+ {
+ // Extract Regex and suffix
+ url_suffix = link.substring(p + endDelimiter.length());
+ regexReplace = link.substring(sqidPos + startLength, p);
+ try
+ {
+ com.stevesoft.pat.Regex rg = com.stevesoft.pat.Regex.perlCode("/"
+ + regexReplace + "/");
+ if (rg == null)
+ {
+ invalidMessage = "Invalid Regular Expression : '" + regexReplace
+ + "'\n";
+ }
+ } catch (Exception e)
+ {
+ invalidMessage = "Invalid Regular Expression : '" + regexReplace
+ + "'\n";
+ }
+ }
+ else
+ {
+ // no regex
+ regexReplace = null;
+ // verify format is really correct.
+ if (link.indexOf("$" + varName + "$") == sqidPos)
+ {
+ url_suffix = link.substring(sqidPos + startLength - 1);
+ regexReplace = null;
+ }
+ else
+ {
+ invalidMessage = "Warning: invalid regex structure for URL link : "
+ + link;
+ }
+ }
}
private static void testUrls(UrlLink ul, String idstring, String[] urls)
@@ -341,7 +412,8 @@ public class UrlLink
* "PF3|http://us.expasy.org/cgi-bin/niceprot.pl?$SEQUENCE_ID=/PFAM:(.+)/=$"
* , "NOTFER|http://notfer.org/$SEQUENCE_ID=/(? 0 && mapLists[0].getFromRatio() == 3)
+ boolean doConsensus = false;
+ for (AlignedCodonFrame mapping : al.getCodonFrames())
+ {
+ // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
+ MapList[] mapLists = mapping.getdnaToProt();
+ // mapLists can be empty if project load has not finished resolving seqs
+ if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
+ {
+ doConsensus = true;
+ break;
+ }
+ }
+ if (doConsensus)
{
if (calculator
.getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
@@ -905,6 +916,37 @@ public abstract class AlignmentViewport implements AlignViewportI,
return false;
}
+ public void setAlignment(AlignmentI align)
+ {
+ this.alignment = align;
+ }
+
+ /**
+ * Clean up references when this viewport is closed
+ */
+ @Override
+ public void dispose()
+ {
+ /*
+ * defensively null out references to large objects in case
+ * this object is not garbage collected (as if!)
+ */
+ consensus = null;
+ complementConsensus = null;
+ strucConsensus = null;
+ conservation = null;
+ quality = null;
+ groupConsensus = null;
+ groupConservation = null;
+ hconsensus = null;
+ hcomplementConsensus = null;
+ // colour scheme may hold reference to consensus
+ globalColourScheme = null;
+ // TODO remove listeners from changeSupport?
+ changeSupport = null;
+ setAlignment(null);
+ }
+
@Override
public boolean isClosed()
{
@@ -1078,6 +1120,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
{
updateHiddenColumns();
}
+ isColSelChanged(true);
}
/**
@@ -1098,6 +1141,13 @@ public abstract class AlignmentViewport implements AlignViewportI,
}
@Override
+ public boolean hasSelectedColumns()
+ {
+ ColumnSelection columnSelection = getColumnSelection();
+ return columnSelection != null && columnSelection.hasSelectedColumns();
+ }
+
+ @Override
public boolean hasHiddenColumns()
{
return colSel != null && colSel.hasHiddenColumns();
@@ -1206,8 +1256,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
*/
public boolean isColSelChanged(boolean b)
{
- int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel
- .hashCode();
+ int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
if (hc != -1 && hc != colselhash)
{
if (b)
@@ -1225,10 +1274,9 @@ public abstract class AlignmentViewport implements AlignViewportI,
return ignoreGapsInConsensusCalculation;
}
- // / property change stuff
-
+ // property change stuff
// JBPNote Prolly only need this in the applet version.
- private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
+ private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
this);
protected boolean showConservation = true;
@@ -1308,7 +1356,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
colSel.hideSelectedColumns();
setSelectionGroup(null);
-
+ isColSelChanged(true);
}
public void hideColumns(int start, int end)
@@ -1321,17 +1369,19 @@ public abstract class AlignmentViewport implements AlignViewportI,
{
colSel.hideColumns(start, end);
}
+ isColSelChanged(true);
}
public void showColumn(int col)
{
colSel.revealHiddenColumns(col);
-
+ isColSelChanged(true);
}
public void showAllHiddenColumns()
{
colSel.revealAllHiddenColumns();
+ isColSelChanged(true);
}
// common hide/show seq stuff
@@ -1411,6 +1461,39 @@ public abstract class AlignmentViewport implements AlignViewportI,
}
/**
+ * Hides the specified sequence, or the sequences it represents
+ *
+ * @param sequence
+ * the sequence to hide, or keep as representative
+ * @param representGroup
+ * if true, hide the current selection group except for the
+ * representative sequence
+ */
+ public void hideSequences(SequenceI sequence, boolean representGroup)
+ {
+ if (selectionGroup == null || selectionGroup.getSize() < 1)
+ {
+ hideSequence(new SequenceI[] { sequence });
+ return;
+ }
+
+ if (representGroup)
+ {
+ hideRepSequences(sequence, selectionGroup);
+ setSelectionGroup(null);
+ return;
+ }
+
+ int gsize = selectionGroup.getSize();
+ SequenceI[] hseqs = selectionGroup.getSequences().toArray(
+ new SequenceI[gsize]);
+
+ hideSequence(hseqs);
+ setSelectionGroup(null);
+ sendSelection();
+ }
+
+ /**
* Set visibility for any annotations for the given sequence.
*
* @param sequenceI
@@ -1418,11 +1501,15 @@ public abstract class AlignmentViewport implements AlignViewportI,
protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
boolean visible)
{
- for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
+ AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
+ if (anns != null)
{
- if (ann.sequenceRef == sequenceI)
+ for (AlignmentAnnotation ann : anns)
{
- ann.visible = visible;
+ if (ann.sequenceRef == sequenceI)
+ {
+ ann.visible = visible;
+ }
}
}
}
@@ -1463,13 +1550,42 @@ public abstract class AlignmentViewport implements AlignViewportI,
}
+ /**
+ *
+ * @return null or the current reference sequence
+ */
+ public SequenceI getReferenceSeq()
+ {
+ return alignment.getSeqrep();
+ }
+
+ /**
+ * @param seq
+ * @return true iff seq is the reference for the alignment
+ */
+ public boolean isReferenceSeq(SequenceI seq)
+ {
+ return alignment.getSeqrep() == seq;
+ }
+
+ /**
+ *
+ * @param seq
+ * @return true if there are sequences represented by this sequence that are
+ * currently hidden
+ */
public boolean isHiddenRepSequence(SequenceI seq)
{
- return alignment.getSeqrep() == seq
- || (hiddenRepSequences != null && hiddenRepSequences
- .containsKey(seq));
+ return (hiddenRepSequences != null && hiddenRepSequences
+ .containsKey(seq));
}
+ /**
+ *
+ * @param seq
+ * @return null or a sequence group containing the sequences that seq
+ * represents
+ */
public SequenceGroup getRepresentedSequences(SequenceI seq)
{
return (SequenceGroup) (hiddenRepSequences == null ? null
@@ -1557,6 +1673,13 @@ public abstract class AlignmentViewport implements AlignViewportI,
@Override
public String[] getViewAsString(boolean selectedRegionOnly)
{
+ return getViewAsString(selectedRegionOnly, true);
+ }
+
+ @Override
+ public String[] getViewAsString(boolean selectedRegionOnly,
+ boolean exportHiddenSeqs)
+ {
String[] selection = null;
SequenceI[] seqs = null;
int i, iSize;
@@ -1570,13 +1693,13 @@ public abstract class AlignmentViewport implements AlignViewportI,
}
else
{
- if (hasHiddenRows())
+ if (hasHiddenRows() && exportHiddenSeqs)
{
- iSize = alignment.getHiddenSequences().getFullAlignment()
- .getHeight();
- seqs = alignment.getHiddenSequences().getFullAlignment()
- .getSequencesArray();
- end = alignment.getHiddenSequences().getFullAlignment().getWidth();
+ AlignmentI fullAlignment = alignment.getHiddenSequences()
+ .getFullAlignment();
+ iSize = fullAlignment.getHeight();
+ seqs = fullAlignment.getSequencesArray();
+ end = fullAlignment.getWidth();
}
else
{
@@ -1744,9 +1867,9 @@ public abstract class AlignmentViewport implements AlignViewportI,
cs.setConsensus(hconsensus);
if (cs.conservationApplied())
{
- cs.setConservation(Conservation.calculateConservation("All",
- ResidueProperties.propHash, 3, alignment.getSequences(), 0,
- alignment.getWidth(), false, getConsPercGaps(), false));
+ cs.setConservation(Conservation.calculateConservation("All", 3,
+ alignment.getSequences(), 0, alignment.getWidth(), false,
+ getConsPercGaps(), false));
}
}
@@ -1797,12 +1920,20 @@ public abstract class AlignmentViewport implements AlignViewportI,
.getCodonFrames();
if (codonMappings != null && !codonMappings.isEmpty())
{
- // fudge: check mappings are not protein-to-protein
- // TODO: nicer
- AlignedCodonFrame mapping = codonMappings.iterator().next();
- MapList[] mapLists = mapping.getdnaToProt();
- // mapLists can be empty if project load has not finished resolving seqs
- if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
+ boolean doConsensus = false;
+ for (AlignedCodonFrame mapping : codonMappings)
+ {
+ // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
+ MapList[] mapLists = mapping.getdnaToProt();
+ // mapLists can be empty if project load has not finished resolving
+ // seqs
+ if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
+ {
+ doConsensus = true;
+ break;
+ }
+ }
+ if (doConsensus)
{
complementConsensus = new AlignmentAnnotation("cDNA Consensus",
"PID for cDNA", new Annotation[1], 0f, 100f,
@@ -2625,6 +2756,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
* all gapped visible regions
*/
int lastSeq = alignment.getHeight() - 1;
+ List seqMappings = null;
for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
{
sequence = getAlignment().getSequenceAt(seqNo);
@@ -2636,15 +2768,16 @@ public abstract class AlignmentViewport implements AlignViewportI,
{
continue;
}
- List seqMappings = MappingUtils
- .findMappingsForSequence(sequence, mappings);
+ seqMappings = MappingUtils
+ .findMappingsForSequenceAndOthers(sequence, mappings,
+ getCodingComplement().getAlignment().getSequences());
if (!seqMappings.isEmpty())
{
break;
}
}
- if (sequence == null)
+ if (sequence == null || seqMappings == null || seqMappings.isEmpty())
{
/*
* No ungapped mapped sequence in middle column - do nothing
@@ -2652,7 +2785,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
return 0;
}
MappingUtils.addSearchResults(sr, sequence,
- sequence.findPosition(middleColumn), mappings);
+ sequence.findPosition(middleColumn), seqMappings);
return seqOffset;
}
@@ -2667,11 +2800,9 @@ public abstract class AlignmentViewport implements AlignViewportI,
public void expandColSelection(SequenceGroup sg, boolean wholewidth)
{
int sgs, sge;
- if (sg != null
- && (sgs = sg.getStartRes()) >= 0
+ if (sg != null && (sgs = sg.getStartRes()) >= 0
&& sg.getStartRes() <= (sge = sg.getEndRes())
- && (colSel == null || colSel.getSelected() == null || colSel
- .getSelected().size() == 0))
+ && !this.hasSelectedColumns())
{
if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
{
@@ -2688,4 +2819,33 @@ public abstract class AlignmentViewport implements AlignViewportI,
}
}
}
+
+ /**
+ * hold status of current selection group - defined on alignment or not.
+ */
+ private boolean selectionIsDefinedGroup = false;
+
+ @Override
+ public boolean isSelectionDefinedGroup()
+ {
+ if (selectionGroup == null)
+ {
+ return false;
+ }
+ if (isSelectionGroupChanged(true))
+ {
+ selectionIsDefinedGroup = false;
+ List gps = alignment.getGroups();
+ if (gps == null || gps.size() == 0)
+ {
+ selectionIsDefinedGroup = false;
+ }
+ else
+ {
+ selectionIsDefinedGroup = gps.contains(selectionGroup);
+ }
+ }
+ return selectionGroup.getContext() == alignment
+ || selectionIsDefinedGroup;
+ }
}
diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java
index 5b55e05..4ac4804 100644
--- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java
+++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java
@@ -27,8 +27,8 @@ import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.renderer.seqfeatures.FeatureRenderer;
-import jalview.schemes.GraduatedColor;
-import jalview.viewmodel.AlignmentViewport;
+import jalview.schemes.FeatureColour;
+import jalview.schemes.UserColourScheme;
import java.awt.Color;
import java.beans.PropertyChangeListener;
@@ -52,21 +52,18 @@ public abstract class FeatureRendererModel implements
*/
protected float transparency = 1.0f;
- protected Map featureColours = new ConcurrentHashMap();
+ protected Map featureColours = new ConcurrentHashMap();
protected Map featureGroups = new ConcurrentHashMap();
- protected Object currentColour;
-
- /*
- * feature types in ordering of rendering, where last means on top
- */
protected String[] renderOrder;
+ Map featureOrder = null;
+
protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
this);
- protected AlignmentViewport av;
+ protected AlignViewportI av;
@Override
public AlignViewportI getViewport()
@@ -194,9 +191,9 @@ public abstract class FeatureRendererModel implements
renderOrder = neworder;
}
- protected Hashtable minmax = new Hashtable();
+ protected Map minmax = new Hashtable