#!/usr/bin/perl
use Digest::SHA1 qw(sha1 sha1_hex);
my @fileName;
my @fileTwoName;
my $inputNameOne;
my $inputNameTwo;
my $maxMatch = 0;
my $round = 0;
my $oneCountMatch;
my $showRound = 0;
my $logFileName = "probability_of_benign.log";
my %seqHash;
if(@ARGV != 2){
        die "Parameter Error!\n";
}
@fileName = glob $ARGV[0]."/*";
foreach (@fileName){
	$seqHash{$_} = 0;
}
my @ducumentTwoName = glob $ARGV[1]."/*";
foreach (@ducumentTwoName){
	@fileTwoName = glob $_."/*";
	print $showRound, "\n";
	$showRound++;
foreach $inputNameOne (@fileName){
	$oneCountMatch = 0;
	foreach $inputNameTwo (@fileTwoName){
		my %hash;
		my $count;
		my $countTwo;
		my @fileOneSeq;
		my @fileTwoSeq;
		my $maxString;
		my @array;
		my $maxX;
		my $maxY;
		my @resultOutput;
		my $tmpHashValue;
		my $checkPoint;
		open FILEONE, "<$inputNameOne";
		open FILETWO, "<$inputNameTwo";
		$array[0][0] = 0;
		while(<FILEONE>){
			if($_ =~ /^([\w\d]+)$/){
				push @fileOneSeq, "$1";
				$array[@fileOneSeq][0] = 0;
			}
		}

		while(<FILETWO>){
			if($_ =~ /\d\d:\d\d:\d\d\.\d\d\d\d\d\d ([\w\d]+)\(/){
				push @fileTwoSeq, "$1";
				$array[0][@fileTwoSeq] = 0;
			}
		}

		close FILEONE;
		close FILETWO;
		for($count = 0, $maxString = 0, $countTwo = 1; $countTwo <= @fileTwoSeq; $countTwo++){
			if($fileOneSeq[$count] =~ $fileTwoSeq[$countTwo - 1]){
				my $counterXX;
				my $counterYY;
				my $seqLength = 0;
				for($counterXX = $count, $counterYY = $countTwo - 1; $counterXX < @fileOneSeq && $counterYY < @fileTwoSeq; $counterXX++, $counterYY++){
					if($fileOneSeq[$counterXX] =~ $fileTwoSeq[$counterYY]){
						$seqLength++;
					}
					else{
						last;
					}
				}
				if($maxString < $seqLength){
					$maxString = $seqLength;
				}
			}
		}
		if($maxString == @fileOneSeq){
			$seqHash{$inputNameOne}++;
			last;
		}
	}
}
}
open LOGFILE, ">$logFileName";
foreach (sort keys %seqHash){
	print LOGFILE $_, ":", $seqHash{$_}, "\n";
}
