You're reading through the entire @fasta_objs array 12 million times. Using a hash, rather than an array, should greatly reduce processing time. Change these three lines:

my @fasta_objs =(); ... push @fasta_objs,$seqFile1->seq; ... $fasta->write_seq($seqFile2) if (grep {$_ eq $seqFile2->seq} @fasta_ob +js);

to

my %fasta_objs =(); ... ++$fasta_objs{$seqFile1->seq}; ... $fasta->write_seq($seqFile2) if exists $fasta_objs{$seqFile2->seq};

I'm not familiar with the Bio:: modules so I can't offer advice on how to capture the headers (perhaps you already know or can find out through the documentation); however, once you have the header, you can store it in the hash. So, instead of:

++$fasta_objs{$seqFile1->seq};

use

$fasta_objs{$seqFile1->seq} = $header;

This assumes header/sequence combinations are unique. If that's not the case, you'll need a more complex storage solution - maybe something like:

seq => [header1, header2, ...]

Finally, I would strongly recommend that you do not comment out use strict; globally. If you really need to, just turn strictures off for a small piece of code, e.g.

# Comment explaining why you're doing this no strict 'refs'; ... small piece of code here ... use strict 'refs';

-- Ken


In reply to Re: Compare fasta files with different headers by kcott
in thread Compare fasta files with different headers by InfoSeeker

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.