使用Ensembl API,有一个#
方法可以在一行中打印一个序列(1xN个字符)。序列的长度可以很长(10K的数量级)。所以,我想分割每100个字符的字符串。目前,要写入文件,我使用
seq()
代码中已定义my $outfilename = $row;
open(my $ofh, '>', $outfilename) or die "Could not open file '$outfilename' $!";
print $ofh $gene->seq();
。
我该怎么做?
答案 0 :(得分:3)
使用unpack
open my $ofh, '>', $outfilename or die qq{Could not open file "$outfilename" for output: $!};
print $ofh "$_\n" for unpack '(A100)*', $gene->seq;
答案 1 :(得分:0)
my $outfilename = $row;
open(my $ofh, '>', $outfilename) or die "Could not open file '$outfilename' $!";
{
my $gene_seq = $gene->seq();
my @chunks = $gene_seq =~ /(.{1,100})/sg; # split $gene_seq into 100 chars chunks
print $ofh join("\n",@chunks),"\n";
}