|||
#!/usr/bin/perl -w
print"input your file,then press Enter!n";
$file=<STDIN>;
open IN,"$file";
open OUT,">rsult";
while(<IN>){
chomp;
if (/>/){
$head=$_;
$head=~s/>//g;
}else{
$seq{$head}.=$_;}
}
local $/=undef;
while (($title,$line)=each %seq){
$count=0;
$num=length$line;
for ($i=0;$i<$num;$i++){
$word=substr($line,$i,1);
if ($word=~/[GC]/){
$count++;
}else{$ratio=$count/$num;}
}
print OUT "$title\t$ratio\n";
}
exit;
#注释文件为awk实现方法
#awk '/^>/ && NR>1{print "";}{ printf "%s",/^>/?$0"\t":$0}' file.fa |awk '{print $1"\n"length($n)}'
# n为你要输出的标头信息的第几列,$0表示整行,$1,$..表示默认被空格分开的第几列内容
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-10-19 22:46
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社