Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein More on Classes, Biopython.

Slides:



Advertisements
Similar presentations
Credit hours: 4 Contact hours: 50 (30 Theory, 20 Lab) Prerequisite: TB143 Introduction to Personal Computers.
Advertisements

Exception Handling Genome 559. Review - classes 1) Class constructors - class myClass: def __init__(self, arg1, arg2): self.var1 = arg1 self.var2 = arg2.
Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein Classes and Objects Object Oriented Programming.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 28 Classes and Methods 6/17/09 Python Mini-Course: Lesson 28 1.
Chapter 1 - VB 2008 by Schneider1 Chapter 1 - An Introduction to Computers and Problem Solving 1.1 An Introduction to Computers 1.2 Windows, Folders, and.
Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein Classes and Objects Object Oriented Programming.
BioPython Tutorial Joe Steele Ishwor Thapa. BioPython home page ial.html.
HCS806 “Methods in Horticulture and Crop Science” Introduction to methods in Bioinformatics for plant science. David Francis (Coordinator) Ian Holford.
CS 1400 Course Reader Introduction. What is Programming? Designing an appropriate algorithm Coding that algorithm in a computer language.
Bioinformatics at WSU Matt Settles Bioinformatics Core Washington State University Wednesday, April 23, 2008 WSU Linux User Group (LUG)‏
Introduction To System Analysis and Design
Chapter 1 Program Design
Computer Skills Preparatory Year Presented by: L.Obead Alhadreti.
Introduction to Computers and Programming
BioPerl. cpan Open a terminal and type /bin/su - start "cpan", accept all defaults install Bio::Graphics.
Classes 2 COMPSCI 105 S Principles of Computer Science.
Group practice in problem design and problem solving
Public Resources (II) – Analysis tools  Web-based analysis tools – easy to use, but often with less customization options.  Stand-alone analysis tools.
COSC 1306—COMPUTER SCIENCE AND PROGRAMMING DATA ABSTRACTION Jehan-François Pâris
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Introduction to Computational Thinking Vicky Chen.
MODELLER hands-on Ben Webb, Sali Lab, UC San Francisco Maya Topf, Birkbeck College, London.
Introduction to Python
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
BioPython Workshop Gershon Celniker Tel Aviv University.
Public Resources for Bioinformatics Databases : how to find relevant information. Analysis Tools.
Introduction to Computational Linguistics Programming I.
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
COMP 171: Principles of Computer Science I John Barr.
CSE 548 Advanced Computer Network Security Document Search in MobiCloud using Hadoop Framework Sayan Cole Jaya Chakladar Group No: 1.
Introduction To System Analysis and Design
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Cohesion and Coupling CS 4311
Cs413_design04.ppt Design and Software Development Design : to create a functional interface that has high usability Development : an organized approach.
Python 의 소개 노한성. Python 이란 ? 간단하고 쉽고 빠른 문법 풍부한 확장 모듈 –(e.g. biopython, numpy) 대화형 언어 – 바로 실행, 테스트 과정 단축, 컴파일 필요 없음 높은 확장성 – 접착제 언어 (Glue Language):
Object Oriented Programming Elhanan Borenstein Lecture #10 copyrights © Elhanan Borenstein.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Classes COMPSCI 105 SS 2015 Principles of Computer Science.
Bioinformatics for biologists Dr. Habil Zare, PhD PI of Oncinfo Lab Assistant Professor, Department of Computer Science Texas State University Presented.
1 Essential Computing for Bioinformatics Bienvenido Vélez UPR Mayaguez Lecture 3 High-level Programming with Python Part III: Files and Directories Reference:
Week 1 Lecture 1 Slide 1 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton CP2028 Visual Basic Programming 2 v Week.
Software. Introduction n A computer can’t do anything without a program of instructions. n A program is a set of instructions a computer carries out.
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
MARC: Developing Bioinformatics Programs Alex Ropelewski PSC-NRBSC Bienvenido Vélez UPR Mayaguez Essential BioPython Manipulating Sequences with Seq 1.
PROTEIN IDENTIFIER IAN ROBERTS JOSEPH INFANTI NICOLE FERRARO.
Biopython 1. What is Biopython? tools for computational molecular biology to program in python and want to make it as easy as possible to use python for.
Getting Started With Python Brendan Routledge
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
CSC 231: Introduction to Data Structures Python and Objects – Day 3 Dr. Curry Guinn.
MARC: Developing Bioinformatics Programs Alex Ropelewski PSC-NRBSC Bienvenido Vélez UPR Mayaguez Essential BioPython: Overview 1.
BioPython Download & Installation Documentation
Example: Vehicles What attributes do objects of Sedan have?
1-1 Logic and Syntax A computer program is a solution to a problem.
Variables, Expressions, and IO
Object-Orientated Programming
Introduction to Object-Oriented Programming (OOP)
BioPython Download & Installation Documentation
An Introduction to Visual Basic .NET and Program Design
Topics Introduction to File Input and Output
Programming Right from the Start with Visual Basic .NET 1/e
Introduction to Object-Oriented Programming (OOP)
Python.
More to Learn Viewing file details
Topics Introduction to File Input and Output
Presentation transcript:

Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein More on Classes, Biopython

