import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
+import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.Profile;
import jalview.datamodel.ProfileI;
import jalview.datamodel.Profiles;
import jalview.datamodel.ResidueCount.SymbolCounts;
import jalview.datamodel.SequenceI;
import jalview.ext.android.SparseIntArray;
+import jalview.schemes.ResidueProperties;
import jalview.util.Comparison;
import jalview.util.Format;
import jalview.util.MappingUtils;
{
public static final String PROFILE = "P";
+ private static final String AMINO = "amino";
+
+ private static final String DNA = "DNA";
+
/*
* Quick look-up of String value of char 'A' to 'Z'
*/
}
return scale;
}
+
+ /**
+ * produces a HMM profile for a column in an alignment
+ *
+ * @param aa
+ * Alignment annotation for which the profile is being calculated
+ * @param column
+ * column in the alignment the profile is being made for
+ * @param removeBelowBackground
+ * boolean, indicating whether to ignore residues with probabilities
+ * less than their background frequencies
+ * @return
+ */
+ public static int[] getHMMProfileFor(AlignmentAnnotation aa, int column,
+ boolean removeBelowBackground)
+ {
+
+ HiddenMarkovModel hmm;
+ hmm = aa.getHMM();
+ if (hmm != null)
+ {
+ String alph = hmm.getAlphabetType();
+ int size = hmm.getNumberOfSymbols();
+ char symbols[] = new char[size];
+ int values[] = new int[size];
+ List<Character> charList = hmm.getSymbols();
+ Integer totalCount = 0;
+
+ for (int i = 0; i < size; i++)
+ {
+ char symbol = charList.get(i);
+ symbols[i] = symbol;
+ Double value;
+
+ value = hmm.getMatchEmissionProbability(column, symbol);
+ double freq;
+
+ if (alph == AMINO && removeBelowBackground)
+ {
+ freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol);
+ if (value < freq)
+ {
+ value = 0d;
+ }
+ }
+ else if (alph == DNA && removeBelowBackground)
+ {
+ freq = ResidueProperties.nucleotideBackgroundFrequencies
+ .get(symbol);
+ if (value < freq)
+ {
+ value = 0d;
+ }
+ }
+ value = value * 10000;
+ values[i] = value.intValue();
+ totalCount += value.intValue();
+ }
+
+ QuickSort.sort(values, symbols);
+
+ int[] profile = new int[3 + size * 2];
+
+ profile[0] = AlignmentAnnotation.SEQUENCE_PROFILE;
+ profile[1] = size;
+ profile[2] = totalCount / 100;
+
+ if (totalCount != 0)
+ {
+ int arrayPos = 3;
+ for (int k = size - 1; k >= 0; k--)
+ {
+ Double percentage;
+ Integer value = values[k];
+ percentage = (value.doubleValue() / totalCount.doubleValue())
+ * 100d;
+ profile[arrayPos] = symbols[k];
+ profile[arrayPos + 1] = percentage.intValue();
+ arrayPos += 2;
+ }
+ }
+ return profile;
+ }
+ return null;
+ }
}
*/
private boolean ignoreGapsInConsensus = true;
+ private boolean ignoreBelowBackground = true;
+
/**
* consensus calculation property
*/
thresholdTextColour = seqsel.thresholdTextColour;
width = seqsel.width;
ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
+ ignoreBelowBackground = seqsel.ignoreBelowBackground;
if (seqsel.conserve != null)
{
recalcConservation(); // safer than
return ignoreGapsInConsensus;
}
+ public void setIgnoreBelowBackground(boolean state)
+ {
+ if (this.ignoreBelowBackground != state)
+ {
+ ignoreBelowBackground = state;
+ }
+ ignoreBelowBackground = state;
+ }
+
+ public boolean getIgnoreBelowBackground()
+ {
+ return true;
+ }
+
/**
* @param showSequenceLogo
* indicates if a sequence logo is shown for consensus annotation
}
else if (FileFormat.HMMER3.equals(format))
{
- HMMFile hmmFile = new HMMFile(new FileParse(file, sourceType));
+ HMMFile hmmFile = new HMMFile(new FileParse(file, sourceType)); // TODO
+ // need
+ // to
+ // follow
+ // standard
+ // pipeline
hmmFile.parse();
HiddenMarkovModel hmm = hmmFile.getHMM();
AlignmentAnnotation annotation = hmm.createAnnotation(
else if (label.indexOf("Consensus") > -1
|| label.indexOf("Information Content") > -1)
{
+ // identifier for type of histogram and/or logo to be shown
+ int type = 2;
+ if (label.indexOf("Consensus") > -1)
+ {
+ type = 0;
+ }
+ else if (label.indexOf("Information Content") > -1)
+ {
+ type = 1;
+ }
+
pop.addSeparator();
// av and sequencegroup need to implement same interface for
+ final AlignmentAnnotation aaa = aa[selectedRow];
+ if (type == 0)
+ {
final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
- MessageManager.getString("label.ignore_gaps_consensus"),
+ MessageManager.getString("label.ignore_gaps_consensus"),
(aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
.getIgnoreGapsConsensus() : ap.av
.isIgnoreGapsConsensus());
- final AlignmentAnnotation aaa = aa[selectedRow];
+
cbmi.addActionListener(new ActionListener()
{
@Override
}
});
pop.add(cbmi);
+ }
+ if (type == 1)
+ {
+ final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
+ "Ignore Below Background Frequency",
+ (aa[selectedRow].groupRef != null)
+ ? aa[selectedRow].groupRef
+ .getIgnoreBelowBackground()
+ : ap.av.isIgnoreBelowBackground());
+
+ cbmi.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ if (aaa.groupRef != null)
+ {
+ // TODO: pass on reference to ap so the view can be updated.
+ aaa.groupRef.setIgnoreBelowBackground(cbmi.getState());
+ ap.getAnnotationPanel()
+ .paint(ap.getAnnotationPanel().getGraphics());
+ }
+ else
+ {
+ ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
+ }
+ ap.alignmentChanged();
+ }
+ });
+ pop.add(cbmi);
+ }
// av and sequencegroup need to implement same interface for
if (aaa.groupRef != null)
{
import jalview.datamodel.Annotation;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.HiddenColumns;
-import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.ProfilesI;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.NucleotideColourScheme;
import jalview.schemes.ResidueProperties;
import jalview.schemes.ZappoColourScheme;
import jalview.util.Platform;
-import jalview.util.QuickSort;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.image.ImageObserver;
import java.util.BitSet;
import java.util.Hashtable;
-import java.util.List;
public class AnnotationRenderer
{
private static final int CHAR_Z = 'Z'; // 90
- private static final int AMINO = 0;
-
- private static final int DNA = 1;
-
/**
* flag indicating if timing and redraw parameter info should be output
*/
av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
}
- public int[] getHMMProfileFor(AlignmentAnnotation aa, int column,
- boolean removeBelowBackground)
- {
-
- HiddenMarkovModel hmm;
- hmm = aa.getHMM();
- int size = 0;
- int alphabet = 0;
- String alph = hmm.getAlphabetType();
- if (alph.equals("amino"))
- {
- size = 20;
- alphabet = AMINO;
- }
- else if (alph.equals("DNA"))
- {
- size = 4;
- alphabet = DNA;
- }
-
- char symbols[] = new char[size];
- int values[] = new int[size];
- List<Character> charList = hmm.getSymbols();
-
- int i = 0;
- for (char character : charList)
- {
- symbols[i] = character;
- i++;
- }
-
- Integer totalCount = 0;
- for (int j = 0; j < size; j++)
- {
- Double value;
- char symbol = symbols[j];
- value = hmm.getMatchEmissionProbability(column, symbol);
- double freq;
-
- if (alphabet == AMINO && removeBelowBackground)
- {
- freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol);
- if (value < freq)
- {
- value = 0d;
- }
- }
- else if (alphabet == DNA && removeBelowBackground)
- {
- freq = ResidueProperties.nucleotideBackgroundFrequencies
- .get(symbol);
- if (value < freq)
- {
- value = 0d;
- }
- }
- value = value * 10000;
- values[j] = value.intValue();
- totalCount += value.intValue();
- }
-
- QuickSort.sort(values, symbols);
-
- int[] profile = new int[3 + size * 2];
-
- profile[0] = AlignmentAnnotation.SEQUENCE_PROFILE;
- profile[1] = size;
- profile[2] = totalCount;
-
- if (totalCount != 0)
- {
- int arrayPos = 3;
- for (int k = size - 1; k >= 0; k--)
- {
- Double percentage;
- Integer value = values[k];
- percentage = (value.doubleValue() / totalCount.doubleValue())
- * 100d;
- profile[arrayPos] = symbols[k];
- profile[arrayPos + 1] = percentage.intValue();
- arrayPos += 2;
- }
- }
-
- return profile;
-
- }
/**
* Returns profile data; the first element is the profile type, the second is
//
if (aa.label.startsWith("Information"))
{
- return getHMMProfileFor(aa, column, true);
+ return AAFrequency.getHMMProfileFor(aa, column,
+ true); // TODO detect setting
}
if (aa.autoCalculated
&& (aa.label.startsWith("Consensus") || aa.label
protected boolean ignoreGapsInConsensusCalculation = false;
+ protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
+
protected ResidueShaderI residueShading = new ResidueShader();
@Override
}
+ public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
+ {
+ ignoreBelowBackGroundFrequencyCalculation = b;
+ if (ap != null)
+ {
+ // updateConsensus(ap);
+ if (residueShading != null)
+ {
+ residueShading.setThreshold(residueShading.getThreshold(),
+ ignoreBelowBackGroundFrequencyCalculation);
+ }
+ }
+
+ }
+
private long sgrouphash = -1, colselhash = -1;
/**
return ignoreGapsInConsensusCalculation;
}
+ public boolean isIgnoreBelowBackground()
+ {
+ return ignoreBelowBackGroundFrequencyCalculation;
+ }
+
// property change stuff
// JBPNote Prolly only need this in the applet version.
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.Annotation;
+import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.ProfileI;
import jalview.datamodel.ProfilesI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.gui.JvOptionPane;
+import jalview.io.DataSourceType;
+import jalview.io.FileParse;
+import jalview.io.HMMFile;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
assertEquals("T 75%", ann.description);
assertEquals("T", ann.displayCharacter);
}
+
+ @Test(groups = { "Functional" })
+ public void testGetHMMProfileFor()
+ throws MalformedURLException, IOException
+ {
+
+ HMMFile hmmFile = new HMMFile(new FileParse(
+ "test/jalview/io/test_MADE1_hmm.txt", DataSourceType.FILE));
+ hmmFile.parse();
+ HiddenMarkovModel hmm = hmmFile.getHMM();
+ AlignmentAnnotation aa = hmm.createAnnotation(80);
+ aa.setHMM(hmm);
+
+ int[] expected = { 0, 4, 100, 'T', 71, 'C', 12, 'G', 9, 'A', 9 };
+ int[] actual = AAFrequency.getHMMProfileFor(aa, 17, false);
+ for (int i = 0; i < actual.length; i++)
+ {
+ if (i == 2)
+ {
+ assertEquals(actual[i], expected[i], 5);
+ }
+ else
+ {
+ assertEquals(actual[i], expected[i], 1);
+ }
+ }
+
+ int[] expected2 = { 0, 4, 85, 'A', 85, 'C', 0, 'G', 0, 'T', 0 };
+ int[] actual2 = AAFrequency.getHMMProfileFor(aa, 2, true);
+ for (int i = 0; i < actual.length; i++)
+ {
+ if (i == 2)
+ {
+ assertEquals(actual[i], expected[i], 5);
+ }
+ else
+ {
+ assertEquals(actual[i], expected[i], 1);
+ }
+ }
+ }
}