annotate dataOverview.pl @ 1:b66f4a551e25 draft

Uploaded
author antmarge
date Tue, 28 Mar 2017 21:56:04 -0400
parents
children 80205e898861
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
1 #!/usr/bin/perl -w
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
2
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
3 #Margaret Antonio 16.08.29
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
4
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
5 #use strict;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
6 use Getopt::Long;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
7 use Bio::SeqIO;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
8 use autodie;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
9 no warnings;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
10
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
11
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
12
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
13 #AVAILABLE OPTIONS. WILL print OUT UPON ERROR
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
14 sub print_usage() {
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
15
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
16 print "\n###############################################################\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
17 print "dataOverview: outputs basic statistics for tn-seq library files \n\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
18
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
19 print "USAGE:\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
20 print "perl dataOverview.pl -i inputs/ -f genome.fasta -r genome.gbk\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
21
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
22 print "\nREQUIRED:\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
23 print " -d\tDirectory containing all input files (results files from\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
24 print " \tcalc fitness script)\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
25 print " \t OR\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
26 print " \tIn the command line (without a flag), input the name(s) of \n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
27 print " \tthe files containing fitness values for individual \n\tinsertion mutants\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
28 print " -f\tFilename for genome sequence, in fasta format\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
29 print " -r\tFilename for genome annotation, in GenBank format\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
30
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
31 print "\nOPTIONAL:\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
32 print " -h\tprint OUT usage\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
33 print " -c\tCutoff average(c1+c2)>c. Default: 15\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
34 print " -o\tFilename for output. Default: standard output\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
35 print " \n~~~~Always check that file paths are correctly specified~~~~\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
36 print " \n###############################################################\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
37
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
38 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
39
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
40 # print "What's on the commandline: ", $ARGV;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
41
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
42 sub get_time() {
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
43 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
44 return "$hour:$min:$sec";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
45 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
46 sub mean {
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
47 my $sum=0;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
48 foreach my $n(@_){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
49 $sum+=$n;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
50 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
51 my $total=scalar @_;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
52 my $mean=$sum/$total;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
53 return $mean;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
54 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
55 sub minmax{
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
56 my @unsorted=@_;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
57 my @sorted = sort { $a <=> $b } @unsorted;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
58 my $min = $sorted[0];
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
59 my $max = $sorted[scalar @sorted -1];
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
60 return ($min, $max);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
61 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
62 sub uniq{
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
63 my @input=@_;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
64 my @unique = do { my %seen; grep { !$seen{$_}++ } @input };
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
65 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
66
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
67 #ASSIGN INPUTS TO VARIABLES
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
68 our ($cutoff,$fastaFile, $outfile,$help,$ref,$weight_ceiling);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
69 GetOptions(
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
70 'r:s' => \$ref,
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
71 'f:s' => \$fastaFile,
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
72 'c:i'=>\$cutoff,
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
73 'o:s' => \$outfile,
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
74 'h'=> \$help,
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
75 'w:i' => \$weight_ceiling,
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
76 );
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
77
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
78 # Set defaults
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
79 #if (!$weight_ceiling){$weight_ceiling=50;}
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
80 #if (!$cutoff){$cutoff=10;}
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
81
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
82 # If help option is specified or required files are not specified:
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
83
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
84 if ($help) {
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
85 print print_usage();
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
86 print "\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
87 exit;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
88 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
89
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
90 if (!$fastaFile or !$ref){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
91 print "\nERROR: Please correctly specify reference genome fasta and genbank files\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
92 print "Most genomes (in fasta and gbk format) are available at NCBI\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
93 print print_usage();
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
94 print "\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
95 exit;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
96 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
97 # Redirect STDOUT to log.txt. Anything print OUTed to the terminal will go into the log file
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
98 if (! $outfile){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
99 $outfile="summary.txt";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
100 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
101
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
102 open OUT, ">",$outfile;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
103
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
104 #Not sure if I'll need this but sometimes funky data inputs have hidden characters
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
105 sub cleaner{
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
106 my $line=$_[0];
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
107 chomp($line);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
108 $line =~ s/\x0d{0,1}\x0a{0,1}\Z//s;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
109 return $line;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
110 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
111
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
112
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
113 #Get the input files out of the input directory, or take off of command line
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
114
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
115 my @files=@ARGV;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
116 foreach my $f(@files){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
117 #print $f;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
118 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
119 my $num=(scalar @files);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
120
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
121 #print OUT "Gathering data overview for Tn-Seq experiment\n\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
122 #print OUT "Begin time: ",get_time(),"\n\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
123
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
124 #CREATE AN ARRAY OF DATA FROM INPUT CSV FILE(S).
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
125 #These are the "results" files from calc_fitness.pl. Insertion location, fitness, etc.
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
126 #Go through each file from the commandline (ARGV array) and read each line as an array
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
127 #into select array if values satisfy the cutoff
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
128
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
129
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
130 #Store ALL insertion locations in this array. Later, get unique insertions
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
131 my @insertions_all;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
132 #Store all genes with valid insertions here
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
133 my @genes_insertions;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
134 #all lines that satisfied cutoff
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
135 my @unsorted;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
136 #array to hold all positions of insertions. Going to use this later to match up with TA sites
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
137 my @insertPos;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
138
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
139 #Markers
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
140 my $rows=-1;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
141 my $last=0;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
142
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
143 print OUT "Library description\n\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
144 my @header=("library","file_path","ins","ins.f","genes.ins");
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
145 print OUT join ("\t",@header),"\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
146
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
147 for (my $i=0; $i<$num; $i++){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
148 #Temp arrays for library
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
149 my(@insertions_all_lib,@genes_insertions_lib,@insertPos_lib);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
150 my $file=$files[$i];
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
151 open(DATA, '<', $file) or die "Could not open '$file' Make sure input .csv files are entered in the command line\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
152 my $dummy=<DATA>; #read and store column names in dummy variable
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
153 while (my $entry = <DATA>) {
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
154 chomp $entry;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
155 my @line=split(",",$entry);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
156 my $locus = $line[9]; #gene id (SP_0000)
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
157 my $w = $line[12]; #nW
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
158 if (!$w){ $w=0 } # For blanks
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
159 my $c1 = $line[2];
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
160 my $c2 = $line[3];
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
161 my $coord= $line[0];
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
162 push (@insertions_all_lib,$coord);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
163 #Average counts must be greater than cutoff (minimum allowed)
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
164 my $avg = ($c1+$c2)/2;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
165 if ($avg > $cutoff) {
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
166 my @select=($coord,$w,$avg,$locus);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
167 my $select=\@select;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
168 push(@unsorted,$select);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
169 push(@insertPos_lib,$line[0]); #keep track of actual insertion site position
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
170 push (@genes_insertions_lib,$locus);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
171 $last=$select[0];
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
172 $rows++;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
173 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
174 if ($avg >= $weight_ceiling) { $avg = $weight_ceiling } # Maximum weight
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
175 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
176 close DATA;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
177 push (@insertions_all,@insertions_all_lib);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
178 @genes_insertions_lib= uniq @genes_insertions_lib;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
179 push (@genes_insertions,@genes_insertions_lib);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
180 push (@insertPos,@insertPos_lib);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
181 my @stat=($i+1,$file,scalar @insertions_all_lib,scalar @insertPos_lib,scalar @genes_insertions_lib);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
182 print OUT join("\t",@stat),"\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
183 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
184
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
185 @insertPos = sort { $a <=> $b } @insertPos;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
186 @insertPos= uniq @insertPos;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
187 @genes_insertions= uniq @genes_insertions;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
188 @insertions_all=uniq @insertions_all;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
189 my $totalAll=scalar @insertions_all;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
190 my $total=scalar @insertPos;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
191 my $temp="1-".$num;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
192 my @all_stat=($temp,"NA",$totalAll,$total,scalar @genes_insertions);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
193 print OUT join("\t",@all_stat),"\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
194
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
195 #Genome description: #TA sites, distance between TA sites, #TA sites in ORFS
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
196 print OUT "\n-------------------------\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
197 print OUT "\nGenome description\n\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
198 print OUT "File for genome: ", $fastaFile,"\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
199
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
200 my @sites;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
201 #First read fasta file into a string
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
202 my $seqio = Bio::SeqIO->new(-file => $fastaFile, '-format' => 'Fasta');
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
203 my $fasta;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
204 while(my $seq = $seqio->next_seq) {
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
205 $fasta = $seq->seq;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
206 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
207 #Just in case $fasta file is in lowercase, change it to uppercase
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
208 $fasta=uc $fasta;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
209
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
210 #Get genomic coordinate for TA sites:
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
211 my $x="TA";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
212 my $offset=0;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
213 my @indices;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
214 my $result=index($fasta,$x,$offset);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
215 while ($result !=-1){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
216 push (@indices,$result);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
217 $offset=$result+1;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
218 $result=index($fasta,$x,$offset);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
219 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
220 my $countTA=scalar @indices;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
221
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
222 #Get longest stretch with no TA sites
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
223 my @tempta=@indices;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
224 my $prev=shift @tempta;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
225 my $current=shift @tempta;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
226 my $lg_dist_ta=$current-$prev;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
227 foreach my $site(@tempta){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
228 $prev=$current;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
229 $current=$site;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
230 my $d=$current-$prev;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
231 if ($d>$lg_dist_ta){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
232 $lg_dist_ta=$d;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
233 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
234 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
235
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
236 #Get longest stretch of with no insertions
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
237 my @tempins=@insertPos;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
238 $prev=shift @tempins;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
239 $current=shift @tempins;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
240 my $lg_dist_ins=$current-$prev;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
241 foreach my $site(@tempins){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
242 $prev=$current;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
243 $current=$site;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
244 my $d=$current-$prev;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
245 if ($d>$lg_dist_ins){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
246 $lg_dist_ins=$d;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
247 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
248 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
249
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
250
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
251 my $genSize=length $fasta;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
252 print OUT "$genSize\tGenome size\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
253 print OUT "$countTA\tTotal number of TA sites\n\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
254
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
255 my $sat=sprintf("%.2f", ($total/$countTA)*100);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
256 my $satAll=sprintf("%.2f", ($totalAll/$countTA)*100);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
257 my $inscov=sprintf("%.2f", ($total/$genSize)*100);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
258 my $tacov=sprintf("%.2f", ($countTA/$genSize)*100);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
259
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
260 #Get GC content of genome
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
261
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
262 my $sequence = ' ';
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
263 my $Ccount = 0;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
264 my $Gcount = 0;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
265 my $identifier = ' ';
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
266
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
267 my @nucleotides = split('', $fasta);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
268
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
269 foreach my $nuc (@nucleotides) {
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
270 if ($nuc eq 'G') {$Gcount++}
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
271 elsif ($nuc eq 'C') {$Ccount++}
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
272 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
273 my $sequencelength=length $fasta;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
274
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
275 my $GCcontent = sprintf("%.2f",((($Gcount + $Ccount) / $sequencelength) * 100));
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
276 my $ATcontent =100-$GCcontent;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
277
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
278 print OUT "$GCcontent%\tGC content of this genome\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
279 print OUT "$ATcontent%\tAT content of this genome\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
280
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
281 print OUT "$satAll%\tSaturation of TA sites before cutoff filter (allInsertions/TAsites)\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
282 print OUT "$sat%\tSaturation of TA sites after cutoff filter (validInsertions/TAsites)\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
283 print OUT "$inscov%\tGenome coverage by insertions (validInsertions/genomeSize)\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
284 print OUT "$tacov%\tGenome coverage by TA sites (TAsites/genomeSize)\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
285 print OUT "$lg_dist_ta\tLargest distance between TA sites\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
286 print OUT "$lg_dist_ins\tLargest distance between insertions\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
287 print OUT "\n\nOpen Reading Frames\n\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
288
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
289 #Store everything to be print OUTed in array
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
290 my @table;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
291
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
292 #Find open reading frames from fasta file
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
293 local $_ = $fasta;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
294 my @orfSize;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
295 my @allc; #numbers of TAs in the ORFS here.
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
296 my $blank=0; #ORFS that don't have any TA sites.
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
297 my $orfCount=0; #keep track of the number of ORFs found.
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
298 my $minSize=0;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
299 #Read somewhere that 99 is a good min but there is an annotated 86 bp gene for 19F
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
300 while ( /ATG/g ) {
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
301 my $start = pos() - 3;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
302 if ( /T(?:AA|AG|GA)/g ) {
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
303 my $stop = pos;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
304 my $size=$stop - $start;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
305 if ($size>=$minSize){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
306 push (@orfSize,$size);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
307 my $seq=substr ($_, $start, $stop - $start);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
308 my @ctemp = $seq =~ /$x/g;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
309 my $countTA = @ctemp;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
310 if ($countTA==0){$blank++}
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
311 push (@allc,$countTA);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
312 $orfCount++;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
313 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
314 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
315 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
316
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
317 print OUT "\nORFs based on Fasta sequence and start (ATG) and end (TAA,TAG,TGA) codons\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
318 push (@table,["Set minimum size for an ORF",$minSize]);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
319 print OUT "$orfCount\tTotal number of ORFs found\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
320 my ($minORF, $maxORF) = minmax(@orfSize);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
321 print OUT "$minORF\tSmallest ORF\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
322 print OUT "$maxORF\tLargest ORF\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
323 my ($mintaORF,$maxtaORF) = minmax(@allc);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
324 print OUT "$mintaORF\tFewest # TA sites in an ORF\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
325 print OUT "$maxtaORF\tGreatest # TA sites in an ORF\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
326 print OUT "$blank\tNumber of ORFs that don't have any TA sites\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
327
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
328
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
329 print OUT "\nGenes using the genbank annotation file\n\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
330 ###Get genbank file. Find all start and stop for genes
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
331 #See how many insertions fall into genes vs intergenic regions
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
332 #Get array of coordinates for all insertions then remove insertion if it is
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
333 #within a gene region
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
334 my $gb = Bio::SeqIO->new(-file => $ref, -format => 'genbank');
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
335 my $refseq = $gb->next_seq;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
336
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
337 #store number of insertions in a gene here
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
338 my @geneIns;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
339 my @allLengths;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
340 my $blankGene=0; #Number of genes that don't have any insertions in them
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
341 my @genomeSeq=split('',$fasta);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
342
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
343
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
344 #keep a copy to remove insertions that are in genes
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
345 my @insertPosCopy=@insertPos;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
346
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
347 my @features = $refseq->get_SeqFeatures(); # just top level
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
348 foreach my $feature ( @features ) {
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
349 if ($feature->primary_tag eq "gene"){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
350 my $start=$feature->start;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
351 my $end=$feature->end;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
352 my $length=$end-$start;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
353 push (@allLengths,$length);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
354 #turn this into a for loop
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
355 my $i=0;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
356 my $ins=0;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
357 my $current=$insertPos[$i];;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
358 while ($current<=$end && $i<scalar @insertPos){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
359 if ($current>=$start){
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
360 splice(@insertPosCopy, $i, 1);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
361 $ins++;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
362 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
363 $current=$insertPos[$i++];
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
364 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
365 if ($ins==0){$blankGene++}
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
366 push (@geneIns,$ins);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
367 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
368 }
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
369 my $avgLength=sprintf("%.2f",mean(@allLengths));
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
370
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
371 my ($minLength, $maxLength) = minmax @allLengths;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
372 my $avgInsGene=sprintf("%.2f",mean(@geneIns));
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
373
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
374
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
375
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
376
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
377
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
378 my ($minInsGene, $maxInsGene) = minmax @geneIns;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
379 my $nonGeneIns=scalar @insertPosCopy;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
380 my $totalIns=scalar @insertPos;
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
381 my $percNon=sprintf("%.2f",($nonGeneIns/$totalIns)*100);
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
382
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
383 print OUT "Length of a gene\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
384 print OUT "$avgLength\tAverage","\n$minLength\tMininum","\n$maxLength\tMaximum\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
385 print OUT "\nFor insertions in a gene:\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
386 print OUT "$avgInsGene\tAverage","\n$minInsGene\tMininum","\n$maxInsGene\tMaximum\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
387 print OUT "Number of genes that do not have any insertions: ",$blankGene,"\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
388 print OUT "\n$nonGeneIns\tInsertions that are not in genes","\n$percNon% of all insertions\n";
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
389 #How many insertions are in genes and how many are in non-gene regions?
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
390
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
391
b66f4a551e25 Uploaded
antmarge
parents:
diff changeset
392