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