-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbedmid.pl
executable file
·53 lines (40 loc) · 1.12 KB
/
bedmid.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
#! /usr/bin/perl
####################
# bedmid.pl - go from chrom start end id to id chrom no chr, midpoint.
# By Madelaine Gogol
# 4/2010
####################
use strict;
use POSIX;
my ($chr,$midpoint,$filename,@columns,@lines,$contents,@items,$col,$i);
my ($value);
$filename = $ARGV[0];
$contents = get_file_data($filename);
@lines = split('\n',$contents);
foreach my $line (@lines)
{
@items = split('\t',$line);
$midpoint = floor(($items[2] - $items[1])/2) + $items[1];
$chr = $items[0];
$chr =~ s/^chr//g;
print "$items[3]\t$chr\t$midpoint\n";
}
######################################################
# subroutine get_file_data
# arguments: filename
# purpose: gets data from file given filename;
# returns file contents
######################################################
sub get_file_data
{
my($filename) = @_;
my @filedata = ();
unless( open(GET_FILE_DATA, $filename))
{
print STDERR "Cannot open file \"$filename\": $!\n\n";
exit;
}
@filedata = <GET_FILE_DATA>;
close GET_FILE_DATA;
return join('',@filedata);
}