introduction to biopython
TRANSCRIPT
Lecture Two
What we want to install in bioinformatics LAB ?
1.Python 2.7.x or later.2.Biopython.
To learn how to use Biopython we must first know how to use python commands
let us start to download it to PCs LAB:
If our PCs has windows as an operating system then we go to this locationhttps://www.python.org/ and install python on the windows.
After installation let us enter to some simple instruction that may be help us to understand python language :
Variables and Some ArithmeticIn Python the basic data types are strings and numbers.
Example:a=324b = 24c = a - bprint 'a - b is', coutput:a - b is 300
You can now use all common arithmetic operations involving numbers:Addition:2 + 3 == 5
Subtraction:5 - 2 == 3
Multiplication:3 * 4 == 12
Division:15 / 3 == 5
Division remainder:18 % 5 == 3
Exponentiation:2 ** 3 == 8
It is important to note that if you try to divide two integers, Python always rounds down the result (so 18/5 == 3).
To obtain a precise result for this division, you need to indicate floating point division in either of the following expressions:
18.0/5 == 3.6
float(18)/5 == 3.6
In Python, the single equals sign (=) means "assign a value to a variable". For example, a = 3 assigns 3 to the integer a. In order to denote equality, Python uses the double equals sign (==).
In Python, a string is an ordered sequence of letters, numbers and other characters. You can create string variables just like you did with :a = "Hello"
b = "World"
Notice that the string must be surrounded by " or ' (but not a mix of both). You can use quotes inside the string, as long as you use the opposite type of quotes to surround the string e.g.: a = "Learning Python" or b = 'Project "Bioinformatics"'.
String operations differ slightly from operations on numbers:
a = 'Bioinformatics'b = 'LAB'c = '!'print a + ' ' + b + c*3Output:Bioinformatic LAB!!!
Get input from user: get an input from user and put it in var. var = raw_input(">>> ")
Example
Given: Two positive integers a and b, each less than 1000.
Return: The integer corresponding to the square of the hypotenuse of the right triangle whose legs have lengths a and b.
var1 = raw_input(">>> ")var2 = raw_input(">>> ")r=(int)var1 ** 2 +(int)var2 ** 2print 'The result is' ,r?
In the above example why we use (int) and what happened if we leave it
try it by yourself.(H.W.)
Strings and lists:We've already seen numbers and strings, but Python also has variable types that can hold more than one piece of data at a time. The simplest such variable is a list.
You can assign data to a list in the following way:list_name = [item_1, item_2, ..., item_n]. The items of the list can be of any other type: integer, float, string. You even explore your inner Zen and make lists of lists!
?
What is Zen?(H.W.)Any item in a list can be accessed by its index, or the number that indicates its place in the list. For example, try running the following code:
tea_party = ['March Hare', 'Hatter', 'Dormouse', 'Alice']print tea_party[2]Your output should be:Dormouse
You can easily change existing list items by reassigning them. Try running the following:
tea_party[1] = 'Cheshire Cat'print tea_party
You can also add items to the end of an existing list by using the function append():
tea_party.append('Jabberwocky')print tea_party
If you need to obtain only some of a list, you can use the notation list_name[a:b] to get only those from index a up to but not including index b.For example, tea_party[1:3] returns : Cheshire Cat, Dormouse, not Cheshire Cat, Dormouse, Alice. This process is called "list slicing".
If the first index of the slice is unspecified, then Python assumes that the slice begins with the beginning of the list (i.e., index 0).
If the second index of the slice is unspecified, then you will obtain the items at the end of the list. For example: tea_party[:2] returns March Hare, Cheshire Cat tea_party[3:]returns Alice, Jabberwocky.
You can also use negative indices to count items backtracking from the end of the list. So tea_party[-2:] returns the same output as tea_party[3:]: Alice, Jabberwocky.
Finally, Python equips you with the magic ability to slice strings the same way that you slice lists. A string can be considered as a list of characters, each of which having its own index starting from 0. For example: try running the following code:a = 'flimsy'b = 'miserable'c = b[0:1] + a[2:]print cThis code will output the string formed by the first character of miserable and the last four characters of flimsy:mimsyExample
Given: A string s of length at most 200 letters and four integers a, b, c and d.
Return: The slice of this string from indices a through b and c through d (with space in between), inclusively.
Solution:s=HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntputHumptyDumptyinhisplaceagain.a=22b=27c=97d=102x=s[a:b+1]+' '+s[c:d+1]print x
The output should be: Humpty Dumpty
Prepared by Suhad Jihad using http://rosalind.info/problems/locations/ as a main reference.