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