-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegions.pl
More file actions
64 lines (52 loc) · 1.9 KB
/
Regions.pl
File metadata and controls
64 lines (52 loc) · 1.9 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
#!/usr/bin/perl
use warnings;
use strict;
my $DEBUG = 0;
@ARGV == 1 or die "usage: $0 < fimo.txt >\n";
my ( $fimo) = @ARGV;
my @fimoResults = readFileToArray( $fimo );
# fimo.txt format
# pattern name sequence name start stop strand score p-value q-value matched sequence
# MA0494.1 chrX:152991526-152993399_hg19_2720.49_. 1008 1026 + 22.0968 7.17e-10 0.00188 TGACCTGGAGTAACCTTTC
# MA0494.1 chr10:24496237-24498236_hg19_3100_. 1434 1452 + 21.6774 1.89e-09 0.00248 TGACCTCGAGTGACCTGTG
my $count = 1;
print "#chrom", "\t", "start", "\t", "end", "\t", "name", "\t", "score", "\t", "strand", "\n";
foreach my $result ( @fimoResults ) {
my @record = split( /\t+/, $result );
my @sequence_name = split(/[\-:_]+/, $record[2]);
my $chrom = $sequence_name[0];
my $begin = $sequence_name[1];
my $end = $sequence_name[2];
my $name = $record[ 1 ];
my $startPosition = $record[ 3 ] - 1;
my $stopPosition = $record[ 4 ];
my $strand = $record[ 5 ];
my $score = $record[ 6 ];
my $len = $stopPosition - $startPosition;
if ( $strand eq "+" ) {
my $first = $end - $stopPosition - 49 + $len;
my $last = $first + 99;
print $chrom,"\t",$first,"\t",$last,"\t",$name,"\t",$score,"\t",$strand, "\n";
}
else {
my $first = $end - $stopPosition -50 +1;
my $last = $first + 99;
print $chrom,"\t",$first,"\t",$last,"\t",$name,"\t",$score,"\t",$strand, "\n";
}
}
#######################################################################
#
# readFileToArray
#
sub readFileToArray {
my ($file) = @_;
my @fileData = ();
open( INFILE, $file ) or die ("Unable to open $file!\n");
while (<INFILE>) {
chomp();
next if /^#/;
push ( @fileData, $_ );
}
close(INFILE);
return( @fileData );
}