#!/usr/bin/perl -w

use strict;

my $count = 0;
my $countU = 0;

my $arxiu;

my $canut = 0;

my $sequ = 0;
my $seqs = 0;
my $seqc = 0;
my $seqp = 0;


while (<STDIN>) {

    if ($_ =~ m/(Query=[\w\d\.\_\#\(\) ]+)/) { #mirar línia de proteïna
	$seqp = $1;
	print "\n";
	print "$seqp\n";
    }

    if ($_ =~ m/(gi[\w\d\+\|\.\_\,\- ]+\d*)/) { #mirar línia de cromosoma
	$seqc = $1;
	print "\n";
	print "$seqc\n";
    }

    if ($_ =~ m/([\+\: \-\w\d\*]+)/ && $canut >= 0) { #Imprimir linia d'alineament
	$seqs = $1;
	print "$seqs\n";
    }

    $canut = $canut - 1;

    if ($_ =~ m/(Query:\s+\d+\s+[\w\*\-]+U[\w\*\-]+\s*\d*)/) { #Imprimir linia de proteïna alineada
	$countU = $countU + 1;
	$sequ = $1;
	print "$sequ\n";
        $canut = 2;
    }

}

print "$countU\n";
