source: tags/arb-6.0/TREEGEN/simcfg.c

Last change on this file was 7811, checked in by westram, 13 years ago

merge from dev [7748] [7749] [7750]

  • comments (C→C++ style)
  • fixed umlauts in TREEGEN
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1#include "readcfg.h"
2#include "rns.h"
3
4#include <math.h>
5#include <stdlib.h>
6#include <string.h>
7
8static struct S_cfgLine cfg_lines[];
9
10static int decodeFrand(str setting, void *frandPtr)
11{
12    str medium = strtok(setting, " "),
13        low    = strtok(NULL, " "),
14        high   = strtok(NULL, " ");
15
16    if (medium && low && high)
17    {
18        double med_val  = atof(medium),
19               low_val  = atof(low),
20               high_val = atof(high);
21
22        if (med_val<=0.0 || med_val>=1.0)
23        {
24            setCfgError("The average value has to be BETWEEN 0.0 and 1.0");
25            return 0;
26        }
27        else
28        {
29            double change = fabs(low_val)+fabs(high_val);
30
31            if (change>=med_val || change>=(1.0-med_val))
32            {
33                setCfgError("The sum of low and high frequent part is too big and "
34                            "reaches one of the borders of the allowed range ]0.0, 1.1[");
35
36                return 0;
37            }
38        }
39
40        *((Frand*)frandPtr) = initFrand(med_val, low_val, high_val);
41
42        return 1;
43    }
44
45    setCfgError("Syntax is: <meanvalue> <lowfreqpart> <highfreqpart>");
46
47    return 0;
48}
49static int decodeInt(str setting, void *intPtr)
50{
51    *((int*)intPtr) = atoi(setting);
52    return 1;
53}
54static int decodeProb(str setting, void *doublePtr)
55{
56    double *dptr = (double*)doublePtr;
57
58    *dptr = atof(setting);
59
60    if (*dptr<0.0 || *dptr>1.0)
61    {
62        setCfgError("Probability has to be between 0.0 and 1.0");
63        return 0;
64    }
65
66    return 1;
67}
68void readSimCfg(cstr fname)
69{
70    int lenTeiler,
71        stepTeiler;
72
73    if (!readCfg(fname, cfg_lines)) errorf("Error reading config '%s'", fname);
74
75    lenTeiler  = (int)sqrt(orgLen);
76    stepTeiler = (int)sqrt(timeSteps);
77
78    mrpb_Init->teiler    = lenTeiler;
79    l2hrpb_Init->teiler  = lenTeiler;
80    pairPart->teiler     = stepTeiler;
81    mutationRate->teiler = stepTeiler;
82    splitRate->teiler    = stepTeiler;
83    helixGcDruck->teiler = stepTeiler;
84    helixGcRate->teiler  = stepTeiler;
85    helixAtRate->teiler  = stepTeiler;
86    loopGcDruck->teiler  = stepTeiler;
87    loopGcRate->teiler   = stepTeiler;
88    loopAtRate->teiler   = stepTeiler;
89}
90
91static struct S_cfgLine cfg_lines[] =
92{
93
94    // --------------------------------------------
95    //      Nur zur Initialisierung notwendig :
96
97    { "OriginLen",          "3000",             decodeInt,          &orgLen,            "Number of base positions in origin species" },
98    { "OriginHelixPart",    "0.5",              decodeProb,         &orgHelixPart,      "size of helical part in origin species (0.5 means 50% helix and 50% loop regions)" },
99    { "MutRatePerBase",     "0.5 0.01 0.4",     decodeFrand,        &mrpb_Init,         "mutation rate per base position (used for origin only)" },
100    { "Loop2HelixRate",     "0.2 0.01 0.1",     decodeFrand,        &l2hrpb_Init,       "loop<->helix conversion rate per base position (used for origin only)" },
101    { "TimeSteps",          "50",               decodeInt,          &timeSteps,         "number of time steps" },
102    { "TransitionRate",     "0.5",              decodeProb,         &transitionRate,    "transition rate" },
103    { "TransversionRate",   "0.5",              decodeProb,         &transversionRate,  "transversion rate" },
104
105    // ----------------------------------------------------------------------
106    //      Parameter, welche sich waehrend des Baumdurchlaufs veraendern :
107
108    { "PairPart",           "0.85 0.1 0.01",    decodeFrand,        &pairPart,          "part of pairing helix positions (mean value, low frequent part, high frequent part)" },
109    { "MutationRate",       "0.01 0.005 0.001", decodeFrand,        &mutationRate,      "mutation rate" },
110    { "SplitProb",          "0.2 0.1 0.01",     decodeFrand,        &splitRate,         "split rate (split into two species)" },
111    { "Helix-GC-Pressure",  "0.72 0.11 0.01",   decodeFrand,        &helixGcDruck,      "part of G-C bonds in helical regions" },
112    { "Helix-GC-Rate",      "0.5 0.001 0.001",  decodeFrand,        &helixGcRate,       "G:C rate in helical regions" },
113    { "Helix-AT-Rate",      "0.5 0.001 0.001",  decodeFrand,        &helixAtRate,       "A:T rate in helical regions" },
114    { "Loop-GC-Pressure",   "0.62 0.05 0.01",   decodeFrand,        &loopGcDruck,       "part of G-C bonds in loop regions" },
115    { "Loop-GC-Rate",       "0.5 0.001 0.001",  decodeFrand,        &loopGcRate,        "G:C rate in loop regions" },
116    { "Loop-AT-Rate",       "0.5 0.001 0.001",  decodeFrand,        &loopAtRate,        "A:T rate in loop regions" },
117
118    { NULL, 0, 0, 0, 0 }
119};
120
Note: See TracBrowser for help on using the repository browser.