Index: cpp/frams/genetics/fT/oper_fTest.cpp
===================================================================
--- cpp/geno_fx/geno_ftest.cpp	(revision 66)
+++ cpp/frams/genetics/fT/oper_fTest.cpp	(revision 194)
@@ -1,128 +1,126 @@
-// This file is a part of the Framsticks GenoFX library.
-// Copyright (C) 2002-2011  Maciej Komosinski.  See LICENSE.txt for details.
+// This file is a part of the Framsticks GDK.
+// Copyright (C) 2002-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
 // Refer to http://www.framsticks.com/ for further information.
 
-#include "geno_ftest.h"
-#include "nonstd.h" //randomN, rnd01
+#include "oper_fTest.h"
+#include <common/nonstd.h> //randomN, rnd01
 
-/** \file
-Sample output (simple examples of various genetic operations):
-\anchor geno_ftest_example
-\include geno_ftest_example
-Produced by the source:
-\include geno_ftest.cpp
+/**
+Sample output (simple examples of various genetic operations) produced by genooper_test_fTest.cpp:
+$ ./genooper_test_fTest.exe
+GATCGATTACA   [mutated 0.0%]
+GATCCATTACA   [mutated 9.1%]
+GATCCTGTACA   [mutated 27.3%]
+GATCCTGTACA   [mutated 0.0%]
+GATCCTGTACA   [mutated 0.0%]
+GATCCTGTATA   [mutated 9.1%]
+GATCCTGTATA   [mutated 0.0%]
+GATACTGTATA   [mutated 9.1%]
+GATACTGTATA   [mutated 9.1%]
+GATACTGTATA   [mutated 0.0%]
+
+Crossing over the last mutant,
+GATACTGTATA
+and the simplest genotype
+GATCGATTACA
+:
+Offspring 1:
+GATACTCGATTACA  (35.7% genes from parent1)
+Offspring 2:
+GATGTATA  (25.0% genes from parent2)
+
+Checking genotype:
+ATGsomethingCG... error at position 4.
+After validation:
+ATGCG
+...and how about YOUR genotype?
 */
 
-#define FIELDSTRUCT Geno_ftest
-static ParamEntry GENOtestparam_tab[]=   //external access to ftest genetic parameters
+
+// To test this genetic format, you can also use the general genooper_test app that supports all genetic formats:
+// $ ./genooper_test.exe /*T*/AAAAAAAAAAA
+
+
+
+#define FIELDSTRUCT GenoOper_fTest
+static ParamEntry GENOtestparam_tab[] =   //external access to ftest genetic parameters
 {
-{"Genetics: ftest",1,1,},
-{"ftest_mut",0,0,"Mutation probability","f 0 1",FIELD(prob),"How many genes should be mutated during single mutation (1=all genes, 0.1=ten percent)",},
-{0,},
+	{ "Genetics: fTest", 1, 1, },
+	{ "fTest_mut", 0, 0, "Mutation probability", "f 0 1", FIELD(prob), "How many genes should be mutated during single mutation (1=all genes, 0.1=ten percent)", },
+	{ 0, },
 };
 #undef FIELDSTRUCT
 
-Geno_ftest::Geno_ftest()
+GenoOper_fTest::GenoOper_fTest()
 {
-   par.setParamTab(GENOtestparam_tab);
-   par.select(this);
-   supported_format='t'; //'0' for f0, '1' for f1, etc.
-   prob=0.1;
+	par.setParamTab(GENOtestparam_tab);
+	par.select(this);
+	supported_format = 'T'; //'0' for f0, '1' for f1, 'F' for fF, etc.
+	prob = 0.1;
 }
 
 ///The only letters allowed are A,T,G,C
-int Geno_ftest::checkValidity(const char* gene)
+int GenoOper_fTest::checkValidity(const char* gene)
 {
-   if (!gene[0]) return 1; //empty is not valid
-   bool ok=true;
-   int i;
-   for(i=0;i<strlen(gene);i++) if (!strchr("ATGC",gene[i])) {ok=false; break;}
-   return ok ? GENOPER_OK : i+1;
+	if (!gene[0]) return 1; //empty is not valid
+	bool ok = true;
+	int i;
+	for (i = 0; i < strlen(gene); i++) if (!strchr("ATGC", gene[i])) { ok = false; break; }
+	return ok ? GENOPER_OK : i + 1;
 }
 
 ///Remove all invalid letters from the genotype
-int Geno_ftest::validate(char *&gene)
+int GenoOper_fTest::validate(char *&gene)
 {
-   SString validated; //new genotype (everything except ATGC is skipped)
-   for(int i=0;i<strlen(gene);i++)
-      if (strchr("ATGC",gene[i])) validated+=gene[i];  //validated contains only ATGC
-   free(gene);
-   gene=strdup(validated); //reallocate
-   return GENOPER_OK;
+	SString validated; //new genotype (everything except ATGC is skipped)
+	for (int i = 0; i < strlen(gene); i++)
+		if (strchr("ATGC", gene[i])) validated += gene[i];  //validated contains only ATGC
+	free(gene);
+	gene = strdup(validated); //reallocate
+	return GENOPER_OK;
 }
 
