Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to write a script that checks if an entered string is an oligonucleotide.

ID: 3583647 • Letter: I

Question

I need to write a script that checks if an entered string is an oligonucleotide. An oligonucleotide is a string of any length that contains only A,G,C,T,a,c,g,t. If they contain any other characters, it is not an oligonucleotide. I have the script below but I get an error (shown after the script). Please help.

#!/bin/bash

clear
echo "Enter your oligonucleotide sequence: "
read SEQ

if [ ("$c" -ne "A") -o ("$c" -ne "T") -o ("$c" -ne "C") -o ("$c" -ne "G") -o ("$c" -ne "a") -o ("$c" -ne "t") -o ("$c" -ne "c") -o ("$c" -ne "g") ];
then
   echo "Your entered oligonucleotide sequence is $SEQ"
else
   echo "Error! $SEQ is not a valid sequence. Enter an oligonucleotide sequence."
fi

When I run the script in UNIX, I get this error:

Enter your oligonucleotide sequence:

ACTGAGTcT

mescript.sh: line 7: [: `)' expected, found A)

Error! ACTGAGTcT is not a valid sequence. Enter an oligonucleotide sequence.

Explanation / Answer

if statement doesnt end with a semicolon. Just remove the semi-colon from the end of the if statement and run it once again. The program will run successfully.

#!/bin/bash

clear
echo "Enter your oligonucleotide sequence: "
read SEQ

if [ ("$c" -ne "A") -o ("$c" -ne "T") -o ("$c" -ne "C") -o ("$c" -ne "G") -o ("$c" -ne "a") -o ("$c" -ne "t") -o ("$c" -ne "c") -o ("$c" -ne "g") ]
then
   echo "Your entered oligonucleotide sequence is $SEQ"
else
   echo "Error! $SEQ is not a valid sequence. Enter an oligonucleotide sequence."
fi