Tuesday, March 30, 2010

Blast - XML output parser

The below script parses the output from blast with XML as option and stores the values in an array.

#!/usr/bin/perl
#---blast output file
my $infile = "blastout";
open(IN, "$infile");


while((my $line = ) && ($hitnumber[0] < $taketill)){ #reading the first $taketill numbers
chomp($line);
if ($line =~ /\/) {#reading hit number
push(@hitnums,split(/\<\/Hit_num\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading definiton
push(@hitdefs,split(/\<\/Hit_def\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading length
push(@hitlens,split(/\<\/Hit_len\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading bitscore
push(@bitscores,split(/\<\/Hsp_bit-score\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {
push(@scores,split(/\<\/Hsp_score\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading evalue
push(@evalues,split(/\<\/Hsp_evalue\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading query match begin
push(@qfroms,split(/\<\/Hsp_query-from\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading query match end
push(@qtos,split(/\<\/Hsp_query-to\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading hit match begin
push(@hfroms,split(/\<\/Hsp_hit-from\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading hit match end
push(@htos,split(/\<\/Hsp_hit-to\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading query frame
push(@qframes,split(/\<\/Hsp_query-frame\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading hit frame
push(@hframes,split(/\<\/Hsp_hit-frame\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading identities
push(@identities,split(/\<\/Hsp_identity\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading positives
push(@positives,split(/\<\/Hsp_positive\>/,(split(/\/, $line))[1]));
}
if ($line =~ /\/) {#reading alignment length
push(@algnlens,split(/\<\/Hsp_align-len\>/,(split(/\/, $line))[1]));
}
}

No comments: