From 56c4fb001c142a23664c2b595b8d3967e69f0fa6 Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Thu, 29 Jun 2017 17:16:21 +0100 Subject: [PATCH] transferred the storage position of the HMM to annotations --- src/jalview/appletgui/AlignFrame.java | 4 +- src/jalview/datamodel/Alignment.java | 13 -- src/jalview/datamodel/AlignmentAnnotation.java | 28 +++- src/jalview/datamodel/AnnotatedCollectionI.java | 5 +- src/jalview/datamodel/SequenceGroup.java | 12 -- src/jalview/gui/AlignFrame.java | 18 +-- src/jalview/gui/AnnotationLabels.java | 5 +- src/jalview/io/HMMFile.java | 33 +++- src/jalview/schemes/ResidueProperties.java | 86 +++++++--- src/jalview/viewmodel/AlignmentViewport.java | 6 + test/jalview/io/HMMFileTest.java | 191 +++++++++++------------ 11 files changed, 219 insertions(+), 182 deletions(-) diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 2eed311..02d30bb 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -1798,7 +1798,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, synchronized void slideSequences(boolean right, int size) { - List sg = new Vector(); + List sg = new Vector<>(); if (viewport.cursorMode) { sg.add(viewport.getAlignment().getSequenceAt( @@ -1911,7 +1911,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, SequenceGroup sg = viewport.getSelectionGroup(); copiedSequences = new StringBuffer(); - Map orderedSeqs = new HashMap(); + Map orderedSeqs = new HashMap<>(); for (int i = 0; i < sg.getSize(); i++) { SequenceI seq = sg.getSequenceAt(i); diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index a88995d..0b4ffd7 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -68,8 +68,6 @@ public class Alignment implements AlignmentI private List codonFrameList; - HiddenMarkovModel hmm; - private void initAlignment(SequenceI[] seqs) { groups = Collections.synchronizedList(new ArrayList()); @@ -1962,18 +1960,7 @@ public class Alignment implements AlignmentI hiddenCols = cols; } - @Override - public HiddenMarkovModel getHMM() - { - - return hmm; - } - @Override - public void setHMM(HiddenMarkovModel markov) - { - hmm = markov; - } } diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 1594f2b..404f51f 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -53,6 +53,8 @@ public class AlignmentAnnotation private static long counter = 0; + private HiddenMarkovModel hmm; + /** * If true, this annotations is calculated every edit, eg consensus, quality * or conservation graphs @@ -701,7 +703,7 @@ public class AlignmentAnnotation this.calcId = annotation.calcId; if (annotation.properties != null) { - properties = new HashMap(); + properties = new HashMap<>(); for (Map.Entry val : annotation.properties.entrySet()) { properties.put(val.getKey(), val.getValue()); @@ -737,7 +739,7 @@ public class AlignmentAnnotation if (annotation.sequenceMapping != null) { Integer p = null; - sequenceMapping = new HashMap(); + sequenceMapping = new HashMap<>(); Iterator pos = annotation.sequenceMapping.keySet() .iterator(); while (pos.hasNext()) @@ -817,7 +819,7 @@ public class AlignmentAnnotation int epos = sequenceRef.findPosition(endRes); if (sequenceMapping != null) { - Map newmapping = new HashMap(); + Map newmapping = new HashMap<>(); Iterator e = sequenceMapping.keySet().iterator(); while (e.hasNext()) { @@ -944,7 +946,7 @@ public class AlignmentAnnotation { return; } - sequenceMapping = new HashMap(); + sequenceMapping = new HashMap<>(); int seqPos; @@ -1223,7 +1225,7 @@ public class AlignmentAnnotation /** * properties associated with the calcId */ - protected Map properties = new HashMap(); + protected Map properties = new HashMap<>(); /** * base colour for line graphs. If null, will be set automatically by @@ -1267,7 +1269,7 @@ public class AlignmentAnnotation .getTo() == sq.getDatasetSequence()) : false; // TODO build a better annotation element map and get rid of annotations[] - Map mapForsq = new HashMap(); + Map mapForsq = new HashMap<>(); if (sequenceMapping != null) { if (sp2sq != null) @@ -1320,7 +1322,7 @@ public class AlignmentAnnotation if (mapping != null) { Map old = sequenceMapping; - Map remap = new HashMap(); + Map remap = new HashMap<>(); int index = -1; for (int mp[] : mapping.values()) { @@ -1378,7 +1380,7 @@ public class AlignmentAnnotation { if (properties == null) { - properties = new HashMap(); + properties = new HashMap<>(); } properties.put(property, value); } @@ -1503,4 +1505,14 @@ public class AlignmentAnnotation { return graphMin < graphMax; } + + public HiddenMarkovModel getHMM() + { + return hmm; + } + + public void setHMM(HiddenMarkovModel hmm) + { + this.hmm = hmm; + } } diff --git a/src/jalview/datamodel/AnnotatedCollectionI.java b/src/jalview/datamodel/AnnotatedCollectionI.java index 45a3787..927f3f4 100644 --- a/src/jalview/datamodel/AnnotatedCollectionI.java +++ b/src/jalview/datamodel/AnnotatedCollectionI.java @@ -61,8 +61,5 @@ public interface AnnotatedCollectionI extends SequenceCollectionI * alignment, parent group). */ AnnotatedCollectionI getContext(); - - public HiddenMarkovModel getHMM(); - - public void setHMM(HiddenMarkovModel hmm); + } diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index a1a655e..520bfaf 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -1460,17 +1460,5 @@ public class SequenceGroup implements AnnotatedCollectionI return (startRes <= apos && endRes >= apos) && sequences.contains(seq); } - @Override - public HiddenMarkovModel getHMM() - { - // TODO Auto-generated method stub - return hmm; - } - @Override - public void setHMM(HiddenMarkovModel markov) - { - hmm = markov; - - } } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 080e260..a91bb66 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -54,6 +54,7 @@ import jalview.datamodel.AlignmentOrder; import jalview.datamodel.AlignmentView; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; +import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.HiddenSequences; import jalview.datamodel.PDBEntry; import jalview.datamodel.SeqCigar; @@ -4652,15 +4653,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else if (FileFormat.HMMER3.equals(format)) { - HMMFile hmm = new HMMFile(new FileParse(file, sourceType)); - hmm.parse(); - - getViewport().getAlignment().setHMM(hmm.getHMM()); - - - - - + HMMFile hmmFile = new HMMFile(new FileParse(file, sourceType)); + hmmFile.parse(); + HiddenMarkovModel hmm = hmmFile.getHMM(); + AlignmentAnnotation annotation = hmm.createAnnotation( + getViewport().getAlignment().getWidth()); + getViewport().getAlignment().addAnnotation(annotation); + annotation.setHMM(hmm); + isAnnotation = true; } else if (FileFormat.Jnet.equals(format)) { diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 8ca1a4e..9127106 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -421,7 +421,8 @@ public class AnnotationLabels extends JPanel implements MouseListener, if (selectedRow < aa.length) { final String label = aa[selectedRow].label; - if (!aa[selectedRow].autoCalculated) + if (!(aa[selectedRow].autoCalculated + || label.indexOf("Information Content") > -1)) { if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH) { @@ -969,7 +970,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, ArrayList hiddenColumns = null; if (av.hasHiddenColumns()) { - hiddenColumns = new ArrayList(); + hiddenColumns = new ArrayList<>(); for (int[] region : av.getAlignment().getHiddenColumns() .getHiddenRegions()) { diff --git a/src/jalview/io/HMMFile.java b/src/jalview/io/HMMFile.java index 6e49af6..6945ea6 100644 --- a/src/jalview/io/HMMFile.java +++ b/src/jalview/io/HMMFile.java @@ -256,7 +256,9 @@ public class HMMFile extends AlignFile } else { - list.add(Double.valueOf(next)); + double prob = Double.valueOf(next); + prob = Math.pow(Math.E, -prob); + list.add(prob); } } return list; @@ -278,7 +280,6 @@ public class HMMFile extends AlignFile StringBuilder file = new StringBuilder(); appendFileProperties(file); appendModel(file); - file.append("//"); PrintWriter output = new PrintWriter(exportLocation); @@ -325,13 +326,18 @@ public class HMMFile extends AlignFile for (double value : list) { String strValue; - if (value == Double.NEGATIVE_INFINITY) + if (value > 0) { - strValue = "*"; + strValue = String.format("%.5f", value); + + } + else if (value == -0.00000d) + { + strValue = "0.00000"; } else { - strValue = String.format("%.5f", value); + strValue = "*"; } strList.add(strValue); @@ -382,6 +388,7 @@ public class HMMFile extends AlignFile List strMatches; List doubleMatches; doubleMatches = hmm.getNode(node).getMatchEmissions(); + convertListToLogSpace(doubleMatches); strMatches = doubleListToStringList(doubleMatches, 5); matchLine += addData(10, 9, strMatches); @@ -402,6 +409,7 @@ public class HMMFile extends AlignFile List strInserts; List doubleInserts; doubleInserts = hmm.getNode(node).getInsertEmissions(); + convertListToLogSpace(doubleInserts); strInserts = doubleListToStringList(doubleInserts, 5); insertLine += addData(17, 9, strInserts); @@ -411,6 +419,7 @@ public class HMMFile extends AlignFile List strTransitions; List doubleTransitions; doubleTransitions = hmm.getNode(node).getStateTransitions(); + convertListToLogSpace(doubleTransitions); strTransitions = doubleListToStringList(doubleTransitions, 5); transitionLine += addData(17, 9, strTransitions); @@ -550,5 +559,19 @@ public class HMMFile extends AlignFile return null; } + + void convertListToLogSpace(List list) + { + + for (int i = 0; i < list.size(); i++) + { + double prob = list.get(i); + double logProb = -1 * Math.log(prob); + + list.set(i, logProb); + } + + + } } diff --git a/src/jalview/schemes/ResidueProperties.java b/src/jalview/schemes/ResidueProperties.java index 751175d..4a56fbc 100755 --- a/src/jalview/schemes/ResidueProperties.java +++ b/src/jalview/schemes/ResidueProperties.java @@ -39,14 +39,20 @@ public class ResidueProperties public static final int[] purinepyrimidineIndex; - public static final Map aa3Hash = new HashMap(); + public static final Map aa3Hash = new HashMap<>(); - public static final Map aa2Triplet = new HashMap(); + public static final Map aa2Triplet = new HashMap<>(); - public static final Map nucleotideName = new HashMap(); + public static final Map nucleotideName = new HashMap<>(); // lookup from modified amino acid (e.g. MSE) to canonical form (e.g. MET) - public static final Map modifications = new HashMap(); + public static final Map modifications = new HashMap<>(); + + // amino acid background Frequencies + public static final Map aminoBackgroundFrequencies = new HashMap<>(); + + // nucleotide background Frequencies + public static final Map nucleotideBackgroundFrequencies = new HashMap<>(); static { @@ -500,18 +506,18 @@ public class ResidueProperties /** * Nucleotide Ambiguity Codes */ - public static final Map ambiguityCodes = new Hashtable(); + public static final Map ambiguityCodes = new Hashtable<>(); /** * Codon triplets with additional symbols for unambiguous codons that include * ambiguity codes */ - public static final Hashtable codonHash2 = new Hashtable(); + public static final Hashtable codonHash2 = new Hashtable<>(); /** * all ambiguity codes for a given base */ - public final static Hashtable> _ambiguityCodes = new Hashtable>(); + public final static Hashtable> _ambiguityCodes = new Hashtable<>(); static { @@ -635,7 +641,7 @@ public class ResidueProperties List codesfor = _ambiguityCodes.get(r); if (codesfor == null) { - _ambiguityCodes.put(r, codesfor = new ArrayList()); + _ambiguityCodes.put(r, codesfor = new ArrayList<>()); } if (!codesfor.contains(acode.getKey())) { @@ -751,27 +757,27 @@ public class ResidueProperties } // Stores residue codes/names and colours and other things - public static Map> propHash = new Hashtable>(); + public static Map> propHash = new Hashtable<>(); - public static Map hydrophobic = new Hashtable(); + public static Map hydrophobic = new Hashtable<>(); - public static Map polar = new Hashtable(); + public static Map polar = new Hashtable<>(); - public static Map small = new Hashtable(); + public static Map small = new Hashtable<>(); - public static Map positive = new Hashtable(); + public static Map positive = new Hashtable<>(); - public static Map negative = new Hashtable(); + public static Map negative = new Hashtable<>(); - public static Map charged = new Hashtable(); + public static Map charged = new Hashtable<>(); - public static Map aromatic = new Hashtable(); + public static Map aromatic = new Hashtable<>(); - public static Map aliphatic = new Hashtable(); + public static Map aliphatic = new Hashtable<>(); - public static Map tiny = new Hashtable(); + public static Map tiny = new Hashtable<>(); - public static Map proline = new Hashtable(); + public static Map proline = new Hashtable<>(); static { @@ -1151,7 +1157,7 @@ public class ResidueProperties public static Hashtable toDssp3State; static { - toDssp3State = new Hashtable(); + toDssp3State = new Hashtable<>(); toDssp3State.put("H", "H"); toDssp3State.put("E", "E"); toDssp3State.put("C", " "); @@ -2509,6 +2515,40 @@ public class ResidueProperties } + static + { + aminoBackgroundFrequencies.put('A', 0.0826f); + aminoBackgroundFrequencies.put('Q', 0.0393f); + aminoBackgroundFrequencies.put('L', 0.0965f); + aminoBackgroundFrequencies.put('S', 0.0661f); + aminoBackgroundFrequencies.put('R', 0.0553f); + aminoBackgroundFrequencies.put('E', 0.0674f); + aminoBackgroundFrequencies.put('K', 0.0582f); + aminoBackgroundFrequencies.put('T', 0.0535f); + aminoBackgroundFrequencies.put('N', 0.0406f); + aminoBackgroundFrequencies.put('G', 0.0708f); + aminoBackgroundFrequencies.put('M', 0.0241f); + aminoBackgroundFrequencies.put('W', 0.0109f); + aminoBackgroundFrequencies.put('D', 0.0546f); + aminoBackgroundFrequencies.put('H', 0.0227f); + aminoBackgroundFrequencies.put('F', 0.0386f); + aminoBackgroundFrequencies.put('Y', 0.0292f); + aminoBackgroundFrequencies.put('C', 0.0137f); + aminoBackgroundFrequencies.put('I', 0.0593f); + aminoBackgroundFrequencies.put('P', 0.0472f); + aminoBackgroundFrequencies.put('V', 0.0686f); + + } + + static + { + nucleotideBackgroundFrequencies.put('A', 0.25f); + nucleotideBackgroundFrequencies.put('C', 0.25f); + nucleotideBackgroundFrequencies.put('T', 0.25f); + nucleotideBackgroundFrequencies.put('G', 0.25f); + + } + public static String getCanonicalAminoAcid(String aA) { String canonical = modifications.get(aA); @@ -2519,7 +2559,7 @@ public class ResidueProperties // / cut here public static void main(String[] args) { - Hashtable> aaProps = new Hashtable>(); + Hashtable> aaProps = new Hashtable<>(); System.out.println("my %aa = {"); // invert property hashes for (String pname : propHash.keySet()) @@ -2530,7 +2570,7 @@ public class ResidueProperties Vector aprops = aaProps.get(rname); if (aprops == null) { - aprops = new Vector(); + aprops = new Vector<>(); aaProps.put(rname, aprops); } Integer hasprop = phash.get(rname); @@ -2572,7 +2612,7 @@ public class ResidueProperties public static List getResidues(boolean forNucleotide, boolean includeAmbiguous) { - List result = new ArrayList(); + List result = new ArrayList<>(); if (forNucleotide) { for (String nuc : nucleotideName.keySet()) diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 60cee46..f86282f 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -95,6 +95,7 @@ public abstract class AlignmentViewport implements AlignViewportI, protected Deque historyList = new ArrayDeque<>(); protected Deque redoList = new ArrayDeque<>(); + /** * alignment displayed in the viewport. Please use get/setter @@ -696,6 +697,8 @@ public abstract class AlignmentViewport implements AlignViewportI, protected AlignmentAnnotation[] groupConservation; + protected AlignmentAnnotation hmmConsensus; + /** * results of alignment consensus analysis for visible portion of view */ @@ -1913,6 +1916,7 @@ public abstract class AlignmentViewport implements AlignViewportI, MessageManager.getString("label.consensus_descr"), new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); initConsensus(consensus); + initGapCounts(); initComplementConsensus(); @@ -2870,4 +2874,6 @@ public abstract class AlignmentViewport implements AlignViewportI, { return searchResults; } + + } diff --git a/test/jalview/io/HMMFileTest.java b/test/jalview/io/HMMFileTest.java index 7350c04..36a2491 100644 --- a/test/jalview/io/HMMFileTest.java +++ b/test/jalview/io/HMMFileTest.java @@ -91,45 +91,28 @@ public class HMMFileTest { assertEquals(hmm.getSymbols(), symbols); - assertEquals(getMatchEmission(0, 19, hmm), 3.43274); - assertEquals(getMatchEmission(12, 12, hmm), 4.33979); - assertEquals(getMatchEmission(23, 7, hmm), 3.65600); - assertEquals(getMatchEmission(54, 1, hmm), 4.76187); - assertEquals(getMatchEmission(79, 0, hmm), 2.81579); - assertEquals(getMatchEmission(100, 0, hmm), 1.86496); - assertEquals(getMatchEmission(112, 14, hmm), 2.77179); - assertEquals(getMatchEmission(143, 17, hmm), 5.10478); - assertEquals(getMatchEmission(156, 4, hmm), 4.69372); - assertEquals(getMatchEmission(178, 3, hmm), 2.52594); - assertEquals(getMatchEmission(210, 2, hmm), 4.23598); - assertEquals(getMatchEmission(260, 19, hmm), 3.81122); - - assertEquals(getInsertEmission(2, 1, hmm), 4.42225); - assertEquals(getInsertEmission(15, 6, hmm), 3.72501); - assertEquals(getInsertEmission(22, 9, hmm), 2.69355); - assertEquals(getInsertEmission(57, 2, hmm), 2.77519); - assertEquals(getInsertEmission(62, 14, hmm), 2.89801); - assertEquals(getInsertEmission(95, 17, hmm), 2.98532); - assertEquals(getInsertEmission(105, 4, hmm), 3.46354); - assertEquals(getInsertEmission(134, 1, hmm), 4.42225); - assertEquals(getInsertEmission(143, 0, hmm), 2.68618); - assertEquals(getInsertEmission(152, 16, hmm), 2.77519); - assertEquals(getInsertEmission(203, 16, hmm), 2.77519); - assertEquals(getInsertEmission(255, 12, hmm), 2.73739); + assertEquals(getMatchEmission(0, 19, hmm), 0.032298, 0.001d); + assertEquals(getMatchEmission(12, 12, hmm), 0.0130, 0.001d); + assertEquals(getMatchEmission(23, 7, hmm), 0.02583, 0.001d); + assertEquals(getMatchEmission(54, 1, hmm), 0.008549, 0.001d); + assertEquals(getMatchEmission(178, 3, hmm), 0.07998, 0.001d); + assertEquals(getMatchEmission(210, 2, hmm), 0.014465, 0.001d); + assertEquals(getMatchEmission(260, 19, hmm), 0.02213, 0.001d); + + assertEquals(getInsertEmission(2, 1, hmm), 0.012, 0.001d); + assertEquals(getInsertEmission(15, 6, hmm), 0.02411, 0.001d); + assertEquals(getInsertEmission(22, 9, hmm), 0.06764, 0.001d); + assertEquals(getInsertEmission(57, 2, hmm), 0.0623, 0.001d); + assertEquals(getInsertEmission(203, 16, hmm), 0.0623, 0.001d); + assertEquals(getInsertEmission(255, 12, hmm), 0.0647, 0.001d); assertEquals(getStateTransition(0, 6, hmm), Double.NEGATIVE_INFINITY); - assertEquals(getStateTransition(3, 6, hmm), 0.95510); - assertEquals(getStateTransition(29, 3, hmm), 0.61958); - assertEquals(getStateTransition(46, 4, hmm), 0.77255); - assertEquals(getStateTransition(53, 1, hmm), 5.01631); - assertEquals(getStateTransition(79, 2, hmm), 5.73865); - assertEquals(getStateTransition(101, 2, hmm), 5.73865); - assertEquals(getStateTransition(120, 5, hmm), 0.48576); - assertEquals(getStateTransition(146, 5, hmm), 0.70219); - assertEquals(getStateTransition(169, 3, hmm), 1.23224); - assertEquals(getStateTransition(209, 0, hmm), 0.01003); - assertEquals(getStateTransition(243, 1, hmm), 5.01631); + assertEquals(getStateTransition(3, 6, hmm), 0.3848, 0.001d); + assertEquals(getStateTransition(29, 3, hmm), 0.5382, 0.001d); + assertEquals(getStateTransition(169, 3, hmm), 0.2916, 0.001d); + assertEquals(getStateTransition(209, 0, hmm), 0.99, 0.001d); + assertEquals(getStateTransition(243, 1, hmm), 0.0066, 0.001d); assertEquals(hmm.getNodeAlignmentColumn(3).intValue(), 3); assertEquals(hmm.getReferenceAnnotation(7), '-'); @@ -239,30 +222,41 @@ public class HMMFileTest { Scanner scanner1 = new Scanner("1.3 2.4 5.3 3.9 9.8 4.7 4.3 2.3 6.9"); ArrayList filledArray = new ArrayList<>(); - filledArray.add(1.3); - filledArray.add(2.4); - filledArray.add(5.3); - filledArray.add(3.9); - filledArray.add(9.8); - filledArray.add(4.7); - filledArray.add(4.3); - filledArray.add(2.3); - filledArray.add(6.9); - - assertEquals(HMMFile.fillList(scanner1, 9), filledArray); + filledArray.add(0.27253); + filledArray.add(0.0907); + filledArray.add(0.00499); + filledArray.add(0.02024); + filledArray.add(0.00005); + filledArray.add(0.00909); + filledArray.add(0.01357); + filledArray.add(0.10026); + filledArray.add(0.001); + + List testList = HMMFile.fillList(scanner1, 9); + + for (int i = 0; i < 9; i++) + { + assertEquals(testList.get(i), filledArray.get(i), 0.001d); + + } + filledArray.clear(); scanner1.close(); Scanner scanner2 = new Scanner( - "1.346554 5.58756754 35.3523645 12345.3564 1.4"); - filledArray.add(1.346554); - filledArray.add(5.58756754); - filledArray.add(35.3523645); - filledArray.add(12345.3564); - filledArray.add(1.4); - - assertEquals(HMMFile.fillList(scanner2, 5), filledArray); - scanner2.close(); + "1.346 5.554 35.345 5.64 1.4"); + filledArray.add(0.2603); + filledArray.add(0.00387); + filledArray.add(0d); + filledArray.add(0.00355); + filledArray.add(0.2466); + + testList = HMMFile.fillList(scanner2, 5); + + for (int i = 0; i < 5; i++) + { + assertEquals(testList.get(i), filledArray.get(i), 0.001d); + } } @@ -282,34 +276,23 @@ public class HMMFileTest { br.close(); fr.close(); - assertEquals(getMatchEmission(0, 2, testHMM), 1.62906); - assertEquals(getMatchEmission(2, 1, testHMM), 2.37873); - assertEquals(getMatchEmission(12, 2, testHMM), 2.61355); - assertEquals(getMatchEmission(26, 0, testHMM), 1.86925); - assertEquals(getMatchEmission(32, 3, testHMM), 2.58263); - assertEquals(getMatchEmission(59, 3, testHMM), 2.20507); - assertEquals(getMatchEmission(63, 0, testHMM), 0.41244); - assertEquals(getMatchEmission(69, 1, testHMM), 3.17398); - assertEquals(getMatchEmission(76, 2, testHMM), 2.65861); - - assertEquals(getInsertEmission(0, 1, testHMM), 1.38629); - assertEquals(getInsertEmission(1, 2, testHMM), 1.38629); - assertEquals(getInsertEmission(31, 3, testHMM), 1.28150); - assertEquals(getInsertEmission(43, 0, testHMM), 1.32290); - assertEquals(getInsertEmission(48, 2, testHMM), 1.52606); - assertEquals(getInsertEmission(52, 1, testHMM), 1.62259); - assertEquals(getInsertEmission(67, 0, testHMM), 1.38141); - assertEquals(getInsertEmission(70, 3, testHMM), 1.38629); - assertEquals(getInsertEmission(80, 3, testHMM), 1.38629); - - assertEquals(getStateTransition(2, 0, testHMM), 0.03725); - assertEquals(getStateTransition(6, 1, testHMM), 3.89715); - assertEquals(getStateTransition(9, 3, testHMM), 1.38021); - assertEquals(getStateTransition(20, 4, testHMM), 0.23815); - assertEquals(getStateTransition(34, 6, testHMM), 0.33363); - assertEquals(getStateTransition(46, 5, testHMM), 1.05474); - assertEquals(getStateTransition(57, 6, testHMM), 0.31164); - assertEquals(getStateTransition(68, 2, testHMM), 3.99242); + assertEquals(getMatchEmission(0, 2, testHMM), 0.1961, 0.001d); + assertEquals(getMatchEmission(2, 1, testHMM), 0.09267, 0.001d); + assertEquals(getMatchEmission(12, 2, testHMM), 0.07327, 0.001d); + assertEquals(getMatchEmission(69, 1, testHMM), 0.04184, 0.001d); + assertEquals(getMatchEmission(76, 2, testHMM), 0.07, 0.001d); + + assertEquals(getInsertEmission(0, 1, testHMM), 0.25, 0.001d); + assertEquals(getInsertEmission(1, 2, testHMM), 0.25, 0.001d); + assertEquals(getInsertEmission(31, 3, testHMM), 0.2776, 0.001d); + assertEquals(getInsertEmission(70, 3, testHMM), 0.25, 0.001d); + assertEquals(getInsertEmission(80, 3, testHMM), 0.25, 0.001d); + + assertEquals(getStateTransition(2, 0, testHMM), 0.9634, 0.001d); + assertEquals(getStateTransition(6, 1, testHMM), 0.0203, 0.001d); + assertEquals(getStateTransition(9, 3, testHMM), 0.2515, 0.001d); + assertEquals(getStateTransition(20, 4, testHMM), 0.78808, 0.001d); + assertEquals(getStateTransition(68, 2, testHMM), 0.01845, 0.001d); assertEquals(getStateTransition(80, 6, testHMM), Double.NEGATIVE_INFINITY); @@ -373,36 +356,36 @@ public class HMMFileTest { @Test(priority = 3) public void testExportFile() throws IOException { - fn3.exportFile("test/jalview/io/test_export_hmm.txt"); - HMMFile fn3Clone = new HMMFile( + pKinase.exportFile("test/jalview/io/test_export_hmm.txt"); + HMMFile pKinaseClone = new HMMFile( new FileParse("test/jalview/io/test_export_hmm.txt", DataSourceType.FILE)); - fn3Clone.parse(); - HiddenMarkovModel fn3HMM = new HiddenMarkovModel(); - HiddenMarkovModel fn3CloneHMM = new HiddenMarkovModel(); - fn3HMM = fn3.getHMM(); - fn3CloneHMM = fn3Clone.getHMM(); + pKinaseClone.parse(); + HiddenMarkovModel pKinaseHMM = new HiddenMarkovModel(); + HiddenMarkovModel pKinaseCloneHMM = new HiddenMarkovModel(); + pKinaseHMM = pKinase.getHMM(); + pKinaseCloneHMM = pKinaseClone.getHMM(); - for (int i = 0; i < fn3HMM.getLength(); i++) + for (int i = 0; i < pKinaseHMM.getLength(); i++) { List list1; List list2; boolean result; - list1 = fn3HMM.getNode(i).getMatchEmissions(); - list2 = fn3CloneHMM.getNode(i).getMatchEmissions(); + list1 = pKinaseHMM.getNode(i).getMatchEmissions(); + list2 = pKinaseCloneHMM.getNode(i).getMatchEmissions(); result = checkIfListsAreIdentical(list1, list2); assertEquals(result, true); - list1 = fn3HMM.getNode(i).getInsertEmissions(); - list2 = fn3CloneHMM.getNode(i).getInsertEmissions(); + list1 = pKinaseHMM.getNode(i).getInsertEmissions(); + list2 = pKinaseCloneHMM.getNode(i).getInsertEmissions(); result = checkIfListsAreIdentical(list1, list2); assertEquals(result, true); - list1 = fn3HMM.getNode(i).getStateTransitions(); - list2 = fn3CloneHMM.getNode(i).getStateTransitions(); + list1 = pKinaseHMM.getNode(i).getStateTransitions(); + list2 = pKinaseCloneHMM.getNode(i).getStateTransitions(); result = checkIfListsAreIdentical(list1, list2); assertEquals(result, true); @@ -412,21 +395,21 @@ public class HMMFileTest { int alignColumn1; int alignColumn2; - alignColumn1 = fn3HMM.getNodeAlignmentColumn(i); - alignColumn2 = fn3CloneHMM.getNodeAlignmentColumn(i); + alignColumn1 = pKinaseHMM.getNodeAlignmentColumn(i); + alignColumn2 = pKinaseCloneHMM.getNodeAlignmentColumn(i); assertEquals(alignColumn1, alignColumn2); char annotation1; char annotation2; - annotation1 = fn3HMM.getReferenceAnnotation(i); - annotation2 = fn3CloneHMM.getReferenceAnnotation(i); + annotation1 = pKinaseHMM.getReferenceAnnotation(i); + annotation2 = pKinaseCloneHMM.getReferenceAnnotation(i); assertEquals(annotation1, annotation2); - annotation1 = fn3HMM.getConsensusResidue(i); - annotation2 = fn3CloneHMM.getConsensusResidue(i); + annotation1 = pKinaseHMM.getConsensusResidue(i); + annotation2 = pKinaseCloneHMM.getConsensusResidue(i); assertEquals(annotation1, annotation2); } -- 1.7.10.2