The rude Anonymous person nailed it about changing the field 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"; } }

In reply to Re: Extract multiple lists od Identifiers from a FASTA file by joluito
in thread Extract multiple lists od Identifiers from a FASTA file by joluito

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.