-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindMotifs.pl
More file actions
executable file
·155 lines (114 loc) · 3.4 KB
/
Copy pathfindMotifs.pl
File metadata and controls
executable file
·155 lines (114 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/perl -w
if(scalar(@ARGV) != 6 || ($ARGV[4] ne 'eric' && $ARGV[4] ne 'mo')) {
print "Usage: ~ <hash_dir> <region.fa> <bin_size> <pattern> <eric|mo> <out_dir>\n";
die "e.g. ~ human human_promters.fa 20 ^AA eric\n";
}
my($hashDir) = $ARGV[0];
my($region) = $ARGV[1];
my($binSize) = $ARGV[2];
my($ptn) = $ARGV[3];
my($prg) = $ARGV[4];
my($OUT_DIR) = $ARGV[5];
use Peak;
my($T_THRESHOLD) = 3;
my($T_DIFF_THRESHOLD) = 3;
my($COUNT_THRESHOLD) = 20;
my(@all_motifs) = getAllMotifs(8);
my(@motifs);
foreach $m (@all_motifs) {
if($m =~ /$ptn/) {
push @motifs, $m;
}
}
findMotifs($hashDir, $region, $binSize, \@motifs);
# get all possible motifs of certain length (> 1)
sub getAllMotifs {
my($size) = @_;
if($size < 2) {
die "Why do you want me to do so simple stuff?\n";
}
my(@result) = ('A', 'T', 'G', 'C');
for(my($i) = 2; $i <= $size; $i++) {
my(@seeds) = @result;
@result = ();
foreach $seed (@seeds) {
push @result, $seed.'A', $seed.'T', $seed.'G', $seed.'C';
}
}
return @result;
}
use Util;
sub findMotifs {
my($hashDir, $region, $binSize, $mtfs) = @_;
my(@motifs) = @{$mtfs};
open MOTIFS, ">>$OUT_DIR/sum$ptn.motifs" || die $!;
open GROVES, ">>$OUT_DIR/dip$ptn.motifs" || die $!;
foreach $m (@motifs) {
print "processing motif $m\n";
# get the positive & negative freq distribution
my($tmp_file, $tmp_out, $hash, $promoters);
$tmp_file = "$OUT_DIR/$m.txt";
$tmp_out = "$OUT_DIR/$m.$binSize";
if($prg eq 'eric') {
`perl FindTssOffsets.pl $m $hashDir $region $binSize > $tmp_file`;
}
else {
# count motifs
Util::run("countPosMotif.pl $hashDir $m > $tmp_out");
Util::run("binIt.pl $tmp_out 0 $binSize 0 > $tmp_file");
}
# my($tmp_sum) = "$OUT_DIR/$organism/$m.sum.txt";
open COUNT, "<$tmp_file" || die $!;
# open SUM, "+>$tmp_sum" || die $!;
while($line = <COUNT>) {
chomp($line);
if(!($line =~ /\#/)) {
last;
}
}
my(@coords, @neg_counts, @sum_counts);
my($i) = 0;
while($line) {
# trim the leading & heading white spaces
$line =~ s/^\s+//;
$line =~ s/\s+$//;
my(@data) = split(/\s+/, $line);
$coords[$i] = $data[0];
$sum_counts[$i] = $data[1];
$neg_counts[$i] = 1000 -$sum_counts[$i]; # negate it to see groves
# print SUM "$data[0]\t$data[1]\n";
$line = <COUNT>;
$i++;
}
close COUNT;
# close SUM;
# find peaks
# my($out_coords, $out_counts) = getPeakData($tmp_pos);
my(@sumPeaks) = getPeakScores(\@coords, \@sum_counts, $T_THRESHOLD, $COUNT_THRESHOLD);
my(@groves) = getPeakScores(\@coords, \@neg_counts, $T_THRESHOLD, $COUNT_THRESHOLD);
# my($sumMaxScore) = scalar(@sumPeaks) > 0?$sumPeaks[0]->[1]:0;
# print "sumMaxScore = $sumMaxScore\n";
my($foundPeak) = 0;
for(my($i) = 0; $i < scalar(@sumPeaks); $i++) {
print MOTIFS "$m\t$coords[$sumPeaks[$i]->[0]->[0]]\t$coords[$sumPeaks[$i]->[0]->[1]]\t$coords[$sumPeaks[$i]->[0]->[2]]\t$sumPeaks[$i]->[1]\n";
$foundPeak = 1;
}
if($foundPeak) {
print MOTIFS "\n";
}
my($foundValley) = 0;
for(my($i) = 0; $i < scalar(@groves); $i++) {
print GROVES "$m\t$coords[$groves[$i]->[0]->[0]]\t$coords[$groves[$i]->[0]->[1]]\t$coords[$groves[$i]->[0]->[2]]\t$groves[$i]->[1]\n";
$foundValley = 1;
}
if($foundValley) {
print GROVES "\n";
}
if(!$foundPeak && !$foundValley) {
# `rm $tmp_file`;
}
`rm $tmp_out`;
}
close MOTIFS;
close GROVES;
}