annotate compStrains.pl @ 2:357379e2d533 draft

Uploaded
author antmarge
date Tue, 28 Mar 2017 22:15:55 -0400
parents c6f89f3e813c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
1 #!/usr/bin/perl -w
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
2
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
3 #Margaret Antonio 16.01.13
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
4
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
5 #DESCRIPTION: Takes two aggregate.pl outputs and compares them using mean difference, pval for each
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
6 #gene. Can compare, for example, 19F in glucose and TIGR4 in glucose.
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
7 #DIFFERENT GENOMES (ie. diff. strains).
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
8 #Requires CONVERSION FILE
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
9
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
10 #USAGE: perl compStrains.pl -c <conversion.csv> <options>
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
11 #[<aggregateFile1.csv aggregateFile2.csv> OR -indir <indir/>]
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
12
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
13 use Data::Dumper;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
14 use strict;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
15 use Getopt::Long;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
16 use warnings;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
17 use File::Path;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
18 use File::Basename;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
19 use Statistics::Distributions;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
20
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
21 #ASSIGN INPUTS TO VARIABLES USING FLAGS
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
22 our ($indir,$h,$out,$sortkey,$round,$l,$cfile);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
23 GetOptions(
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
24 'd:s' => \$indir,
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
25 'h' => \$h,
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
26 'o:s' =>\$out,
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
27 's:i' => \$sortkey,
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
28 'r:i'=> \$round,
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
29 'l1:s'=> \$l1,
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
30 'l2:s'=> \$l2,
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
31 'c:s'=> \$cfile,
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
32 );
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
33
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
34 sub print_usage() {
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
35 print "\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
36 print "\n##################################################################\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
37 print "compStrains.pl: compare genes from a tn-seq experiment\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
38 print "\tfor two DIFFERENT strains/genomes using aggregate files\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
39
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
40 print "\nDESCRIPTION: Takes two aggregate.pl outputs and compares them by\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
41 print "calculating the difference in mean fitness.\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
42
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
43 print "Example: two strains tested under same condition.\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
44 print "Note: For same strains (genomes), use compGenes.pl\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
45
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
46 print "\nUSAGE:\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
47 print "perl compStrains.pl -c conversion.csv -d inputs/\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
48
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
49 print "\nREQUIRED:\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
50 print " -d\tDirectory containing all input files (files from\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
51 print " \taggregate fitness script)\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
52 print " \tOR\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
53 print " \tIn the command line (without a flag), input the name(s) of\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
54 print " \ttwo files containing aggregate gene fitness values. \n\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
55 print " -c\tConversion file: two columns with homologs for both organisms\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
56
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
57 print "\nOPTIONAL:\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
58 print " -h\tPrints usage and exits program\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
59 print " -o\tOutput file for comparison data. Default: label1label2.csv\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
60 print " -s\tSort output by this index of the file (indices begin at 0).\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
61 print " \tDefault: by mean\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
62 print " -r\tRound final output numbers to this number of decimals\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
63 print " -l\tLabels for input files. Default: filenames\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
64 print " \tTwo strings, comma separated (i.e. -l expt1,expt2).\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
65 print " \tOrder should match file order.\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
66 print " \n~~~~Always check that file paths are correctly specified~~~~\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
67 print "\n##################################################################\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
68 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
69 if ($h){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
70 print_usage();
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
71 exit;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
72 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
73 if (!$indir and (scalar @ARGV==0)){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
74 print "\nERROR: Please correctly specify input files or directory\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
75 print_usage();
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
76 print "\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
77 exit;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
78 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
79 if (!$cfile){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
80 print "\nERROR: Please correctly specify the required conversion file\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
81 print_usage();
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
82 print "\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
83 exit;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
84 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
85
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
86 #THE @files ARRAY WILL CONTAIN INPUT FILE NAMES, EXTRACTED FROM A DIRECTORY (-indir) OR ARGV
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
87 my @files;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
88 if ($indir){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
89 my $directory="$indir";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
90 opendir(DIR, $directory) or (print "Couldn't open $directory: $!\n" and print_usage() and exit);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
91 my @direct= readdir DIR;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
92 my $tail=".csv";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
93 foreach (@direct){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
94 if (index($_, $tail) != -1){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
95 $_=$indir.$_;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
96 push (@files,$_);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
97 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
98 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
99 closedir DIR;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
100 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
101 else{
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
102 @files=@ARGV;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
103 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
104
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
105 #GET LABELS: USE (-l) OR USE FILNEAMES AS LABELS FOR COLUMNS IN OUTPUT FILE
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
106
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
107 my @labels;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
108
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
109 my @labels = ($l1,$l2);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
110 #if ($l){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
111 # @labels=split(',',$l);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
112 #}
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
113 #else{
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
114 # foreach (@files){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
115 # my $filename=basename($_);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
116 # my @temp=split('\\.',$filename);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
117 # my $colName=$temp[0];
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
118 # push (@labels,$colName);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
119 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
120 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
121
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
122 #CHECK IF REQ. VARIABLES WERE DEFINED USING FLAGS. IF NOT THEN USE DEFAULT VALUES
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
123
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
124 if (!$out) {$out="comp.".$labels[0].$labels[1].".csv"}
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
125 if (!$round){$round='%.4f'}
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
126
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
127 #OPEN INPUTTED AGGREGATE GENE FILES AND STORE THEIR CONTENTS INTO TWO HASHES
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
128 #FILE1 GOES INTO HASH %ONE AND FILE2 GOES INTO HASH %TWO.
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
129
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
130 #FILE1 OPENING ---> %one WHERE KEY:VALUE IS GENE_ID:(GENE_ID,INSERTIONS,MEAN,ETC.)
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
131 my @header;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
132 my %one;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
133
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
134 open (F1,'<',$files[0]);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
135
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
136 #STORE COLUMN NAMES (FIRST LINE OF FILE1) FOR HEADER AND APPEND LABELS
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
137 my $head=<F1>; #the header in the file
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
138 my @cols=split(',',$head);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
139 @cols=@cols[0,1,2,3,4,5,6]; #get rid of blank columns
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
140 for (my $j=0;$j<scalar @cols;$j++){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
141 $cols[$j]=$cols[$j].'-'.$labels[0]; #mark each column name with file it comes from
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
142 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
143 push (@header,@cols);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
144
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
145 while (my $line=<F1>){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
146 chomp $line;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
147 my @info=split(",",$line);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
148 #Only keep the first 7 columns (Ones about blanks aren't needed for comparisons)
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
149 @info=@info[0,1,2,3,4,5,6];
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
150 #Sometimes genes that don't have a gene name can't be blank, so fill with NA
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
151 if (!$info[5]){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
152 $info[5]="NA";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
153 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
154 #If there are no insertions in the column "total", then make it =0 rather than blank
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
155 if (!$info[6]){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
156 $info[6]=0;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
157 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
158 $one{$info[0]}=\@info;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
159 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
160 close F1;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
161
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
162 #FILE2 OPENING ---> %two WHERE KEY:VALUE IS GENE_ID:(GENE_ID,INSERTIONS,MEAN,ETC.)
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
163
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
164 my %two;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
165 open (F2,'<',$files[1]);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
166
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
167 #STORE COLUMN NAMES (FIRST LINE OF FILE2) FOR HEADER AND APPEND LABELS
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
168 $head=<F2>; #the header in the file
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
169 @cols=split(',',$head);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
170 @cols=@cols[0,1,2,3,4,5,6]; #get rid of blank columns
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
171 for (my $j=0;$j<scalar @cols;$j++){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
172 $cols[$j]=$cols[$j].'-'.$labels[1]; #mark each column name with file it comes from
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
173 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
174 push (@header,@cols);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
175
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
176 while (my $line=<F2>){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
177 chomp $line;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
178 my @info=split(",",$line);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
179 @info=@info[0,1,2,3,4,5,6];
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
180 if (!$info[5]){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
181 $info[5]="NA";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
182 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
183 if (!$info[6]){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
184 $info[6]=0;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
185 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
186 $two{$info[0]}=\@info;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
187 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
188 close F2;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
189
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
190
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
191 #READ CONVERSION FILE INTO ARRAY.
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
192 #Conversion file must have strain 1 for file 1 in column 1 (index 0) and
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
193 #strain 2 for file 2 in column 2 (index 1)
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
194 #conversion file must be tab delimited with no NA fields
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
195 #If homologs (exist then take info from hashes (%one and %two) by referring to gene_id in KEY
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
196
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
197 my @all; #store all homologs in this hash
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
198 open (CONV,'<',$cfile);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
199 while (my $line=<CONV>){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
200 chomp $line;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
201 my @genes=split("\t",$line); #Array @genes will contain two genes (SP_0000,SPT_0000)
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
202 if (scalar @genes==2 and $genes[0] ne "" and $genes[1] ne ""){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
203 my @info;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
204 my @oneArray=@{$one{$genes[0]}};
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
205 my @twoArray=@{$two{$genes[1]}};
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
206 push (@info,@oneArray,@twoArray);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
207 my $diff=sprintf("$round",($info[1]-$info[8]));
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
208 my $total1=$info[6];
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
209 my $total2=$info[13];
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
210 my $sd1=$info[3];
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
211 my $se1=$info[4];
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
212 my $sd2=$info[10];
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
213 my $se2=$info[11];
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
214 my $df=$total1+$total2-2;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
215 my $tdist;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
216 my $pval;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
217 #TDIST, PVAL calculations with fail if standard dev, error, or counts are not real numbers
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
218 #or if 0 ends up in denominator
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
219 if ($se1 eq "X" or $se2 eq "X" or $sd1 eq "X" or $sd2 eq "X" or $total1==0 or $total2==0 or $sd1==0 or $sd2==0){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
220 ($tdist,$pval)=("NA","NA");
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
221 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
222 else{
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
223 $tdist=sqrt((($diff)/(sqrt((($sd1**2)/$total1)+(($sd2**2)/$total2))))**2);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
224 $pval=Statistics::Distributions::tprob($df,$tdist);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
225 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
226 push (@info,$diff,$df,$tdist,$pval);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
227 push (@all,\@info);
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
228 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
229 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
230 close CONV;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
231
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
232 #SORT THE HOMOLOGS BY THE SORTKEY OR BY DEFAULT DIFFERENCE IN MEAN FITNESSES
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
233 if (!$sortkey){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
234 $sortkey=14; #for mean difference
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
235 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
236 my @sorted = sort { $b->[$sortkey] <=> $a->[$sortkey] } @all;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
237
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
238 #FINISH THE HEADER BY ADDING COLUMN NAMES FOR MEAN-DIFF, DOF, TDIST, AND PVALUE
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
239 my $field="MeanDiff(".$labels[0].'.'.$labels[1].")";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
240 push (@header,$field,"DOF","TDIST","PVALUE");
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
241
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
242 #PRINT MATCHED HOMOLOG INFORMATION INTO A SINGLE OUTPUT FILE
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
243 open OUT, '>',"$out";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
244 print OUT (join(',',@header),"\n");
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
245 foreach (@sorted){
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
246 my @woo=@{$_};
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
247 print OUT join(',',@woo),"\n";
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
248 }
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
249
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
250 close OUT;
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
251
c6f89f3e813c Uploaded
antmarge
parents:
diff changeset
252