Python Lesson Review Of Final Process
As discussed before, the top section is a function called ‘countSubStringMatchRecursive’. This function is simply defined in the top section. It is called (or it’s told to run its code) in the line highlighted in yellow.
In all actuality there are two parts to this piece of code below. The top half is the definition of the function, with lists detailed after. I’ve changed the font of the non-interactive pieces to blue. The font in black is the code that is actually telling the terminal to do something. It will reference the information in blue and use it when necessary, but it’s not technically part of the active piece.
def countSubStringMatchRecursive(target, key, x): x = find(target, key, x) if x == -1: return 0 else: return countSubStringMatchRecursive(target, key, x+1) +1 target = ["atgacatgcacaagtatgcat", "atgaatgcatggatgtaaatgcag"] key = ["a", "atg", "atgc", "atgca"] for t in target: for k in key: print "There were " + str(countSubStringMatchRecursive(t, k, 0)) + " occurances of your key " + k + " in " + t |
So, as we’ve discussed what the top two parts are in previous entries, I’m going to focus on the bottom for loop, and how it actually processes all the information.
As shown in the last entry, the ‘for loop’ will go through all of the information in the lists. The ‘for loop’ then runs the ‘print’ statement and thereby also processes the function. It also asks for certain words to be printed along with it. Once this piece of code runs it will provide the results shown below.
There were 8 occurances of your key a in atgacatgcacaagtatgcat There were 3 occurances of your key atg in atgacatgcacaagtatgcat There were 2 occurances of your key atgc in atgacatgcacaagtatgcat There were 2 occurances of your key atgca in atgacatgcacaagtatgcat There were 9 occurances of your key a in atgaatgcatggatgtaaatgcag There were 5 occurances of your key atg in atgaatgcatggatgtaaatgcag There were 2 occurances of your key atgc in atgaatgcatggatgtaaatgcag There were 2 occurances of your key atgca in atgaatgcatggatgtaaatgcag |
So, what was the point of this piece of code? It was reviewing two different example DNA strings. The ‘key’s’ are subsections of a DNA string, in particular sections in which we already know their function within the body. It was then checking to see how many known sequences were in this DNA strand. It’s an example of what some scientists may need to do, in order to more easily process information on a larger scale.