计算每条DNA序列的长度及其GC含量

脚本程序


原始序列

运行程序:perl calculateDNA_length_GCcontent.pl


第一步合并结果


第二步计算结果

——————————————————————————————————————————————————

#!/usr/bin/perl -w

use strict;

my $content="";

open In,"sampleDNA.fasta";

open Out,">sampleDNA.fasta.out";

while(<In>){

chomp;

if(/^>/){

if($content ne ""){

print Out "$content\n";

$content="";}

print Out "$_\n";

}

else{$content.=$_;}

}

print Out "$content\n";

close In;close Out;

open In,"sampleDNA.fasta.out";

open Out,">sampleDNAresult.out";

while(<In>){

chomp;

my $GC=0;my $length=0;my $GC_count=0;

if(/^>(\S+)/){

print Out "$1\t";}

else {$_=~s/\s//g;

$length=length($_);

while($_=~/c|g/ig){$GC++;};

$GC_count=$length?($GC/$length):0;

$GC_count*=100;

printf Out "%d\t%.2f",$length,$GC_count;

printf Out "%%\n";}

}

close In;close Out;


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容