//
//	The 3-bit number generator Written by Dzinleski Jasenko Jun,2005 and later
//					Copyright (C) 2005 and later Jasenko Dzinleski 
//
//	This source and the 3-bit number generator apply to GNU General Public License. 
//					
//
//		This program is free software; you can redistribute it
//	and/or modify it under the terms of the GNU General Public License as
//	published by the Free Software Foundation; either version 2 of the
//	License, or (at your option) any later version. 
//
//	This program is distributed in the hope that it will be useful, but
//	WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//	General Public License for more details. 
//
//	You should have received a copy of the GNU General Public License along
//	with this program; if not, write to the Free Software Foundation, Inc.,
//	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


//  			The 3-bit number generator
//
//     			to my daughter Maria Dzinleska


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

FILE 	*f1;
char	infn[256]="fasta__.txt";
int 	ba15[8][8][8][8][8][3];
int		ba15i=0;
int 	ba16[256][256];
char	sv[256];
//char 	sa[256]="CCGTGGCGTCGCGCAGGCTCGGCTTACCGAGGTCGGCCTCTGGGACGCGGTCAAGGATCGGCTCAGCGAT";

int p_1(char sa[256])
{

//000
//110
//011
//101

int i,j,k,l,m,n;
int mi,mj,mk,ml,mm;
int a,b,mx;
long lb;
char sa_[256];

for(i=0;i<256;++i){for(j=0;j<256;++j){ba16[i][j]=0;}}
for(i=0;i<=7;++i){for(j=0;j<=7;++j){for(k=0;k<=7;++k){for(l=0;l<=7;++l){for(m=0;m<=7;++m)
{
	ba15[i][j][k][l][m][0]=-1;
	ba15[i][j][k][l][m][1]=0;
	ba15[i][j][k][l][m][2]=0;
}}}}}
ba15i=0;

for(a=0;a<-1+strlen(sa);++a)
{
	lb=(sa[a]<<8)|(sa[1+a]<<0);
	i=(~((0xffff>>0)<<3))&(lb>>12);
	j=(~((0xffff>>0)<<3))&(lb>>9 );
	k=(~((0xffff>>0)<<3))&(lb>>6 );
	l=(~((0xffff>>0)<<3))&(lb>>3 );
	m=(~((0xffff>>0)<<3))&(lb>>0 );
	if(ba15[i][j][k][l][m][0]==-1){ba15[i][j][k][l][m][0]=ba15i;++ba15i;++ba15[i][j][k][l][m][1];}else{++ba15[i][j][k][l][m][1];}
}

//for(i=0;i<=7;++i){for(j=0;j<=7;++j){for(k=0;k<=7;++k){for(l=0;l<=7;++l){for(m=0;m<=7;++m)
//{
//	if(ba15[i][j][k][l][m][0]!=-1){printf("%d%d%d%d%d %d\n",i,j,k,l,m,ba15[i][j][k][l][m][1]);}
//}}}}}

mx=-1;
for(i=0;i<=7;++i){for(j=0;j<=7;++j){for(k=0;k<=7;++k){for(l=0;l<=7;++l){for(m=0;m<=7;++m)
{
	if(ba15[i][j][k][l][m][0]!=-1){if(mx==-1){mx=ba15[i][j][k][l][m][1];mi=i;mj=j;mk=k;ml=l;mm=m;}else{if(mx<ba15[i][j][k][l][m][1]){mx=ba15[i][j][k][l][m][1];mi=i;mj=j;mk=k;ml=l;mm=m;}}}
}}}}}

for(a=0;a<-1+strlen(sa);++a)
{
	lb=(sa[a]<<8)|(sa[1+a]<<0);
	i=(~((0xffff>>0)<<3))&(lb>>12);
	j=(~((0xffff>>0)<<3))&(lb>>9 );
	k=(~((0xffff>>0)<<3))&(lb>>6 );
	l=(~((0xffff>>0)<<3))&(lb>>3 );
	m=(~((0xffff>>0)<<3))&(lb>>0 );

	b=0;
	if(i==mi){++b;}
	if(j==mj){++b;}
	if(k==mk){++b;}
	if(l==ml){++b;}
	if(m==mm){++b;}
	if(b>=4){++ba16[sa[a]][sa[1+a]];}	
}
for(a=0;a<strlen(sa);++a){sa_[a]=sa[a];}
for(a=0;a<-1+strlen(sa);++a)
{
	if(ba16[sa[a]][sa[1+a]]!=0){sa_[a]=sa[a];}else{sa_[a]='_';}
}
for(a=0;a<strlen(sa);++a){printf("%c",sa_[a]);}printf("\n");

return(0);

}

int main(int argc,char *argv[])
{

int	a,b;
int	d,e;
int	i,j,k,l,m,n;
int	fb;

	//if(argc<2){return(0);}
	//if(strlen(argv[1])==0){return(0);}
	//if(strlen(argv[2])==0){return(0);}

	//strcpy(infn,argv[1]);
	//strcpy(lsfn,argv[2]);

	f1=fopen(infn,"rb");
	fb=getc(f1);
	while(!feof(f1))
	{
		for(i=0;i<256;++i){sv[i]='\0';}i=0;
		while((fb!=10)&&(fb!=13)){sv[i]=fb;++i;fb=getc(f1);}
		while((fb==10)||(fb==13)){fb=getc(f1);}
		p_1(sv);
	}
	fclose(f1);

	return(0);

}