Debian Codegraph @

metastudentPkg/lib/groupB/perl/parse_blast.pl

raw
1
2
3 # usage: ./parse_blast.pl <inputFile> <outputFile>
4
5 use strict;
6
7 open(INFILE, "< $ARGV[0]") or die "could not open input file!\n";
8 open(OUTFILE, "> $ARGV[1]") or die "could not open output file!\n";
9
10 #my $iteration = 2;
11 my $output = "";
12
13 while(my $line=<INFILE>) {
14
15 chomp($line);
16
17 # if there is a new round, erase results from previous round (we are only interested in the last PSI-BLAST iteration)
18 if(index($line, "Results from round") == 0) {
19
20 print $line, "\n";
21 $output = "";
22
23 } elsif(index($line, ">") == 0) {
24
25 # extract the first identifier line from the FASTA header
26 my $current_go_terms = substr($line,1);
27
28 # continue reading the header in case it is wrapped into multiple lines, until we hit the line containing "Length"
29 while($line = <INFILE> and index($line, "Length") < 0) {
30 $line =~ s/\s//g;
31 $current_go_terms .= $line;
32 }
33
34 # then continue reading until we hit the line containing the E-value and extrat it
35 do {
36 $line = <INFILE>;
37 } until ($line =~ m/Expect = (.*),/i);
38
39 print $current_go_terms, "\t", $1, "\n";
40 $output .= $current_go_terms . "\t$1\n";
41 }
42
43 }
44
45 print OUTFILE $output;
46
47 close(INFILE);
48 close(OUTFILE);