其他
Perl学习17之生信简单运用
"pythonic生物人"的第29篇分享
感觉不错可以点个“赞“或"在看"哦
正文开始啦
1、计算一条DNA序列中的ATGC个数GC含量格式化输出
gccount_read.pl
#!/usr/bin/perl
use strict;
use warnings;
my $read = "AACAAACCCCTTTTCTCTATTAAAAAATACAAAATAGCTTAGCTGCGGCATAGTGGAGCACG";
my $G = ($read =~ s/G/G/g);#s为匹配表示匹配,($read =~ s/G/G/g)返回匹配次数个数
my $C = ($read =~ s/C/C/g);
my $A = ($read =~ s/A/A/g);
my $T = ($read =~ s/T/T/g);
my $total = $G + $C + $A +$T;
my $GC_P = ($G + $C)/$total;
#格式化输出printf
printf "\$G:%d\n\$C:%d\n\$A:%d\n\$T:%d\n\$total:%d\n\$GC_P:%.2f\n",($G,$C,$A,$T,$total,$GC_P);
#sprintf格式化不输出
my $result = sprintf("\$G:%d\n\$C:%d\n\$A:%d\n\$T:%d\n\$total:%d\n\$GC_P:%.2f\n",($G,$C,$A,$T,$total,$GC_P));
#输出到文件GC.file
open OUT,">","./GC.file";
print OUT $result;
close OUT;
perl gccount_read.pl
cat GC.file
#!/usr/bin/perl
use strict;
use warnings;
open IN,"./sumfile";
while(<IN>){
chomp;
my @t=split;
my $sum=0;
for my $i (1..5){
$sum+=$t[$i];
}
print "$t[0]\t$sum\t";#求和
for my $i (1..5){
my $percent=$t[$i]/$sum;
printf "%.2f\t","$percent";
}
print "\n";#换行
}
perl sum1.pl
a 15 0.07 0.13 0.20 0.27 0.33
b 15 0.07 0.13 0.20 0.27 0.33
Perl学习14之$0,ARGV,use warnings,use stricts使用