Mercurial > repos > guru-ananda > rhmm
comparison hmm/hmm.xml @ 0:e090cf6dd3f5 draft
Imported from capsule None
author | devteam |
---|---|
date | Thu, 22 Jan 2015 10:40:18 -0500 |
parents | |
children | 38f5cd46ffd3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e090cf6dd3f5 |
---|---|
1 <tool id="hmm_1" name="Fit HMM " version="1.0.0"> | |
2 <description>on numeric data</description> | |
3 <command interpreter="bash">\$R_SCRIPT_PATH/r_wrapper.sh $script_file</command> | |
4 | |
5 <inputs> | |
6 <param name="input" type="data" format="tabular" label="Dataset"/> | |
7 <param name="var_cols" label="Select columns containing observations " type="data_column" data_ref="input" numerical="True" multiple="true" > | |
8 <validator type="no_options" message="Please select at least one column."/> | |
9 </param> | |
10 <param name="samp_col" label="Select column containing sample numbers " type="data_column" data_ref="input" numerical="True" multiple="false" > | |
11 <validator type="no_options" message="Please select a column."/> | |
12 </param> | |
13 <param name="header" type="select" label="Treat first line as header? "> | |
14 <option value="yes" selected="true">Yes</option> | |
15 <option value="no">No</option> | |
16 </param> | |
17 <param name="nStates" size="10" type="integer" value="2" label="Number of hidden states " /> | |
18 <conditional name="disChoice"> | |
19 <param name="dis" type="select" label="Distribution"> | |
20 <option value="NORMAL" selected="true">Normal</option> | |
21 <option value="DISCRETE">Discrete</option> | |
22 <option value="MIXTURE">Mixture</option> | |
23 </param> | |
24 <when value="NORMAL" /> | |
25 <when value="DISCRETE" /> | |
26 <when value="MIXTURE"> | |
27 <param name="nMixt" size="10" type="integer" value="2" label="Number of mixtures of normal distributions " /> | |
28 </when> | |
29 </conditional> | |
30 <!-- | |
31 <conditional name="asymptChoice"> | |
32 <param name="asymptCov" type="select" label="Compute asymptotic covariance matrix? "> | |
33 <option value="FALSE" selected="true">No</option> | |
34 <option value="TRUE">Yes</option> | |
35 </param> | |
36 <when value="FALSE" /> | |
37 <when value="TRUE"> | |
38 <param name="asymptMethod" type="select" label="Method for computing asymptotic covariance matrix "> | |
39 <option value="nlme" selected="true">nlme</option> | |
40 <option value="optim">optim</option> | |
41 </param> | |
42 </when> | |
43 </conditional> | |
44 --> | |
45 </inputs> | |
46 | |
47 <configfiles> | |
48 <configfile name="script_file"> | |
49 ## Setup R error handling to go to stderr | |
50 options( show.error.messages=F, | |
51 error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) }, | |
52 warn = -1 ) | |
53 suppressPackageStartupMessages(library('RHmm')) | |
54 | |
55 #if str($header) == "yes" | |
56 inp = read.table( "${input.file_name}", header=T ) | |
57 #else | |
58 inp = read.table( "${input.file_name}", header=F ) | |
59 #end if | |
60 | |
61 samp_numbers = unique(inp[, ${samp_col}]) | |
62 | |
63 if (length(samp_numbers) == 1){ | |
64 samp_list = inp[,c(${var_cols})] | |
65 } else { | |
66 samp_list=list() | |
67 for (i in 1:length(samp_numbers)) { | |
68 samp_list[[i]] = inp[(inp[,${samp_col}] == samp_numbers[i]),c(${var_cols})] | |
69 } | |
70 } | |
71 | |
72 nStates = ${nStates} | |
73 dis = "$disChoice['dis']" | |
74 nMixt = 0 | |
75 | |
76 #if $disChoice['dis'] == "MIXTURE" | |
77 nMixt = ${disChoice.nMixt} | |
78 #end if | |
79 | |
80 ##asymptCov = $asymptChoice['asymptCov'] | |
81 asymptCov = "FALSE" | |
82 asymptMethod = "nlme" | |
83 | |
84 ##if (asymptCov == "TRUE") { | |
85 ## asymptMethod = "${asymptChoice.asymptMethod}" | |
86 ##} | |
87 | |
88 #if $disChoice['dis'] == "MIXTURE" | |
89 if (asymptCov == "TRUE") { | |
90 myfit = HMMFit(samp_list, nStates=nStates, dis=dis, nMixt=nMixt, asymptCov=asymptCov, asymptMethod=asymptMethod) | |
91 } else { | |
92 myfit = HMMFit(samp_list, nStates=nStates, dis=dis, nMixt=nMixt) | |
93 } | |
94 #else | |
95 if (asymptCov == "TRUE") { | |
96 myfit = HMMFit(samp_list, nStates=nStates, dis=dis, asymptCov=asymptCov, asymptMethod=asymptMethod) | |
97 } else { | |
98 myfit = HMMFit(samp_list, nStates=nStates, dis=dis) | |
99 } | |
100 #end if | |
101 | |
102 myfittxt=capture.output(myfit) | |
103 cat(myfittxt,file="${out_file1}",sep="\n") | |
104 | |
105 | |
106 samp_list_stateSol = list() | |
107 if (length(samp_numbers) == 1){ | |
108 samp_list_stateSol[[1]]=unlist(viterbi(myfit, samp_list)["states"]) | |
109 } else { | |
110 for (i in 1:length(samp_numbers)) { | |
111 samp_list_stateSol[[i]]=unlist(viterbi(myfit, samp_list[[i]])["states"]) | |
112 } | |
113 } | |
114 inp_stateSol=cbind(inp,unlist(samp_list_stateSol)) | |
115 write.table(inp_stateSol,file="${out_file2}",sep="\t",row.names=F,col.names=F,quote=F) | |
116 | |
117 </configfile> | |
118 </configfiles> | |
119 | |
120 <outputs> | |
121 <data format="txt" name="out_file1" /> | |
122 <data format="input" name="out_file2" /> | |
123 </outputs> | |
124 | |
125 <requirements> | |
126 <requirement type="set_environment">R_SCRIPT_PATH</requirement> | |
127 <requirement type="package" version="2.15.0">R</requirement> | |
128 </requirements> | |
129 | |
130 <help> | |
131 | |
132 .. class:: infomark | |
133 | |
134 **What it does** | |
135 | |
136 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. | |
137 | |
138 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. | |
139 | |
140 *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.* | |
141 | |
142 ----- | |
143 | |
144 .. class:: warningmark | |
145 | |
146 **Note** | |
147 | |
148 The tool fails if any of the observation columns contain non-numeric data. | |
149 | |
150 | |
151 </help> | |
152 </tool> |