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