#!/usr/bin/perl
#################################
#
#Program: newID
# 	the program is used to retrieve the seqIDs from two sets of IDs, that only contained
#	in one set, the common IDs contained in both sets will not be included
#
#############################

if ($#ARGV != 2)
{
	print "Usage: newID idFile1 idFile2 newFile \n";
	exit;
}

$idFile1 = $ARGV[0];
$idFile2 = $ARGV[1];
$newFile = $ARGV[2];
open (INPUT, $idFile1) || die ("Cannot open file $idFile1 !!\n");
@content1 = <INPUT>;
close (INPUT);

open (INPUT, $idFile2) || die ("Cannot open file $idFile2 !!\n");
@content2 = <INPUT>;
close (INPUT);


@idArray = ();
$id = '';
print "It is in progress ...\n";
$flag = 0;
foreach $line1 (@content1)
{
	$flag = 0;
	chomp($line1);
	@tmp = split(/ /, $line1);
	$s1 = $tmp[0];
	foreach $line2 (@content2)
	{
		chomp($line2);
		@tmp2 = split(/ /, $line2);
		$s2 = $tmp2[0];

		if ($s1 eq $s2)
		{
			$flag = 1;
			last;
		}
	}
	if ($flag ==0)
	{
		push(@idArray, $s1."\n");
	}
}

#oreach $line2 (@content2)
#
#$flag = 0;
#chomp($line2);
#foreach $line1 (@content1)
#{
#	chomp($line1);
#
#	if ($line2 eq $line1)
#	{
#		$flag = 1;
#		last;
#	}
#}
#if ($flag == 0)
#{
#	push(@idArray, $line2."\n");
#}
#}

open (OUTPUT, ">$newFile") || die ("Cannot open for writing file $newFile !\n");
print OUTPUT (@idArray);
close OUTPUT;

print "The work is done!\n";

exit;


