String Processing

Splicing Arrays

In this lesson the student will learn how to:
  1. Use the splice function
  2. Slice an array
By the end of this lesson the student will be able to:

	Write a script which allows the user to
	insert strings within another string.

Mutations

Mutations are changes which occur in a DNA sequence. They can be changes to a single nucleotide in the form of an insertion, a deletion, or a substitution of just one nucleotide. Insertions, deletions, and substitutions of more than one nucleotide can also occur. Sequences can sometimes get copied from one point in the genome to another or sometimes sequences from a virus, for instance, can get spliced into the nucleotide sequence in a cell. These sequences can, if they are inserted in the middle of a gene sequence, disrupt the gene and render it non-functional. Most often a cell containing a mutation will die or be unable to replicate, but sometimes it will survive to generate daughter cells. If a mutation occurs in germline cells, it is possible that the mutation could be copied to the offspring of an organism.

Single nucleotide insertions or deletions will result in what is known as a frameshift if they occur within an exon of a gene. This will mess up the codon sequence so that the amino acid sequence is totally different and the resulting protein most likely will no longer work.

Splicing

The splice function allows you to insert items into an array.

#!/usr/bin/perl @sent = ("The", "hog", "walked", "down", "the", "road", "."); print "@sent\n"; #not over-written splice(@sent, 3,0,"<---->"); print "@sent\n"; #over-written splice(@sent, 3,1,"slowly"); print "@sent\n"; #over-write more items splice(@sent,2,3,"ate"); print "@sent\n";
Notice that you can replace items or simply insert items depending on how you use the splice function. The third argument to the function controls the number if items which are over-written. If this argument is zero, then nothing is over-written.

Slicing

Not to be confused with splicing is slicing:

#!/usr/bin/perl @list = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18); print "@list\n"; @s1 = @list[3..6]; print "@s1\n"; @s2 = @list[0..5]; print "@s2\n"; @s3 = @list[3,5,10]; print "@s3\n"; @s4 = @list[-5..-1]; print "@s4\n";
This example shows several ways of taking a slice of an array. Play around with this example to get a clear idea of how slicing works. Note that the negative numbers allow you to slice from the end of the array. What happens if you use a range in reverse?

ASSIGNMENT:

Write a script which allows the user to insert a sequence within another sequence. This script must use the splice function to do the actual insertion, which means that source and destination must be arrays as opposed to strings. (Don't forget that it's pretty easy to convert from array to string and vice versa.) Allow the user to do the following things:

  1. Specify original sequence
  2. Specify where insertion will take place
  3. Indicate overwrite or not
  4. Repeatedly insert strings
  5. Exit script using Q key