Mercurial > repos > iuc > windowmasker
comparison windowmasker_to_bed.pl @ 0:d90ae4a02efd draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/windowmasker/ commit d529dafd5a2d3a017de226cd59e42cf630348e06
| author | iuc |
|---|---|
| date | Thu, 14 Dec 2023 16:04:27 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d90ae4a02efd |
|---|---|
| 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 } |
