perl 指定长度并生成一个随机的DNA序列的脚本代码

 更新时间:2020年6月29日 13:42  点击:1985

复制代码 代码如下:

#!/bin/perl

use strict; 
use warnings;

#进行定义 
my @dna; 
my $dna_length; 
my $newbase; 
my $i=0; 

print "please input the DNA length\n"; 
chomp($dna_length=<>); 

while($i<$dna_length) 

  #从四个碱基中随机选取一个 
  my(@nucleotides)=qw/A T G C/; 
  $newbase=$nucleotides[rand @nucleotides]; 

  #将随机生成的序列添加到@dna的数组中 
  push(@dna,$newbase); 
  ++$i; 

print "@dna";

[!--infotagslink--]

相关文章