#!/usr/bin/perl -w
my
$hitsection
= 0;
my
%data
;
my
(
$evalue
,
$bitscore
,
$header
,
$outfile
) = ( 10, 0);
GetOptions(
'b|bitscore|bits:f'
=> \
$bitscore
,
'e|evalue:f'
=> \
$evalue
,
'header'
=> \
$header
,
'o|out|outfile:s'
=> \
$outfile
,
'h|help'
=>
sub
{
exec
(
'perldoc'
,$0);
exit
; }
);
my
$outfh
;
if
(
$outfile
) {
open
(
$outfh
,
">$outfile"
) ||
die
(
"$outfile: $!"
);
}
else
{
$outfh
= \
*STDOUT
;
}
my
@fields
=
qw(qname hname percid alen mmcount gapcount
qstart qend hstart hend evalue score bits fs sw-score
percsim qlen hlen qgap hgap)
;
print
$outfh
"#"
,
uc
(
join
(
""
,
map
{
sprintf
(
"%-10s"
,
$_
) }
@fields
)),
"\n"
if
$header
;
while
(<>) {
my
$linestr
=
$_
;
if
( /^\s*\d+>>>(\S+).+/ ) {
$data
{
'qname'
} = $1;
if
( /\-\s+(\d+)\s+(aa|nt)\s+$/ ){
$data
{
'qlen'
} = $1;
}
}
elsif
(
$hitsection
&& /^>>>\Q
$data
{
'qname'
}/ ) {
$hitsection
= 0;
}
elsif
( /^The best scores are:/ ) {
$hitsection
= 1;
}
elsif
( /^\s+$/ ) {
}
elsif
(
$hitsection
) {
if
( s/^(\S+)\s+(.+)\(\s*(\d+)\)\s+// ) {
my
(
$hit
,
$desc
,
$hitlen
) = ($1,$2,$3);
my
(
$dir
) = ( s/^\[(r|f)\]\s+// );
my
@line
=
split
(/\s+/,
$_
);
$data
{
'hname'
} =
$hit
;
$data
{
'hlen'
} =
$hitlen
;
$data
{
'score'
} =
shift
@line
;
$data
{
'bits'
} =
shift
@line
;
$data
{
'evalue'
} =
shift
@line
;
$data
{
'percid'
} =
shift
@line
;
$data
{
'percsim'
} =
shift
@line
;
$data
{
'sw-score'
} =
shift
@line
;
$data
{
'alen'
} =
shift
@line
;
$data
{
'qstart'
} =
shift
@line
;
$data
{
'qend'
} =
shift
@line
;
$data
{
'pn0'
} =
shift
@line
;
$data
{
'px0'
} =
shift
@line
;
$data
{
'hstart'
} =
shift
@line
;
$data
{
'hend'
} =
shift
@line
;
$data
{
'pn1'
} =
shift
@line
;
$data
{
'px1'
} =
shift
@line
;
$data
{
'qgap'
} =
shift
@line
;
$data
{
'hgap'
} =
shift
@line
;
$data
{
'gapcount'
} =
$data
{
'qgap'
} +
$data
{
'hgap'
};
$data
{
'fs'
} =
shift
@line
;
$data
{
'mmcount'
} =
$data
{
'alen'
} - (
int
(
$data
{
'percid'
} *
$data
{
'alen'
}) +
$data
{
'gapcount'
});
for
(
$data
{
'percid'
},
$data
{
'percsim'
} ) {
$_
=
sprintf
(
"%.2f"
,
$_
*100);
}
print
$outfh
join
(
"\t"
,
map
{
$data
{
$_
} }
@fields
),
"\n"
;
}
else
{
}
}
else
{
}
}