2维韦恩图各部分基因上下调数量统计

2维韦恩图各部分基因上下调数量统计

attachments-2018-07-OUUPVJJ95b5ad8df04466.jpg

画上面这种韦恩图,有时候会需要统计各部分基因的上下调数量,这时就可以使用下面的代码了。

用法如下:

perl venn_up_or_down.pl  -in All_DEG_venn.xls  -id1 left_DEG.final.xls  -id2 right_DEG.final.xls  -k trans_full_table.xls  -od out

该脚本的输入文件都为转录组分析结果文件,All_DEG_venn.xls是画韦恩图时生成的,*_DEG.final.xls分别是两个差异组合的。trans_full_table.xls是总的所有基因统计文件。

Usage
Forced parameter:
    -in All_DEG_venn.xls <infile>   must be given
-od         outdir                   <dir>     must be given
-id1         left DEG.final.xls       <infile>     must be given
-id2         right DEG.final.xls      <infile>     must be given
-k noRef_trans_full_table.xls (kegg anno) <infile>     must be given

Other parameter:
-h           Help document


脚本代码:

#!/usr/bin/perl -w
use strict;
use warnings;
use Getopt::Long;
use Data::Dumper;
use Config::General;
use Cwd qw(abs_path getcwd);
use FindBin qw($Bin $Script);
use File::Basename qw(basename dirname);
use Math::BigFloat;
use Bio::SeqIO;
use Bio::Seq;
my $version = "1.3";
## prepare parameters #######################################################################
## -------------------------------------------------------------------------------------------
## GetOptions
my %opts;
GetOptions(\%opts,  "in=s", "id1=s", "id2=s", "k=s", "od=s","h");
if(!defined($opts{in}) || !defined($opts{id1}) || !defined($opts{k}) || !defined($opts{id2}) || !defined($opts{od}) ||defined($opts{h}))
{
print <<"Usage End.";
Description:
$version:lefse analysis
Usage
Forced parameter:
   -inAll_DEG_venn.xls<infile>   must be given
-od         outdir                   <dir>     must be given
-id1         left DEG.final.xls                     <infile>     must be given
-id2         right DEG.final.xls                     <infile>     must be given
-k noRef_trans_full_table.xls (kegg anno)

Other parameter:
-h           Help document
Usage End.
exit;
}
open(IN,"$opts{in}")||die "open file $opts{in} failed.\n";
my %left;
my %right;
my %center;
while(<IN>){
next if(/^all_id/);
chomp;
my @line = split ("\t",$_);
if($line[1] ne "-" && $line[2] eq "-"){
$left{$line[0]} = $line[0];
}
if($line[1] eq "-" && $line[2] ne "-"){
$right{$line[0]} = $line[0];
}
if($line[1] ne "-" && $line[2] ne "-"){
$center{$line[0]} = $line[0];
}
}
close(IN);
open(IN,"$opts{k}") || die "open file $opts{k} failed.\n";
open(ID1,"$opts{id1}")||die "open file $opts{id1} failed.\n";
open(ID2,"$opts{id2}")||die "open file $opts{id2} failed.\n";
my %kegg;
while(<IN>){
chomp;
my @line = split("\t");
if(/^#/){print "$line[23]\n\n";}
$kegg{$line[0]} = $line[23];

}
close(IN);
my %deg1;
while(<ID1>){
next if(/^#/);
chomp;
my @line = split("\t");
$deg1{$line[0]} = $_;
}
close(ID1);
my %deg2;
while(<ID2>){
next if(/^#/);
chomp;
my @line = split("\t");
$deg2{$line[0]} = $_;
}
close(ID2);
open(UP,">$opts{od}/left_up.txt")||die "open file $opts{od}/left_up.txt failed.\n";
open(DOWN,">$opts{od}/left_down.txt")||die "open file $opts{od}/left_down.txt failed.\n";
while((my $key,my $value) = each %left){
my @line = split("\t",$deg1{$key});
if($line[7] eq "up"){
print UP "$deg1{$key}\t$kegg{$key}\n";
}
if($line[7] eq "down"){
print DOWN "$deg1{$key}\t$kegg{$key}\n";
}
}
close(UP);
close(DOWN);

open(UP,">$opts{od}/right_up.txt")||die "open file $opts{od}/right_up.txt failed.\n";
open(DOWN,">$opts{od}/right_down.txt")||die "open file $opts{od}/right_down.txt failed.\n";
while((my $key,my $value) = each %right){
my @line = split("\t",$deg2{$key});
if($line[7] eq "up"){
print UP "$deg2{$key}\t$kegg{$key}\n";
}
if($line[7] eq "down"){
print DOWN "$deg2{$key}\t$kegg{$key}\n";
}
}
close(UP);
close(DOWN);

open(UP,">$opts{od}/center_up.txt")||die "open file $opts{od}/center_up.txt failed.\n";
open(DOWN,">$opts{od}/center_down.txt")||die "open file $opts{od}/center_down.txt failed.\n";
open(DIFF,">$opts{od}/center_diff.txt")||die "open file $opts{od}/center_diff.txt failed.\n";
while((my $key,my $value) = each %center){
my @line1 = split("\t",$deg1{$key});
my @line2 = split("\t",$deg2{$key});
if($line1[7] eq "up" && $line2[7] eq "up"){
print UP "$deg1{$key}\t$deg2{$key}\t$kegg{$key}\n";
}elsif($line1[7] eq "down" && $line2[7] eq "down"){
print DOWN "$deg1{$key}\t$deg2{$key}\t$kegg{$key}\n";
}else{
print DIFF "$deg1{$key}\t$deg2{$key}\t$kegg{$key}\n";
}
}
close(UP);
close(DOWN);
close(DIFF);


  • 发表于 2018-07-27 11:34
  • 阅读 ( 4275 )
  • 分类:perl

0 条评论

请先 登录 后评论
安生水
安生水

347 篇文章

作家榜 »

  1. omicsgene 698 文章
  2. 安生水 347 文章
  3. Daitoue 167 文章
  4. 生物女学霸 120 文章
  5. xun 82 文章
  6. 红橙子 78 文章
  7. rzx 74 文章
  8. CORNERSTONE 72 文章