in reply to formatting output question (use of recursive subroutine?)
I was bored :)
my $ref = 'agctagctagctagcatgctagctagctgatcgatgctagctagctgactgacgacg'; my @subseq_to_find = qw{ gctagctag tagcatgctagctag gctagctgac tag }; my @output; for my $subseq ( @subseq_to_find ) { my $p = -1; MATCH: while (1) { $p = index $ref, $subseq, $p + 1; last if $p < 0; my $len = length $subseq; for ( @output ) { my $substr = \ substr $_, $p, $len; $$substr = $subseq and next MATCH unless $$substr =~ /\S/; } push @output, " " x length $ref; substr $output[-1], $p, $len, $subseq; } } print "$_\n" for $ref, @output;
Output:
agctagctagctagcatgctagctagctgatcgatgctagctagctgactgacgacg gctagctag tag gctagctag gctagctag gctagctag tag tag gctagctgac tag tag tagcatgctagctag tag tag
Update: next SUBSEQ should be next MATCH. Added a smaller pattern to test the fix. I guess I'm still bored.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: formatting output question (use of recursive subroutine?)
by rogerd (Sexton) on Aug 04, 2008 at 21:24 UTC |