Mercurial > repos > amadeo > amadeo
comparison Tools/Motif_search/rules_galaxy.pl @ 0:229d36377838 draft
Uploaded
author | amadeo |
---|---|
date | Mon, 05 Sep 2016 05:53:08 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:229d36377838 |
---|---|
1 #!/usr/bin/perl -w | |
2 | |
3 $|=1; | |
4 use warnings; | |
5 use strict; | |
6 #Script that looks for genes that have motifs from a certain rule. | |
7 | |
8 #Declaration of variables | |
9 my $line; | |
10 my $line2; | |
11 my @cols; | |
12 my @cols2; | |
13 my %hash; | |
14 my %hash1; | |
15 my %hash3; | |
16 | |
17 my $gene; | |
18 my $TF; | |
19 my $num_motifs; | |
20 my @genes_rules; | |
21 | |
22 | |
23 $num_motifs=$ARGV[2]; | |
24 | |
25 | |
26 open(FIMO, "<$ARGV[0]") || | |
27 die "File '$ARGV[0]' not found\n"; | |
28 | |
29 open(OUTPUT, ">$ARGV[1]") || | |
30 die "File '>$ARGV[1]' not found\n"; | |
31 | |
32 | |
33 while (<FIMO>) { | |
34 $line=$_; | |
35 chomp $line; | |
36 @cols=split; | |
37 if (not $line=~/^ /){ | |
38 $TF= substr $cols[8],5,8; | |
39 $gene=substr $cols[0],0,21; | |
40 | |
41 if (not exists $hash{$gene}) { | |
42 $hash1{$gene}=0; | |
43 | |
44 } | |
45 if (not exists $hash{$gene}{$TF}) { | |
46 $hash1{$gene}++; | |
47 $hash{$gene}{$TF}=1; | |
48 #print $hash1{$gene}; | |
49 } | |
50 | |
51 | |
52 if ($hash1{$gene}==$num_motifs and not exists $hash3{$gene}) { | |
53 $hash3{$gene}=1; | |
54 #print $line, "\n"; | |
55 | |
56 } | |
57 | |
58 | |
59 | |
60 } | |
61 | |
62 } | |
63 | |
64 close FIMO; | |
65 open(FIMO, "<$ARGV[0]") || | |
66 die "File '$ARGV[0]' not found\n"; | |
67 | |
68 while (<FIMO>) { | |
69 $line2=$_; | |
70 chomp $line2; | |
71 @cols2=split; | |
72 | |
73 if (not $line2=~/^ /){ | |
74 $TF= substr $cols2[8],5,8; | |
75 $gene=substr $cols2[0],0,21; | |
76 foreach my $gene_listed (keys %hash3){ | |
77 | |
78 if ($gene_listed eq $gene) { | |
79 printf OUTPUT "%s\n", $line2; | |
80 | |
81 } | |
82 | |
83 | |
84 } | |
85 | |
86 } | |
87 } | |
88 | |
89 | |
90 print "Genes that have this rule:", "\n"; | |
91 foreach my $gene_listed (keys %hash3){ | |
92 print $gene_listed,"\n"; | |
93 } | |
94 | |
95 |