Chat room

Create a Meebo Chat Room
Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Saturday, December 18, 2010

Python Strings:gcufbioinfo


Let's take a look at the example code in more detail. The first thing we did was to create a string and assign it to a variable. Strings in Python are sequences of characters. You create a string literal by enclosing the characters in single ('), double (") or triple (''' or """) quotes. In the example we assigned the string literal CTGACCACTTTACGAGGTTAGC to the variable named dna.
>>> dna = 'CTGACCACTTTACGAGGTTAGC'
Then we simply typed the name of the variable, and Python responded by displaying the value of that variable, surrounding the value with quotes to remind us that the value is a string.
>>> dna 
'CTGACCACTTTACGAGGTTAGC' 
A Python string has several built-in capabilities. One of them is the ability to return a copy of itself with all lowercase letters. These capabilities are known as methods. To invoke a method of an object, use the dot syntax. That is, you type the name of the variable (which in this case is a reference to a string object) followed by the dot (.) operator, then the name of the method followed by opening and closing parentheses.
>>> dna.lower() 
'ctgaccactttacgaggttagc' 
You can access part of a string using the indexing operator s[i]. Indexing begins at zero, so s[0] returns the first character in the string, s[1] returns the second, and so on.
>>> dna[0] 
'C' 
>>> dna[1] 
'T' 
>>> dna[2] 
'G' 
>>> dna[3] 
'A' 
The final line in our screen shot shows PyCrust's autocompletion feature, whereby a list of valid methods (and properties) of an object are displayed when a dot is typed following an object variable. As you can see, Python lists have many built-in capabilities that you can experiment with in the Python shell. Now let's look at one of the other Python sequence types, the list.

Beginning Python for Bioinformatics:gcufbioinfo

Bioinformatics, the use of computers in biological research, is the newest wrinkle on one of the oldest pursuits--trying to uncover the secret of life. While we may not know all of life's secrets, at the very least computers are helping us understand many of the biological processes that take place inside of living things. In fact, the use of computers in biological research has risen to such a degree that computer programming has now become an important and almost essential skill for today's biologists.
The purpose of this article is to introduce Python as a useful and viable development language for the computer programming needs of the bioinformatics community. In this introduction, we'll identify some of the advantages of using Python for bioinformatics. Then we'll create and demonstrate examples of working code to get you started. In subsequent articles we'll explore some significant bioinformatics projects that make use of Python.

download python cookbook:gcufbioinfo

Twitter Delicious Facebook Digg Stumbleupon Favorites More