annotate compute_motifs_frequency.pl @ 0:46325357b948 draft

Uploaded tool tarball.
author devteam
date Wed, 25 Sep 2013 10:05:37 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
1 #!/usr/bin/perl -w
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
2
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
3 # a program to compute the frequency of each motif at each window in both upstream and downstream sequences flanking indels
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
4 # in a chromosome/genome.
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
5 # the first input is a TABULAR format file containing the motif names and sequences, such that the file consists of two
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
6 # columns: the left column represents the motif names and the right column represents the motif sequence, one line per motif.
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
7 # the second input is a TABULAR format file containing the upstream and downstream sequences flanking indels, one line per indel.
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
8 # the fourth input is an integer number representing the window size according to which the upstream and downstream sequences
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
9 # flanking each indel will be divided.
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
10 # the first output is a TABULAR format file containing the windows into which both upstream and downstream sequences flanking
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
11 # indels are divided.
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
12 # the second output is a TABULAR format file containing the motifs and their corresponding frequencies at each window in both
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
13 # upstream and downstream sequences flanking indels, one line per motif.
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
14
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
15 use strict;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
16 use warnings;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
17
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
18 #variable to handle the falnking sequences information
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
19 my $sequence = "";
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
20 my $upstreamFlankingSequence = "";
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
21 my $downstreamFlankingSequence = "";
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
22 my $discardedSequenceLength = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
23 my $lengthOfDownstreamFlankingSequenceAfterTrimming = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
24
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
25 #variable to handle the window information
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
26 my $window = "";
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
27 my $windowStartIndex = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
28 my $windowNumber = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
29 my $totalWindowsNumber = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
30 my $totalNumberOfWindowsInUpstreamSequence = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
31 my $totalNumberOfWindowsInDownstreamSequence = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
32 my $totalWindowsNumberInBothFlankingSequences = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
33 my $totalWindowsNumberInMotifCountersTwoDimArray = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
34 my $upstreamAndDownstreamFlankingSequencesWindows = "";
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
35
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
36 #variable to handle the motif information
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
37 my $motif = "";
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
38 my $motifSequence = "";
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
39 my $motifNumber = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
40 my $totalMotifsNumber = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
41
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
42 #arrays to sotre window and motif data
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
43 my @windowsArray = ();
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
44 my @motifNamesArray = ();
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
45 my @motifSequencesArray = ();
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
46 my @motifCountersTwoDimArray = ();
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
47
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
48 #variables to store line counter values
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
49 my $lineCounter1 = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
50 my $lineCounter2 = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
51
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
52 # check to make sure having correct files
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
53 my $usage = "usage: compute_motifs_frequency.pl [TABULAR.in] [TABULAR.in] [windowSize] [TABULAR.out] [TABULAR.out]\n";
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
54 die $usage unless @ARGV == 5;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
55
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
56 #get the input and output arguments
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
57 my $motifsInputFile = $ARGV[0];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
58 my $indelFlankingSequencesInputFile = $ARGV[1];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
59 my $windowSize = $ARGV[2];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
60 my $indelFlankingSequencesWindowsOutputFile = $ARGV[3];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
61 my $motifFrequenciesOutputFile = $ARGV[4];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
62
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
63 #open the input and output files
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
64 open (INPUT1, "<", $motifsInputFile) || die("Could not open file $motifsInputFile \n");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
65 open (INPUT2, "<", $indelFlankingSequencesInputFile) || die("Could not open file $indelFlankingSequencesInputFile \n");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
66 open (OUTPUT1, ">", $indelFlankingSequencesWindowsOutputFile) || die("Could not open file $indelFlankingSequencesWindowsOutputFile \n");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
67 open (OUTPUT2, ">", $motifFrequenciesOutputFile) || die("Could not open file $motifFrequenciesOutputFile \n");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
68
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
69 #store the motifs input file in the array @motifsData
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
70 my @motifsData = <INPUT1>;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
71
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
72 #iterated through the motifs (lines) of the motifs input file
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
73 foreach $motif (@motifsData){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
74 chomp ($motif);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
75 #print ($motif . "\n");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
76
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
77 #split the motif data into its name and its sequence
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
78 my @motifNameAndSequenceArray = split(/\t/, $motif);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
79
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
80 #store the name of the motif into the array @motifNamesArray
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
81 push @motifNamesArray, $motifNameAndSequenceArray[0];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
82
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
83 #store the sequence of the motif into the array @motifSequencesArray
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
84 push @motifSequencesArray, $motifNameAndSequenceArray[1];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
85 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
86
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
87 #compute the size of the motif names array
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
88 $totalMotifsNumber = @motifNamesArray;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
89
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
90 #store the input file in the array @sequencesData
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
91 my @sequencesData = <INPUT2>;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
92
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
93 #iterated through the sequences of the second input file in order to create windwos file
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
94 foreach $sequence (@sequencesData){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
95 chomp ($sequence);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
96 $lineCounter1++;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
97
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
98 my @indelAndSequenceArray = split(/\t/, $sequence);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
99
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
100 #get the upstream falnking sequence
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
101 $upstreamFlankingSequence = $indelAndSequenceArray[3];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
102
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
103 #if the window size is 0, then the whole upstream will be one window only
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
104 if ($windowSize == 0){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
105 $totalNumberOfWindowsInUpstreamSequence = 1;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
106 $windowSize = length ($upstreamFlankingSequence);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
107 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
108 else{
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
109 #compute the total number of windows into which the upstream flanking sequence will be divided
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
110 $totalNumberOfWindowsInUpstreamSequence = length ($upstreamFlankingSequence) / $windowSize;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
111
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
112 #compute the length of the subsequence to be discared from the upstream flanking sequence if any
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
113 $discardedSequenceLength = length ($upstreamFlankingSequence) % $windowSize;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
114
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
115 #check if the sequence could be split into windows of equal sizes
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
116 if ($discardedSequenceLength != 0) {
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
117 #trim the upstream flanking sequence
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
118 $upstreamFlankingSequence = substr($upstreamFlankingSequence, $discardedSequenceLength);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
119 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
120 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
121
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
122 #split the upstream flanking sequence into windows
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
123 for ($windowNumber = 0; $windowNumber < $totalNumberOfWindowsInUpstreamSequence; $windowNumber++){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
124 $windowStartIndex = $windowNumber * $windowSize;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
125 print OUTPUT1 (substr($upstreamFlankingSequence, $windowStartIndex, $windowSize) . "\t");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
126 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
127
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
128 #add a column representing the indel
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
129 print OUTPUT1 ("indel" . "\t");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
130
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
131 #get the downstream falnking sequence
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
132 $downstreamFlankingSequence = $indelAndSequenceArray[4];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
133
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
134 #if the window size is 0, then the whole upstream will be one window only
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
135 if ($windowSize == 0){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
136 $totalNumberOfWindowsInDownstreamSequence = 1;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
137 $windowSize = length ($downstreamFlankingSequence);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
138 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
139 else{
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
140 #compute the total number of windows into which the downstream flanking sequence will be divided
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
141 $totalNumberOfWindowsInDownstreamSequence = length ($downstreamFlankingSequence) / $windowSize;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
142
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
143 #compute the length of the subsequence to be discared from the upstream flanking sequence if any
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
144 $discardedSequenceLength = length ($downstreamFlankingSequence) % $windowSize;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
145
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
146 #check if the sequence could be split into windows of equal sizes
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
147 if ($discardedSequenceLength != 0) {
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
148 #compute the length of the sequence to be discarded
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
149 $lengthOfDownstreamFlankingSequenceAfterTrimming = length ($downstreamFlankingSequence) - $discardedSequenceLength;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
150
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
151 #trim the downstream flanking sequence
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
152 $downstreamFlankingSequence = substr($downstreamFlankingSequence, 0, $lengthOfDownstreamFlankingSequenceAfterTrimming);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
153 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
154 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
155
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
156 #split the downstream flanking sequence into windows
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
157 for ($windowNumber = 0; $windowNumber < $totalNumberOfWindowsInDownstreamSequence; $windowNumber++){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
158 $windowStartIndex = $windowNumber * $windowSize;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
159 print OUTPUT1 (substr($downstreamFlankingSequence, $windowStartIndex, $windowSize) . "\t");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
160 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
161
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
162 print OUTPUT1 ("\n");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
163 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
164
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
165 #compute the total number of windows on both upstream and downstream sequences flanking the indel
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
166 $totalWindowsNumberInBothFlankingSequences = $totalNumberOfWindowsInUpstreamSequence + $totalNumberOfWindowsInDownstreamSequence;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
167
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
168 #add an additional cell to store the name of the motif and another one for the indel itself
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
169 $totalWindowsNumberInMotifCountersTwoDimArray = $totalWindowsNumberInBothFlankingSequences + 1 + 1;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
170
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
171 #initialize the two dimensional array $motifCountersTwoDimArray. the first column will be initialized with motif names
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
172 for ($motifNumber = 0; $motifNumber < $totalMotifsNumber; $motifNumber++){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
173
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
174 for ($windowNumber = 0; $windowNumber < $totalWindowsNumberInMotifCountersTwoDimArray; $windowNumber++){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
175
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
176 if ($windowNumber == 0){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
177 $motifCountersTwoDimArray [$motifNumber] [0] = $motifNamesArray[$motifNumber];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
178 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
179 elsif ($windowNumber == $totalNumberOfWindowsInUpstreamSequence + 1){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
180 $motifCountersTwoDimArray [$motifNumber] [$windowNumber] = "indel";
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
181 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
182 else{
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
183 $motifCountersTwoDimArray [$motifNumber] [$windowNumber] = 0;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
184 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
185 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
186 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
187
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
188 close(OUTPUT1);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
189
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
190 #open the file the contains the windows of the upstream and downstream flanking sequences, which is actually the first output file
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
191 open (INPUT3, "<", $indelFlankingSequencesWindowsOutputFile) || die("Could not open file $indelFlankingSequencesWindowsOutputFile \n");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
192
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
193 #store the first output file containing the windows of both upstream and downstream flanking sequences in the array @windowsData
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
194 my @windowsData = <INPUT3>;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
195
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
196 #iterated through the lines of the first output file. Each line represents
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
197 #the windows of the upstream and downstream flanking sequences of an indel
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
198 foreach $upstreamAndDownstreamFlankingSequencesWindows (@windowsData){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
199
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
200 chomp ($upstreamAndDownstreamFlankingSequencesWindows);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
201 $lineCounter2++;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
202
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
203 #split both upstream and downstream flanking sequences into their windows
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
204 my @windowsArray = split(/\t/, $upstreamAndDownstreamFlankingSequencesWindows);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
205
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
206 $totalWindowsNumber = @windowsArray;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
207
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
208 #iterate through the windows to search for matched motifs and increment their corresponding counters accordingly
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
209 WINDOWS:
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
210 for ($windowNumber = 0; $windowNumber < $totalWindowsNumber; $windowNumber++){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
211
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
212 #get the window
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
213 $window = $windowsArray[$windowNumber];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
214
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
215 #if the window is the one that contains the indel, then skip the indel window
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
216 if ($window eq "indel") {
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
217 next WINDOWS;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
218 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
219 else{ #iterated through the motif sequences to check their occurrences in the winodw
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
220 #and increment their corresponding counters accordingly
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
221
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
222 for ($motifNumber = 0; $motifNumber < $totalMotifsNumber; $motifNumber++){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
223 #get the motif sequence
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
224 $motifSequence = $motifSequencesArray[$motifNumber];
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
225
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
226 #if the motif is found in the window, then increment its corresponding counter
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
227 if ($window =~ m/$motifSequence/i){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
228 $motifCountersTwoDimArray [$motifNumber] [$windowNumber + 1]++;
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
229 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
230 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
231 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
232 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
233 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
234
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
235 #store the motif counters values in the second output file
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
236 for ($motifNumber = 0; $motifNumber < $totalMotifsNumber; $motifNumber++){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
237
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
238 for ($windowNumber = 0; $windowNumber <= $totalWindowsNumber; $windowNumber++){
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
239
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
240 print OUTPUT2 $motifCountersTwoDimArray [$motifNumber] [$windowNumber] . "\t";
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
241 #print ($motifCountersTwoDimArray [$motifNumber] [$windowNumber] . " ");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
242 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
243 print OUTPUT2 "\n";
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
244 #print ("\n");
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
245 }
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
246
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
247 #close the input and output files
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
248 close(OUTPUT2);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
249 close(OUTPUT1);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
250 close(INPUT3);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
251 close(INPUT2);
46325357b948 Uploaded tool tarball.
devteam
parents:
diff changeset
252 close(INPUT1);