NOThing Is Impossible! —— 原创文章,谢绝转载!
Q:想请教一下怎么把fasta格式的DNA序列切割成一定长度的序列?
现有一个很长的序列,保存为fasta格式,希望切成一定长度的较短的序列。应该怎么输入呢?比如是一段很长的序列,要切割成一小段一小段的70的序列。为:1-70为第一小段,2-71为第二小段,3-72为第三小段。。。这样滑动切割,最后还是保存为fasta格式。
A:
use strict;
use Bio::SeqIO;
my $filename = 'file.fasta';
my $width = 70;
my $stream = Bio::SeqIO->new(-file => $filename, -format => 'fasta');
my $seq = $stream->next_seq;
my $len = $seq->length;
for(1 .. $len-$width+1) {
my ($start, $end) = ($_, $_+$width-1);
print '>',$seq->id," $start:$endn";
print $seq->subseq($start,$end),"n";
}
You can be the first to comment!