annotate nuclescore.sample @ 0:82dce1eb9074 draft default tip

Uploaded
author dcouvin
date Fri, 03 Sep 2021 22:36:56 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
1 <tool id="nuclescoretool" name="nuclescore" version="0.1.0">
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
2 <description>nuclescore</description>
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
3
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
4
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
5 <command detect_errors="aggressive"><![CDATA[
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
6
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
7 #import re
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
8 ## Creates symlinks for each input file based on the Galaxy 'element_identifier'
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
9 ## Used so that a human-readable name appears in the output table (instead of 'dataset_xyz.dat')
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
10 #set $named_input_files = ''
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
11 #for $input_file in $input_files
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
12 ## Add single quotes around each input file identifier
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
13 #set $_input_file = "'{}'".format($input_file.element_identifier)
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
14 ln -s '${input_file}' ${_input_file} &&
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
15 #set $named_input_files = $named_input_files + ' ' + $_input_file
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
16 #end for
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
17
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
18 perl '$__tool_directory__/nucleScore.pl' $_input_file $output
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
19
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
20
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
21
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
22
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
23 ]]></command>
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
24 <!-- ./nuclescore.sh ${named_input_files} > "$output" -->
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
25
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
26 <inputs>
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
27 <param format="fasta" name="input_files" type="data" label="Genome fasta file : " multiple="true" display="checkboxes"/>
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
28 </inputs>
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
29
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
30 <outputs>
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
31 <data format="tabular" name="output" />
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
32 </outputs>
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
33
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
34 <help>
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
35 No documentation
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
36 </help>
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
37
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
38 </tool>
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
39
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
40
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
41 -------------------------------------------------------------------------------------------------------------------------------------------------------------------
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
42
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
43 #!/usr/bin/perl
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
44
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
45 use strict;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
46 use warnings;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
47 use Bio::SeqIO;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
48 use Shannon::Entropy qw/entropy/;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
49 use File::Basename;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
50 #use Bio::Species;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
51
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
52 #use FindBin;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
53 #use lib "$FindBin::RealBin/../perl5";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
54
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
55 my $input = $ARGV[0];
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
56 #chercher comment faire une liste perl pour input
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
57 my @liste = split(/,/, $input);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
58 my $recap_total_seq = $ARGV[1];
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
59
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
60 #my ($input, $recap_total_seq) = @ARGV;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
61
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
62 my $start = time();
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
63
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
64 #my $file = ""; #= $ARGV[0];
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
65 #my $recap_total_seq = "nucleScore_result.xls";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
66
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
67 open (RECAP,'>', $recap_total_seq) or die "could not open $!";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
68 print RECAP "File\tA percent\tT percent\tC percent\tG percent\tGC percent\tAT/GC ratio\tNucleScore\tShannon Entropy\tAAA\tAAT\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
69 close(RECAP);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
70
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
71
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
72 #FASTA files
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
73 #if(@ARGV){
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
74
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
75 #for (my $i = 0; $i <= $#ARGV; $i++) {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
76 #if ($ARGV[$i]=~/-output/i or $ARGV[$i]=~/-o/i) {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
77 # $recap_total_seq = $ARGV[$i+1];
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
78 #}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
79 #}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
80
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
81
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
82 open (RECAP,'>>', $recap_total_seq) or die "could not open $!";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
83
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
84 #refaire le for pour la liste input
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
85 #for my $arg (@ARGV){
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
86 for my $arg (@liste){
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
87 # if ($arg =~ m/.fasta/ or $arg =~ m/.fna/ or $arg =~ m/.fa/){
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
88
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
89 #print "Traitement du fichier de sequence: $arg\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
90 print "Traitement du fichier de sequence: $arg\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
91 #my $file = $arg;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
92 my $file = $arg;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
93
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
94
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
95 my $seqIO = Bio::SeqIO->new(-format=>'Fasta', -file=>$file);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
96 my $globalSeq = "";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
97 while (my $seq = $seqIO->next_seq()) {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
98 my $seqID = $seq->id;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
99 my $seqNuc = $seq->seq;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
100 $globalSeq .= $seqNuc;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
101 #push @arrayID, $seqID;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
102 #$hSeq{$seqID} = $seqNuc;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
103 #my @seqArray = split //, $seqNuc;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
104 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
105
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
106 my $gcpercent = gc_percent($globalSeq);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
107 my ($ade, $thy, $gua, $cyt, $n, $length) = number_nuc_length_seq($file);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
108 my ($aPercent, $tPercent, $gPercent, $cPercent, $nPercent) = nucleotid_percent($ade, $thy, $gua, $cyt, $n, $length);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
109
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
110 my $atgcRatio = atgc_ratio($ade, $thy, $gua, $cyt);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
111
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
112 my @percentList = ($aPercent, $tPercent, $gPercent, $cPercent, $nPercent);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
113
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
114 my $variance = shift_data_variance(@percentList);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
115 my $nucleScore = nucle_score($variance, $gcpercent, $atgcRatio, $length);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
116 my $entropy = entropy($globalSeq);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
117
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
118 print "The sequence length for $file is: $length\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
119 print "A percent: $aPercent\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
120 print "T percent: $tPercent\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
121 print "G percent: $gPercent\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
122 print "C percent: $cPercent\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
123 print "N percent: $nPercent\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
124
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
125 print "GC percent: $gcpercent\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
126
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
127 print "AT/GC ratio: $atgcRatio\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
128
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
129 print "NucleScore: $nucleScore\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
130
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
131 print "Shannon Entropy: $entropy\n\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
132
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
133 print "3 digits:\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
134 my @trinucs=($globalSeq=~/(?=(.{3}))/g);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
135 my %tri_count=();
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
136 $tri_count{$_}++ for @trinucs;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
137 print $_,":",$tri_count{$_},"\n" for sort keys(%tri_count);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
138 print "\n2 digits:\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
139 my @trinucs2=($globalSeq=~/(?=(.{2}))/g);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
140 my %tri_count2=();
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
141 $tri_count2{$_}++ for @trinucs2;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
142 print $_,":",$tri_count2{$_},"\n" for sort keys(%tri_count2);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
143
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
144 my $aaa = $tri_count{'AAA'};
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
145 my $aat = $tri_count{'AAT'};
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
146
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
147 print "--------------------------------------\n\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
148
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
149 my $label = basename($file);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
150
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
151
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
152 #Summary file
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
153 #print RECAP "$file\t$aPercent\t$tPercent\t$cPercent\t$gPercent\t$gcpercent\t$atgcRatio\t$nucleScore\t$entropy\t$aaa\t$aat\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
154 print RECAP "$label\t$aPercent\t$tPercent\t$cPercent\t$gPercent\t$gcpercent\t$atgcRatio\t$nucleScore\t$entropy\t$aaa\t$aat\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
155 #}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
156 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
157 close (RECAP) or die "close file error : $!";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
158 #}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
159
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
160 my $end = time();
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
161
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
162 my $total = $end - $start;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
163
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
164 print "***** Total time (in seconds) is: $total *****\n";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
165
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
166 #------------------------------------------------------------------------------
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
167 # number nucleotid and length
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
168 sub number_nuc_length_seq {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
169 my ($fastaFile) = @_;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
170 my $ade = 0;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
171 my $thy = 0;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
172 my $gua = 0;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
173 my $cyt = 0;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
174 my $n = 0;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
175 my $length = 0;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
176
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
177 open (FASTA, "<", $fastaFile) or die "Could not open $!";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
178 while (<FASTA>) {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
179 chomp;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
180 if ($_ !~ />/) {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
181 my @seq = split //, $_;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
182
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
183 for my $nuc (@seq) {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
184 $length +=1 ;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
185 if ($nuc =~ /a/i) {$ade+=1;}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
186 elsif ($nuc =~ /t/i) {$thy+=1;}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
187 elsif ($nuc =~ /g/i) {$gua+=1;}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
188 elsif ($nuc =~ /c/i) {$cyt+=1;}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
189 elsif ($nuc =~ /n/i) {$n+=1;}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
190 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
191 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
192 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
193 close(FASTA) or die "Error close file :$!";
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
194 return ($ade, $thy, $gua, $cyt, $n, $length);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
195
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
196 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
197
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
198 #------------------------------------------------------------------------------
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
199 # compute percentage of nucleotid
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
200 sub nucleotid_percent {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
201 my($ade, $thy, $gua, $cyt, $n, $length) = @_;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
202
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
203 my $adePercent = $ade / $length * 100;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
204 my $thyPercent = $thy / $length * 100;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
205 my $guaPercent = $gua / $length * 100;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
206 my $cytPercent = $cyt / $length * 100;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
207 my $nPercent = $n / $length * 100;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
208
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
209 return ($adePercent, $thyPercent, $guaPercent, $cytPercent, $nPercent);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
210
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
211 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
212
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
213 #------------------------------------------------------------------------------
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
214 # compute GC pourcent
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
215 sub gc_percent {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
216 my ($seq) = @_;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
217
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
218 my @charSeq = split(//, uc($seq));
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
219 my %hashFlank = ();
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
220
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
221 foreach my $v (@charSeq) {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
222 $hashFlank{$v} += 1;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
223 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
224
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
225 if (! $hashFlank{'G'}) { $hashFlank{'G'} = 0;}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
226 if (! $hashFlank{'C'}) { $hashFlank{'C'} = 0;}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
227
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
228 if(length($seq) == 0) {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
229 return 0;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
230 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
231 else {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
232 return (($hashFlank{'G'} + $hashFlank{'C'}) / (length($seq))) * 100;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
233 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
234
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
235 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
236 #------------------------------------------------------------------------------
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
237 # compute ATGC ratio
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
238 sub atgc_ratio {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
239 my ($ade, $thy, $gua, $cyt) = @_;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
240
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
241 return (($ade + $thy) / ($gua + $cyt));
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
242
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
243 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
244 #------------------------------------------------------------------------------
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
245 # variance
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
246 sub shift_data_variance {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
247 my (@data) = @_;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
248
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
249 if ($#data + 1 < 2) { return 0.0; }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
250
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
251 my $K = $data[0];
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
252 my ($n, $Ex, $Ex2) = 0.0;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
253
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
254 for my $x (@data) {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
255 $n = $n + 1;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
256 $Ex += $x - $K;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
257 $Ex2 += ($x - $K) * ($x - $K);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
258 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
259
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
260 my $variance = ($Ex2 - ($Ex * $Ex) / $n) / ($n); ## ($n - 1)
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
261
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
262 return $variance;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
263
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
264 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
265 #------------------------------------------------------------------------------
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
266 # nucle score
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
267 #sub nucle_score {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
268 # my ($variance, $gcPercent, $atgcRatio, $length) = @_;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
269 #
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
270 # return (($variance * $gcPercent * $atgcRatio) / $length);
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
271 #}
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
272 sub nucle_score {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
273 my ($variance, $gcPercent, $atgcRatio, $length) = @_;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
274 return log2(($variance * $gcPercent * $atgcRatio) / sqrt($length));
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
275 }
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
276
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
277 #------------------------------------------------------------------------------
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
278 sub log2 {
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
279 my $n = shift;
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
280 return (log($n) / log(2));
82dce1eb9074 Uploaded
dcouvin
parents:
diff changeset
281 }