#!/usr/bin/perl

use strict;

my $tablasAnopheles = $ARGV[0];
my $seq;
my $domaininfo;
my @info;

open ('READ', $tablasAnopheles);
my $currentid = '';
 while (<READ>) {
	@info = split ('\t',$_);
	$info[0].=".0";	
	if ($currentid eq '') { $currentid = $info[0]; }
	if (($currentid ne $info[0]) || (eof('READ'))) {
		open ('FETCH', "/usr/molbio/perl/fetch -c ../fetchdm.conf dm:$currentid |");
        	<FETCH>;
        	while (<FETCH>){
                	$seq.=$_;
                }
        	close(FETCH);
		open ('ADD', ">> modifiedtablasDrosophila");
		print ADD ">dm:$currentid $domaininfo\n";
		print ADD "$seq\n";
		close (ADD);		
		$currentid=$info[0];
		$seq = '';
		$domaininfo = '';
	#redo unless eof(READ);
	}	
	
# create the domain info
#print "here add domain info";
$domaininfo.= "\[$info[5]_$info[1]\-$info[2]\]";
print $info[0], $domaininfo, "\n";
}

exit 0;
