#!/usr/bin/perl -w use Bio::SearchIO; use strict; print "start program\n"; my $directory = '/home/Hubert/result_1'; opendir(DIR, $directory) || die("Cannot open directory"); print "opened directory\n"; foreach my $file (readdir(DIR)) { if ($file =~ /txt/) { print "read file $file \n"; $file = $directory . '/' . $file; my $search = new Bio::SearchIO (-format => 'blast', -file => $file); my $cutoff_len = 10; #iterate over each query sequence print "try to enter while loop\n"; while (my $result = $search->next_result) { print "entered 1st while loop\n"; #iterate over each hit on the query sequence while (my $hit = $result->next_hit) { print "entered 2nd while loop\n"; #iterate over each HSP in the hit while (my $hsp = $hit->next_hsp) { print "entered 3rd while loop\n"; if ($hsp->length('sbjct') <= $cutoff_len) { #print $hsp->hit_string, "\n"; for ($hsp->hit_string) { #$hsp->hit_string print $hsp->hit_string,"\n"; if (tr/K// >= 2 || tr/R// >= 2 && tr/W// >= 2 || tr/K// == 1 && tr/R// == 1 && tr/W// >= 2) { print "create and open to write file\n"; open (bigShot, ">>result_adv_4.txt") || die ("Could not open file. $!"); #print $result->query_name, "\t"; # print $hit->significance, "\t"; print bigShot $hit->name, "-->"; print bigShot $hit->description, "\n"; #print bigShot "Query: ", $hsp->start('query'), " ", $hsp->query_string, " ", $hsp->end('query'), "\n"; print bigShot "Seq: ", $hsp->start('hit'), " ", $hsp->hit_string, " ", $hsp->end('hit'), "\n"; # print $hsp->rank, "\t"; # print $hsp->percent_identity, "\t"; # print $hsp->evalue, "\t"; # print $hsp->hsp_length, "\n"; close (bigShot); }#end if condition }#end for loop }#end if condition }#end 3rd while loop }#end 2nd while loop }#end 1st while loop }#end if condition }#end foreach loop closedir(DIR);