A quick review  Class inheritance class HotDate(Date): __init__(self, day, month, year, toothbrush): super(day, month, year) self.bringToothbrush = toothbrush  Exception Handling try: self.day = int(day) except ValueError: print 'Date constructor: day must be an int’  Creating your own Exception  Just inherit: exceptions.Exception

More about classes and inheritance

Consider two classes class A: def __init__(self, number): self.num = number Class B: str = “hello”

Relationships between classes  There are two basic methods through which class B can “use” class A (e.g., have access to members of A): 1.Class A has a member object of class B 2.Class A inherits class B  How do we know when to use each of these methods? Class B: str = “hello” obj_A = A(7) Class B(A): str = “hello”

The “has” vs. “is” test  If B “has” an A:  If B “is” A:  Examples:  B describes a protein, A described a domain  B describes an enzyme, A described a protein Class B: str = “hello” obj_A = A(7) Class B(A): str = “hello”

Example 1 class Date: def __init__(self, day, month): self.day = day self.mon = month def printNice(self): print self.mon, "/", self.day class Person: def __init__(self, name, DOB): self.name = name self.DOB = DOB def printNice(self): print "Name:", self.name print "DOB:", self.DOB.printNice() person_1 = Person("John", Date(22, 11)) person_1.printNice() Name: John DOB: 11 / 22

Example 2 class Date: class Person: class Student(Person): def __init__(self, name, DOB, student_id): self.ID = student_id Person.__init__(self,name,DOB) def printNice(self): Person.printNice(self) print "ID:", self.ID student_1 = Student("John", Date(22, 11),32353) student_1.printNice() Name: John DOB: 11 / 22 ID: 32353

Multiple inheritance  A class can inherit from more than one class …  A good way to create a very powerful class by inheriting multiple capabilities class DerivedClassName(Base1, Base2, Base3):.

Beware of diamonds … class Person: class Student(Person): class TA(Person): Class StudentTA(Student,TA)  This should work, right?  What’s interesting about this case?

A very (very very) short introduction to Biopython

Biopython  Biopython is a tool kit, not a program – a set of Python modules useful in bioinformatics  Features include:  Sequence class (can transcribe, translate, invert, etc)  Parsing files in different database formats  Interfaces to progs/DBs like Blast, Entrez, PubMed  Code for handling alignments of sequences  Clustering algorithms, etc, etc.  Useful tutorials at

Making Biopython run on your computer  Runs on Windows, MaxOSX, and Linux  Go to  Look for download/install instructions  May require “Admin” privileges

Example: sequence class  Hold the sequence string and an associated alphabet >>> from Bio.Seq import Seq # seq class >>> myseq = Seq("AGTACACTGGT") >>> myseq.alphabet Alphabet() >>> myseq.tostring() ‘AGTACACTGGT’

Example: sequence class, cont’  More functionality than a plain string >>> myseq Seq('AGTACACTGGT', Alphabet()) >>> myseq.complement() Seq('TCATGTGACCA', Alphabet()) >>> myseq.reverse_complement() Seq('ACCAGTGTACT', Alphabet())

Biopython and Blast  Biopython can run Blast!  Either locally or over net  Save results  Parse and analyze results

(get used to reading software documentation)

Sample problem #1  In addition to the class Date you implemented last week, implement the following classes:  Time() – this class should maintain information about the time of the day (hour and minutes)  Meeting() – this class will be used to handle a meeting time slot (date, start time and end time).  Create an object of the class meeting (providing date, start and end time), and call its print method.  Note: What should be the relationships between these 3 classes?

class Date: def __init__(self, day, month): self.day = day self.month = month def __str__(self) : return '%s' % self.day+"/"+'%s' % self.month class Time: def __init__(self, hour, minutes): self.H = hour self.M = minutes def __str__(self) : return '%s' % self.H+":"+'%s' % self.M class Meeting: def __init__(self, m_date, m_start, m_end): self.date = m_date self.start = m_start self.end = m_end def printNice(self) : print "Meeting on", self.date, "from", self.start, "to", self.end my_class = Meeting(Date(3,3), Time(3,30), Time(4,50)) my_class.printNice() Solution #1 Meeting on 3/3 from 3:30 to 4:50

Sample problem #2  Now, implement the class GroupMeeting that will be used to handle meetings of group of people. In addition to the details required for a Meeting class, this class should also store (and initialize and print) the names of the people that are to attend the meeting.

class Date: class Time: class Meeting: class GroupMeeting(Meeting): def __init__(self, m_date, m_start, m_end, people_list): Meeting.__init__(self, m_date, m_start, m_end) self.group = people_list def printNice(self) : Meeting.printNice(self) print "The following people should attend:", self.group g_meeting = GroupMeeting(Date(3,3),Time(3,30),Time(4,50),["Elhanan","Jim"]) g_meeting.printNice() Solution #2 Meeting on 3/3 from 3:30 to 4:50 The following people should attend: ["Elhanan","Jim"]

Challenge Problem 1.Think which classes you would implement to model a neural network. What data should they hold? What methods should they provide. 2.Implement these classes and build the simple XOR network we described in class. 3.Make sure to implement the “run” function that gets the values of all the input nodes and return the calculated output value. Make sure your network indeed calculates the XOR function.