perl生成特定碱基比例的随机序列的代码
时间:2023-12-08 05:27:07
方法一(不使用模块,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
标签:碱基比例,随机序列
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python 虚拟环境的创建与使用方法
2022-11-09 18:21:50
![](https://img.aspxhome.com/file/2023/4/121054_0s.png)
从网页设计开始
2008-06-30 12:17:00
python保留两位小数的3种方法实例
2022-01-28 20:20:36
用selenium解决滑块验证码的实现步骤
2021-06-02 01:44:39
![](https://img.aspxhome.com/file/2023/5/95465_0s.png)
python进行两个表格对比的方法
2021-12-15 20:31:57
Django中使用Celery的方法示例
2021-08-05 06:12:08
![](https://img.aspxhome.com/file/2023/6/133346_0s.png)
Python性能测试工具Locust安装及使用
2021-08-17 23:22:56
MySQL索引的基本语法
2024-01-26 00:48:44
Sqlserver2005日志文件太大如何减小
2024-01-25 10:48:53
Mysql动态更新数据库脚本的示例讲解
2024-01-23 11:22:49
Python lambda表达式原理及用法解析
2021-03-02 18:52:12
JS中ESModule和commonjs介绍及使用区别
2023-10-20 22:23:51
序列化Python对象的方法
2022-07-09 22:51:59
python 接口_从协议到抽象基类详解
2021-06-18 02:22:06
![](https://img.aspxhome.com/file/2023/9/121089_0s.jpg)
浅析python 通⽤爬⾍和聚焦爬⾍
2021-06-13 00:14:23
![](https://img.aspxhome.com/file/2023/2/91912_0s.jpg)
Python中Dict两种实现的原理详解
2022-11-13 06:20:29
原生JS封装_new函数实现new关键字的功能
2023-09-05 00:44:27
![](https://img.aspxhome.com/file/2023/1/56041_0s.png)
Python实现简单猜拳游戏
2022-07-08 04:40:10
![](https://img.aspxhome.com/file/2023/0/124210_0s.jpg)
学习ASP.NET八天入门:第一天
2007-08-07 13:08:00
![](https://img.aspxhome.com/file/UploadPic/up/2007080714434946.jpg)
js数组与字符串的相互转换方法
2023-06-24 09:41:48