input file:
11880 13417 - S00010GM001 sml_056 sp|YV02233 desc
13804 14685 - S00010GM002 sml_045 sp|YV02643 desc
15525 18026 - S00001GM001 sml_032 sp|V023334 desc
32763 34239 + S00002GM001 sml_028 sp|YV02376 desc
67929 68933 - S00003GM001 sml_025 sp|YV02346 desc
90562 91368 + S00012GM001 sml_025 sp|YV02376 desc
10209 10433 - S00012GM002 sml_046 sp|YV02355 desc
12522 12576 + S00013GM001 sml_027 sp|0235777 desc
13247 13349 - S00013GM002 sml_088 sp|YV02375 desc
####
sample output files:
filename:output_1.txt
15525 18026 - S00001GM001 sml_032 sp|V023334 desc
filename:output_2.txt
32763 34239 + S00002GM001 sml_028 sp|YV02376 desc
filename:output_3.txt
67929 68933 - S00003GM001 sml_025 sp|YV02346 desc
filename:output_4.txt
NO HITS
files 5 to 9 = same as above(like output 4, because there are no S00005 files found, neither the others till S00009).
filename:output_10.txt
11880 13417 - S00010GM001 sml_056 sp|YV02233 desc
13804 14685 - S00010GM002 sml_045 sp|YV02643 desc
files 11 and 12 = same as above (like output 10, because there are hits found with S00011 and S00012).
##
##
#!/usr/bin/perl
use strict;
use warnings;
open(FH,"input.txt")or die "can not open input file\n";
for(my $i=1;$i<=15;$i++){
open(OUT,">output_$i.txt") or die "can not create new files\n";
my $pattern=sprintf '%05s',$i;
$pattern="S".$pattern."GM";
my $c=0;my $search;
while(my $line=){
my($one,$two,$three,$four,$five,$six,$seven)=split("\t",$line);
if($four=~m/(S\d+GM)/){
$search=$1;
$search=~s/\s+//g;
}
if($search=~m/$pattern/){
print OUT "$line";
$c++;
}
}
if($c==0){
print OUT "NO HITS\n";
}
$pattern=();$search=();
}