# HG changeset patch
# User devteam
# Date 1421941218 18000
# Node ID e090cf6dd3f5885ddf63ed952e283526f0d0cc5d
Imported from capsule None
diff -r 000000000000 -r e090cf6dd3f5 hmm/hmm.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hmm/hmm.xml Thu Jan 22 10:40:18 2015 -0500
@@ -0,0 +1,152 @@
+
+ on numeric data
+ \$R_SCRIPT_PATH/r_wrapper.sh $script_file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ## Setup R error handling to go to stderr
+ options( show.error.messages=F,
+ error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) },
+ warn = -1 )
+ suppressPackageStartupMessages(library('RHmm'))
+
+ #if str($header) == "yes"
+ inp = read.table( "${input.file_name}", header=T )
+ #else
+ inp = read.table( "${input.file_name}", header=F )
+ #end if
+
+ samp_numbers = unique(inp[, ${samp_col}])
+
+ if (length(samp_numbers) == 1){
+ samp_list = inp[,c(${var_cols})]
+ } else {
+ samp_list=list()
+ for (i in 1:length(samp_numbers)) {
+ samp_list[[i]] = inp[(inp[,${samp_col}] == samp_numbers[i]),c(${var_cols})]
+ }
+ }
+
+ nStates = ${nStates}
+ dis = "$disChoice['dis']"
+ nMixt = 0
+
+ #if $disChoice['dis'] == "MIXTURE"
+ nMixt = ${disChoice.nMixt}
+ #end if
+
+ ##asymptCov = $asymptChoice['asymptCov']
+ asymptCov = "FALSE"
+ asymptMethod = "nlme"
+
+ ##if (asymptCov == "TRUE") {
+ ## asymptMethod = "${asymptChoice.asymptMethod}"
+ ##}
+
+ #if $disChoice['dis'] == "MIXTURE"
+ if (asymptCov == "TRUE") {
+ myfit = HMMFit(samp_list, nStates=nStates, dis=dis, nMixt=nMixt, asymptCov=asymptCov, asymptMethod=asymptMethod)
+ } else {
+ myfit = HMMFit(samp_list, nStates=nStates, dis=dis, nMixt=nMixt)
+ }
+ #else
+ if (asymptCov == "TRUE") {
+ myfit = HMMFit(samp_list, nStates=nStates, dis=dis, asymptCov=asymptCov, asymptMethod=asymptMethod)
+ } else {
+ myfit = HMMFit(samp_list, nStates=nStates, dis=dis)
+ }
+ #end if
+
+ myfittxt=capture.output(myfit)
+ cat(myfittxt,file="${out_file1}",sep="\n")
+
+
+ samp_list_stateSol = list()
+ if (length(samp_numbers) == 1){
+ samp_list_stateSol[[1]]=unlist(viterbi(myfit, samp_list)["states"])
+ } else {
+ for (i in 1:length(samp_numbers)) {
+ samp_list_stateSol[[i]]=unlist(viterbi(myfit, samp_list[[i]])["states"])
+ }
+ }
+ inp_stateSol=cbind(inp,unlist(samp_list_stateSol))
+ write.table(inp_stateSol,file="${out_file2}",sep="\t",row.names=F,col.names=F,quote=F)
+
+
+
+
+
+
+
+
+
+
+ R_SCRIPT_PATH
+ R
+
+
+
+
+.. class:: infomark
+
+**What it does**
+
+This tool uses the 'HMMFit' and 'viterbi' functions from 'RHmm' library from R statistical package to fit an Hidden Markov Model using Baum-Welch algorithm, and calculate the optimal hidden states sequence using Viterbi's algorithm.
+
+It returns two outputs - one containing summary statistics for HMMFit, and the other containing state numbers appended as a new column to the input data.
+
+*Ollivier TARAMASCO and Sebastian Bauer (2010). RHmm: Hidden Markov Models simulations and estimations. R package version 1.4.4. http://CRAN.R-project.org/package=RHmm.*
+
+-----
+
+.. class:: warningmark
+
+**Note**
+
+The tool fails if any of the observation columns contain non-numeric data.
+
+
+
+
diff -r 000000000000 -r e090cf6dd3f5 hmm/r_wrapper.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hmm/r_wrapper.sh Thu Jan 22 10:40:18 2015 -0500
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+### Run R providing the R script in $1 as standard input and passing
+### the remaining arguments on the command line
+
+# Function that writes a message to stderr and exits
+function fail
+{
+ echo "$@" >&2
+ exit 1
+}
+
+# Ensure R executable is found
+which R > /dev/null || fail "'R' is required by this tool but was not found on path"
+
+# Extract first argument
+infile=$1; shift
+
+# Ensure the file exists
+test -f $infile || fail "R input file '$infile' does not exist"
+
+# Invoke R passing file named by first argument to stdin
+R --vanilla --slave $* < $infile
diff -r 000000000000 -r e090cf6dd3f5 hmm/tool_dependencies.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hmm/tool_dependencies.xml Thu Jan 22 10:40:18 2015 -0500
@@ -0,0 +1,9 @@
+
+
+
+ $REPOSITORY_INSTALL_DIR
+
+
+
+
+