# Name of your program
package "RNApvmin" # don't use package if you're using automake

purpose "Calculate a perturbation vector that minimizes discripancies between predicted and observed pairing probabilities"
usage "RNApvmin [options] <file.shape>"
#version "2.0"   # don't use version if you're using automake


# command line options passed to gengetopt
args "--file-name=RNApvmin_cmdl --include-getopt --default-optional --unamed-opts --func-name=RNApvmin_cmdline_parser --arg-struct-name=RNApvmin_args_info"


description "The program reads a RNA sequence from stdin and uses an iterative minimization process to \
calculate a perturbation vector that minimizes the discripancies between predicted pairing probabilites \
and observed pairing probabilities (deduced from given shape reactivities). \
Experimental data is read from a given SHAPE file and normalized to pairing probabilities. \
The experimental data has to be provided in a multiline plain text file where \
each line has the format '[position] [nucleotide] [absolute shape reactivity]' (e.g. '3 A 0.7'). \
The objective function used for the minimization may be weighted by choosing appropriate values for \
sigma and tau.\n\

The minimization progress will be written to stderr. \
Once the minimization has terminated, the obtained perturbation vector is written to stdout."

# Options

option  "verbose" v
"Be verbose.\n"
details="Lower the log level setting such that even INFO messages are passed through.\n\n"
flag
off


section "I/O Options"
sectiondesc="Command line options for input and output (pre-)processing\n\n"

option  "numThreads"  j
"Set the number of threads used for calculations.\n\n"
int
optional


option  "log-level" -
"Set log level threshold.\n"
details="By default, any log messages are filtered such that only warnings (level 2) or errors (level 3)\
 are printed. This setting allows for specifying the log level threshold, where higher values result in\
 fewer information. Log-level 5 turns off all messages, even errors and other critical information.\n\n"
int
typestr="level"
default="2"
hidden


option  "log-file" -
"Print log messages to a file instead of stderr.\n"
string
typestr="filename"
default="RNApvmin.log"
argoptional
hidden


option  "log-time" -
"Include time stamp in log messages.\n\n"
flag
off
hidden


option  "log-call" -
"Include file and line of log calling function.\n\n"
flag
off
hidden


section "Algorithms"
sectiondesc="Select additional algorithms which should be included in the calculations.\nThe Minimum free energy\
 (MFE) and a structure representative are calculated in any case.\n\n"

