Didn't expect to find such trolls in a place like this...
But anyway, he nailed it about changing the filed separator.
Here's is the FUNCTIONAL code (may indentation not be that good, and the code not obfuscated enough as to win a contest...but we need it to be mantained by different people, some of who are new to programming).
#!usr/bin/perl -w
use strict;
use Getopt::Long;
#usage example: perl /path_to_script/bay_seqret.pl -p /path_to_lists -
+f /path_to_fasta/FASTA_file.faa
my ($path, $fasta);
GetOptions(
'path=s' => \$path,
'fasta=s' => \$fasta,
);
chdir $path or die "ERROR: Unable to enter $path: $!\n";
opendir (TEMP , ".");
my @files = readdir (TEMP);
closedir TEMP;
my $name;
my $found=0;
my $totalist=0;
$/ = "\>";###CHANGED HERE TO SPLIT FASTA by ">"
open (INFILE, "$path/$fasta") || die ("cannot open input file");
chomp(my @data = <INFILE>);
print"@data\n";
$/ = "\n";####"REGENERATED" HERE NOT TO INTERFERE WITH THE REST OF THE
+ DATA PROCESSING
for my $file (@files) {
if($file=~/(\w+)\.txt/){
$name = "$1";
print"Lista: $path/$name.txt\n";
open (INFILE2, "$path/$name.txt") || die ("cannot open input f
+ile");
chomp(my @lista = <INFILE2>);
open OUT,'>'."$path/$name.out" or die "ERROR: Unable to open
+$file $!\n";
foreach my $li (@lista){
chomp $li;
print"$li\n";
$totalist++;
for(@data){
if(/$li/){
$found++;
print ">"."$_\n";
print OUT ">"."$_\n";
}
}
}
print "For $name we found $found of a total $totalist\n";
}
}
|