Your difficulty may have been from not declaring variables with my. When you use strict; you have to be strict. In any case, substr would be effective for this. Assuming it's sane to have the DNA file all in memory:
There are several tidbits here for a student of perl. Untested but It Ought To Work(TM). It might be worthwhile to make this do without hardcoded file names.#!/usr/local/bin/perl -w use strict; open SEQ, "< dna.file" or die $!; my @dna = <SEQ>; close SEQ or die $!; chomp @dna; my $dna = join '', @dna; @dna = map {length} @dna; open LOCS, "< positions.input" or die $!; for (<LOCS>) { # I don't know how your data is counted, watch for fencepost error +s my ($start, $end) = split " "; substr( $dna, $start, $end - $start) =~ tr/CGAT/X/; } close LOCS or die $!; { local $\ = $/; open OUTFILE, "> $$.output" or die $!; # print OUTFILE for map { substr $dna, 0, $_, '' } @dna; print OUTFILE substr( $dna, 0, $_, '') for @dna; close OUTFILE or die $!; }
Update: I like map too much. Modified output loop to save memory.
After Compline,
Zaxo
In reply to Re: in need of wisdom
by Zaxo
in thread in need of wisdom: handling DNA strings
by lolly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |