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