SlideShare a Scribd company logo
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 location
https://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 Arithmetic
In Python the basic data types are strings and numbers.
Example:
a=324
b = 24
c = a - b
print 'a - b is', c
output:
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*3
Output:
Bioinformatic LAB!!!
Get input from user: get an input from user and put it in var.
var = raw_input(">>> ")
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 ** 2
print '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 c
This code will output the string formed by the first character of miserable
and the last four characters of flimsy:
mimsy
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=HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntpu
tHumptyDumptyinhisplaceagain.
a=22
b=27
c=97
d=102
x=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.
print c
This code will output the string formed by the first character of miserable
and the last four characters of flimsy:
mimsy
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=HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntpu
tHumptyDumptyinhisplaceagain.
a=22
b=27
c=97
d=102
x=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.

More Related Content

PPTX
scripting in Python
PPTX
FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.
PPTX
C# Operators. (C-Sharp Operators)
PDF
Python :variable types
PPTX
7array in c#
PPTX
iPython
PPTX
Sequence Types in Python Programming
PPTX
List in Python
scripting in Python
FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.
C# Operators. (C-Sharp Operators)
Python :variable types
7array in c#
iPython
Sequence Types in Python Programming
List in Python

What's hot (20)

PDF
PPTX
C# Arrays
PPTX
Data Structures in Python
PDF
Arrays In Python | Python Array Operations | Edureka
PPTX
Parts of python programming language
DOC
Arrays In General
PDF
1. python
PPTX
Python- Regular expression
PDF
List , tuples, dictionaries and regular expressions in python
PDF
Python programming : Arrays
PPTX
Assignment statements
PPTX
String in python lecture (3)
PDF
Python List Comprehensions
PDF
Python programming : List and tuples
PDF
Python programming : Strings
C# Arrays
Data Structures in Python
Arrays In Python | Python Array Operations | Edureka
Parts of python programming language
Arrays In General
1. python
Python- Regular expression
List , tuples, dictionaries and regular expressions in python
Python programming : Arrays
Assignment statements
String in python lecture (3)
Python List Comprehensions
Python programming : List and tuples
Python programming : Strings
Ad

Similar to Introduction to biopython (20)

PPT
Python course in_mumbai
PPT
Python course in_mumbai
PDF
Python workshop
PPTX
Python Workshop
ODP
Python course Day 1
PPTX
Learning python
PPTX
Learning python
PPTX
Learning python
PPTX
Learning python
PPTX
Learning python
PPTX
Learning python
PPTX
Learning python
PPT
Python programming tutorial for beginners
PPT
Python study material
PDF
Python Objects
PDF
Python Cheatsheet_A Quick Reference Guide for Data Science.pdf
PPTX
Python bible
PDF
Python 101 1
PDF
AmI 2017 - Python basics
Python course in_mumbai
Python course in_mumbai
Python workshop
Python Workshop
Python course Day 1
Learning python
Learning python
Learning python
Learning python
Learning python
Learning python
Learning python
Python programming tutorial for beginners
Python study material
Python Objects
Python Cheatsheet_A Quick Reference Guide for Data Science.pdf
Python bible
Python 101 1
AmI 2017 - Python basics
Ad

Recently uploaded (20)

PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Cell Structure & Organelles in detailed.
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Presentation on HIE in infants and its manifestations
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
master seminar digital applications in india
PPTX
Final Presentation General Medicine 03-08-2024.pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Cell Structure & Organelles in detailed.
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Final Presentation General Medicine 03-08-2024.pptx
VCE English Exam - Section C Student Revision Booklet
STATICS OF THE RIGID BODIES Hibbelers.pdf
GDM (1) (1).pptx small presentation for students
Presentation on HIE in infants and its manifestations
Chinmaya Tiranga quiz Grand Finale.pdf
A systematic review of self-coping strategies used by university students to ...
Microbial diseases, their pathogenesis and prophylaxis
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
O7-L3 Supply Chain Operations - ICLT Program
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Supply Chain Operations Speaking Notes -ICLT Program
master seminar digital applications in india
Final Presentation General Medicine 03-08-2024.pptx

Introduction to biopython

  • 1. 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 location https://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 Arithmetic In Python the basic data types are strings and numbers. Example: a=324 b = 24 c = a - b print 'a - b is', c output: 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
  • 2. •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
  • 3. 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*3 Output: Bioinformatic LAB!!! Get input from user: get an input from user and put it in var. var = raw_input(">>> ") 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 ** 2 print '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.)
  • 4. 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():
  • 5. 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:]
  • 6. print c This code will output the string formed by the first character of miserable and the last four characters of flimsy: mimsy 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=HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntpu tHumptyDumptyinhisplaceagain. a=22 b=27 c=97 d=102 x=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.
  • 7. print c This code will output the string formed by the first character of miserable and the last four characters of flimsy: mimsy 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=HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntpu tHumptyDumptyinhisplaceagain. a=22 b=27 c=97 d=102 x=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.