annotate tools/regVariation/compute_motifs_frequency.pl @ 1:cdcb0ce84a1b

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