Mercurial > repos > yating-l > windowmasker_2_5_0
comparison windowmasker_to_bed.pl @ 0:f80c9e6700ba draft default tip
planemo upload commit 91a780909d1eda07d17f6aebf7f08f0c024b6a25
author | yating-l |
---|---|
date | Tue, 16 May 2017 13:18:12 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f80c9e6700ba |
---|---|
1 #!/usr/bin/env perl | |
2 use warnings; | |
3 use strict; | |
4 | |
5 =head1 NAME | |
6 | |
7 windowmasker_to_bed.pl - Convert WindowMasker output to BED format | |
8 | |
9 =head1 SYNOPSIS | |
10 | |
11 windowmasker_to_bed.pl < ${input.interval} > ${output.bed} | |
12 | |
13 =head1 DESCRIPTION | |
14 | |
15 This scripts converts the interval output from WindowMasker ustat | |
16 to bed 4 format. | |
17 | |
18 =head1 VERSION | |
19 | |
20 Last update: 2017-04-28 | |
21 | |
22 =cut | |
23 | |
24 | |
25 #==================== | |
26 # Libraries | |
27 #==================== | |
28 use Getopt::Long; | |
29 use Pod::Usage; | |
30 use Carp; | |
31 | |
32 sub main { | |
33 parse_arguments(); | |
34 | |
35 my $chrom; | |
36 my $idx = 0; | |
37 | |
38 while ( defined(my $line = <>) ) { | |
39 next if ($line =~ /^\s*$/x); | |
40 | |
41 if ($line =~ /^>(\S+)/x) { | |
42 $chrom = $1; | |
43 | |
44 } elsif ($line =~ /(\d+)\s+\-\s+(\d+)/x) { | |
45 # interval coordinates are 0-based | |
46 my $start = $1; | |
47 my $end = $2 + 1; | |
48 my $name = sprintf("wm_%d", $idx++); | |
49 | |
50 print join("\t", $chrom, $start, $end, $name), "\n"; | |
51 | |
52 } else { | |
53 croak("Invalid line: ${line}"); | |
54 } | |
55 } | |
56 | |
57 return; | |
58 } | |
59 | |
60 main(); | |
61 | |
62 | |
63 | |
64 #==================== | |
65 # Parse command-line arguments | |
66 #==================== | |
67 sub parse_arguments { | |
68 my $help = 0; | |
69 | |
70 GetOptions('help|?' => \$help) or usage(); | |
71 | |
72 pod2usage({ verbose => 2 }) if ($help); | |
73 | |
74 return; | |
75 } | |
76 | |
77 sub usage { | |
78 my $msg = shift; | |
79 | |
80 pod2usage({ verbose => 1, message => $msg || "" }); | |
81 exit 1; | |
82 } |