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";
In reply to Trouble with Transliterate Function by ccelt09
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |