/**
- * reads in and writes out a HMMER standard file
+ * Adds capability to read in and write out HMMER3 files. Currently only supports HMMER3/f.
*
*
* @author TZVanaalten
private final String NEW_LINE = "\n";
-
// file header
String fileHeader;
+ //number of symbols in the alphabet used in the hidden Markov model
int numberOfSymbols;
private final String SPACE = " ";
private final String EMPTY = "";
+ //This is a line that needs to be added to each HMMER£ file. It is purely for readability.
private static final String TRANSITIONTYPELINE = "m->m m->i m->d i->m i->i d->m d->d";
+ /**
+ * Constructor for HMMFile
+ * @param source
+ * @throws IOException
+ */
public HMMFile(FileParse source) throws IOException
{
super(false, source);
}
+ /**
+ * Default constructor, do not use!
+ */
public HMMFile()
{
}
+ /**
+ * Returns the HMM produced by reading in a HMMER3 file.
+ *
+ * @return
+ */
public HiddenMarkovModel getHMM()
{
return hmm;
}
+ /**
+ * Sets the HMM used in this file.
+ *
+ * @param model
+ */
public void setHMM(HiddenMarkovModel model)
{
this.hmm = model;
}
+ /**
+ * Gets the name of the hidden Markov model.
+ *
+ * @return
+ */
public String getName()
{
return hmm.getName();
}
/**
- * reads data from HMM file
+ * Reads the data from HMM file into the HMM field on this object.
*
* @throws IOException
*/
/**
- * imports file properties from hmm file
+ * Imports the file properties from a HMMER3 file.
*
* @param input
- * buffered reader used to read in file
+ * The buffered reader used to read in the file.
* @throws IOException
*/
void parseFileProperties(BufferedReader input) throws IOException
}
/**
- * parses the model data from the hmm file
+ * Parses the model data from the HMMER3 file
*
* @param input
- * buffered reader used to read file
+ * The buffered reader used to read the file.
* @throws IOException
*/
void parseModel(BufferedReader input) throws IOException
}
/**
- * parses annotations on match emission line
+ * Parses the annotations on the match emission line.
*
* @param scanner
- * scanner which is processing match emission line
+ * The scanner which is processing match emission line.
* @param index
- * index of node which is beign scanned
+ * The index of node which is being scanned.
*/
void parseAnnotations(Scanner scanner, int index)
{
/**
+ * Fills a list of doubles based on an input line.
*
* @param input
- * scanner for line containing data to be transferred to list
+ * The scanner for the line containing the data to be transferred to
+ * the list.
* @param numberOfElements
- * number of elements in the list to be filled
- * @return filled list
+ * The number of elements in the list to be filled.
+ * @return filled list Returns the list of doubles.
*/
static List<Double> fillList(Scanner input,
int numberOfElements)
if (next.contains("*")) // state transitions to or from delete states
// occasionally have values of -infinity. These
// values are represented by an * in the .hmm
- // file, and by a null value in the
- // HiddenMarkovModel class
+ // file.
{
list.add(Double.NEGATIVE_INFINITY);
}
/**
- * writes a HiddenMarkovModel to a file
+ * Writes a HMM to a file/
*
* @param exportLocation
- * Filename, URL or Pasted String to write to
+ * Filename, URL or Pasted String to write to.
* @throws FileNotFoundException
* @throws UnsupportedEncodingException
*
}
+ /**
+ * Returns a string to be added to the StringBuilder containing the entire
+ * output String.
+ *
+ * @param initialColumnSeparation
+ * The initial whitespace separation between the left side of the
+ * file and first character.
+ * @param columnSeparation
+ * The separation between subsequent data entries.
+ * @param data
+ * The list fo data to be added to the String.
+ * @return
+ */
String addData(int initialColumnSeparation,
int columnSeparation, List<String> data)
{
return line;
}
+ /**
+ * Converts list of characters into a list of Strings.
+ *
+ * @param list
+ * @return Returns the list of Strings.
+ */
List<String> charListToStringList(List<Character> list)
{
List<String> strList = new ArrayList<>();
return strList;
}
- List<String> doubleListToStringList(List<Double> list,
- int noOfDecimals)
+ /**
+ * Converts a list of doubles into a list of Strings, rounded to the nearest
+ * 5th decimal place.
+ *
+ * @param list
+ * @param noOfDecimals
+ * @return
+ */
+ List<String> doubleListToStringList(List<Double> list)
{
List<String> strList = new ArrayList<>();
for (double value : list)
return strList;
}
+ /**
+ * Converts a primitive array of Strings to a list of Strings.
+ *
+ * @param array
+ * @return
+ */
List<String> stringArrayToStringList(String[] array)
{
List<String> list = new ArrayList<>();
return list;
}
+ /**
+ * Appends the hidden Markov model data to the StringBuilder containing the
+ * output
+ *
+ * @param file
+ * The StringBuilder containing the output.
+ */
void appendModel(StringBuilder file)
{
String symbolLine = "HMM";
List<Double> doubleMatches;
doubleMatches = hmm.getNode(node).getMatchEmissions();
convertListToLogSpace(doubleMatches);
- strMatches = doubleListToStringList(doubleMatches, 5);
+ strMatches = doubleListToStringList(doubleMatches);
matchLine += addData(10, 9, strMatches);
List<Double> doubleInserts;
doubleInserts = hmm.getNode(node).getInsertEmissions();
convertListToLogSpace(doubleInserts);
- strInserts = doubleListToStringList(doubleInserts, 5);
+ strInserts = doubleListToStringList(doubleInserts);
insertLine += addData(17, 9, strInserts);
file.append(insertLine + NEW_LINE);
List<Double> doubleTransitions;
doubleTransitions = hmm.getNode(node).getStateTransitions();
convertListToLogSpace(doubleTransitions);
- strTransitions = doubleListToStringList(doubleTransitions, 5);
+ strTransitions = doubleListToStringList(doubleTransitions);
transitionLine += addData(17, 9, strTransitions);
file.append(transitionLine + NEW_LINE);
}
}
+ /**
+ * Appends the hidden Markov model file properties to the StringBuilder
+ * containing the output
+ *
+ * @param file
+ * The StringBuilder containing the output.
+ */
void appendFileProperties(StringBuilder file)
{
String line;
}
-
+ /**
+ * Returns the char value of a single lettered String.
+ *
+ * @param string
+ * @return
+ */
char charValue(String string)
{
char character;
character = string.charAt(0);
return character;
+
}
@Override
return null;
}
+ /**
+ * Converts the probabilities contained in a list into log space.
+ *
+ * @param list
+ */
void convertListToLogSpace(List<Double> list)
{