-
Notifications
You must be signed in to change notification settings - Fork 2
/
EChO_1.0.pl
58 lines (55 loc) · 1.47 KB
/
EChO_1.0.pl
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
#!/usr/bin/perl
#This script reads a bed file from EChO_1.0.sh with fragments mapped
#onto it and reports offset and length values for each fragment mapped.
use strict;
my @newoutput;
my %points;
my $chr=0;
my $start=0;
my $stop=0;
my $center;
my $i = 1;
my $bedlen = $ARGV[4]-1;
open(BUFFER, $ARGV[0]);
while(my $line = <BUFFER>){
chomp($line);
my @fields = split("\t", $line);
if($chr ne $fields[0] || $start != $fields[1] || $stop != $fields[2]){
unless(keys %points < 10){
open(OUT, ">$ARGV[1].test.txt");
foreach my $key (keys %points){
print OUT "$points{$key}{offset}\t$points{$key}{len}\n";
}
close(OUT);
my $output = `Rscript $ARGV[3] --frame=$ARGV[1].test.txt --center=$center --chr=$chr --output=$ARGV[1] --span=$ARGV[2]`;
push(@newoutput, $output);
}
%points = ();
$i = 1;
$chr = $fields[0];
$start = $fields[1];
$stop = $fields[2];
if(($stop - $start)%2 == 1){
$center = (($stop - $start + 1)/2)+$start;
}else{
$center = (($stop-$start)/2)+$start;
}
}
my $fragstart = $fields[$bedlen+2];
my $fragstop = $fields[$bedlen+3];
my $fragcenter;
if(($fragstop - $fragstart)%2 == 1){
$fragcenter = (($fragstop - $fragstart + 1)/2)+$fragstart;
}else{
$fragcenter = (($fragstop-$fragstart)/2)+$fragstart;
}
my $offset = $fragcenter - $center;
my $fraglength = $fields[$bedlen+3] - $fields[$bedlen+2];
my $index = $i;
$i++;
$points{$index}{offset} = $offset;
$points{$index}{len} = $fraglength;
}
foreach(@newoutput){
print "$_\n";
}