1

Good evening, i have a bioperl code to count the number of sequences in a fasta file, but i am trying to modify the code to count sequences shorter than 20 and longer from 120 in any given fasta file. The code is below

use strict;

use Bio::SeqIO;

my $seqfile = 'sequences.fa';

my $in = Bio::SeqIO->new
        (
                -format => 'fasta',
                -file => $seqfile
        ) ;

my $count = 0;

while (my $seq = $in->next_seq)
{
        $count++;
}

print "There are $count sequences\n";
Oluwole
  • 71
  • 4

1 Answers1

4

You can use the length function of the sequence object to construct an if statement inside your while loop.

my $len = $seq->length();
if($len < 20 || $len > 120){
    $count++;
}
RossCampbell
  • 103
  • 7