From 8e884069ac5b4f02f1cabf435e4a7506ae91f0e0 Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Thu, 22 Jun 2017 15:01:34 +0100 Subject: [PATCH] fully integrate HMMER3 file format into Jalview --- src/jalview/datamodel/HiddenMarkovModel.java | 175 ++++++-- src/jalview/gui/AlignFrame.java | 41 +- src/jalview/io/FileFormat.java | 16 + src/jalview/io/HMMFile.java | 153 +++---- src/jalview/io/IdentifyFile.java | 5 + test/jalview/io/HMMFileTest.java | 579 ++++++++++++++++---------- 6 files changed, 611 insertions(+), 358 deletions(-) diff --git a/src/jalview/datamodel/HiddenMarkovModel.java b/src/jalview/datamodel/HiddenMarkovModel.java index cd6490e..f614013 100644 --- a/src/jalview/datamodel/HiddenMarkovModel.java +++ b/src/jalview/datamodel/HiddenMarkovModel.java @@ -26,9 +26,16 @@ public class HiddenMarkovModel // 0. Node 0 contains average emission probabilities for each symbol List nodes = new ArrayList<>(); - final String YES = "yes"; + // contains the HMM node for each alignment column + Map nodeLookup = new HashMap<>(); + + //contains the symbol index for each symbol + Map symbolIndexLookup = new HashMap<>(); + - final String NO = "no"; + final static String YES = "yes"; + + final static String NO = "no"; int numberOfSymbols; @@ -95,14 +102,26 @@ public class HiddenMarkovModel return TRANSITION_TYPES[index]; } + public Map getNodeLookup() + { + return nodeLookup; + } + + public void setNodeLookup(Map nodeLookup) + { + this.nodeLookup = nodeLookup; + } + public String[] getTransitionTypes() { return TRANSITION_TYPES; } - public char getSymbol(int index) + + public List getSymbols() { - return getSymbols().get(index); + return symbols; } + public Map getFileProperties() { return fileProperties; @@ -258,49 +277,66 @@ public class HiddenMarkovModel } /** - * gets the match emission at a node for a symbol - * @param nodeIndex - * position of node in model - * @param symbolIndex - * index of symbol being searched + * get match emission probability for a given symbol at a column in the + * alignment + * + * @param alignColumn + * @param symbol * @return - * negative log probability of a match emission of the given symbol + * */ - public double getMatchEmission(int nodeIndex, int symbolIndex) + public Double getMatchEmissionProbability(int alignColumn, char symbol) { - double value = nodes.get(nodeIndex).getMatchEmissions().get(symbolIndex); - return value; + int symbolIndex; + int nodeIndex; + Double probability; + symbolIndex = symbolIndexLookup.get(symbol); + nodeIndex = nodeLookup.get(alignColumn); + probability = getNode(nodeIndex).getMatchEmissions().get(symbolIndex); + return probability; + } - + /** - * gets the insert emission at a node for a symbol - * @param nodeIndex - * position of node in model - * @param symbolIndex - * index of symbol being searched + * get insert emission probability for a given symbol at a column in the + * alignment + * + * @param alignColumn + * @param symbol * @return - * negative log probability of an insert emission of the given symbol */ - public double getInsertEmission(int nodeIndex, int symbolIndex) + public Double getInsertEmissionProbability(int alignColumn, char symbol) { - double value = nodes.get(nodeIndex).getInsertEmissions().get(symbolIndex); - return value; + int symbolIndex; + int nodeIndex; + Double probability; + symbolIndex = symbolIndexLookup.get(symbol); + nodeIndex = nodeLookup.get(alignColumn); + probability = getNode(nodeIndex).getInsertEmissions().get(symbolIndex); + return probability; + } /** - * gets the state transition at a node for a specific transition - * @param nodeIndex - * position of node in model - * @param transitionIndex - * index of stransition being searched + * get state transition probability for a given transition type at a column in + * the alignment + * + * @param alignColumn + * @param transition * @return - * negative log probability of a state transition of the given type */ - public double getStateTransition(int nodeIndex, int transitionIndex) - { - double value = nodes.get(nodeIndex).getStateTransitions() + public Double getStateTransitionProbability(int alignColumn, + String transition) + { + int transitionIndex; + int nodeIndex; + Double probability; + transitionIndex = getTransitionType(transition); + nodeIndex = nodeLookup.get(alignColumn); + probability = getNode(nodeIndex).getStateTransitions() .get(transitionIndex); - return value; + return probability; + } public Integer getNodeAlignmentColumn(int nodeIndex) @@ -356,11 +392,7 @@ public class HiddenMarkovModel this.numberOfSymbols = numberOfSymbols; } - public List getSymbols() - { - return symbols; - } - + /** * fills symbol array and also finds numberOfSymbols @@ -370,11 +402,14 @@ public class HiddenMarkovModel */ public void fillSymbols(Scanner parser) { + int i = 0; while (parser.hasNext()) { String strSymbol = parser.next(); char[] symbol = strSymbol.toCharArray(); symbols.add(symbol[0]); + symbolIndexLookup.put(symbol[0], i); + i++; } numberOfSymbols = symbols.size(); } @@ -616,5 +651,69 @@ public class HiddenMarkovModel fileProperties.put(CONSENSUS_STRUCTURE, NO); } } + + /** + * + * @param transition + * type of transition occuring + * @return index value representing position along stateTransition array. + */ + public Integer getTransitionType(String transition) + { + Integer index; + switch (transition) + { + case "mm": + index = 0; + break; + case "mi": + index = 1; + break; + case "md": + index = 2; + break; + case "im": + index = 3; + break; + case "ii": + index = 4; + break; + case "dm": + index = 5; + break; + case "dd": + index = 6; + break; + default: + index = null; + } + return index; + } + + /** + * find the index of the node in a hidden Markov model based on the column in + * the alignment + * + * @param alignmentColumn + */ + + public Integer findNodeIndex(int alignmentColumn) + { + Integer index; + index = nodeLookup.get(alignmentColumn); + return index; + } + + public static String findStringFromBoolean(boolean value) + { + if (value) + { + return YES; + } + else + { + return NO; + } + } } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index a9a970f..2140ed9 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -72,6 +72,7 @@ import jalview.io.FileFormats; import jalview.io.FileLoader; import jalview.io.FileParse; import jalview.io.FormatAdapter; +import jalview.io.HMMFile; import jalview.io.HtmlSvgOutput; import jalview.io.IdentifyFile; import jalview.io.JPredFile; @@ -167,7 +168,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public AlignViewControllerI avc; - List alignPanels = new ArrayList(); + List alignPanels = new ArrayList<>(); /** * Last format used to load or save alignments in this window @@ -396,8 +397,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, addKeyListener(); - final List selviews = new ArrayList(); - final List origview = new ArrayList(); + final List selviews = new ArrayList<>(); + final List origview = new ArrayList<>(); final String menuLabel = MessageManager .getString("label.copy_format_from"); ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel, @@ -410,7 +411,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, origview.clear(); origview.add(alignPanel); // make an array of all alignment panels except for this one - List aps = new ArrayList( + List aps = new ArrayList<>( Arrays.asList(Desktop.getAlignmentPanels(null))); aps.remove(AlignFrame.this.alignPanel); return aps.toArray(new AlignmentPanel[aps.size()]); @@ -1732,7 +1733,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, synchronized void slideSequences(boolean right, int size) { - List sg = new ArrayList(); + List sg = new ArrayList<>(); if (viewport.cursorMode) { sg.add(viewport.getAlignment().getSequenceAt( @@ -1751,7 +1752,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return; } - List invertGroup = new ArrayList(); + List invertGroup = new ArrayList<>(); for (SequenceI seq : viewport.getAlignment().getSequences()) { @@ -1884,7 +1885,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, ArrayList hiddenColumns = null; if (viewport.hasHiddenColumns()) { - hiddenColumns = new ArrayList(); + hiddenColumns = new ArrayList<>(); int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport .getSelectionGroup().getEndRes(); for (int[] region : viewport.getAlignment().getHiddenColumns() @@ -1994,7 +1995,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } int alwidth = 0; - ArrayList newGraphGroups = new ArrayList(); + ArrayList newGraphGroups = new ArrayList<>(); int fgroup = -1; if (newAlignment) @@ -2826,7 +2827,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ protected List getExistingViewNames(List comps) { - List existingNames = new ArrayList(); + List existingNames = new ArrayList<>(); for (Component comp : comps) { if (comp instanceof AlignmentPanel) @@ -3760,7 +3761,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, List comps = PaintRefresher.components.get(viewport .getSequenceSetId()); - List treePanels = new ArrayList(); + List treePanels = new ArrayList<>(); for (Component comp : comps) { if (comp instanceof TreePanel) @@ -4020,7 +4021,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void run() { - final List legacyItems = new ArrayList(); + final List legacyItems = new ArrayList<>(); try { // System.err.println("Building ws menu again " @@ -4035,7 +4036,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // TODO: group services by location as well as function and/or // introduce // object broker mechanism. - final Vector wsmenu = new Vector(); + final Vector wsmenu = new Vector<>(); final IProgressIndicator af = me; /* @@ -4403,8 +4404,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // Java's Transferable for native dnd evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = evt.getTransferable(); - List files = new ArrayList(); - List protocols = new ArrayList(); + List files = new ArrayList<>(); + List protocols = new ArrayList<>(); try { @@ -4424,8 +4425,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Object[] { String,SequenceI} */ - ArrayList filesmatched = new ArrayList(); - ArrayList filesnotmatched = new ArrayList(); + ArrayList filesmatched = new ArrayList<>(); + ArrayList filesnotmatched = new ArrayList<>(); for (int i = 0; i < files.size(); i++) { String file = files.get(i).toString(); @@ -4649,6 +4650,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, "label.successfully_loaded_matrix", sm.getMatrixName())); } + else if (FileFormat.HMMER3.equals(format)) + { + HMMFile hmm = new HMMFile(new FileParse(file, sourceType)); + hmm.parse(); + System.out.println("successful"); + } else if (FileFormat.Jnet.equals(format)) { JPredFile predictions = new JPredFile(file, sourceType); @@ -5416,7 +5423,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { return; } - List cdnaSeqs = new ArrayList(); + List cdnaSeqs = new ArrayList<>(); for (SequenceI aaSeq : alignment.getSequences()) { for (AlignedCodonFrame acf : mappings) diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java index 3354b88..50d2aa7 100644 --- a/src/jalview/io/FileFormat.java +++ b/src/jalview/io/FileFormat.java @@ -353,8 +353,24 @@ public enum FileFormat implements FileFormatI { return false; } + }, + HMMER3("HMMER3", "hmm", false, false) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new HMMFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new HMMFile(); + } }; + private boolean writable; private boolean readable; diff --git a/src/jalview/io/HMMFile.java b/src/jalview/io/HMMFile.java index 7063fe9..6e49af6 100644 --- a/src/jalview/io/HMMFile.java +++ b/src/jalview/io/HMMFile.java @@ -2,12 +2,12 @@ package jalview.io; import jalview.datamodel.HMMNode; import jalview.datamodel.HiddenMarkovModel; +import jalview.datamodel.SequenceI; import java.io.BufferedReader; -import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; +import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; @@ -21,19 +21,19 @@ import java.util.Scanner; * @author TZVanaalten * */ -public class HMMFile extends FileParse +public class HMMFile extends AlignFile + implements AlignmentFileReaderI, AlignmentFileWriterI { // HMM to store file data - HiddenMarkovModel hmm = new HiddenMarkovModel(); + private HiddenMarkovModel hmm = new HiddenMarkovModel(); + - // Source of file - String dataObject; // number of possible transitions - final static int NUMBER_OF_TRANSITIONS = 7; + private final int NUMBER_OF_TRANSITIONS = 7; - final static String NEW_LINE = "\n"; + private final String NEW_LINE = "\n"; // file header @@ -41,58 +41,50 @@ public class HMMFile extends FileParse int numberOfSymbols; - final static String SPACE = " "; + private final String SPACE = " "; - final static String COMPO = "COMPO"; + private final String COMPO = "COMPO"; - final static String EMPTY = ""; + private final String EMPTY = ""; + public HMMFile(FileParse source) throws IOException + { + super(false, source); + } - /** - * Constructor which contains model to be filled or exported - * - * @param dataSource - * Filename, URL or Pasted String to read from - */ - public HMMFile(String dataSource) + public HMMFile() { - dataObject = dataSource; + } - public HiddenMarkovModel getHmm() + public HiddenMarkovModel getHMM() { return hmm; } - public void setHmm(HiddenMarkovModel model) + public void setHMM(HiddenMarkovModel model) { this.hmm = model; } + public String getName() + { + return hmm.getName(); + } + /** * reads data from HMM file * * @throws IOException */ + @Override public void parse() throws IOException { - File file = new File(dataObject); - FileReader fr = new FileReader(file); - BufferedReader br = new BufferedReader(fr); - parseFileProperties(br); - parseModel(br); - + parseFileProperties(dataIn); + parseModel(dataIn); } - public String getDataObject() - { - return dataObject; - } - public void setDataObject(String value) - { - this.dataObject = value; - } /** * imports file properties from hmm file @@ -101,7 +93,7 @@ public class HMMFile extends FileParse * buffered reader used to read in file * @throws IOException */ - public void parseFileProperties(BufferedReader input) throws IOException + void parseFileProperties(BufferedReader input) throws IOException { boolean readingFile = true; fileHeader = input.readLine(); @@ -156,7 +148,7 @@ public class HMMFile extends FileParse * buffered reader used to read file * @throws IOException */ - public void parseModel(BufferedReader input) throws IOException + void parseModel(BufferedReader input) throws IOException { for (int i = 0; i < hmm.getLength() + 1; i++) { @@ -205,13 +197,14 @@ public class HMMFile extends FileParse * @param index * index of node which is beign scanned */ - public void parseAnnotations(Scanner scanner, int index) + void parseAnnotations(Scanner scanner, int index) { if (hmm.mapIsActive()) { int column; column = scanner.nextInt(); hmm.getNodes().get(index).setAlignmentColumn(column); + hmm.getNodeLookup().put(column, index); } else { @@ -236,43 +229,6 @@ public class HMMFile extends FileParse hmm.getNodes().get(index).setConsensusStructure(consensusS); } - /** - * - * @param transition - * type of transition occuring - * @return index value representing position along stateTransition array. - */ - public Integer getTransitionType(String transition) - { - Integer index; - switch (transition) - { - case "mm": - index = 0; - break; - case "mi": - index = 1; - break; - case "md": - index = 2; - break; - case "im": - index = 3; - break; - case "ii": - index = 4; - break; - case "dm": - index = 5; - break; - case "dd": - index = 6; - break; - default: - index = null; - } - return index; - } /** * @@ -282,7 +238,7 @@ public class HMMFile extends FileParse * number of elements in the list to be filled * @return filled list */ - public static List fillList(Scanner input, + static List fillList(Scanner input, int numberOfElements) { List list = new ArrayList<>(); @@ -325,9 +281,13 @@ public class HMMFile extends FileParse file.append("//"); + PrintWriter output = new PrintWriter(exportLocation); + output.append(file); + output.close(); + } - public String addData(int initialColumnSeparation, + String addData(int initialColumnSeparation, int columnSeparation, List data) { String line = EMPTY; @@ -347,7 +307,7 @@ public class HMMFile extends FileParse return line; } - public static List charListToStringList(List list) + List charListToStringList(List list) { List strList = new ArrayList<>(); for (char value : list) @@ -358,7 +318,7 @@ public class HMMFile extends FileParse return strList; } - public static List doubleListToStringList(List list, + List doubleListToStringList(List list, int noOfDecimals) { List strList = new ArrayList<>(); @@ -379,7 +339,7 @@ public class HMMFile extends FileParse return strList; } - public static List stringArrayToStringList(String[] array) + List stringArrayToStringList(String[] array) { List list = new ArrayList<>(); for (String value : array) @@ -489,26 +449,40 @@ public class HMMFile extends FileParse line = String.format("%-5s %1s", "ALPH", hmm.getAlphabetType()); file.append((line + NEW_LINE)); + boolean status; + String statusStr; + + status = hmm.referenceAnnotationIsActive(); + statusStr = HiddenMarkovModel.findStringFromBoolean(status); line = String.format("%-5s %1s", "RF", - hmm.getFileProperties().get("RF")); + statusStr); file.append((line + NEW_LINE)); + status = hmm.maskValueIsActive(); + statusStr = HiddenMarkovModel.findStringFromBoolean(status); line = String.format("%-5s %1s", "MM", - hmm.getFileProperties().get("MM")); + statusStr); file.append((line + NEW_LINE)); + status = hmm.consensusResidueIsActive(); + statusStr = HiddenMarkovModel.findStringFromBoolean(status); line = String.format("%-5s %1s", "CONS", - hmm.getFileProperties().get("CONS")); + statusStr); file.append((line + NEW_LINE)); + status = hmm.consensusStructureIsActive(); + statusStr = HiddenMarkovModel.findStringFromBoolean(status); line = String.format("%-5s %1s", "CS", - hmm.getFileProperties().get("CS")); + statusStr); file.append((line + NEW_LINE)); + status = hmm.mapIsActive(); + statusStr = HiddenMarkovModel.findStringFromBoolean(status); line = String.format("%-5s %1s", "MAP", - hmm.getFileProperties().get("MAP")); + statusStr); file.append((line + NEW_LINE)); + if (hmm.getDate() != null) { line = String.format("%-5s %1s", "DATE", hmm.getDate()); @@ -563,11 +537,18 @@ public class HMMFile extends FileParse - public static char charValue(String string) + char charValue(String string) { char character; character = string.charAt(0); return character; } + + @Override + public String print(SequenceI[] seqs, boolean jvsuffix) + { + + return null; + } } diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index 035c1fa..6573cbb 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -149,6 +149,11 @@ public class IdentifyFile reply = FileFormat.ScoreMatrix; break; } + if (data.startsWith("HMMER3")) + { + reply = FileFormat.HMMER3; + break; + } if (data.startsWith("H ") && !aaIndexHeaderRead) { aaIndexHeaderRead = true; diff --git a/test/jalview/io/HMMFileTest.java b/test/jalview/io/HMMFileTest.java index 55e3721..8ac2cf8 100644 --- a/test/jalview/io/HMMFileTest.java +++ b/test/jalview/io/HMMFileTest.java @@ -7,6 +7,7 @@ import jalview.datamodel.HMMNode; import jalview.datamodel.HiddenMarkovModel; import java.io.BufferedReader; +import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; @@ -17,41 +18,52 @@ import org.testng.annotations.Test; public class HMMFileTest { - HMMFile fn3 = new HMMFile("H:/fn3.hmm"); - HMMFile emptyFile = new HMMFile("H:/EmptyFile.hmm"); - HMMFile pKinase = new HMMFile("H:/Pkinase.hmm"); + HMMFile fn3 = new HMMFile( + new FileParse("H:/fn3.hmm", DataSourceType.FILE)); + + HMMFile pKinase = new HMMFile( + new FileParse("H:/Pkinase.hmm", DataSourceType.FILE)); + + HMMFile made1 = new HMMFile( + new FileParse("H:/MADE1.hmm", DataSourceType.FILE)); + + HMMFileTest() throws IOException + { + + } + + - HMMFile made1 = new HMMFile("H:/MADE1.hmm"); @Test public void testParse() throws IOException { - + pKinase.parse(); - - assertEquals(pKinase.hmm.getName(), "Pkinase"); - assertEquals(pKinase.hmm.getAccessionNumber(), "PF00069.17"); - assertEquals(pKinase.hmm.getDescription(), "Protein kinase domain"); - assertEquals(pKinase.hmm.getLength().intValue(), 260); - assertNull(pKinase.hmm.getMaxInstanceLength()); - assertEquals(pKinase.hmm.getAlphabetType(), "amino"); - assertEquals(pKinase.hmm.referenceAnnotationIsActive(), false); - assertEquals(pKinase.hmm.maskValueIsActive(), false); - assertEquals(pKinase.hmm.consensusResidueIsActive(), true); - assertEquals(pKinase.hmm.consensusStructureIsActive(), + HiddenMarkovModel hmm = pKinase.getHMM(); + assertEquals(hmm.getName(), "Pkinase"); + assertEquals(hmm.getAccessionNumber(), "PF00069.17"); + assertEquals(hmm.getDescription(), "Protein kinase domain"); + assertEquals(hmm.getLength().intValue(), 260); + assertNull(hmm.getMaxInstanceLength()); + assertEquals(hmm.getAlphabetType(), "amino"); + assertEquals(hmm.referenceAnnotationIsActive(), false); + assertEquals(hmm.maskValueIsActive(), false); + assertEquals(hmm.consensusResidueIsActive(), true); + assertEquals(hmm.consensusStructureIsActive(), true); - assertEquals(pKinase.hmm.mapIsActive(), true); - assertEquals(pKinase.hmm.getDate(), "Thu Jun 16 11:44:06 2011"); - assertNull(pKinase.hmm.getCommandLineLog()); - assertEquals(pKinase.hmm.getNumberOfSequences().intValue(), 54); - assertEquals(pKinase.hmm.getEffectiveNumberOfSequences(), 3.358521, 4d); - assertEquals(pKinase.hmm.getCheckSum().longValue(), 3106786190l); - assertEquals(pKinase.hmm.getGatheringThreshold(), "70.30 70.30"); - assertEquals(pKinase.hmm.getTrustedCutoff(), "70.30 70.30"); - assertEquals(pKinase.hmm.getNoiseCutoff(), "70.20 70.20"); - + assertEquals(hmm.mapIsActive(), true); + assertEquals(hmm.getDate(), "Thu Jun 16 11:44:06 2011"); + assertNull(hmm.getCommandLineLog()); + assertEquals(hmm.getNumberOfSequences().intValue(), 54); + assertEquals(hmm.getEffectiveNumberOfSequences(), 3.358521, 4d); + assertEquals(hmm.getCheckSum().longValue(), 3106786190l); + assertEquals(hmm.getGatheringThreshold(), "70.30 70.30"); + assertEquals(hmm.getTrustedCutoff(), "70.30 70.30"); + assertEquals(hmm.getNoiseCutoff(), "70.20 70.20"); + List symbols = new ArrayList<>(); symbols.add('A'); symbols.add('C'); @@ -73,75 +85,75 @@ public class HMMFileTest { symbols.add('V'); symbols.add('W'); symbols.add('Y'); - - assertEquals(pKinase.hmm.getSymbols(), symbols); - - assertEquals(pKinase.hmm.getMatchEmission(0, 19), 3.43274); - assertEquals(pKinase.hmm.getMatchEmission(12, 12), 4.33979); - assertEquals(pKinase.hmm.getMatchEmission(23, 7), 3.65600); - assertEquals(pKinase.hmm.getMatchEmission(54, 1), 4.76187); - assertEquals(pKinase.hmm.getMatchEmission(79, 0), 2.81579); - assertEquals(pKinase.hmm.getMatchEmission(100, 0), 1.86496); - assertEquals(pKinase.hmm.getMatchEmission(112, 14), 2.77179); - assertEquals(pKinase.hmm.getMatchEmission(143, 17), 5.10478); - assertEquals(pKinase.hmm.getMatchEmission(156, 4), 4.69372); - assertEquals(pKinase.hmm.getMatchEmission(178, 3), 2.52594); - assertEquals(pKinase.hmm.getMatchEmission(210, 2), 4.23598); - assertEquals(pKinase.hmm.getMatchEmission(260, 19), 3.81122); - - assertEquals(pKinase.hmm.getInsertEmission(2, 1), 4.42225); - assertEquals(pKinase.hmm.getInsertEmission(15, 6), 3.72501); - assertEquals(pKinase.hmm.getInsertEmission(22, 9), 2.69355); - assertEquals(pKinase.hmm.getInsertEmission(57, 2), 2.77519); - assertEquals(pKinase.hmm.getInsertEmission(62, 14), 2.89801); - assertEquals(pKinase.hmm.getInsertEmission(95, 17), 2.98532); - assertEquals(pKinase.hmm.getInsertEmission(105, 4), 3.46354); - assertEquals(pKinase.hmm.getInsertEmission(134, 1), 4.42225); - assertEquals(pKinase.hmm.getInsertEmission(143, 0), 2.68618); - assertEquals(pKinase.hmm.getInsertEmission(152, 16), 2.77519); - assertEquals(pKinase.hmm.getInsertEmission(203, 16), 2.77519); - assertEquals(pKinase.hmm.getInsertEmission(255, 12), 2.73739); - - assertEquals(pKinase.hmm.getStateTransition(0, 6), + + 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(getStateTransition(0, 6, hmm), Double.NEGATIVE_INFINITY); - assertEquals(pKinase.hmm.getStateTransition(3, 6), 0.95510); - assertEquals(pKinase.hmm.getStateTransition(29, 3), 0.61958); - assertEquals(pKinase.hmm.getStateTransition(46, 4), 0.77255); - assertEquals(pKinase.hmm.getStateTransition(53, 1), 5.01631); - assertEquals(pKinase.hmm.getStateTransition(79, 2), 5.73865); - assertEquals(pKinase.hmm.getStateTransition(101, 2), 5.73865); - assertEquals(pKinase.hmm.getStateTransition(120, 5), 0.48576); - assertEquals(pKinase.hmm.getStateTransition(146, 5), 0.70219); - assertEquals(pKinase.hmm.getStateTransition(169, 3), 1.23224); - assertEquals(pKinase.hmm.getStateTransition(209, 0), 0.01003); - assertEquals(pKinase.hmm.getStateTransition(243, 1), 5.01631); - - assertEquals(pKinase.hmm.getNodeAlignmentColumn(3).intValue(), 3); - assertEquals(pKinase.hmm.getReferenceAnnotation(7), '-'); - assertEquals(pKinase.hmm.getConsensusResidue(23), 't'); - assertEquals(pKinase.hmm.getMaskedValue(30), '-'); - assertEquals(pKinase.hmm.getConsensusStructure(56), 'S'); - - assertEquals(pKinase.hmm.getNodeAlignmentColumn(78).intValue(), 136); - assertEquals(pKinase.hmm.getReferenceAnnotation(93), '-'); - assertEquals(pKinase.hmm.getConsensusResidue(145), 'a'); - assertEquals(pKinase.hmm.getMaskedValue(183), '-'); - assertEquals(pKinase.hmm.getConsensusStructure(240), 'H'); - + 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(hmm.getNodeAlignmentColumn(3).intValue(), 3); + assertEquals(hmm.getReferenceAnnotation(7), '-'); + assertEquals(hmm.getConsensusResidue(23), 't'); + assertEquals(hmm.getMaskedValue(30), '-'); + assertEquals(hmm.getConsensusStructure(56), 'S'); + + assertEquals(hmm.getNodeAlignmentColumn(78).intValue(), 136); + assertEquals(hmm.getReferenceAnnotation(93), '-'); + assertEquals(hmm.getConsensusResidue(145), 'a'); + assertEquals(hmm.getMaskedValue(183), '-'); + assertEquals(hmm.getConsensusStructure(240), 'H'); + } - + @Test public void testParseFileProperties() throws IOException { - FileReader fr = new FileReader(fn3.getDataObject()); + FileReader fr = new FileReader(new File("H:/fn3.hmm")); BufferedReader br = new BufferedReader(fr); fn3.parseFileProperties(br); fn3.parseModel(br); // this is for a later test HiddenMarkovModel testHMM = new HiddenMarkovModel(); - testHMM = fn3.getHmm(); + testHMM = fn3.getHMM(); br.close(); fr.close(); - + assertEquals(testHMM.getName(), "fn3"); assertEquals(testHMM.getAccessionNumber(), "PF00041.13"); assertEquals(testHMM.getDescription(), @@ -165,48 +177,15 @@ public class HMMFileTest { assertEquals(testHMM.getViterbi(), "-9.7737 0.71847"); assertEquals(testHMM.getMSV(), "-9.4043 0.71847"); assertEquals(testHMM.getForward(), "-3.8341 0.71847"); - - FileReader fr2 = new FileReader(emptyFile.getDataObject()); - BufferedReader br2 = new BufferedReader(fr2); - emptyFile.parseFileProperties(br2); - testHMM = emptyFile.getHmm(); - br2.close(); - fr2.close(); - - assertNull(testHMM.getName()); - assertNull(testHMM.getAccessionNumber()); - assertNull(testHMM.getDescription()); - assertNull(testHMM.getLength()); - assertNull(testHMM.getMaxInstanceLength()); - assertNull(testHMM.getAlphabetType()); - assertEquals(testHMM.referenceAnnotationIsActive(), false); - assertEquals(testHMM.maskValueIsActive(), false); - assertEquals(testHMM.consensusResidueIsActive(), false); - assertEquals(testHMM.consensusStructureIsActive(), - false); - assertEquals(testHMM.mapIsActive(), false); - assertNull(testHMM.getDate()); - assertNull(testHMM.getCommandLineLog()); - assertNull(testHMM.getNumberOfSequences()); - assertNull(testHMM.getEffectiveNumberOfSequences()); - assertNull(testHMM.getCheckSum()); - assertNull(testHMM.getGatheringThreshold()); - assertNull(testHMM.getGatheringThreshold()); - assertNull(testHMM.getTrustedCutoff()); - assertNull(testHMM.getTrustedCutoff()); - assertNull(testHMM.getNoiseCutoff()); - assertNull(testHMM.getNoiseCutoff()); - assertNull(testHMM.getViterbi()); - assertNull(testHMM.getMSV()); - assertNull(testHMM.getForward()); - - FileReader fr3 = new FileReader(made1.getDataObject()); + + + FileReader fr3 = new FileReader(new File("H:/MADE1.hmm")); BufferedReader br3 = new BufferedReader(fr3); made1.parseFileProperties(br3); - testHMM = made1.getHmm(); + testHMM = made1.getHMM(); br3.close(); fr3.close(); - + assertEquals(testHMM.getName(), "MADE1"); assertEquals(testHMM.getAccessionNumber(), "DF0000629.2"); assertEquals(testHMM.getDescription(), @@ -230,31 +209,31 @@ public class HMMFileTest { assertEquals(testHMM.getViterbi(), "-9.3632 0.71858"); assertEquals(testHMM.getMSV(), "-8.5786 0.71858"); assertEquals(testHMM.getForward(), "-3.4823 0.71858"); - - + + } - + @Test public void testGetTransitionType() { - - assertEquals(fn3.getTransitionType("mm").intValue(), 0); - assertEquals(fn3.getTransitionType("mi").intValue(), 1); - assertEquals(fn3.getTransitionType("md").intValue(), 2); - assertEquals(fn3.getTransitionType("im").intValue(), 3); - assertEquals(fn3.getTransitionType("ii").intValue(), 4); - assertEquals(fn3.getTransitionType("dm").intValue(), 5); - assertEquals(fn3.getTransitionType("dd").intValue(), 6); - assertNull(fn3.getTransitionType("df")); - + HiddenMarkovModel hmm = fn3.getHMM(); + assertEquals(hmm.getTransitionType("mm").intValue(), 0); + assertEquals(hmm.getTransitionType("mi").intValue(), 1); + assertEquals(hmm.getTransitionType("md").intValue(), 2); + assertEquals(hmm.getTransitionType("im").intValue(), 3); + assertEquals(hmm.getTransitionType("ii").intValue(), 4); + assertEquals(hmm.getTransitionType("dm").intValue(), 5); + assertEquals(hmm.getTransitionType("dd").intValue(), 6); + assertNull(hmm.getTransitionType("df")); + } - + @Test public void testFillList() { 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); @@ -264,11 +243,11 @@ public class HMMFileTest { filledArray.add(4.3); filledArray.add(2.3); filledArray.add(6.9); - + assertEquals(HMMFile.fillList(scanner1, 9), filledArray); filledArray.clear(); scanner1.close(); - + Scanner scanner2 = new Scanner( "1.346554 5.58756754 35.3523645 12345.3564 1.4"); filledArray.add(1.346554); @@ -276,16 +255,16 @@ public class HMMFileTest { filledArray.add(35.3523645); filledArray.add(12345.3564); filledArray.add(1.4); - + assertEquals(HMMFile.fillList(scanner2, 5), filledArray); scanner2.close(); - + } - + @Test public void testParseModel() throws IOException { - FileReader fr = new FileReader(made1.getDataObject()); + FileReader fr = new FileReader(new File("H:/MADE1.hmm")); BufferedReader br = new BufferedReader(fr); HiddenMarkovModel testHMM = new HiddenMarkovModel(); for (int i = 0; i < 24; i++) @@ -293,95 +272,169 @@ public class HMMFileTest { br.readLine(); } made1.parseModel(br); - testHMM = made1.getHmm(); + testHMM = made1.getHMM(); br.close(); fr.close(); - - assertEquals(testHMM.getMatchEmission(0, 2), 1.62906); - assertEquals(testHMM.getMatchEmission(2, 1), 2.37873); - assertEquals(testHMM.getMatchEmission(12, 2), 2.61355); - assertEquals(testHMM.getMatchEmission(26, 0), 1.86925); - assertEquals(testHMM.getMatchEmission(32, 3), 2.58263); - assertEquals(testHMM.getMatchEmission(59, 3), 2.20507); - assertEquals(testHMM.getMatchEmission(63, 0), 0.41244); - assertEquals(testHMM.getMatchEmission(69, 1), 3.17398); - assertEquals(testHMM.getMatchEmission(76, 2), 2.65861); - - assertEquals(testHMM.getInsertEmission(0, 1), 1.38629); - assertEquals(testHMM.getInsertEmission(1, 2), 1.38629); - assertEquals(testHMM.getInsertEmission(31, 3), 1.28150); - assertEquals(testHMM.getInsertEmission(43, 0), 1.32290); - assertEquals(testHMM.getInsertEmission(48, 2), 1.52606); - assertEquals(testHMM.getInsertEmission(52, 1), 1.62259); - assertEquals(testHMM.getInsertEmission(67, 0), 1.38141); - assertEquals(testHMM.getInsertEmission(70, 3), 1.38629); - assertEquals(testHMM.getInsertEmission(80, 3), 1.38629); - - assertEquals(testHMM.getStateTransition(2, 0), 0.03725); - assertEquals(testHMM.getStateTransition(6, 1), 3.89715); - assertEquals(testHMM.getStateTransition(9, 3), 1.38021); - assertEquals(testHMM.getStateTransition(20, 4), 0.23815); - assertEquals(testHMM.getStateTransition(34, 6), 0.33363); - assertEquals(testHMM.getStateTransition(46, 5), 1.05474); - assertEquals(testHMM.getStateTransition(57, 6), 0.31164); - assertEquals(testHMM.getStateTransition(68, 2), 3.99242); - assertEquals(testHMM.getStateTransition(80, 6), + + 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(getStateTransition(80, 6, testHMM), Double.NEGATIVE_INFINITY); - + } - + @Test public void testParseAnnotations() { - HMMFile testFile = new HMMFile("H:/EmptyFile.hmm"); - testFile.hmm.getNodes().add(new HMMNode()); - testFile.hmm.getNodes().add(new HMMNode()); - - testFile.hmm.setConsensusResidueStatus(true); - testFile.hmm.setMAPStatus(true); - testFile.hmm.setReferenceAnnotationStatus(true); - testFile.hmm.setConsensusStructureStatus(true); - testFile.hmm.setMaskedValueStatus(true); + HMMFile testFile = new HMMFile(); + testFile.getHMM().getNodes().add(new HMMNode()); + testFile.getHMM().getNodes().add(new HMMNode()); + testFile.getHMM().getNodes().add(new HMMNode()); + + + testFile.getHMM().setConsensusResidueStatus(true); + testFile.getHMM().setMAPStatus(true); + testFile.getHMM().setReferenceAnnotationStatus(true); + testFile.getHMM().setConsensusStructureStatus(true); + testFile.getHMM().setMaskedValueStatus(true); Scanner scanner = new Scanner("1345 t t t t"); - testFile.parseAnnotations(scanner, 0); - assertEquals(testFile.hmm.getNodeAlignmentColumn(0).intValue(), 1345); - assertEquals(testFile.hmm.getConsensusResidue(0), 't'); - assertEquals(testFile.hmm.getReferenceAnnotation(0), 't'); - assertEquals(testFile.hmm.getMaskedValue(0), 't'); - assertEquals(testFile.hmm.getConsensusStructure(0), 't'); - - scanner.close(); - - testFile.hmm.setConsensusResidueStatus(true); - testFile.hmm.setMAPStatus(false); - testFile.hmm.setReferenceAnnotationStatus(true); - testFile.hmm.setConsensusStructureStatus(false); - testFile.hmm.setMaskedValueStatus(false); + testFile.parseAnnotations(scanner, 1); + + testFile.getHMM().setConsensusResidueStatus(true); + testFile.getHMM().setMAPStatus(false); + testFile.getHMM().setReferenceAnnotationStatus(true); + testFile.getHMM().setConsensusStructureStatus(false); + testFile.getHMM().setMaskedValueStatus(false); Scanner scanner2 = new Scanner("- y x - -"); - testFile.parseAnnotations(scanner2, 1); - assertNull(testFile.hmm.getNodeAlignmentColumn(1)); - assertEquals(testFile.hmm.getConsensusResidue(1), 'y'); - assertEquals(testFile.hmm.getReferenceAnnotation(1), 'x'); - assertEquals(testFile.hmm.getMaskedValue(1), '-'); - assertEquals(testFile.hmm.getConsensusStructure(1), '-'); - + testFile.parseAnnotations(scanner2, 2); + + HiddenMarkovModel hmm = testFile.getHMM(); + + assertEquals(hmm.getNodeAlignmentColumn(1).intValue(), 1345); + assertEquals(hmm.getConsensusResidue(1), 't'); + assertEquals(hmm.getReferenceAnnotation(1), 't'); + assertEquals(hmm.getMaskedValue(1), 't'); + assertEquals(hmm.getConsensusStructure(1), 't'); + + assertEquals(hmm.findNodeIndex(1345).intValue(), 1); + + scanner.close(); + + assertNull(hmm.getNodeAlignmentColumn(2)); + assertEquals(hmm.getConsensusResidue(2), 'y'); + assertEquals(hmm.getReferenceAnnotation(2), 'x'); + assertEquals(hmm.getMaskedValue(2), '-'); + assertEquals(hmm.getConsensusStructure(2), '-'); + + assertNull(hmm.findNodeIndex(2)); + scanner2.close(); } + + /** + * tests to see if file produced by the output matches the file from the input + * + * @throws IOException + */ + @Test(priority = 3) public void testExportFile() throws IOException { - - fn3.exportFile("H:/WriteFileTest.hmm"); + fn3.exportFile("H:/WriteFileTest.txt"); + HMMFile fn3Clone = new HMMFile( + new FileParse("H:/WriteFileTest.txt", DataSourceType.FILE)); + fn3Clone.parse(); + HiddenMarkovModel fn3HMM = new HiddenMarkovModel(); + HiddenMarkovModel fn3CloneHMM = new HiddenMarkovModel(); + fn3HMM = fn3.getHMM(); + fn3CloneHMM = fn3Clone.getHMM(); + + for (int i = 0; i < fn3HMM.getLength(); i++) + { + List list1; + List list2; + boolean result; + + list1 = fn3HMM.getNode(i).getMatchEmissions(); + list2 = fn3CloneHMM.getNode(i).getMatchEmissions(); + + result = checkIfListsAreIdentical(list1, list2); + assertEquals(result, true); + + list1 = fn3HMM.getNode(i).getInsertEmissions(); + list2 = fn3CloneHMM.getNode(i).getInsertEmissions(); + + result = checkIfListsAreIdentical(list1, list2); + assertEquals(result, true); + + list1 = fn3HMM.getNode(i).getStateTransitions(); + list2 = fn3CloneHMM.getNode(i).getStateTransitions(); + + result = checkIfListsAreIdentical(list1, list2); + assertEquals(result, true); + + if (i > 0) + { + int alignColumn1; + int alignColumn2; + + alignColumn1 = fn3HMM.getNodeAlignmentColumn(i); + alignColumn2 = fn3CloneHMM.getNodeAlignmentColumn(i); + + assertEquals(alignColumn1, alignColumn2); + + char annotation1; + char annotation2; + + annotation1 = fn3HMM.getReferenceAnnotation(i); + annotation2 = fn3CloneHMM.getReferenceAnnotation(i); + + assertEquals(annotation1, annotation2); + + annotation1 = fn3HMM.getConsensusResidue(i); + annotation2 = fn3CloneHMM.getConsensusResidue(i); + + assertEquals(annotation1, annotation2); + } + + } + } - + @Test(priority = 1) public void testAppendFileProperties() { StringBuilder testBuilder = new StringBuilder(); fn3.appendFileProperties(testBuilder); Scanner testScanner = new Scanner(testBuilder.toString()); - + String[] expected = new String[] { "HMMER3/f [3.1b1 | May 2013]", "NAME fn3", "ACC PF00041.13", "DESC Fibronectin type III domain", "LENG 86", "ALPH amino", @@ -391,15 +444,15 @@ public class HMMFileTest { "NC 7.90 7.90", "STATS LOCAL MSV -9.4043 0.71847", "STATS LOCAL VITERBI -9.7737 0.71847", "STATS LOCAL FORWARD -3.8341 0.71847" }; - + for (String value : expected) { assertEquals(testScanner.nextLine(), value); } - + testScanner.close(); } - + @Test(priority = 2) public void testAppendModel() { @@ -408,17 +461,40 @@ public class HMMFileTest { String string = testBuilder.toString(); assertEquals(findValue(2, 2, 2, string), "4.42225"); assertEquals(findValue(12, 14, 1, string), "2.79307"); + assertEquals(findValue(6, 24, 3, string), "0.48576"); + assertEquals(findValue(19, 33, 2, string), "4.58477"); + assertEquals(findValue(20, 64, 2, string), "3.61505"); + assertEquals(findValue(3, 72, 3, string), "6.81068"); + assertEquals(findValue(10, 80, 2, string), "2.69355"); + assertEquals(findValue(16, 65, 1, string), "2.81003"); + assertEquals(findValue(14, 3, 1, string), "2.69012"); + assertEquals(findValue(11, 32, 1, string), "4.34805"); + } + + /** + * + * @param symbolIndex + * index of symbol being searched. First symbol has index 1. + * @param nodeIndex + * index of node being searched. Begin node has index 0. First node + * has index 1. + * @param line + * index of line being searched in node. First line has index 1. + * @param model + * string model being searched + * @return value at specified position + */ public String findValue(int symbolIndex, int nodeIndex, int line, String model) { - + String value = ""; Scanner scanner = new Scanner(model); scanner.nextLine(); scanner.nextLine(); - + for (int lineIndex = 0; lineIndex < line - 1; lineIndex++) { scanner.nextLine(); @@ -429,7 +505,7 @@ public class HMMFileTest { scanner.nextLine(); scanner.nextLine(); } - + for (int symbol = 0; symbol < symbolIndex; symbol++) { value = scanner.next(); @@ -441,10 +517,79 @@ public class HMMFileTest { { scanner.next(); } - + + } + return value; + + } + + public boolean checkIfListsAreIdentical(List list1, + List list2) + { + boolean isDifferent = false; + for (int i = 0; i < list1.size(); i++) + { + Double entry1; + Double entry2; + entry1 = list1.get(i); + entry2 = list2.get(i); + if (!(entry1 == entry2)) + { + isDifferent = true; + } } + return isDifferent; + } + + /** + * gets the match emission at a node for a symbol + * + * @param nodeIndex + * position of node in model + * @param symbolIndex + * index of symbol being searched + * @return negative log probability of a match emission of the given symbol + */ + public double getMatchEmission(int nodeIndex, int symbolIndex, + HiddenMarkovModel hmm) + { + double value = hmm.getNodes().get(nodeIndex).getMatchEmissions() + .get(symbolIndex); + return value; + } + + /** + * gets the insert emission at a node for a symbol + * + * @param nodeIndex + * position of node in model + * @param symbolIndex + * index of symbol being searched + * @return negative log probability of an insert emission of the given symbol + */ + public double getInsertEmission(int nodeIndex, int symbolIndex, + HiddenMarkovModel hmm) + { + double value = hmm.getNodes().get(nodeIndex).getInsertEmissions() + .get(symbolIndex); return value; + } + /** + * gets the state transition at a node for a specific transition + * + * @param nodeIndex + * position of node in model + * @param transitionIndex + * index of stransition being searched + * @return negative log probability of a state transition of the given type + */ + public double getStateTransition(int nodeIndex, int transitionIndex, + HiddenMarkovModel hmm) + { + double value = hmm.getNodes().get(nodeIndex).getStateTransitions() + .get(transitionIndex); + return value; } } -- 1.7.10.2