better living through python

An adventure in programming and recovery.

Python Lesson Review Of Final Process

June 06, 2011

 

Python Lesson: Final Analysis

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.
See you tomorrow!

 

Retro Contours New Logo

June 04, 2011

Updated some materials for the Retro Contours Live Wallpaper we have on the android market and wanted to share.  I'll probably end up redoing it later, but I'm happy enough with the result for now.



Retro Contours New Logo

June 03, 2011

Updated some materials for the Retro Contours Live Wallpaper we have on the android market and wanted to share.  I'll probably end up redoing it later, but I'm happy enough with the result for now.



Python Lesson For Loops

June 03, 2011

 

I think I’ve discussed ‘for loops’ before, but I’ll give it another short go here for you.  ‘For loops’, like shown below, help you review groups of information in sets.

 

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

 


Here I am going through each list.  Let me revise this code quickly, and I’ll show you how it goes thought each combination.  

 

target = ["atgacatgcacaagtatgcat", "atgaatgcatggatgtaaatgcag"]
key = ["a", "atg", "atgc", "atgca"]

for t in target:
for k in key:
print t + " " + k

 


If I run this piece of code I get this back:

 

atgacatgcacaagtatgcat a
atgacatgcacaagtatgcat atg
atgacatgcacaagtatgcat atgc
atgacatgcacaagtatgcat atgca
atgaatgcatggatgtaaatgcag a
atgaatgcatggatgtaaatgcag atg
atgaatgcatggatgtaaatgcag atgc
atgaatgcatggatgtaaatgcag atgca 

 


As you can tell, it prints each piece of the ‘target’ list against the ‘key’ list.  It is quite handy when attempting to compare and create new information based on varying lists.

On Monday awaits this codes final analysis!  Be ready or be quadratic!

 

Python Lesson Lists

June 02, 2011

 

Below you’ll see the code I began with yesterday.  

 

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

 


Highlighted in yellow is what are called ‘lists’.  Lists are good for collecting and manipulating data.  There are TONS of ways to interact with lists, you can view more at python.org.  We all like them, lists are very usable in everyday life.  However in order to interact with them in Python there are many different options given.


One of the interesting things about lists is the fact that you can manipulate them.  In other words, you can adjust what’s inside them. There are other things that are not mutable (changeable), such as tuples.  


Above I have two lists; target, and key.  Lists in python can be written with this syntax.  The name is placed on the left, then an equals sign (also known as the assignment), brackets and then each item in the list is separated with a comma.  


 

listname = [item1, item2, item3]

 


The only difference you might see from my code above, and the list just given, is the “” around the information.  Those “” indicate that it’s a string, versus an integer (or int).  A string is anything that shouldn’t be treated like a number (as in mathematically).  If you want to make sure that your number is treated like a word, so that you can’t accidentally add it to something, you put “” around it.  

Tomorrow more of an explanation regarding the last part of the code.  Then a review of what it’s actually meant to do (for those of you wondering).    

 

Python Lesson Recursion

June 01, 2011

Recursion.  This is one aspect that I’m still working on grasping, at least, within programming.  In order to explain what this means within programming, I’m going to give an example from a current problem set I’m working on.  First I’ll show you my code.


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

 

At the beginning you can view my defined function.  It’s highlighted in yellow.  The definition of Recursion, as defined by wikipedia, is the process of repeating items in a self-similar way. For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion.   The most common application of recursion is in mathematics and computer science, in which it refers to a method of defining functions in which the function being defined is applied within its own definition.  The name of the function is “countSubStringMatchRecursive”, and both locations of the function are highlighted in red above.  


One way to viewing recursion within literary aspects, would be to review a book by reviewing it’s chapters.  Then review a chapter by reviewing it’s pages, then review a page by reviewing it’s paragraphs, then reviewing a paragraph by reviewing it’s sentences.  Then you review the sentence’s grammar.  Use each review and then amalgamate your data into one larger review in order to get the full picture of whether or not you like the author, or the book.  


Within programming recursion can help to minimize your code, while still completing the same task.  It can, however, make things more complicated to understand.  It’s considered to be more elegant to use, in terms of creating code.  Sometimes it isn’t always more helpful though. As a side note you should google recursion for fun, or just check it out on wikipedia.


Tomorrow I’ll continue on with explaining the code above.         

 

Vlog

May 31, 2011


http://www.youtube.com/watch?v=LMkwXPRc5D4

See you tomorrow!

Why did Silent Movies go out of style again?

May 27, 2011

 

Today I made a silent movie for our Android Application, Curvy.  About halfway through I started getting a headache and slight nausea simply from restarting the background music over and over again, so I could set the written aspects set up appropriately in time with the music.  I’m still a bit under the weather from it as I write now.  

On a brighter note, despite the head and stomach aches, I rediscovered my drive today.  I found that the creation aspect of making that little ditty was so enthralling, that the one thing that really made me move away was physical illness.  That is quite amazing.  It gives me excitement for creating my next big thing, a cribbage tutorial for the Cribbage website.   

In the mean time, here is my video.  I hope you enjoy, and don’t also have a stomach/head ache from it all.  If you do let me know, I may need to make a disclaimer. ;)

 

My personal take on 'Kan haz Cheeseburger?'

May 26, 2011
I just spent 6 hours working with a program that, upon final save and move to production, noted that it will only allow video editing production when I purchase a subscription.  That is just wicked mean.  Seriously, that kind of advertising is just cruel.    
 
I should have expected it really, so it’s partially my fault.  Still a bit peeved though.  However, on the bright side I’ve gotten the hang of how I want my video to look.  Now I just have to find a program to make it in.  It did show me just how addictive and fun video making is.  I’ve already planned on adding videos to my blog as a way of supplementing my required creativity regimen.  So, for this entry you get to see my first Vlog (Video Blog).

So I did find a program, it’s called Windows Movie Maker.  Also, no animals were harmed in the making of this film. You can also view this film on youtube at Kitteh Noises.


 

Poetry Wednesday

May 25, 2011

 

My palms are dusty and clammy
My calves ache and my feet throb
my throat clenches, my shoulders are tight, and my forehead is drawn into worry frowns

Music plays in the other room
Upbeat with good tempo
he hums along and off again
as he goes through creation antics
and produces money with finger strokes

There is no quite
There is no stillness
There is no calm
There is only frantic thoughts and worn out dreams
Dreams that threaten to fall
as my brain attacks them and hacks at them mercilessly

creativity is lacking
my heart it boils

 

Links