in reply to String character replacement based on position

Since I'm not much of an expert in genome problems (which is what you're working on, right?) I'm going to have to say that I need more information to understand where you're having difficulty. Could you show a few example rules that are giving you trouble in implementing? substr is a pretty useful tool for string manipulation that must occur in absolute positions. Some more complex manipulations based on in-string triggers may benefit from regexp implementations. But (I can't speak for everyone)... I need more info to know where the problem is. The case of converting the ninth character from the left of a string to upper case is probably not the problem you're having trouble solving, is it?


Dave

  • Comment on Re: String character replacement based on position

Replies are listed 'Best First'.
Re^2: String character replacement based on position
by shu_uemura (Initiate) on Feb 23, 2011 at 06:02 UTC

    @"The case of converting the ninth character from the left of a string to upper case is probably not the problem you're having trouble solving, is it?"

    Yes, the problem I'm having is how to develop a general solution for changing the case of specific letters in a DNA sequence. So, I have many variable sequence positions where the letter case needs to be changed. Furthermore, letter case changes must sometimes occur more than once per DNA sequence.
      ... more than once per DNA sequence.

      Maybe:

      >perl -wMstrict -le "my $seq = 'atcgcgtacatcgatac'; my $rule = '01234567890123456'; my @uc_offsets = (0, 8, 15); ;; print qq{$rule}; print qq{$seq}; for my $offset (@uc_offsets) { substr($seq, $offset, 1) = uc substr $seq, $offset, 1; } print qq{$seq}; " 01234567890123456 atcgcgtacatcgatac AtcgcgtaCatcgatAc

      Easy to put that into a function.

      Update: Looking back, I see that BrowserUk essentially gave this solution already, so... Never mind.