COG database annotation

Step 1
wget -bc -r -np -nH -nd  ftp://ftp.ncbi.nih.gov/pub/COG/COG2020/data/fasta

wget -bc ftp://ftp.ncbi.nih.gov/pub/COG/COG2020/data/cog-20.cog.csv

wget -bc ftp://ftp.ncbi.nih.gov/pub/COG/COG2020/data/cog-20.def.tab


Step 2

cat fasta/*fa.gz > COG_2020.fa.gz

seqkit rmdup COG_2020.fa.gz > COG_2020_rmdup.fa.gz

diamond makedb --in COG_2020_rmdup.fa.gz -d COG_2020_rmdup.dmnd


Step3

diamond blastx -d COG_2020_rmdup.dmnd -b 6 -q test_file.fa -f 5 -o test_file.xml  #for nucleotide sequence

diamond blastp -d COG_2020_rmdup.dmnd -b 6 -q test_file.fa -f 5 -o test_file.xml  #for amino acid sequence


Step4

perl gene_cog_annotaion.pl -x test_file.xml -c cog-20.cog.csv -t cog-20.def.tab

result file: test_file_cog_func_anno.tsv, test_file.tsv

use strict;

use warnings;

use Getopt::Long;

use Bio::SearchIO;

my $ver = 0.77;

my %opts;

GetOptions(\%opts, "x=s", "t=s", "c=s", "h" );

if(!defined($opts{x}) || !defined($opts{c}) || !defined($opts{t}) || defined($opts{h})){

        print <<"      Usage End.";

#-------------------------------------------------------------------------------------------------------------------------------------------

        Description: COG database annotation from blast xml format out

      example:perl $0 -x test_file.xml -c cog-20.cog.csv -t cog-20.def.tab


      Version: $ver 

        General options:

                -x          blast/diamond output xml file                                          <infile>      xml format[must]

                -c          Comma-delimited plain text file assigning proteins to COGs(cog-20.cog.csv)      <infile>      csv format[must]

                -t          Tab-delimited plain text file with COG descriptions(cog-20.def.tab)            <infile>      tsv format[must]

                -h          Help document

#-------------------------------------------------------------------------------------------------------------------------------------------

      Usage End.

        exit;

}

my $blastxml = $opts{x};

my $csv = $opts{c};

my $tsv = $opts{t};

my ($name) = $blastxml=~/(\S+?)\.xml/;

open TSV,">$name.tsv";

print TSV "qseqid\tsseqid\thit_desc\thit_rank\tpercent_identity\tquery_start\tquery_end\tsubject_start\tsubject_end\tevalue\tbits\n";

my $searchio = Bio::SearchIO->new( -format => 'blastxml', -file => $blastxml );

my %info;

while ( my $result = $searchio->next_result() ) { #perldoc Bio::Search::Result::ResultI

my $id = $result->query_name();

my $query_desc = $result->query_description();

my $dbname = $result->database_name();

my $size = $result->database_letters();

my $num_entries = $result->database_entries();

#print "#dbname\t$dbname\nnum_entries\t$num_entries\nsize\t$size";

while( my $hit = $result->next_hit ) {  #process the Bio::Search::Hit::HitI object

my $hit_name = $hit->name();

my $hit_desc = $hit->description();

        my $len = $hit->length();

my $rank = $hit->rank(); #the Nth hit for a specific query

print TSV "$query_desc\t";

print TSV "$hit_name\t$hit_desc\t$rank\t";

while( my $hsp = $hit->next_hsp ) {    # process the Bio::Search::HSP::HSPI object

my $query_start = $hsp->start('query');

my $query_end = $hsp->end('query');

my $subject_start = $hsp->start('subject');

my $subject_end = $hsp->end('subject');

my $evalue = $hsp->evalue;

#my $num_identical = $obj->num_identical(); #returns the number of identical residues in the alignment

my $percent_identity = sprintf "%.2f",$hsp->percent_identity(); #Returns the calculated percent identity for an HSP(0,100)

#my $num_conserved = $obj->num_conserved($newval)  #returns the number of conserved residues in the alignment

my $query_len = $hsp->length('query');          #length of query seq (without gaps)

my $hit_len = $hsp->length('hit');              #length of hit seq (without gaps)

my $total_len = $hsp->length('total');          #length of alignment (with gaps)

my $query_gaps = $hsp->gaps('query');            #num conserved / length of query seq (without gaps)

my $hit_gaps = $hsp->gaps('hit');                #num conserved / length of hit seq (without gaps)

my $total_gaps = $hsp->gaps('tatla');            #num conserved / length of alignment (with gaps)

my $hit = $hsp->hit;

my $score = $hsp->score();

my $bits = $hsp->bits();

print TSV "$percent_identity\t$query_start\t$query_end\t$subject_start\t$subject_end\t$evalue\t$bits\n";

$info{$query_desc}="$hit_name\t$hit_desc\t$evalue" if $rank==1;

}

}

}

#-----------------------------------------------------------------------------------------------------------------------------------------------

my %cog_cog=&cog_csv;

my %cog_def=&cog_tab;

open F, ">$name\_cog_func_anno.tsv";

print F "#query_id\tprot_id\tcog_id\tgene_id\tcog_membership_class\tcog_functional_category\tcog_name\tcog_functional_pathway\n";

for my $query_id(sort keys %info){

my ($prot_id, $prot_disc, $evalue) = split/\t/, $info{$query_id};

print F "$query_id\t$prot_id\t";

my ($cog_id, $gene_id,$cog_membership_class) = split/\t/, $cog_cog{$prot_id};

print F "$cog_id\t$gene_id\t$cog_membership_class\t";

my ($cog_functional_category,$cog_name,$cog_functional_pathway)=split/\t/,$cog_def{$cog_id};

print F "$cog_functional_category\t$cog_name\t$cog_functional_pathway\n";

}

#-----------------------------------------------------------------------------------------------------------------------------------------------

sub cog_csv{

open IN, $csv;

my %cog_cog;

while(<IN>){

chomp;

my ($gene_id, $protein_id, $cog_id, $cog_membership_class) = (split/\,/,$_)[0, 2, 6, 8];

$cog_cog{$protein_id} = "$cog_id\t$gene_id\t$cog_membership_class";

}

return %cog_cog;

close;

}

sub cog_tab{

open IN, $tsv;

my %cog_def;

while(<IN>){

chomp;

my ($cog_id, $cog_functional_category,$cog_name,$cog_functional_pathway) = (split/\t/,$_)[0, 1, 2, 4];

$cog_functional_pathway = $cog_functional_pathway?$cog_functional_pathway:"NA";

$cog_def{$cog_id} = "$cog_functional_category\t$cog_name\t$cog_functional_pathway";

}

return %cog_def;

close IN;

}

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,635评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,628评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,971评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,986评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,006评论 6 394
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,784评论 1 307
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,475评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,364评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,860评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,008评论 3 338
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,152评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,829评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,490评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,035评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,156评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,428评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,127评论 2 356

推荐阅读更多精彩内容