#!/usr/bin/perl -w
use strict;
use Getopt::Std;

###############################################################################
# Print usage message
sub usage {
    $0 =~ s/.*?([^\/]+)$/$1/;
    printf "usage: %s FILE\n", $0;
    printf "From RegulonDB, get pages of E-Coli genes listed in FILE\n";
    printf "\n";
    printf "  -h,? show this message\n";
    exit 1;
}

###############################################################################
# Main

my (%opt);

getopts "h?", \%opt;
usage if ($opt{"h"} || $opt{"?"} || @ARGV == 0);

my (@line, %gene);

while (<>) {
    chomp $_;
    @line = split /\t/, $_;
    $gene{$line[0]} = $line[1];
}

my ($gene, $url, $procedure, $query, $pattern, $result);

$url="http://kinich.cifn.unam.mx:8850/";
$procedure="regulondb_queries.print_gene";
$query="?v_gene_id=";

my ($gene_name);

foreach $gene_name (sort keys %gene) {
    system "wget -nc -q -O - \"$url$procedure$query$gene{$gene_name}\" > $gene_name.html";
}
