华域联盟 perl perl生成特定碱基比例的随机序列的代码

perl生成特定碱基比例的随机序列的代码

方法一(不使用模块,by agonyr)

复制代码 代码如下:

#!/usr/bin/perl -w

use strict;

my @seq = ( "A", "T", "C", "G" );

my $length = 10000;

undef my %hash;

$hash{"A"} = int( $length * 0.3 );

$hash{"C"} = int( $length * 0.3 );

$hash{"G"} = int( $length * 0.2 );

$hash{"T"} = int( $length * 0.2 );

my $i = 0;

while ( $i 《 $length ) {

    my $word = $seq[ rand(@seq) ];

    if ( $hash{$word} ) {

        print "$word";

        $i++;

    }

    $hash{$word}--;

}

print "n";

方法二(使用模块,by yixf)

复制代码 代码如下:

#!/usr/bin/perl

use strict;

use warnings;

use BioX::SeqUtils::RandomSequence;

my $randomizer = BioX::SeqUtils::RandomSequence-》new(

    {

        l =》 10000,

        s =》 1,

        y =》 "dna",

        a =》 3,

        c =》 3,

        g =》 2,

        t =》 2

    }

);

print $randomizer-》rand_seq(), "n";

两种方法比较

设定长度为10000,ACGT的比例为3:3:2:2。

复制代码 代码如下:

withoutModule Length=10000 GC=49.42% A=2558,C=2503,G=2439,T=2500,Others=0

withModule Length=10000 GC=50.00% A=3000,C=3000,G=2000,T=2000,Others=0

您可能感兴趣的文章:

本文由 华域联盟 原创撰写:华域联盟 » perl生成特定碱基比例的随机序列的代码

转载请保留出处和原文链接:https://www.cnhackhy.com/77056.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部