#include <fstream>
#include <string>
#include <iostream>
#include <math.h>
#include <cstring>
// Designed by Peter A Noble, 2011, Alabama State University
// panoble@washington.edu

using namespace std;

char id[50];
char probe[5000][5000];
char seq[5000];
int array[5000];

int compare(char* target,char* probe);
char* subst(char* str,int start, int num);
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //

int compare(char* target,char* probe)
{
int g=strlen(probe); 
int match=0;
int answer=0;

for (int s=0;s<g;s++) 	
    {	 
   if (((target[s]=='A')  && (probe[s]=='A')) || ((target[s]=='T')  && (probe[s]=='T')) ||  ((target[s]=='C')  && (probe[s]=='C')) ||  ((target[s]=='G')  && (probe[s]=='G')))
	{match=match+1;}
    }
if (match==g) { answer=1;} else {answer=0;} 
return answer;
}
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
char* subst(char* str,int start, int num)
{
	int i,j=0;
	char str1[6];  //only restriction
	
for (i=0;i<(num);i++)
	{
	str1[i]=str[start+j];j=j+1; 
	}
	str1[num]='\0';
	strcpy(str,str1);
	return str;
}
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //


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

ifstream in(argv[1]); 		//probeseq
ifstream in2(argv[2]);		//output
ofstream out(argv[3]);		//output

int j=0;
char piece_seq[6];
char temp2[6];

while(!in2.eof())
	{
	in2 >> temp2;
	strcpy(probe[j],temp2);
	array[j]=0;
	j=j+1;
	}

int seq_length=0;
char temp[5000];
char temp3[5000];
char temp4[5000];
int c=0;
int g=0;
	
while(!in.eof())
	{
	in >> id;
	in >> temp;
	strcpy(temp3,temp);
	strcpy(temp4,temp);
	
	seq_length=strlen(temp3);
	c=c+1;
	if (c==1000) {g=g+1; std::cout << "sample= " << (g*1000) << "\n"; c=0;}

	for (int x=0; x<((seq_length+1)-6);x++)
		{
		strcpy(seq,temp4);
		strcpy(piece_seq,subst(seq,x,6));
	
		for (int y=0; y<j;y++)
			{
			if (compare(probe[y],piece_seq)==1) 
				{ 
				array[y]=array[y]+1;
				} 
				else 
				{
				}
			}
		}
	}
		
	for (int y=0; y<j;y++)
		{
		std::cout << probe[y] << "\t" << array[y] << "\n";
		out << probe[y] << "\t" << array[y] << "\n";
		}
	
    std::cout << "Hello, World!\n";
    return 0;
}
