annotate Wig_to_bedGraph/script/wig2bedGraph_converter.pl @ 0:45f3fa82369f default tip

Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
author vipints
date Tue, 07 Jun 2011 18:08:31 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
1 #!/usr/bin/env perl
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
2 #
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
3 # This program is free software; you can redistribute it and/or modify
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
5 # the Free Software Foundation; either version 3 of the License, or
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
6 # (at your option) any later version.
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
7 #
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
8 # Written (W) 2010 Vipin T. Sreedharan, Friedrich Miescher Laboratory of the Max Planck Society
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
9 # Copyright (C) 2010 Max Planck Society
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
10 #
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
11 # Description: - read fixedStep and variableStep wiggle input data,
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
12 # output four column bedGraph format data
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
13
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
14 use warnings;
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
15 use strict;
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
16
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
17 my ($position, $chr, $step, $span) = (0, "", 1, 1);
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
18
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
19 my $usage = q(
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
20 fixedStep2BED.pl - Program to convert a valid fixedStep or variableStep wiggle input data to BED format.
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
21 USAGE: wig2bedGraph_converter <fixedStep/variableStep Wiggle format> > <output file name>
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
22
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
23 );
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
24 if (scalar(@ARGV) != 1) {
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
25 print $usage;
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
26 exit
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
27 }
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
28
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
29 my $inFile = $ARGV[0];
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
30 open WIG, "<$inFile" || die "Can't open the Wiggle file \n";
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
31 while (my $dataValue = <WIG>)
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
32 {
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
33 chomp $dataValue;
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
34 next if ( $dataValue =~ m/^track /);
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
35 if ( $dataValue =~ m/^fixedStep/ || $dataValue =~ m/^variableStep/ ) {
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
36 ($position, $chr, $step, $span) = (0, "", 1, 1);
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
37 my @a = split('\s', $dataValue);
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
38 for (my $i = 1; $i < scalar(@a); ++$i) {
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
39 my ($ident, $value) = split('=',$a[$i]);
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
40 if ($ident =~ m/chrom/) { $chr = $value; }
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
41 elsif ($ident =~ m/start/) { $position = $value-1; }
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
42 elsif ($ident =~ m/step/) { $step = $value; }
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
43 elsif ($ident =~ m/span/) { $span = $value; }
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
44 else {
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
45 print STDERR "ERROR: unrecognized fixedStep/variableStep line: $dataValue\n";
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
46 exit 255;
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
47 }
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
48 }
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
49 }
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
50 else {
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
51 my @b = split('\s', $dataValue);
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
52 if (scalar(@b)>1) {
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
53 $position = $b[0];
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
54 $dataValue = $b[1];
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
55 }
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
56 my $loc_pos = $position+$span;
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
57 print "$chr\t$position\t$loc_pos\t$dataValue\n";
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
58 $position = $position + $step;
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
59 }
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
60 }
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
61 close WIG;
45f3fa82369f Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
vipints
parents:
diff changeset
62 exit;