jhh130910的个人博客分享 http://blog.sciencenet.cn/u/jhh130910

博文

fasta序列GC含量统计

已有 5124 次阅读 2014-10-19 15:02 |个人分类:Perl|系统分类:科研笔记| 统计

#!/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,$..表示默认被空格分开的第几列内容



https://wap.sciencenet.cn/blog-1051713-836925.html


下一篇:miREvo 软件使用
收藏 IP: 221.212.172.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-3-29 14:40

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部