#!/usr/bin/perl

# 1.0 (26 AGO 2008)

#Altera os arquivos html do diretorio do interpro
#mudando o endereço do hmmer

#entra com o nome do diretorio do interpro
print "Enter interpro directory name: ";

my $inter_dir = <STDIN>;
chomp $inter_dir;

#lista os arquivos do diretorio do interpro
my $ls1 = `ls`;

my @directories1 = split("\n",$ls1);

foreach my $dir1 (@directories1){
    
    if($dir1 =~ m/interpro_dir$/){
		
 	my $dir_list1 = `ls $dir1`;
		
 	my @directories2 = split("\n",$dir_list1);

 	foreach my $file (@directories2){
	    
 	    if($file =~ m/.*\.html$/){
		
		my $path = $dir1 . "/" . $file;

		open(HTMLFILE, "<$path") 
		    or die "Could not open file:$path for reading\n";
		
		my @all_lines = <HTMLFILE>;
		
	# 	close(HTMLFILE);
		
# 		open(HTMLFILE2, ">$path") 
# 		    or die "Could not open file:$path for writing\n";
		
		my $flag;
		$flag = 0;


		foreach my $lines (@all_lines){

		    #print STDERR "---$lines\n";
		    
 		    $lines =~ s/http:\/\/www.sanger.ac.uk\/cgi-bin\/Pfam\/getacc?/http:\/\/pfam.sanger.ac.uk\/family\?entry=/g;

 		    $lines =~ s/entry=\?PF/entry=PF/g;
		    
		    if($lines =~ m/<table border="0">/){
			$flag = 1;
		    }
		    
		    if($lines =~ m/<\/table>/){
			$flag = 0;
		    }
		    
		    if(! $flag ){
			print HTMLFILE "$lines";
		    }

		}
		
		close(HTMLFILE);
	    }
	}
    }
}
    
#close(HTMLFILE2);