option  "shapeConversion" -
"Specify the method used to convert SHAPE reactivities to pairing probabilities.\n"
details="The following methods can be used to convert SHAPE reactivities into the probability for a certain nucleotide to be unpaired.\n
'M': Use linear mapping according to Zarringhalam et al. 2012\n
'C': Use a cutoff-approach to divide into paired and unpaired nucleotides (e.g. \"C0.25\")\n
'S': Skip the normalizing step since the input data already represents probabilities for being unpaired rather than raw reactivity values\n
'L': Use a linear model to convert the reactivity into a probability for being unpaired (e.g. \"Ls0.68i0.2\" to use a slope of 0.68 and an intercept of 0.2)\n
'O': Use a linear model to convert the log of the reactivity into a probability for being unpaired (e.g. \"Os1.6i-2.29\" to use a slope of 1.6 and an intercept of -2.29)\n\n"
string
default="O"
optional

option  "tauSigmaRatio"  -
"Ratio of the weighting factors tau and sigma.\n"
details="A high ratio will lead to a solution as close as possible to the experimental data, \
while a low ratio will lead to results close to the thermodynamic prediction without guiding pseudo energies.\n\n"
double
default="1.0"
optional

option "objectiveFunction"  -
"The energies of the perturbation vector and the discripancies between predicted and observed pairing probabilities contribute to the objective \
function. This parameter defines, which function is used to process the contributions before summing them up.
0 square
1 absolute.\n\n"
int
default="0"
optional

option  "sampleSize"  -
"The iterative minimization process requires to evaluate the gradient of the objective function.\n"
details="A sample size of 0 leads to an analytical evaluation which scales as O(N^4). \
Choosing a sample size >0 estimates the gradient by sampling the given number of sequences from the ensemble, \
which is much faster.\n\n"
int
default="1000"
optional

option "nonRedundant" N
"Enable non-redundant sampling strategy.\n\n"
flag
off

option  "intermediatePath"  -
"Write an output file for each iteration of the minimization process.\n"
details="Each file contains the used perturbation vector and the score \
of the objective function. The number of the iteration will be appended to the given path.\n\n"
string
optional

option  "initialVector"  -
"Specify the vector of initial pertubations.\n"
details="Defines the initial perturbation vector which will be used as starting vector for the minimization process. \
The value 0 results in a null vector. Every other value x will be used to populate the initial vector with \
random numbers from the interval [-x,x].\n\n"
double
default="0"
optional

option  "minimizer"  -
"Set the minimizing algorithm used for finding an appropriate perturbation vector.\n"
details="The default option uses a custom implementation of the gradient descent algorithms while all \
other options represent various algorithms implemented in the GNU Scientific Library. \
When the GNU Scientific Library can not be found, only the default minimizer is available.\n\n"
enum
values="conjugate_fr","conjugate_pr","vector_bfgs", "vector_bfgs2", "steepest_descent", "default"
default="default"
optional

option  "initialStepSize" -
"The initial stepsize for the minimizer methods.\n\n"
double
default="0.01"
optional
hidden

option  "minStepSize" -
"The minimal stepsize for the minizimer methods.\n\n"
double
default="1e-15"
optional
hidden

option  "minImprovement" -
"The minimal improvement in the default minizimer method that has to be surpassed to considered a new result a better one.\n\n"
double
default="1e-3"
optional
hidden

option  "minimizerTolerance" -
"The tolerance to be used in the GSL minimizer methods.\n\n"
double
default="1e-3"
optional
hidden

option  "pfScale" S
"In the calculation of the pf use scale*mfe as an estimate for the ensemble free energy (used to avoid\
 overflows).\n"
details="The default is 1.07, useful values are 1.0 to 1.2. Occasionally needed for long sequences.\n\n"
double
default="1.07"
optional
hidden

section "Structure Constraints"
sectiondesc="Command line options to interact with the structure constraints feature of this program\n\n"

option  "maxBPspan" -
"Set the maximum base pair span.\n\n"
int
default="-1"
optional


section "Energy Parameters"
sectiondesc="Energy parameter sets can be adapted or loaded from user-provided input files\n\n"

option  "temp"  T
"Rescale energy parameters to a temperature of temp C. Default is 37C.\n\n"
double
default="37.0"
optional

option  "paramFile" P
"Read energy parameters from paramfile, instead of using the default parameter set.\n"
details="Different sets of energy parameters for RNA and DNA should accompany your distribution.\nSee the\
 RNAlib documentation for details on the file format. The placeholder file name 'DNA' can be used\
 to load DNA parameters without the need to actually specify any input file.\n\n"
string
typestr="paramfile"
optional

option  "noTetra" 4
"Do not include special tabulated stabilizing energies for tri-, tetra- and hexaloop hairpins.\n"
details="Mostly for testing.\n\n"
flag
off
hidden

option  "salt" -
"Set salt concentration in molar (M). Default is 1.021M.\n\n"
double
optional


section "Model Details"
sectiondesc="Tweak the energy model and pairing rules additionally using the following parameters\n\n"

option  "dangles" d
"How to treat \"dangling end\" energies for bases adjacent to helices in free ends and multi-loops.\n"
details="\nWith -d1 only unpaired bases can participate in at most one dangling end. With -d2 this\
 check is ignored, dangling energies will be added for the bases adjacent to a helix on both sides in\
 any case; this is the default for mfe and partition function folding (-p).\nThe option -d0 ignores\
 dangling ends altogether (mostly for debugging).\nWith -d3 mfe folding will allow coaxial stacking\
 of adjacent helices in multi-loops. At the moment the implementation will not allow coaxial stacking\
 of the two enclosed pairs in a loop of degree 3 and works only for mfe folding.\n\nNote that with\
 -d1 and -d3 only the MFE computations will be using this setting while partition function uses\
 -d2 setting, i.e. dangling ends will be treated differently.\n\n"
int
default="2"
optional

option  "noLP"  -
"Produce structures without lonely pairs (helices of length 1).\n"
details="For partition function folding this only disallows pairs that can only occur isolated. Other\
 pairs may still occasionally occur as helices of length 1.\n\n"
flag
off

option  "noGU"  -
"Do not allow GU pairs.\n\n"
flag
off
hidden

option  "noClosingGU" -
"Do not allow GU pairs at the end of helices.\n\n"
flag
off
hidden

option  "nsp" -
"Allow other pairs in addition to the usual AU,GC,and GU pairs.\n"
details="Its argument is a comma separated list of additionally allowed pairs. If the\
 first character is a \"-\" then AB will imply that AB and BA are allowed pairs, e.g.\
 --nsp=\"-GA\"  will allow GA and AG pairs. Nonstandard pairs are given 0 stacking\
 energy.\n\n"
string
optional
hidden

option  "energyModel" -
"Set energy model.\n"
details="Rarely used option to fold sequences from the artificial ABCD... alphabet, where\
 A pairs B, C-D etc.  Use the energy parameters for GC (--energyModel 1) or AU (--energyModel 2) pairs.\n\n"
int
optional
hidden

option  "helical-rise"  -
"Set the helical rise of the helix in units of Angstrom.\n"
details="Use with caution! This value will be re-set automatically to 3.4 in case DNA\
 parameters are loaded via -P DNA and no further value is provided.\n\n"
float
optional
default="2.8"
hidden

option  "backbone-length"  -
"Set the average backbone length for looped regions in units of Angstrom.\n"
details="Use with caution! This value will be re-set automatically to 6.76 in case DNA\
 parameters are loaded via -P DNA and no further value is provided.\n\n"
float
optional
default="6.0"
hidden


text    "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to\
 rna@tbi.univie.ac.at.\n\n"
