annotate compStrains.pl @ 8:5bd43e313819 draft

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