-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfixedStep2BED.pl
executable file
·67 lines (59 loc) · 1.79 KB
/
fixedStep2BED.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
59
60
61
62
63
64
65
66
67
#!/usr/bin/env perl
# Description: - read fixedStep or variableStep wiggle input data,
# output four column bedGraph format data
# Author: Vipin
use warnings;
use strict;
my ($position, $chr, $step, $span) = (0, "", 1, 1);
=head Make compactible with cmd
my $usage = q(
fixedStep2BED.pl - Program to convert a valid fixedStep or variableStep wiggle input data to BED format.
USAGE: fixedStep2BED.pl <fixedStep/variableStep Wiggle format> > <output file name>
);
if (scalar(@ARGV) != 1) {
print $usage;
exit
}
my $inFile = $ARGV[0];
open WIG, "<$inFile" || die "Can't open the Wiggle file \n";
while (my $dataValue = <WIG>)
=cut
#my $cnt = 1;
while (my $dataValue = <STDIN>)
{
chomp $dataValue;
if ( $dataValue =~ m/^track /) {
print STDERR "Skipping track line\n";
next;
}
if ( $dataValue =~ m/^fixedStep/ || $dataValue =~ m/^variableStep/ ) {
$position = 0;
$chr = "";
$step = 1;
$span = 1;
my @a = split /\s/, $dataValue;
for (my $i = 1; $i < scalar(@a); ++$i) {
my ($ident, $value) = split('=',$a[$i]);
if ($ident =~ m/chrom/) { $chr = $value; }
elsif ($ident =~ m/start/) { $position = $value-1; }
elsif ($ident =~ m/step/) { $step = $value; }
elsif ($ident =~ m/span/) { $span = $value; }
else {
print STDERR "ERROR: unrecognized fixedStep line: $dataValue\n";
exit 255;
}
}
}
else {
my @b = split('\s', $dataValue);
if (scalar(@b)>1) {
$position = $b[0];
$dataValue = $b[1];
}
my $loc_pos = $position+$span;
print "chr$chr\t$position\t$loc_pos\t$dataValue\t-\n";
$position = $position + $step;
}
}
#close WIG;
exit;