如何使用Bioperl计算fasta文件中的序列

时间:2022-01-29 00:15:38

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

晚上好,我有一个bioperl代码来计算fasta文件中的序列数,但是我试图在任何给定的fasta文件中修改代码以计算短于20和更长的序列。代码如下

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";

1 个解决方案

#1


4  

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

您可以使用sequence对象的length函数在while循环中构造if语句。

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

#1


4  

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

您可以使用sequence对象的length函数在while循环中构造if语句。

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