Write a script which can add or remove one item at a time from the front or the end of and array.
Ends of a DNA Sequence
As you might expect, a DNA sequence has two ends. The ends of a DNA sequence are chemically distinct. The two ends are usually called the 5' (five-prime) end and the 3' (three-prime) end. A phosphate group is found at the 5' end and a hydroxyl (-OH) group is found at the 3' end. A chain of nucleotides is linked covalently by phosphodiester bonds.
Complementary strands of DNA can be written like this:
5'-ATTCCTCCA-3' 3'-TAAGGAGGT-5'Although normally only the 5' to 3' strand is written:
ATTCCTCCASince the content of the complementary strand can be inferred from the first strand.
The two strands are held together by hydrogen bonds. Two hydrogen bonds form between A and T nucleotides and three hydrogen bonds form between G and C nucleotides. (The chemical properties of DNA are important to know about, but not for our focus in this unit and so we will not go into further detail here.)
push and unshift
You can use push and unshift to add items to an array. The big difference between the two functions is that one adds items to the front of the array and the other adds items to the end of the array.
You might not be familiar with the .. construct (called the range operator). To understand this construct do some experimentation with the following script:
You can also remove items from an array with pop and shift:
Here's a slightly modified version of the same script giving you an array-centric view of the results of shift and pop:
ASSIGNMENT:
Write a script which prompts the user to add or remove one item at a time from the front or end of an array. Ensure that the items added are single nucleotides. In other words reject any input which is not "A", "C", "G", or "T". Display the altered array after each iteration of the loop containing the actions. Also provide for "Q" as the exit code the user enters to end the loop. Begin the script with an array containing only five nucleotides.