in reply to Re: compare a list from one file with another text file
in thread compare a list from one file with another text file

The sequence file could be as large as 40Mb and the list could contain as many as 35000 sequences. I'm new to perl and have been struggling with this for a couple of days. Here's the part I wrote, but it doesn't give me the full list I want:(
my $nohit_list = "data.txt"; open (NOHIT, "<$nohit_list")or die "can't open file: $!"; foreach $line (<NOHIT>) { print $line; my $all = "all.txt"; open (ALL, "<$all") or die "can't open file: $!"; { local $/ = '>'; @fasta = <ALL>; } my $requery = "requery.txt"; open (FASTA, ">$requery")or die "can't open file: $!"; my @nohit_fasta = (); @nohit_fasta = grep /$line/,@fasta; print FASTA @nohit_fasta;

Replies are listed 'Best First'.
Re^3: compare a list from one file with another text file
by jethro (Monsignor) on Apr 06, 2008 at 00:28 UTC
    Arunbear already provided an efficient solution, but if you are interested, here is the reason why your version didn't work:

    1) First of all there is a '}' missing at the end, but I guess this is the fault of the copy and paste

    2) For every line in data.txt you reread all.txt, grep for the result and then write the data into requery.txt (highly inefficient but a working idea). Sadly every time you open requery.txt again you delete the previous version of requery.txt, so that eventually only the last result is in there. Your program would work by simply changing the '>' in
    open (FASTA, ">requery.txt" ...
    to '>>'

    Even better would be to open requery.txt before the foreach loop (same place where you open data.txt). That way it gets opened only once

      Thanks a lot. That was very helpful. It works now. I really appreciate all the feedback.