-///Very simple mutation
-int Geno_ftest::mutate(char *&gene,float &chg)
+///Very simple mutation; should be improved to guarantee at least one gene changed
+int GenoOper_fTest::mutate(char *&geno, float &chg, int &method)
 {
-   static char a[]="ATGC";
-   int changes=0,len=strlen(gene);
-   for(int i=0;i<len;i++)
-      if (rnd01<prob) //normalize prob with length of genotype
-         {gene[i]=a[randomN(4)]; changes++;}
-   chg=(float)changes/len;
-   return GENOPER_OK;
+	static char a[] = "ATGC";
+	method = 0;
+	int changes = 0, len = strlen(geno);
+	for (int i = 0; i < len; i++)
+		if (rnd01 < prob) //normalize prob with length of genotype
+		{
+			geno[i] = a[randomN(4)];
+			changes++;
+		}
+	chg = (float)changes / len;
+	return GENOPER_OK;
 }
 
 ///A simple one-point crossover
-int Geno_ftest::crossOver(char *&g1,char *&g2,float& chg1,float& chg2)
+int GenoOper_fTest::crossOver(char *&g1, char *&g2, float& chg1, float& chg2)
 {
-   int len1=strlen(g1),len2=strlen(g2);
-   int p1=randomN(len1);  //random cut point for first genotype
-   int p2=randomN(len2);  //random cut point for second genotype
-   char *child1=(char*)malloc(p1+len2-p2+1);
-   char *child2=(char*)malloc(p2+len1-p1+1);
-   strncpy(child1,g1,p1);   strcpy(child1+p1,g2+p2);
-   strncpy(child2,g2,p2);   strcpy(child2+p2,g1+p1);
-   free(g1); g1=child1;
-   free(g2); g2=child2;
-   chg1=(float)p1/strlen(child1);
-   chg2=(float)p2/strlen(child2);
-   return GENOPER_OK;
+	int len1 = strlen(g1), len2 = strlen(g2);
+	int p1 = randomN(len1);  //random cut point for first genotype
+	int p2 = randomN(len2);  //random cut point for second genotype
+	char *child1 = (char*)malloc(p1 + len2 - p2 + 1);
+	char *child2 = (char*)malloc(p2 + len1 - p1 + 1);
+	strncpy(child1, g1, p1);   strcpy(child1 + p1, g2 + p2);
+	strncpy(child2, g2, p2);   strcpy(child2 + p2, g1 + p1);
+	free(g1); g1 = child1;
+	free(g2); g2 = child2;
+	chg1 = (float)p1 / strlen(child1);
+	chg2 = (float)p2 / strlen(child2);
+	return GENOPER_OK;
 }
 
 ///Applying some colors and font styles...
-unsigned long Geno_ftest::style(const char *g, int pos)
+unsigned long GenoOper_fTest::style(const char *g, int pos)
 {
-   char ch=g[pos];
-   unsigned long style=GENSTYLE_CS(0,GENSTYLE_INVALID); //default, should be changed below
-   if (ch=='A') style=GENSTYLE_RGBS(200,0,0,GENSTYLE_BOLD);
-   if (ch=='T') style=GENSTYLE_RGBS(0,200,0,GENSTYLE_BOLD);
-   if (ch=='G') style=GENSTYLE_RGBS(0,0,200,GENSTYLE_NONE);
-   if (ch=='C') style=GENSTYLE_RGBS(200,200,0,GENSTYLE_NONE);
-   return style;
+	char ch = g[pos];
+	unsigned long style = GENSTYLE_CS(0, GENSTYLE_INVALID); //default, should be changed below
+	if (ch == 'A') style = GENSTYLE_RGBS(200, 0, 0, GENSTYLE_BOLD);
+	if (ch == 'T') style = GENSTYLE_RGBS(0, 200, 0, GENSTYLE_BOLD);
+	if (ch == 'G') style = GENSTYLE_RGBS(0, 0, 200, GENSTYLE_NONE);
+	if (ch == 'C') style = GENSTYLE_RGBS(200, 200, 0, GENSTYLE_NONE);
+	return style;
 }
-
-
-#ifdef GENO_FTEST_APPL //define this macro to compile a simple testing main function
-
-Geno_ftest gft;
-
-void main()
-{
-   float chg;
-   char *g=strdup(gft.getSimplest());
-   for(int i=0;i<10;i++)
-   {
-      int result=gft.mutate(g,chg);
-      printf("%s   [mutated %.1f%%]\n",g,chg*100);
-   }
-
-   char *g2=strdup(gft.getSimplest());
-   float chg2;
-   printf("\nCrossing over the last mutant, \n\t%s\nand the simplest genotype\n\t%s\n:\n",g,g2);
-   gft.crossOver(g,g2,chg,chg2);
-   printf("Offspring 1:\n\t%s  (%.1f%% genes from parent1)\n",g,chg*100);
-   printf("Offspring 2:\n\t%s  (%.1f%% genes from parent2)\n",g2,chg2*100);
-   free(g);
-   free(g2);
-
-   g=strdup("ATGsomethingCG");
-   printf("\nChecking genotype:\n\t%s... error at position %d.\n",g,gft.checkValidity(g));
-   gft.validate(g);
-   printf("After validation:\n\t%s\n",g);
-   free(g);
-   printf("...and is YOUR genotype O.K.?\n\n");
-}
-
-#endif
-
