From a65f29a05ee5e32af96ccaa9b7a2b4e41b6216ce Mon Sep 17 00:00:00 2001 From: Adam David Scott Date: Fri, 29 Sep 2017 19:16:16 -0500 Subject: [PATCH] script adds random weights to a .maf; used in demo weight example --- scripts/addRandomWeight.pl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 scripts/addRandomWeight.pl diff --git a/scripts/addRandomWeight.pl b/scripts/addRandomWeight.pl new file mode 100644 index 0000000..cf18edc --- /dev/null +++ b/scripts/addRandomWeight.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl +#25 September 2017 - Adam D Scott - + +use strict; +use warnings; + +use IO::File; +use FileHandle; + +my $usage = 'perl addRandomWeight.pl +'; + +die $usage , unless @ARGV == 2; +my ( $maf , $output ) = @ARGV; + +my $IN1 = FileHandle->new( $maf , "r" ); +if ( not defined $IN1 ) { die "ADSERROR: Could not open/read ".$maf."\n"; } + +my $IN2 = FileHandle->new( $output , "w" ); +if ( not defined $IN2 ) { die "ADSERROR: Could not open/write ".$output."\n"; } + +while ( my $line = <$IN1> ) { + chomp( $line ); + $IN2->print( $line."\t" ); + if ( $line =~ /Hugo/ ) { + $IN2->print( "RandomWeight" ); + } else { + my $r = int( rand( 40 ) ); + $r -= 20; + $IN2->print( $r ) + } + $IN2->print( "\n" ); +} +$IN1->close(); +$IN2->close();