Bioinformatics Programming Using Python

Book description

Powerful, flexible, and easy to use, Python is an ideal language for building software tools and applications for life science research and development. This unique book shows you how to program with Python, using code examples taken directly from bioinformatics. In a short time, you'll be using sophisticated techniques and Python modules that are particularly effective for bioinformatics programming.

Bioinformatics Programming Using Python is perfect for anyone involved with bioinformatics -- researchers, support staff, students, and software developers interested in writing bioinformatics applications. You'll find it useful whether you already use Python, write code in another language, or have no programming experience at all. It's an excellent self-instruction tool, as well as a handy reference when facing the challenges of real-life programming tasks.

  • Become familiar with Python's fundamentals, including ways to develop simple applications
  • Learn how to use Python modules for pattern matching, structured text processing, online data retrieval, and database access
  • Discover generalized patterns that cover a large proportion of how Python code is used in bioinformatics
  • Learn how to apply the principles and techniques of object-oriented programming
  • Benefit from the "tips and traps" section in each chapter

Publisher resources

View/Submit Errata

Table of contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. Introduction
      1. About This Book
      2. About Bioinformatics
      3. About the Reader
    2. Python
      1. Some Context
      2. The Python Language
      3. Installing Python
      4. Running Python
    3. Notes
      1. Reading and Reference Recommendations
      2. Example Code
      3. Unfortunate and Unavoidable Vocabulary Overlap
      4. Comments
    4. Conventions Used in This Book
    5. We’d Like to Hear from You
    6. Using Code Examples
    7. Safari® Books Online
    8. Acknowledgments
  3. 1. Primitives
    1. Simple Values
      1. Booleans
      2. Integers
      3. Floats
      4. Strings
    2. Expressions
      1. Numeric Operators
      2. Logical Operations
      3. String Operations
        1. String operators
        2. Subscription
        3. Slicing
      4. Calls
        1. Function calls
        2. Method calls
      5. Compound Expressions
    3. Tips, Traps, and Tracebacks
      1. Tips
        1. Statements and expressions
        2. Running Python interactively
      2. Traps
      3. Tracebacks
  4. 2. Names, Functions, and Modules
    1. Assigning Names
    2. Defining Functions
      1. Function Parameters
      2. Comments and Documentation
      3. Assertions
      4. Default Parameter Values
    3. Using Modules
      1. Importing
        1. Module namespaces
        2. The random module
      2. Python Files
    4. Tips, Traps, and Tracebacks
      1. Tips
        1. Names
        2. Function definitions
        3. Executing code
        4. Using IDLE
        5. Managing Python files
      2. Traps
      3. Tracebacks
  5. 3. Collections
    1. Sets
    2. Sequences
      1. Strings, Bytes, and Bytearrays
        1. Creating
        2. Testing
        3. Searching
        4. Replacing
        5. Changing case
        6. Reformatting
        7. The format method and function
      2. Ranges
      3. Tuples
        1. Tuple syntax
        2. Tuple packing and unpacking
      4. Lists
        1. Statements that modify lists
        2. List modification methods
        3. Sequence-oriented string methods
    3. Mappings
      1. Dictionaries
        1. Dictionary example: RNA codon translation table
        2. Dictionary operations
        3. Dictionary methods
    4. Streams
      1. Files
        1. Creating file objects
        2. File methods
        3. Example
      2. Generators
    5. Collection-Related Expression Features
      1. Comprehensions
        1. List comprehensions
        2. Set and dictionary comprehensions
        3. Generator expressions
        4. Conditional comprehensions
        5. Nested comprehensions
      2. Functional Parameters
        1. The parameter “key”
        2. Function objects
        3. Anonymous functions
    6. Tips, Traps, and Tracebacks
      1. Tips
        1. Language features
        2. Developing and testing code
      2. Traps
      3. Tracebacks
  6. 4. Control Statements
    1. Conditionals
    2. Loops
      1. Simple Loop Examples
      2. Initialization of Loop Values
      3. Looping Forever
      4. Loops with Guard Conditions
    3. Iterations
      1. Iteration Statements
      2. Kinds of Iterations
        1. Do
        2. Collect
        3. Combine
        4. Search
        5. Filter
        6. Nested iterations
        7. Recursive iterations
    4. Exception Handlers
      1. Python Errors
        1. Tracebacks
        2. Runtime errors
      2. Exception Handling Statements
        1. Optional features of exception handling statements
        2. Exception handling and generator objects
      3. Raising Exceptions
        1. The raise statement
        2. Raising an exception to end a loop
    5. Extended Examples
      1. Extracting Information from an HTML File
      2. The Grand Unified Bioinformatics File Parser
        1. Reading the sequences in a FASTA file
        2. Generalized parsing
      3. Parsing GenBank Files
      4. Translating RNA Sequences
        1. Step 1
        2. Step 2
        3. Step 3
        4. Step 4
        5. Step 5
      5. Constructing a Table from a Text File
        1. Step 1
        2. Step 2
        3. Step 3
        4. Step 4
        5. Step 5
    6. Tips, Traps, and Tracebacks
      1. Tips
      2. Traps
      3. Tracebacks
  7. 5. Classes
    1. Defining Classes
      1. Instance Attributes
        1. Access methods
        2. Predicate methods
        3. Initialization methods
        4. String methods
        5. Modification methods
        6. Action methods
        7. Support methods
        8. Summary
      2. Class Attributes
        1. Class fields
        2. Class methods
        3. Classes as objects
    2. Class and Method Relationships
      1. Decomposition
        1. Class decomposition
        2. Method decomposition
        3. Singleton classes
      2. Inheritance
        1. Defining subclasses
        2. Factoring out common code
        3. Generalization
        4. Subclass methods
    3. Tips, Traps, and Tracebacks
      1. Tips
      2. Traps
      3. Tracebacks
  8. 6. Utilities
    1. System Environment
      1. Dates and Times: datetime
        1. Classes
        2. Instance creation
        3. Operations
        4. Methods
      2. System Information
        1. The Python runtime environment: sys
        2. The system clock: time
      3. Command-Line Utilities
        1. Reading multiple files: fileinput
        2. Command-line options: optparse
        3. Command-line commands: subprocess
      4. Communications
        1. Sending email: smtplib
        2. Logging: logging
    2. The Filesystem
      1. Operating System Interface: os
        1. Environment access
        2. Managing files and directories
          1. Directories
          2. Files
          3. Directory contents
        3. Temporary files: tempfile
      2. Manipulating Paths: os.path
        1. Path components
        2. Path manipulations
        3. Path information
      3. Filename Expansion: fnmatch and glob
        1. fnmatch
        2. glob
      4. Shell Utilities: shutil
      5. Comparing Files and Directories
        1. File and directory comparison: filecmp
        2. Showing the differences between two files: difflib
    3. Working with Text
      1. Formatting Blocks of Text: textwrap
      2. String Utilities: string
      3. Comma- and Tab-Separated Formats: csv
      4. String-Based Reading and Writing: io
    4. Persistent Storage
      1. Persistent Text: dbm
      2. Persistent Objects: pickle
      3. Keyed Persistent Object Storage: shelve
      4. Debugging Tools
        1. The Python debugger: pdb
        2. The IDLE debugger
    5. Tips, Traps, and Tracebacks
      1. Tips
      2. Traps
      3. Tracebacks
  9. 7. Pattern Matching
    1. Fundamental Syntax
      1. Fixed-Length Matching
        1. Literal matches
        2. Character sets
        3. Character classes
        4. Boundaries
      2. Variable-Length Matching
        1. Repetition
      3. Greedy Versus Nongreedy Matching
      4. Grouping and Disjunction
    2. The Actions of the re Module
      1. Functions
      2. Flags
      3. Methods
    3. Results of re Functions and Methods
      1. Match Object Fields
      2. Match Object Methods
    4. Putting It All Together: Examples
      1. Some Quick Examples
        1. Using regular expressions to ignore case
        2. Listing files in a directory, excluding some
        3. Finding open reading frames
      2. Extracting Descriptions from Sequence Files
      3. Extracting Entries From Sequence Files
        1. Using regular expressions to extract entries
        2. Keeping track of the position between calls
        3. Buffering input
    5. Tips, Traps, and Tracebacks
      1. Tips
      2. Traps
      3. Tracebacks
  10. 8. Structured Text
    1. HTML
      1. Simple HTML Processing
        1. Searching HTML text
        2. More elaborate HTML pattern matching
        3. Turning HTML into plain text
      2. Structured HTML Processing
        1. Problems with HTML pattern matching
        2. Structured HTML parsing: html.parser
    2. XML
      1. The Nature of XML
      2. An XML File for a Complete Genome
      3. The ElementTree Module
        1. Getting started with ElementTree
        2. Navigating around an ElementTree
      4. Event-Based Processing
        1. Function calls, exceptions, and the call stack
        2. Callbacks: Reversed function calls
        3. Programming for an event-based processor
      5. expat
        1. Obtaining a single piece of information
        2. Extracting a few pieces of data
        3. Getting the content of all tags with a specified name
    3. Tips, Traps, and Tracebacks
      1. Tips
      2. Traps
      3. Tracebacks
  11. 9. Web Programming
    1. Manipulating URLs: urllib.parse
      1. Disassembling URLs
      2. Assembling URLs
    2. Opening Web Pages: webbrowser
      1. Module Functions
      2. Constructing and Submitting Queries
      3. Constructing and Viewing an HTML Page
    3. Web Clients
      1. Making the URLs in a Response Absolute
      2. Constructing an HTML Page of Extracted Links
      3. Downloading a Web Page’s Linked Files
    4. Web Servers
      1. Sockets and Servers
        1. Server fundamentals
        2. Running a server: The http.server module
      2. CGI
        1. Serving CGI requests
        2. Setting up CGI
        3. CGI script arguments and responses
      3. Simple Web Applications
        1. Using CGI scripts
        2. HTML forms with CGI scripts
    5. Tips, Traps, and Tracebacks
      1. Tips
        1. Web pages
        2. Debugging CGI scripts
        3. HTTP servers
      2. Traps
      3. Tracebacks
  12. 10. Relational Databases
    1. Representation in Relational Databases
      1. Database Tables
        1. Avoiding duplication of values
        2. Representation of relationships
        3. Database definition
      2. A Restriction Enzyme Database
        1. The data
        2. Reading the data
        3. A schema for the Rebase database
    2. Using Relational Data
      1. SQL Basics
        1. Using the sqlite3 module
        2. Connecting to the database
        3. Creating the database
        4. Loading data into tables
      2. SQL Queries
        1. Simple database queries
        2. Qualified database queries
        3. Relationship queries
      3. Querying the Database from a Web Page
        1. HTML frames
        2. An HTML page of query forms
    3. Tips, Traps, and Tracebacks
      1. Tips
      2. Traps
      3. Tracebacks
  13. 11. Structured Graphics
    1. Introduction to Graphics Programming
      1. Concepts
        1. Coordinate system
        2. Components
        3. Properties
      2. GUI Toolkits
        1. GUI toolkits for Python
        2. Using a GUI toolkit
    2. Structured Graphics with tkinter
      1. tkinter Fundamentals
        1. The basic steps
        2. Common widget options
        3. Canvas drawing methods
        4. Writing the contents of a canvas to a PostScript file
      2. Examples
        1. An abstract class for tkinter graphics
        2. Dot plots
        3. Histograms
    3. Structured Graphics with SVG
      1. SVG File Contents
        1. SVG tags
        2. SVG styles
      2. Examples
        1. Histograms of codon use
        2. Sequencing trace file curves using SVG
    4. Tips, Traps, and Tracebacks
      1. Tips
      2. Traps
        1. SVG traps
      3. Tracebacks
  14. A. Python Language Summary
    1. Language Components
      1. Special Syntactic Elements
      2. Keywords
      3. Special Names
      4. Operators
      5. Anonymous Functions
    2. Types and Expressions
    3. Statements
    4. Notes
  15. B. Collection Type Summary
    1. Types and General Operations
      1. Common Operations
      2. Creating Collections
    2. Specific Collection Types
      1. Sets
      2. Sequences
        1. Strings
        2. Lists
      3. Mappings
      4. Streams
        1. File objects
        2. Generators
    3. Iteration Templates
      1. Basic Iteration Templates
      2. Filtering Templates
      3. Other Kinds of Templates
  16. Index
  17. About the Author
  18. Colophon
  19. Copyright

Product information

  • Title: Bioinformatics Programming Using Python
  • Author(s): Mitchell L Model
  • Release date: December 2009
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596154509