diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/windowmasker_to_bed.pl	Tue May 16 13:18:12 2017 -0400
@@ -0,0 +1,82 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+=head1 NAME
+
+windowmasker_to_bed.pl - Convert WindowMasker output to BED format
+
+=head1 SYNOPSIS
+
+  windowmasker_to_bed.pl < ${input.interval} > ${output.bed}
+
+=head1 DESCRIPTION
+
+This scripts converts the interval output from WindowMasker ustat
+to bed 4 format.
+
+=head1 VERSION
+
+Last update: 2017-04-28
+
+=cut
+
+
+#====================
+# Libraries
+#====================
+use Getopt::Long;
+use Pod::Usage;
+use Carp;
+
+sub main {
+  parse_arguments();
+
+  my $chrom;
+  my $idx = 0;
+
+  while ( defined(my $line = <>) ) {
+    next if ($line =~ /^\s*$/x);
+
+    if ($line =~ /^>(\S+)/x) {
+      $chrom = $1;
+
+    } elsif ($line =~ /(\d+)\s+\-\s+(\d+)/x) {
+      # interval coordinates are 0-based
+      my $start = $1;
+      my $end = $2 + 1;
+      my $name = sprintf("wm_%d", $idx++);
+
+      print join("\t", $chrom, $start, $end, $name), "\n";
+
+    } else {
+      croak("Invalid line: ${line}");
+    }
+  }
+
+  return;
+}
+
+main();
+
+
+
+#====================
+# Parse command-line arguments
+#====================
+sub parse_arguments {
+  my $help = 0;
+
+  GetOptions('help|?' => \$help) or usage();
+
+  pod2usage({ verbose => 2 }) if ($help);
+
+  return;
+}
+
+sub usage {
+  my $msg = shift;
+
+  pod2usage({ verbose => 1, message => $msg || "" });
+  exit 1;
+}