Mercurial > repos > vipints > fml_wig2bed
annotate 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 | 
| rev | line source | 
|---|---|
| 0 
b4f83e06d7bf
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 | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 2 # | 
| 
b4f83e06d7bf
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 | 
| 
b4f83e06d7bf
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 | 
| 
b4f83e06d7bf
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 | 
| 
b4f83e06d7bf
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. | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 7 # | 
| 
b4f83e06d7bf
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 | 
| 
b4f83e06d7bf
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 | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 10 # | 
| 
b4f83e06d7bf
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, | 
| 
b4f83e06d7bf
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 | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 13 | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 14 use warnings; | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 15 use strict; | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 16 | 
| 
b4f83e06d7bf
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); | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 18 | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 19 my $usage = q( | 
| 
b4f83e06d7bf
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. | 
| 
b4f83e06d7bf
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> | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 22 | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 23 ); | 
| 
b4f83e06d7bf
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) { | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 25 print $usage; | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 26 exit | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 27 } | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 28 | 
| 
b4f83e06d7bf
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]; | 
| 
b4f83e06d7bf
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"; | 
| 
b4f83e06d7bf
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>) | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 32 { | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 33 chomp $dataValue; | 
| 
b4f83e06d7bf
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 /); | 
| 
b4f83e06d7bf
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/ ) { | 
| 
b4f83e06d7bf
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); | 
| 
b4f83e06d7bf
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); | 
| 
b4f83e06d7bf
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) { | 
| 
b4f83e06d7bf
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]); | 
| 
b4f83e06d7bf
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; } | 
| 
b4f83e06d7bf
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; } | 
| 
b4f83e06d7bf
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; } | 
| 
b4f83e06d7bf
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; } | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 44 else { | 
| 
b4f83e06d7bf
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"; | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 46 exit 255; | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 47 } | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 48 } | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 49 } | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 50 else { | 
| 
b4f83e06d7bf
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); | 
| 
b4f83e06d7bf
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) { | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 53 $position = $b[0]; | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 54 $dataValue = $b[1]; | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 55 } | 
| 
b4f83e06d7bf
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; | 
| 
b4f83e06d7bf
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"; | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 58 $position = $position + $step; | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 59 } | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 60 } | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 61 close WIG; | 
| 
b4f83e06d7bf
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
 vipints parents: diff
changeset | 62 exit; | 
