annotate crossBedWithGenes_hist.pl @ 6:c36291280fa2 draft default tip

Uploaded
author jbrayet
date Mon, 04 Jan 2016 10:40:38 -0500
parents 96d7a14f8313
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
1 #!/usr/bin/perl -w
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
2
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
3 #for a complete list of genes and a list of sites, sorts genes close to sites
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
4 #printDistance
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
5
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
6 #read only gene files with refSeqGenes
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
7 #counts only once overlapping transcripts or genes
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
8
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
9 #calculates some stats about locations of peaks
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
10
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
11 use strict;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
12
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
13 my $SitesFilename ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
14 my $SitesFilename2 ="";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
15 my $GenesFilename ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
16 my $MirFilename = "";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
17 my $BIGNUMBER = 10000000;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
18 my $verbose = 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
19 my $header = 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
20 my $noXY = 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
21 my $minscore = 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
22
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
23 my $usage = qq{
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
24 $0
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
25
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
26 -----------------------------
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
27 mandatory parameters:
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
28
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
29 -g filename file with all genes
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
30 -f filename file with sites in BED format
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
31
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
32 -----------------------------
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
33 optional parameters:
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
34 -v for verbose
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
35 -minScore minimal score
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
36 -mir filename file with positions of miRNA
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
37 -head if there is a header
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
38 -reg filename file with FoldChanges or expression values and annotation (should in colomn 4)
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
39 -noXY
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
40 -o filename output file
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
41 };
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
42
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
43 if(scalar(@ARGV) == 0){
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
44 print $usage;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
45 exit(0);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
46 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
47
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
48 my $ResFilename = "";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
49
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
50 my $regFilename = "";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
51
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
52 while(scalar(@ARGV) > 0){
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
53 my $this_arg = shift @ARGV;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
54 if ( $this_arg eq '-h') {print "$usage\n"; exit; }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
55
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
56 elsif ( $this_arg eq '-g') {$GenesFilename = shift @ARGV;}
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
57 elsif ( $this_arg eq '-f') {$SitesFilename = shift @ARGV;}
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
58 elsif ( $this_arg eq '-mir') {$MirFilename = shift @ARGV;}
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
59 elsif ( $this_arg eq '-v') {$verbose = 1;}
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
60 elsif ( $this_arg eq '-head') {$header = 1;}
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
61 elsif ( $this_arg eq '-noXY') {$noXY = 1;}
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
62 elsif ( $this_arg eq '-o') {$ResFilename = shift @ARGV;}
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
63 elsif ( $this_arg eq '-reg') {$regFilename = shift @ARGV;}
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
64 elsif ( $this_arg eq '-minScore') {$minscore = shift @ARGV;}
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
65 elsif ( $this_arg =~ m/^-/ ) { print "unknown flag: $this_arg\n";}
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
66 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
67
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
68 if ($ResFilename eq "") {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
69 $ResFilename = $SitesFilename.".withGenes.txt";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
70 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
71
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
72
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
73
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
74 #------------read expression/foldChange annotation of genes---------
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
75
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
76 my %geneReg;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
77 if ( $regFilename eq ""){
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
78 print "you did not specify file with expression of fold change values\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
79 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
80 else {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
81 open (REG, "<$regFilename ") or die "Cannot open file $regFilename !!!!: $!";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
82 #Gene median mad flag
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
83 #RPL41 13.60755187 0.074233841 EXPRESSED
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
84 #A 1110013L07Rik 0.26 up-regulated
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
85
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
86 while (<REG>) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
87 chomp;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
88 my ($name, $value) = (split)[1,3];
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
89 $geneReg{$name} = $value;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
90 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
91 close REG;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
92 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
93 #-----------read genes----------------
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
94
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
95 my %genes;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
96
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
97 my $count = 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
98
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
99 open (GENES, "<$GenesFilename") or die "Cannot open file $GenesFilename!!!!: $!";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
100 <GENES>;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
101
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
102 my ($name,$chr,$strand,$leftPos,$rightPos);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
103
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
104 while (<GENES>) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
105 chomp;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
106 if (/(chr\S*)\s(\d+)\s(\d+)\s([-]?1)\s\S+\s\S+\s(\S+)/){
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
107 $name = $5;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
108 $chr = $1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
109
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
110 $strand = $4;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
111 if ($strand eq '1') {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
112 $strand = 1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
113 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
114 else {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
115 $strand = -1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
116 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
117 $leftPos = $2;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
118 $rightPos = $3;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
119 next if (($chr =~ m/[XY]/)&&($noXY));
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
120 next if ($name =~ m/MIR/);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
121 } elsif (/(chr\S*)\s([+-])\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S+)\s(\S+)\s\S+\s(\S+)/) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
122 $name = $10;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
123 $chr = $1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
124 $strand = $2;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
125 $leftPos = $3;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
126 $rightPos = $4;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
127 next if (($chr =~ m/[XY]/)&&($noXY));
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
128 next if ($name =~ m/MIR/);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
129
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
130 if ($strand eq '+') {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
131 $strand = 1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
132 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
133 else {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
134 $strand = -1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
135 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
136 } else {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
137 print "Wrong type: ",$_,"\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
138 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
139 my $ID = "$name\t$chr:$leftPos-$rightPos";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
140 my $reg = "NA";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
141 if (exists($geneReg{$name})) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
142 $reg = $geneReg{$name};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
143 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
144 unless (exists($genes{$chr})) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
145 my %h;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
146 $genes{$chr} = \%h;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
147 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
148 unless (exists($genes{$chr}->{$ID})) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
149 my %h1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
150 $genes{$chr}->{$ID} = \%h1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
151 $count++;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
152 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
153 $genes{$chr}->{$ID}{'name'} = $name ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
154 $genes{$chr}->{$ID}{'left'} = $leftPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
155 $genes{$chr}->{$ID}{'right'} = $rightPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
156
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
157 $genes{$chr}->{$ID}{'strand'} = $strand;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
158
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
159 $genes{$chr}->{$ID}{'TSS'} = ($strand == 1) ? $leftPos :$rightPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
160 $genes{$chr}->{$ID}{'TE'} = ($strand == -1) ? $leftPos :$rightPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
161 $genes{$chr}->{$ID}{'reg'} = $reg;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
162 $genes{$chr}->{$ID}{'length'} = abs ($leftPos-$rightPos);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
163 $genes{$chr}->{$ID}{'closestPicDist'} = $BIGNUMBER;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
164 $genes{$chr}->{$ID}{'closestPositivePicDist'} = $BIGNUMBER;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
165 $genes{$chr}->{$ID}{'closestNegativePicDist'} = -$BIGNUMBER;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
166
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
167 $genes{$chr}->{$ID}{'closestPicDistTE'} = $BIGNUMBER;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
168
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
169 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
170 print "Total genes : $count\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
171
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
172
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
173
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
174 close GENES;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
175 print "\t\t$GenesFilename is read!\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
176 #for my $gName (sort keys %{$genes{'chr18'}}) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
177
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
178 # print "$gName\t$genes{'chr18'}->{$gName}{'TSS'}\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
179 #}
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
180
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
181 #-----------read file with sites miRNA, store as genes-----
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
182
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
183 if ( $MirFilename eq ""){
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
184 print "you did not specify file with miRNA\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
185 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
186 else {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
187
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
188
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
189 open (MIR, "<$MirFilename ") or die "Cannot open file $MirFilename !!!!: $!";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
190 #chr1 20669090 20669163 mmu-mir-206 960 +
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
191 while (<MIR>) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
192 chomp;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
193 my ($name, $chr, $leftPos, $rightPos, $strand );
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
194 #1 . miRNA 20669091 20669163 . + . ACC="MI0000249"; ID="mmu-mir-206";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
195 if (/([0-9XYM]+)\s.\smiRNA\s(\d+)\s(\d+)\s.\s([+-])\s.\sACC=.*ID=\"(.*)\"/) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
196 $name = $5;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
197 $chr = $1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
198 $leftPos = $2;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
199 $rightPos = $3;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
200 $strand = $4;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
201 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
202 elsif (/(.*)\s(\d+)\s(\d+)\s(.*)\s(.*)\s(.*)/){
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
203 $name = $4;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
204 $chr = $1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
205 $leftPos = $2;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
206 $rightPos = $3;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
207 $strand = $6;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
208 } else {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
209 next;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
210 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
211
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
212 unless ($chr =~ m/chr/) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
213 $chr = "chr".$chr;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
214 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
215 my $ID = "$name\t$chr:$leftPos-$rightPos";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
216
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
217 if ($strand eq '+') {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
218 $strand = 1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
219 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
220 else {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
221 $strand = -1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
222 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
223
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
224 unless (exists($genes{$chr})) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
225 my %h;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
226 $genes{$chr} = \%h;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
227 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
228 unless (exists($genes{$chr}->{$ID})) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
229 my %h1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
230 $genes{$chr}->{$ID} = \%h1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
231 $count++;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
232 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
233 $genes{$chr}->{$ID}{'name'} = $name ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
234 $genes{$chr}->{$ID}{'left'} = $leftPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
235 $genes{$chr}->{$ID}{'right'} = $rightPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
236 $genes{$chr}->{$ID}{'cdsStart'} = $leftPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
237 $genes{$chr}->{$ID}{'cdsEnd'} = $rightPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
238 $genes{$chr}->{$ID}{'strand'} = $strand;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
239 $genes{$chr}->{$ID}{'length'} = abs ($leftPos-$rightPos);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
240 $genes{$chr}->{$ID}{'exonCount'} = 1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
241 $genes{$chr}->{$ID}{'exonStarts'} = $leftPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
242 $genes{$chr}->{$ID}{'exonEnds'} = $rightPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
243 $genes{$chr}->{$ID}{'TSS'} = ($strand == 1) ? $leftPos :$rightPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
244 $genes{$chr}->{$ID}{'TE'} = ($strand == -1) ? $leftPos :$rightPos ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
245 $genes{$chr}->{$ID}{'reg'} = "miRNA";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
246 ($genes{$chr}->{$ID}{'firstIntronStart'},$genes{$chr}->{$ID}{'firstIntronEnd'}) = (0,0);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
247 $genes{$chr}->{$ID}{'closestPicDist'} = $BIGNUMBER;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
248 $genes{$chr}->{$ID}{'closestPicDistTE'} = $BIGNUMBER;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
249 $genes{$chr}->{$ID}{'closestPositivePicDist'} = $BIGNUMBER;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
250 $genes{$chr}->{$ID}{'closestNegativePicDist'} = -$BIGNUMBER;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
251
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
252
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
253 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
254
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
255
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
256 close MIR;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
257 print "\t\t$MirFilename is read!\n" if ($verbose) ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
258 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
259
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
260
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
261
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
262 #-----------read file with sites and find overlapping genes-----
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
263 my $numberOfAllSites = 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
264
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
265 my $lengthLosses = 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
266 my $lengthGains = 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
267
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
268 open (FILE, "<$SitesFilename") or die "Cannot open file $SitesFilename!!!!: $!";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
269 open (OUT , ">$ResFilename") or die "Cannot open file $ResFilename!!!!: $!";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
270 print OUT "chrom start end max_coord score Dist DistTE geneName geneCoord Reg\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
271 open (GENESOUT , ">$ResFilename.genes") or die "Cannot open file $ResFilename.genes!!!!: $!";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
272
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
273 print GENESOUT "Name\tGeneCoord\tDistS\tDistE\tDistTE\tReg\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
274
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
275 my $correction = 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
276
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
277 if ($header) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
278 my $headerString = <FILE>; #read header
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
279 my @a = split (/\t/,$header );
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
280
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
281 if ($a[1] =~m/chr/) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
282 $correction=1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
283 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
284 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
285
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
286 $count = 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
287 print $SitesFilename, "\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
288 while (<FILE>) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
289 chomp;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
290 next if (/track/);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
291 my $string = $_;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
292 chomp $string;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
293 $numberOfAllSites++;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
294 my @a = split /\t/;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
295 if (($a[1] =~m/chr/)&&($correction==0)) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
296 $correction=1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
297 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
298 my $chro = $a[0+$correction];
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
299 next if (($chro =~ m/[XY]/)&&($noXY));
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
300 unless ($chro =~ m/chr/) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
301 $chro = "chr".$chro;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
302 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
303
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
304 my $fpos = $a[1+$correction];
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
305 my $lpos = $a[2+$correction];
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
306 my $score = $a[4+$correction];
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
307 if ($minscore>0) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
308 next if ($score<$minscore);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
309 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
310 next if ($chro=~m/M/);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
311
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
312 print OUT $string, "\t";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
313
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
314 findClosestTSS ($fpos,$lpos,$chro,\%genes);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
315
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
316 $count ++;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
317 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
318 close FILE;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
319 close OUT ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
320 close GENESOUT;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
321 print "Total Sites: $count\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
322
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
323 open (GENESOUT , ">$ResFilename.genes.ClosestPeakDist") or die "Cannot open file $ResFilename.genes.ClosestPeakDist!!!!: $!";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
324 print GENESOUT "Name Coord Dist DistTE Reg posDist negDist\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
325 for my $chro (keys %genes) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
326 for my $gName (keys %{$genes{$chro}}) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
327 print GENESOUT "$gName\t",$genes{$chro}->{$gName}{'closestPicDist'},"\t",$genes{$chro}->{$gName}{'closestPicDistTE'},"\t",$genes{$chro}->{$gName}{'reg'},"\t",$genes{$chro}->{$gName}{'closestPositivePicDist'},"\t",$genes{$chro}->{$gName}{'closestNegativePicDist'},"\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
328 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
329 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
330 close GENESOUT;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
331
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
332 #my @arr = @{$genes{'chr'}};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
333
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
334 sub overlapGenes {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
335 my ($otherGene,$bestGene,$chro,$genes)= @_;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
336 my $a1 = $genes->{$chro}{$otherGene}{'left'};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
337 my $a2 = $genes->{$chro}{$bestGene}{'left'};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
338 my $e1 = $genes->{$chro}{$otherGene}{'right'};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
339 my $e2 = $genes->{$chro}{$bestGene}{'right'};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
340 if (($a1 >= $a2)&&($a1 <= $e2)) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
341 return 1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
342 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
343 if (($a2 >= $a1)&&($a2 <= $e1)) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
344 return 1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
345 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
346 return 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
347 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
348
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
349 sub overlap {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
350 my ($a1,$a2,$e1,$e2)= @_; #e for genes
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
351
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
352 if ($a1 > $a2) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
353 ($a1,$a2) = ($a2,$a1);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
354 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
355
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
356 if ($e1 > $e2) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
357 ($e1,$e2) = ($e2,$e1);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
358 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
359
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
360
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
361 if (($a1 >= $e1)&&($a1 <= $e2)) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
362 return 2;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
363 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
364 if (($a2 >= $e1)&&($a2 <= $e2)) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
365 return 2;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
366 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
367 if (($e1 >= $a1)&&($e2 <= $a2)) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
368 return 1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
369 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
370
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
371 return 0;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
372 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
373
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
374
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
375 sub findClosestTSS {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
376 my ($fpos,$lpos,$chro,$genes) = @_;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
377 my $pos = ($fpos+$lpos)/2;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
378 my $gene = "";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
379 my $tssDist=$BIGNUMBER;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
380 my $teDist=$BIGNUMBER;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
381
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
382 for my $gName (keys %{$genes->{$chro}}) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
383 my $TSS = $genes->{$chro}{$gName}{'TSS'};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
384 #print $gName,":",$TSS," " if ($chro eq "chr15");
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
385 my $geneDist = ($pos-$TSS)*$genes->{$chro}{$gName}{'strand'};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
386 $geneDist = ($fpos-$TSS)*$genes->{$chro}{$gName}{'strand'} if (abs($fpos-$TSS)<abs($geneDist)) ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
387 $geneDist = ($lpos-$TSS)*$genes->{$chro}{$gName}{'strand'} if (abs($lpos-$TSS)<abs($geneDist)) ;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
388 $geneDist = 0 if ($TSS>=$fpos && $TSS<=$lpos);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
389
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
390 if (abs($geneDist)<abs($tssDist)) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
391 $gene=$gName;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
392 $tssDist = $geneDist;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
393 $teDist = ($pos-$genes->{$chro}{$gName}{'TE'})*$genes->{$chro}{$gName}{'strand'};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
394 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
395 if (abs($geneDist)<$BIGNUMBER) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
396 ###HERE!!!
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
397 print GENESOUT "$gName\t",($fpos-$TSS)*$genes->{$chro}{$gName}{'strand'},"\t",($lpos-$TSS)*$genes->{$chro}{$gName}{'strand'},"\t",($pos-$genes->{$chro}{$gName}{'TE'})*$genes->{$chro}{$gName}{'strand'},"\t",$genes->{$chro}{$gName}{'reg'},"\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
398
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
399 if (abs($geneDist)<abs($genes->{$chro}{$gName}{'closestPicDist'})) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
400 $genes->{$chro}{$gName}{'closestPicDist'} = $geneDist;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
401 $genes->{$chro}{$gName}{'closestPicDistTE'} = ($pos-$genes->{$chro}{$gName}{'TE'})*$genes->{$chro}{$gName}{'strand'};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
402 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
403 if ($geneDist>=0 && abs($geneDist)<$genes{$chro}->{$gName}{'closestPositivePicDist'} ) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
404 $genes->{$chro}{$gName}{'closestPositivePicDist'} = $geneDist;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
405 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
406 if (($geneDist)*$genes->{$chro}{$gName}{'strand'}<=0 && -1*abs($pos-$TSS)>$genes{$chro}->{$gName}{'closestNegativePicDist'} ) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
407 $genes->{$chro}{$gName}{'closestNegativePicDist'} = ($pos-$TSS)*$genes->{$chro}{$gName}{'strand'};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
408 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
409
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
410 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
411 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
412 print OUT "$tssDist\t$teDist\t$gene\t$genes{$chro}->{$gene}{'reg'}\n" if ($gene ne "");
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
413 if ($gene eq "") {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
414 print OUT "$tssDist $teDist NA NA NA\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
415 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
416
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
417 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
418
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
419 sub printOvelapingGenes {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
420 my ($fpos,$lpos,$chro,$genes,$globalH,$type) = @_;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
421 #print $fpos,$lpos,$chro,$genes,$globalH,$type,"\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
422 my %hash1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
423 my %hash2;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
424 my @array2return;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
425 for my $gName (keys %{$genes->{$chro}}) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
426 my $TSS = $genes->{$chro}{$gName}{'TSS'};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
427 my $TE = $genes->{$chro}{$gName}{'TE'};
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
428
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
429 if (overlap($fpos,$lpos,$TSS,$TE)==1) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
430 $hash1{$gName} = overlap($fpos,$lpos,$TSS,$TE);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
431 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
432 if (overlap($fpos,$lpos,$TSS,$TE)==2) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
433 $hash2{$gName} = overlap($fpos,$lpos,$TSS,$TE);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
434 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
435 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
436 print OUT join(",", sort keys %hash1),"\t",join(",", sort keys %hash2),"\n";
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
437 if ($type eq "loss") {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
438 for my $key (sort keys %hash1) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
439 $globalH->{$key} = 1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
440 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
441 for my $key (sort keys %hash2) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
442 $globalH->{$key} = 1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
443 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
444 }else {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
445 for my $key (sort keys %hash1) {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
446 $globalH->{$key} = 1;
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
447 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
448 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
449
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
450 }
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
451
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
452 sub min {
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
453 return $_[0] if ($_[0]<$_[1]);
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
454 $_[1];
96d7a14f8313 Uploaded
jbrayet
parents:
diff changeset
455 }