ccelt09 has asked for the wisdom of the Perl Monks concerning the following question:
A few days ago I was very kindly helped with writing a program to replace certain values in a long string of characters, as seen here here. I've attempted to modify and to use the program with short test files as shown below to change al characters outside my intervals to 'N', but the values changed are not consistent with the program's goal. Can anyone see an error in the code?
INPUT FILE: 0000000000 ------------- INTERVALS: chrX 1 3 chrX 5 6 chrX 8 9 ------------ DESIRED OUTPUT FILE: 000N00N00N ----------------- OUTPUT FILE: N00NNNNNNN ---------------- CODE: #!/usr/bin/perl -w use strict; use warnings; my $population = "test"; open( INPUT, "</Users/logancurtis-whitchurch/Desktop/test.mask.txt") o +r die "can't open masked file\n"; open( OUT, ">/Users/logancurtis-whitchurch/Desktop/filtered.test.mask. +txt") or die "can't open output file\n"; my $mask_input = <INPUT>; close INPUT; my $filtered_sites = "/Users/logancurtis-whitchurch/Desktop/test.inter +val"; open (INTERVAL, "<$filtered_sites") or die "can't open $filtered_sites +"; my $lastEnd = 1; while ( <INTERVAL> ) { my (undef, $start, $end) = split '\s', $_; ## change everything from the end of the last range ## to the start of this range to 'N' substr( $mask_input, $lastEnd, $start ) =~ tr[\x00-\xff][N]; $lastEnd = $end; } close INTERVAL; ## change everything from the end of the last range to the end of stri +ng to 'N' substr( $mask_input, $lastEnd, length( $mask_input ) ) =~ tr[\x00-\xff +][N]; print OUT "$mask_input";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trouble with Transliterate Function
by choroba (Cardinal) on Aug 28, 2013 at 23:12 UTC | |
by abualiga (Scribe) on Aug 29, 2013 at 03:05 UTC | |
|
Re: Trouble with Transliterate Function
by jwkrahn (Abbot) on Aug 29, 2013 at 03:00 UTC | |
|
Re: Trouble with Transliterate Function
by hdb (Monsignor) on Aug 29, 2013 at 08:34 UTC | |
|
Re: Trouble with Transliterate Function
by jwkrahn (Abbot) on Aug 29, 2013 at 09:31 UTC | |
|
Re: Trouble with Transliterate Function
by QM (Parson) on Aug 29, 2013 at 11:20 UTC | |
|
Re: Trouble with Transliterate Function
by jwkrahn (Abbot) on Aug 29, 2013 at 21:28 UTC |