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;
* @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
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
* 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();
* 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++)
{
* @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
{
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;
- }
/**
*
* number of elements in the list to be filled
* @return filled list
*/
- public static List<Double> fillList(Scanner input,
+ static List<Double> fillList(Scanner input,
int numberOfElements)
{
List<Double> list = new ArrayList<>();
file.append("//");
+ PrintWriter output = new PrintWriter(exportLocation);
+ output.append(file);
+ output.close();
+
}
- public String addData(int initialColumnSeparation,
+ String addData(int initialColumnSeparation,
int columnSeparation, List<String> data)
{
String line = EMPTY;
return line;
}
- public static List<String> charListToStringList(List<Character> list)
+ List<String> charListToStringList(List<Character> list)
{
List<String> strList = new ArrayList<>();
for (char value : list)
return strList;
}
- public static List<String> doubleListToStringList(List<Double> list,
+ List<String> doubleListToStringList(List<Double> list,
int noOfDecimals)
{
List<String> strList = new ArrayList<>();
return strList;
}
- public static List<String> stringArrayToStringList(String[] array)
+ List<String> stringArrayToStringList(String[] array)
{
List<String> list = new ArrayList<>();
for (String value : array)
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());
- 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;
+ }
}