题目来源:http://rosalind.info/problems/hamm/
一、程序目的:计算序列点突变(Point Mutations)
输入:
GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
输出:
7
二、程序设计
读取序列后利用split分割字串,然后注意比较,注意perl字符比较用“ne”(不等于)。
#!/usr/bin/perl/ use strict; my (@seq, @seq1, @seq2, $distance); @seq = <>; # @seq1 = split //, chomp($seq[0]); # 这样会出错,chomp有返回值0 1 # @seq2 = split //, chomp($seq[1]); @seq1 = split //, $seq[0]; @seq2 = split //, $seq[1]; for(my $i = 0; $i <= $#seq1; $i++){ if($seq1[$i] ne $seq2[$i]){ $distance++; } } print $distance."\n";
三、补充
perl比较
数字 | 字符 | |
大于 | > | lt |
小于 | < | gt |
等于 | == | eq |
不等于 | != | ne |
大于或等于 | >= | ge |
小于或等于 | <= | le |
其他的代码:
#!/usr/bin/perl # my @str = <STDIN>; my $c = 0; for ($i = 0; $i < length($str[0]); $i++){ $c++ if (substr ($str[0], $i, 1)) ne (substr ($str[1], $i, 1)); } print "$c\n";
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}