我编写了一个perl程序来查找给定的DNA string.But中GC含量的百分比,该程序正在执行错误情况(条件语句的其他部分)。
$dna = "AGTC";
$a = 0;
$g = 0;
$t = 0;
$c = 0;
for ($p = 0; p < length $dna; ++$p) {
$ch = substr($dna,$p,1);
if($ch eq 'A') {
++$a;
} elsif($ch eq 'G') {
++$g;
} elsif($ch eq 'T') {
++$t;
} elsif($ch eq 'C') {
++$c;
} else {
print "error";
}
}
$total = $a + $g + $t + $c;
$gc = $g + $c;
$percentagegc = ($gc/$total) * 100;
print "percentage gc content is = $percentagegc";请帮帮忙。
发布于 2014-03-06 18:37:55
在这行中,您在使用$时缺少了一个$p:
for($p = 0;p < length $dna;++$p)
^ -- here修复它并运行您的脚本,我得到了正确的结果:
percentage gc content is = 50https://stackoverflow.com/questions/22233026
复制相似问题