3

I'm looking at protein sequence that is highly repetitive and I'm trying to format a specific letter in three-letter motif. For example here's a short snippet of the sequence using the single-letter abbreviations for the amino acids (it's highly repetitive):

PGGSGPAAATAAAGSGPSGYGPGASGPVGADAAAAAATGSAGPGRQQAYGPGESGAAAAAASGAGPGRQLGYGPGGSGAAAAAAAGGPGYGGQQGYGPGGAGAAAAAAAGGAGPGRQQTYGPGGSGAAATAAGGSGPGGYGQGPSGYGPSGPGGQQGYGPGGSGAAAAAAAGEAGPGRQQGYGPRGSGAAAAAAAGGPGYGGQSGYGPGGAGAAAAAAAGGAGPGRQQEYGPGGSGAAAAAAAAAGSG

I want to find in the above sequence, all occurrences of a three letter motif (e.g. AAA or GAA) and change the format (highlight/underline/bold etc) of the middle letter BUT NOT the surrounding letters. (e.g AAA or GAA)

Using RegEx it's very easy to find what I'm looking for using the lookaround functions (e.g (?<=A)[A](?=A)) but most RegEx editors I've found don't let you change the format of the returned expressions, only replace them with another expression. Is there any way to accomplish this is in word using the built-in wildcards? Or is there some other way to use RegEx editors to do this?

EDITS:

For reference, this image is exactly what I want. All the highlighted letters need formatting. I cannot figure out how to copy this into word in a way that will save the highlighted letters. I've gotten to the desperate point of trying to OCR this image (with predictably terrible results).

For reference, this is exactly what I want. All the highlighted letters need formatting.

3
  • If the sequence is AAAAAA or AAAA, which As must be formatted? Apr 2, 2021 at 12:39
  • In any occurrence of AAA only the central A is formatted.
    – David O.
    Apr 2, 2021 at 18:06
  • I should probably clarify that in the central A needs to be formatted in any reading frame. Using your example sequence above: AAAAAAA I would like A(AAAAA)A with the the letters in parentheses formatted. I hope that makes sense.
    – David O.
    Apr 2, 2021 at 19:21

2 Answers 2

2

MS Word regex engine does not work the way others do. You can use LibreOffice Writer to accomplish what you are looking for.

  • Press Ctrl+H to open the Find and Replace window
  • Find what: (?<=G)[A](?=A)|(?<=A)[A](?=A)
  • Replace with: $0
  • With your cursor still on the Replace box, click Format. On the Font tab, set the style to Bold. Click the Highlighting tab, select a color. Click OK.
  • Click Replace or Replace All.

IMG:

1
  • Thank you so much! This did exactly what I needed. Should've figured LibreOffice would have this.
    – David O.
    Apr 2, 2021 at 21:42
0

In Word, you can use the following VBA macro:

Sub Bold_codon_middle()
  Dim codon As String: codon = "GAA"
  With Selection.Paragraphs(1).Range
    .Collapse wdCollapseStart
    .Select
  End With
  With Selection.Find
    .MatchCase = True
    Do While .Execute(Forward:=True, FindText:=codon)
      Selection.MoveStart Unit:=wdCharacter, Count:=1
      Selection.MoveEnd Unit:=wdCharacter, Count:=-1
      Selection.Font.Bold = True
      Selection.MoveStart Unit:=wdCharacter, Count:=1
    Loop
  End With
End Sub

Put your mouse in the paragraph that you're interested in.
Paste the script in a VBA module.
Replace the value in codon = "GAA" with the value that you need.
Run the script.

enter image description here

However, I think you need to check stacks of 3 letters, not just any place in the text. The following code should check text in chunks of 3 letters.

Sub Bold_codon_middle()
  Dim codon As String: codon = "GAA"
  With Selection.Paragraphs(1).Range
    .Collapse wdCollapseStart
    .Select
  End With
  With Selection
    Do
      .MoveRight wdCharacter, 3, wdExtend
      If InStr(Selection, vbCr) Then Exit Sub
      If Selection = codon Then
        .MoveStart wdCharacter, 1
        .MoveEnd wdCharacter, -1
        .Font.Bold = True
        .MoveEnd wdCharacter, -2
      End If
      .MoveStart wdCharacter, 3
    Loop
  End With
End Sub

enter image description here

1
  • Thanks, but not quite. Seems to have trouble with multiple A characters in a row and only highlights every other one in a long run of A.
    – David O.
    Apr 2, 2021 at 19:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .