int symbolIndex;
int nodeIndex;
Double probability;
- if (symbol == '-')
+ if (!symbolIndexLookup.containsKey(symbol))
{
return 0d;
}
int symbolIndex;
int nodeIndex;
Double probability;
- if (symbol == '-')
+ if (!symbolIndexLookup.containsKey(symbol))
{
return 0d;
}
--- /dev/null
+package jalview.schemes;
+
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.HiddenMarkovModel;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.awt.Color;
+import java.util.Map;
+
+public class HMMERColourScheme extends ResidueColourScheme
+{
+
+ AnnotatedCollectionI alignment;
+
+ HiddenMarkovModel hmm;
+
+ boolean peptideSpecific;
+
+ boolean nucleotideSpecific;
+
+ public HMMERColourScheme(HiddenMarkovModel markov)
+ {
+ hmm = markov;
+ }
+ public HMMERColourScheme()
+ {
+
+ }
+
+ @Override
+ public Color findColour(char symbol, int position, SequenceI seq,
+ String consensusResidue, float pid)
+ {
+ if (hmm ==null)
+ {
+ return new Color(255, 255, 255);
+ }
+ return findColour(symbol, position);
+ }
+
+ public Color findColour(char symbol, int position)
+ {
+
+
+ Double probability;
+ probability = hmm.getMatchEmissionProbability(position, symbol);
+ // Double redModifier = Math.pow(probability, 0.9);
+ Double doubleGreenModifier;
+ float greenModifier;
+ if (probability < 0.5)
+ {
+ doubleGreenModifier = probability;
+ greenModifier = doubleGreenModifier.floatValue();
+ }
+ else
+ {
+ doubleGreenModifier = Math.pow(probability, 1 / 1.9);
+ greenModifier = doubleGreenModifier.floatValue();
+ }
+ // Double blueModifier = Math.pow(probability, 0.9);
+ return new Color(1f, 1f - greenModifier, 0.f);
+
+ }
+
+ @Override
+ public void alignmentChanged(AnnotatedCollectionI collection,
+ Map<SequenceI, SequenceCollectionI> hiddenReps)
+ {
+
+ collection.setHMM(hmm);
+ }
+
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI sg,
+ Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+ {
+
+
+
+
+
+ HMMERColourScheme markov = new HMMERColourScheme(sg.getHMM());
+ return markov;
+ }
+
+ @Override
+ public boolean isApplicableTo(AnnotatedCollectionI ac)
+ {
+ return true;
+
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+
+ return JalviewColourScheme.HMMER.name();
+ }
+
+ @Override
+ public boolean isSimple()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
HMMFile fn3 = new HMMFile(
- new FileParse("H:/fn3.hmm", DataSourceType.FILE));
+ new FileParse("test/jalview/io/test_fn3_hmm.txt",
+ DataSourceType.FILE));
HMMFile pKinase = new HMMFile(
- new FileParse("H:/Pkinase.hmm", DataSourceType.FILE));
+ new FileParse("test/jalview/io/test_PKinase_hmm.txt",
+ DataSourceType.FILE));
HMMFile made1 = new HMMFile(
- new FileParse("H:/MADE1.hmm", DataSourceType.FILE));
+ new FileParse("test/jalview/io/test_MADE1_hmm.txt",
+ DataSourceType.FILE));
HMMFileTest() throws IOException
{
@Test
public void testParseFileProperties() throws IOException
{
- FileReader fr = new FileReader(new File("H:/fn3.hmm"));
+ FileReader fr = new FileReader(
+ new File("test/jalview/io/test_fn3_hmm.txt"));
BufferedReader br = new BufferedReader(fr);
fn3.parseFileProperties(br);
fn3.parseModel(br); // this is for a later test
assertEquals(testHMM.getForward(), "-3.8341 0.71847");
- FileReader fr3 = new FileReader(new File("H:/MADE1.hmm"));
+ FileReader fr3 = new FileReader(
+ new File("test/jalview/io/test_MADE1_hmm.txt"));
BufferedReader br3 = new BufferedReader(fr3);
made1.parseFileProperties(br3);
testHMM = made1.getHMM();
@Test
public void testParseModel() throws IOException
{
- FileReader fr = new FileReader(new File("H:/MADE1.hmm"));
+ FileReader fr = new FileReader(
+ new File("test/jalview/io/test_MADE1_hmm.txt"));
BufferedReader br = new BufferedReader(fr);
HiddenMarkovModel testHMM = new HiddenMarkovModel();
for (int i = 0; i < 24; i++)
@Test(priority = 3)
public void testExportFile() throws IOException
{
- fn3.exportFile("H:/WriteFileTest.txt");
+ fn3.exportFile("test/jalview/io/test_export_hmm.txt");
HMMFile fn3Clone = new HMMFile(
- new FileParse("H:/WriteFileTest.txt", DataSourceType.FILE));
+ new FileParse("test/jalview/io/test_export_hmm.txt",
+ DataSourceType.FILE));
fn3Clone.parse();
HiddenMarkovModel fn3HMM = new HiddenMarkovModel();
HiddenMarkovModel fn3CloneHMM = new HiddenMarkovModel();
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.io.DataSourceType;
+import jalview.io.FileParse;
+import jalview.io.HMMFile;
+
+import java.awt.Color;
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.testng.annotations.Test;
+
+public class HMMERColourSchemeTest {
+ HMMERColourScheme scheme = new HMMERColourScheme();
+
+ @Test
+ public void testFindColour() throws MalformedURLException, IOException
+ {
+
+ HMMFile file = new HMMFile(new FileParse(
+ "test/jalview/io/test_PKinase_hmm.txt", DataSourceType.FILE));
+ file.parse();
+ scheme.hmm = file.getHMM();
+
+ Color actual = scheme.findColour('A', 1);
+ Color expected = new Color(1f, 1f - 0.06253430455f, 0f);
+ assertEquals(actual, expected);
+
+ actual = scheme.findColour('Y', 3);
+ expected = new Color(1f, 1f - 0.02082023351f, 0f);
+ assertEquals(actual, expected);
+
+ actual = scheme.findColour('M', 109);
+ expected = new Color(1f, 1f, 0);
+ assertEquals(actual, expected);
+
+ actual = scheme.findColour('I', 128);
+ expected = new Color(1f, 1f - 0.15097062462f, 0);
+ assertEquals(actual, expected);
+
+ actual = scheme.findColour('D', 181);
+ expected = new Color(1f, 1f - 0.08686935114f, 0);
+ assertEquals(actual, expected);
+
+ actual = scheme.findColour('Z', 1);
+ expected = new Color(1f, 1f, 0);
+ assertEquals(actual, expected);
+
+ actual = scheme.findColour('A', 4000);
+ expected = new Color(1f, 1f, 0);
+ assertEquals(actual, expected);
+
+ }
+
+}