0

I have this variable whose length should always be 9 characters

PEPTIDE_SEQ="AAAAAAAAA"

Then i created the length variable as

len=9 

What i want to do is to start from the PEPTIDE_SEQ and output to file a block like this:

AAAAAAAAA
CAAAAAAAA
DAAAAAAAA
EAAAAAAAA
FAAAAAAAA
GAAAAAAAA
HAAAAAAAA
IAAAAAAAA
KAAAAAAAA
LAAAAAAAA
MAAAAAAAA
NAAAAAAAA
PAAAAAAAA
QAAAAAAAA
RAAAAAAAA
SAAAAAAAA
TAAAAAAAA
VAAAAAAAA
WAAAAAAAA
YAAAAAAAA

Excluding characters B,J,O,U,X,Z, I was able to only repeat the PEPTIDE variable and output it to a file using this code

while [ $i -le 20 ]
do
    printf '%*s\n' "$len" | tr ' ' "$PEPTIDE_SEQ"  >> demo.txt
    i=$(( i+1 ))     # increments $i
done 

how can I be able to simulate that block of code either using sed or awk? and then create another block of code but this time replacing the second letters then repeat the loop for the third block replacing the third letters and so forth.

  • Could you supply a sample of your input file and what you want ouputted from that input file? That will help determine a solution. – Lewis M Dec 7 '18 at 16:52
  • I do not use an input file i just take the value of the PEPTIDE variable then sort and modify it, ideally i want the file i output to, to look this: AAAAAAAAA CAAAAAAAA DAAAAAAAA EAAAAAAAA FAAAAAAAA GAAAAAAAA HAAAAAAAA IAAAAAAAA KAAAAAAAA LAAAAAAAA MAAAAAAAA NAAAAAAAA PAAAAAAAA QAAAAAAAA RAAAAAAAA SAAAAAAAA TAAAAAAAA VAAAAAAAA WAAAAAAAA YAAAAAAAA AAAAAAAAC AAAAAAAAD AAAAAAAAE AAAAAAAAF AAAAAAAAG AAAAAAAAH AAAAAAAAI AAAAAAAAK AAAAAAAAL AAAAAAAAM AAAAAAAAN AAAAAAAAP Till Y on the last line..but also modifying other lines like that. – Morena Dec 7 '18 at 17:09
  • I'm afraid your script doesn't print anything but 20 AAAAAAAAA... – RudiC Dec 7 '18 at 21:37
  • Please don't put updates in the comments. Out then in the Question. And use the {} formatting button to show your blocks of data and code. – roaima Dec 7 '18 at 22:41
0

With bash:

#!/bin/bash

pep="AAAAAAAA"

pos=1
while [ "$pos" -le "${#pep}" ]; do
    for aa in A C D E F G H I K L M N P Q R S T V W X Y
    do
        printf '%s%s%s\n' "${pep:0:pos-1}" "$aa" "${pep:pos}"
    done
    pos=$(( pos + 1 ))
done

The outer while loop steps through the positions in the given peptide sequence, and for each position the valid amino acid codes are put into the peptide one by one at that position (this uses substring expansion of the part of the peptide up to the relevant position, inserts the altered amino acid, and then does another substring expansion for the tail end of the peptide).

  • Thank you, this works when I run the script on windows but when I run it in Linux Ubuntu 18.04 I get a bad substitution error. Also is it possible that after each block I skip 2 lines before starting to iterate the next block? – Morena Dec 8 '18 at 1:46
  • @Morena Are you running the script with bash on Ubuntu? It requires that you run it with bash. To output on empty line, just insert echo "" in the script after the line that increments the variable pos. – Kusalananda Dec 8 '18 at 7:09
  • Alright, thank you so much everything works. – Morena Dec 9 '18 at 3:24
0

Your spec is not TOO clear. How far would

awk -vPS="$PEPTIDE_SEQ" -vLEN=$len -vXCLI="B,J,O,U,X,Z" '
BEGIN   {PS = substr (PS, 2)     
         for (n=split (XCLI, T, ","); n; n--) XCL[T[n]]
         for (i=65; i<=90; i++) {C = sprintf ("%c", i)
                                 if (!(C in XCL)) printf "%s%s ", C, PS
                                }
         printf RS
        }
'
AAAAAAAAA CAAAAAAAA DAAAAAAAA EAAAAAAAA FAAAAAAAA GAAAAAAAA HAAAAAAAA IAAAAAAAA KAAAAAAAA LAAAAAAAA MAAAAAAAA NAAAAAAAA PAAAAAAAA QAAAAAAAA RAAAAAAAA SAAAAAAAA TAAAAAAAA VAAAAAAAA WAAAAAAAA YAAAAAAAA 

get you?

EDIT: Rereading the spec after having read your comment, I came up with

awk -vPS="$PEPTIDE_SEQ" -vXCL="B,J,O,U,X,Z" '
BEGIN   {for (i=65; i<=90; i++) if (!(index(XCL, S = sprintf ("%c", i)))) print C[++n] = S, n
         for (i=1; i<=length(PS); i++)  {for (j=1; j<=n; j++) print substr (PS, 1, i-1) C[j] substr (PS, i+1)
                                         print ""
                                        }
        }
'

Does this fit your needs? Pls be aware that you only need to specify the chars-to-be-excluded, not all the "good" chars with the "bad" ones missing.

  • Thanks, it works but it only outputs a single block, I want it to continue editing the PEPTIDE_SEQ until the last character each time outputting a new modified block – Morena Dec 8 '18 at 1:50
  • Edited in a correction due to your comment... – RudiC Dec 8 '18 at 12:30
  • Thank you mate, your solution works like a charm too, but I can only choose one answer. – Morena Dec 9 '18 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.