comparison DEGseq_2.pl @ 0:07745c0958dd draft

Uploaded
author big-tiandm
date Thu, 18 Sep 2014 21:40:25 -0400
parents
children 22d79320085c
comparison
equal deleted inserted replaced
-1:000000000000 0:07745c0958dd
1 #!/usr/bin/perl -w
2 #Filename:
3 #Author: Tian Dongmei
4 #Email: tiandm@big.ac.cn
5 #Date: 2009-05-06
6 #Modified:
7 #Description: ɾ³ýmatched reads
8 my $version=1.00;
9
10 use strict;
11 use Getopt::Long;
12 use File::Basename;
13
14 my %opts;
15 GetOptions(\%opts,"i=s","outdir=s","column1:i","mark1=s","depth1:i","depth2:i","column2:i","mark2=s","h");
16 if (!(defined $opts{i} and defined $opts{outdir} and defined $opts{mark1} and defined $opts{mark2}) || defined $opts{h}) { #necessary arguments
17 &usage;
18 }
19
20 my $filein=$opts{'i'};
21 my $outputdir=$opts{'outdir'};
22 unless ($outputdir=~/\/$/) {$outputdir .="/";}
23 my $column1=defined $opts{column1} ? $opts{column1} : 3;
24 my $column2=defined $opts{column2} ? $opts{column2} : 4;
25 my $mark1=$opts{mark1};
26 my $mark2=$opts{mark2};
27 my $fileout=$outputdir."degseq.R";
28 my $log=$outputdir."LOG.txt";
29
30 open OUT,">$fileout"; #output file
31 open LOG,">$log";
32 print LOG "JOB start!\t";
33 print LOG `date`;
34 print LOG "\n";
35 #my ($name,$dir);
36 #$name=basename($filein);
37 print OUT "library(DEGseq)\n";
38 print OUT "geneExpFile <- system.file(package=\"DEGseq\")\n";
39 print OUT "geneExpFile<-file.path(\"$filein\")\n";
40 print OUT "layout(matrix(c(1,2,3,4,5,6), 3, 2, byrow=TRUE))\npar(mar=c(2, 2, 2,2))\n";
41 print OUT "outputdir<-file.path(\"$outputdir\")\n";
42 print OUT "geneExpMatrix1 <- readGeneExp(file=geneExpFile, geneCol=1, valCol=c($column1))\n";
43 print OUT "geneExpMatrix2 <- readGeneExp(file=geneExpFile, geneCol=1, valCol=c($column2))\n";
44 if(defined $opts{'depth1'} && defined $opts{'depth2'}){
45 print OUT "DEGexp(geneExpMatrix1=geneExpMatrix1, geneCol1=1, expCol1=c(2), groupLabel1=\"$mark1\",geneExpMatrix2=geneExpMatrix2, geneCol2=1, expCol2=c(2), groupLabel2=\"$mark2\",depth1=$opts{depth1},depth2=$opts{depth2},outputDir=outputdir,method=\"MARS\")\n";
46 }
47 else{
48 print OUT "DEGexp(geneExpMatrix1=geneExpMatrix1, geneCol1=1, expCol1=c(2), groupLabel1=\"$mark1\",geneExpMatrix2=geneExpMatrix2, geneCol2=1, expCol2=c(2), groupLabel2=\"$mark2\",outputDir=outputdir,method=\"MARS\")\n";
49 }
50 close OUT;
51
52 print LOG "Prepare for DEGseq!\t";
53 print LOG `date`;
54 print LOG "\n";
55
56 system("R CMD BATCH $fileout");
57
58 wait;
59
60 my $outfile=$outputdir."result.txt";
61 open OUT ,">$outfile";
62 my $deg=$outputdir."output_score.txt";
63 open IN,"<$deg";
64 my %hash;
65 while (my $aline=<IN>) {
66 chomp $aline;
67 if($aline=~/^\"/){print OUT "#GeneID\tchromsome\tvalue1\tvalue2\ttag\n";next;}
68 my @temp=split/\t/,$aline;
69 #$hash{$temp[0].$temp[1].$temp[2]}=$temp[$#temp];
70 #my @tmp=split/\|/,$temp[0];
71 #my @tmp=split/\:/,$temp[0];
72 #my @po=split/\-/,$tmp[1];
73 print OUT $temp[0],"\t",$temp[1],"\t",$temp[2],"\t",$temp[-1],"\n";
74 }
75 close IN;
76
77 #open IN,"<$filein";
78 #while (my $aline=<IN>) {
79 # chomp $aline;
80 # my @temp=split/\t/,$aline;
81 # if (defined $hash{$temp[0].$temp[2].$temp[3]}) {print OUT $aline,"\t",$hash{$temp[0].$temp[2].$temp[3]},"\n";
82 # }
83 #}
84
85 print LOG "Finish all JOB !\t";
86 print LOG `date`;
87 print LOG "\n";
88
89 sub usage{
90 print <<"USAGE";
91 Version $version
92 Usage:
93 $0 -i -outdir -column1 -mark1 -column2 -mark2 -depth1 -depth2
94 options:
95 -i input file
96 -outdir output file dir
97 -column1 the first column for DEGseq
98 -mark1 the name of the column1
99 -depth1 depth for the first file,use for normalize
100 -column2 the second column for DEGseq
101 -mark2 the name of the column2
102 -depth2 depth for the second file,use for normalize
103
104 -h help
105 USAGE
106 exit(1);
107 }
108