#!/usr/bin/perl
# 2003/10/29 - I. Dutour

# Ignorer toutes les lignes jusqu'au trait horizontal
while (<>) {
    last
	if (/^----------/);
}

print '<HTML>';
print '<HEAD><TITLE>Yeast ORFs in 5-kb blocks</TITLE></HEAD>';
print '<BODY>';
print '<H1>Yeast ORFs in 5-kb blocks</H1>';
print '<UL><LI>';
my $block_size = 0;

# Lire toutes les lignes. 
while (<>) {
    chomp;
    last 
	if (/----------/ or /^$/);
    ($orf,$start,$stop,$gene,$disrupt,
     $length,$cai,$mo,$tm,$class,$desc) =
        ($_ =~ /^
	        \s* ([-\w]+)      \s*    \| # id de l'ORF
  		\s* \((\d+)-(\d+) [^\|]* \| # coordonnées
	        \s* ([^\|]*)      \s*    \| # gene
	        \s* ([\/\w]*)     \s*    \| # disrupt
	        \s* ([\w]*)       \s*    \| # length
	        \s* ([\.\w]*)     \s*    \| # cai
	        \s* ([\w]*)       \s*    \| # mo
	        \s* ([\w]*)       \s*    \| # tm
	        \s* ([\w]*)       \s*    \| # class
	        \s* ([^\|]*)                # desc
	       $/x);

    my $size = abs($stop - $start);

    if ($block_size + $size <= 5000) {
	imprimer_orf($orf);
	$block_size += $size; # et continuer
    } else {
	imprimer_sommaire($block_size);
	print '<LI>';
	imprimer_orf($orf);
	$block_size = $size;
    }
}

if ($block_size>0) {
    imprimer_sommaire($block_size);
}
print '</UL>';
print '</BODY>';
print '</HTML>';

# liste des arguments dans la variable tableau @_
# 1er arg $_[0], 2eme arg $_[1], ...
sub imprimer_orf {
    my $orf = $_[0];
    printf "<A HREF=\"%s\">%s</A>\n",
	   "http://mips.gsf.de/genre/proj/yeast/searchEntryAction.do?text=$orf",
	   $orf;
}

# liste des arguments dans la variable tableau @_
# 1er arg $_[0], 2eme arg $_[1], ...
sub imprimer_sommaire {
    my $size  = $_[0];
    printf "(%4.2f kb)\n", $size / 1000.0;
}

