Ebooks File Python For Bioinformatics, Second Edition Sebastian Bassi All Chapters
Ebooks File Python For Bioinformatics, Second Edition Sebastian Bassi All Chapters
com
https://textbookfull.com/product/python-for-
bioinformatics-second-edition-sebastian-bassi/
https://textbookfull.com/product/mastering-python-for-bioinformatics-
ken-youens-clark/
textbookfull.com
https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-loucas/
textbookfull.com
https://textbookfull.com/product/bioinformatics-algorithms-design-and-
implementation-in-python-1st-edition-miguel-rocha/
textbookfull.com
https://textbookfull.com/product/the-science-of-nutrition-5e-janice-l-
thompson/
textbookfull.com
Trusted By The Highlander A Scottish Time Travel Romance
Highlander Forever Book 8 1st Edition Rebecca Preston
https://textbookfull.com/product/trusted-by-the-highlander-a-scottish-
time-travel-romance-highlander-forever-book-8-1st-edition-rebecca-
preston/
textbookfull.com
https://textbookfull.com/product/mastercam-2018-lathe-training-
tutorial-1st-edition-mariana-lendel/
textbookfull.com
https://textbookfull.com/product/women-vs-feminism-why-we-all-need-
liberating-from-the-gender-wars-first-edition-williams/
textbookfull.com
https://textbookfull.com/product/elementary-linear-algebra-metric-
version-eighth-edition-ron-larson/
textbookfull.com
Series Editors
N. F. Britton
Department of Mathematical Sciences
University of Bath
Xihong Lin
Department of Biostatistics
Harvard University
Nicola Mulder
University of Cape Town
South Africa
Mona Singh
Department of Computer Science
Princeton University
Anna Tramontano
Department of Physics
University of Rome La Sapienza
Proposals for the series should be submitted to one of the series editors above or directly to:
CRC Press, Taylor & Francis Group
3 Park Square, Milton Park
Abingdon, Oxfordshire OX14 4RN
UK
Published Titles
An Introduction to Systems Biology: Statistical Methods for QTL Mapping
Design Principles of Biological Circuits Zehua Chen
Uri Alon An Introduction to Physical Oncology:
Glycome Informatics: Methods and How Mechanistic Mathematical
Applications Modeling Can Improve Cancer Therapy
Kiyoko F. Aoki-Kinoshita Outcomes
Computational Systems Biology of Vittorio Cristini, Eugene J. Koay,
Cancer and Zhihui Wang
Emmanuel Barillot, Laurence Calzone, Normal Mode Analysis: Theory and
Philippe Hupé, Jean-Philippe Vert, and Applications to Biological and Chemical
Andrei Zinovyev Systems
Python for Bioinformatics, Second Edition Qiang Cui and Ivet Bahar
Sebastian Bassi Kinetic Modelling in Systems Biology
Quantitative Biology: From Molecular to Oleg Demin and Igor Goryanin
Cellular Systems Data Analysis Tools for DNA Microarrays
Sebastian Bassi Sorin Draghici
Methods in Medical Informatics: Statistics and Data Analysis for
Fundamentals of Healthcare Microarrays Using R and Bioconductor,
Programming in Perl, Python, and Ruby Second Edition
Jules J. Berman Sorin Drăghici
Chromatin: Structure, Dynamics, Computational Neuroscience:
Regulation A Comprehensive Approach
Ralf Blossey Jianfeng Feng
Computational Biology: A Statistical Biological Sequence Analysis Using
Mechanics Perspective the SeqAn C++ Library
Ralf Blossey Andreas Gogol-Döring and Knut Reinert
Game-Theoretical Models in Biology Gene Expression Studies Using
Mark Broom and Jan Rychtář Affymetrix Microarrays
Computational and Visualization Hinrich Göhlmann and Willem Talloen
Techniques for Structural Bioinformatics Handbook of Hidden Markov Models
Using Chimera in Bioinformatics
Forbes J. Burkowski Martin Gollery
Structural Bioinformatics: An Algorithmic Meta-analysis and Combining
Approach Information in Genetics and Genomics
Forbes J. Burkowski Rudy Guerra and Darlene R. Goldstein
Spatial Ecology Differential Equations and Mathematical
Stephen Cantrell, Chris Cosner, and Biology, Second Edition
Shigui Ruan D.S. Jones, M.J. Plank, and B.D. Sleeman
Cell Mechanics: From Single Scale- Knowledge Discovery in Proteomics
Based Models to Multiscale Modeling Igor Jurisica and Dennis Wigle
Arnaud Chauvière, Luigi Preziosi, Introduction to Proteins: Structure,
and Claude Verdier Function, and Motion
Bayesian Phylogenetics: Methods, Amit Kessel and Nir Ben-Tal
Algorithms, and Applications
Ming-Hui Chen, Lynn Kuo, and Paul O. Lewis
Published Titles (continued)
RNA-seq Data Analysis: A Practical Introduction to Bio-Ontologies
Approach Peter N. Robinson and Sebastian Bauer
Eija Korpelainen, Jarno Tuimala, Dynamics of Biological Systems
Panu Somervuo, Mikael Huss, and Garry Wong Michael Small
Introduction to Mathematical Oncology Genome Annotation
Yang Kuang, John D. Nagy, and Jung Soh, Paul M.K. Gordon, and
Steffen E. Eikenberry Christoph W. Sensen
Biological Computation Niche Modeling: Predictions from
Ehud Lamm and Ron Unger Statistical Distributions
Optimal Control Applied to Biological David Stockwell
Models Algorithms for Next-Generation
Suzanne Lenhart and John T. Workman Sequencing
Clustering in Bioinformatics and Drug Wing-Kin Sung
Discovery Algorithms in Bioinformatics: A Practical
John D. MacCuish and Norah E. MacCuish Introduction
Spatiotemporal Patterns in Ecology Wing-Kin Sung
and Epidemiology: Theory, Models, Introduction to Bioinformatics
and Simulation Anna Tramontano
Horst Malchow, Sergei V. Petrovskii, and
The Ten Most Wanted Solutions in
Ezio Venturino
Protein Bioinformatics
Stochastic Dynamics for Systems Anna Tramontano
Biology
Combinatorial Pattern Matching
Christian Mazza and Michel Benaïm
Algorithms in Computational Biology
Statistical Modeling and Machine Using Perl and R
Learning for Molecular Biology Gabriel Valiente
Alan M. Moses
Managing Your Biological Data with
Engineering Genetic Circuits Python
Chris J. Myers Allegra Via, Kristian Rother, and
Pattern Discovery in Bioinformatics: Anna Tramontano
Theory & Algorithms Cancer Systems Biology
Laxmi Parida Edwin Wang
Exactly Solvable Models of Biological Stochastic Modelling for Systems
Invasion Biology, Second Edition
Sergei V. Petrovskii and Bai-Lian Li Darren J. Wilkinson
Computational Hydrodynamics of Big Data Analysis for Bioinformatics and
Capsules and Biological Cells Biomedical Discoveries
C. Pozrikidis Shui Qing Ye
Modeling and Simulation of Capsules Bioinformatics: A Practical Approach
and Biological Cells Shui Qing Ye
C. Pozrikidis
Introduction to Computational
Cancer Modelling and Simulation Proteomics
Luigi Preziosi Golan Yona
PYTHON FOR
BIOINFORMATICS
SECOND EDITION
SEBASTIAN BASSI
MATLAB• is a trademark of The MathWorks, Inc. and is used with permission. The MathWorks does not warrant the
accuracy of the text or exercises in this book. This book’s use or discussion of MATLAB • software or related products
does not constitute endorsement or sponsorship by The MathWorks of a particular pedagogical approach or particular
use of the MATLAB• software.
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been
made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity
of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright
holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this
form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may
rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized
in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying,
microfilming, and recording, or in any information storage or retrieval system, without written permission from the
publishers.
For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://
www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923,
978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For
organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for
identification and explanation without intent to infringe.
Acknowledgments xxix
Section I Programming
Chapter 1 Introduction 3
1.1 WHO SHOULD READ THIS BOOK 3
1.1.1 What the Reader Should Already Know 4
1.2 USING THIS BOOK 4
1.2.1 Typographical Conventions 4
1.2.2 Python Versions 5
1.2.3 Code Style 5
1.2.4 Get the Most from This Book without Reading It All 6
1.2.5 Online Resources Related to This Book 7
1.3 WHY LEARN TO PROGRAM? 7
1.4 BASIC PROGRAMMING CONCEPTS 8
1.4.1 What Is a Program? 8
1.5 WHY PYTHON? 10
1.5.1 Main Features of Python 10
1.5.2 Comparing Python with Other Languages 11
1.5.3 How Is It Used? 14
1.5.4 Who Uses Python? 15
1.5.5 Flavors of Python 15
1.5.6 Special Python Distributions 16
1.6 ADDITIONAL RESOURCES 17
vii
viii Contents
Section IV Appendices
Index 417
List of Figures
3.1 Intersection. 60
3.2 Union. 61
3.3 Difference. 61
3.4 Symmetric difference. 62
3.5 Case 1. 65
3.6 Case 2. 66
xvii
xviii LIST OF FIGURES
22.1 Product of Listing 22.2, using the demo dataset (NODBDEMO). 356
xxi
Preface to the First Edition
This book is a result of the experience accumulated during several years of working
for an agricultural biotechnology company. As a genomic database curator, I gave
support to staff scientists with a broad range of bioinformatics needs. Some of them
just wanted to automate the same procedure they were already doing by hand, while
others would come to me with biological problems to ask if there were bioinformat-
ics solutions. Most cases had one thing in common: Programming knowledge was
necessary for finding a solution to the problem. The main purpose of this book is to
help those scientists who want to solve their biological problems by helping them
to understand the basics of programming. To this end, I have attempted to avoid
taking for granted any programming-related concepts. The chosen language for this
task is Python.
Python is an easy-to-learn computer language that is gaining traction among
scientists. This is likely because it is easy to use, yet powerful enough to accomplish
most programming goals. With Python the reader can start doing real programming
very quickly. Journals such as Computing in Science and Engineering, Briefings
in Bioinformatics, and PLOS Computational Biology have published introductory
articles about Python. Scientists are using Python for molecular visualization, ge-
nomic annotation, data manipulation, and countless other applications.
In the particular case of the life sciences, the development of Python has been
very important; the best exponent is the Biopython package. For this reason, Section
II is devoted to Biopython. Anyhow, I don’t claim that Biopython is the solution to
every biology problem in the world. Sometimes a simple custom-made solution may
better fit the problem at hand. There are other packages like BioNEB and CoreBio
that the reader may want to try.
The book begins from the very basic, with Section I (“Programming”), teaching
the reader the principles of programming. From the very beginning, I place a special
emphasis on practice, since I believe that programming is something that is best
learned by doing. That is why there are code fragments spread over the book. The
reader is expected to experiment with them, and attempt to internalize them. There
are also some spare comparisons with other languages; they are included only when
doing so enlightens the current topic. I believe that most language comparisons do
more harm than good when teaching a new language. They introduce information
that is incomprehensible and irrelevant for most readers.
In an attempt to keep the interest of the reader, most examples are somehow
related to biology. In spite of that, these examples can be followed even if the reader
doesn’t have any specific knowledge in that field.
To reinforce the practical nature of this book, and also to use as reference
xxiii
xxiv Preface to the First Edition
Eräs uutinen.
Ratsastajat pysähtyivät.
"Isä sai kirjeen noin tunti sitten", kertoi Olga ihastuneena. "Nick
tulee kotiin! Nick tulee kotiin! Etkö olekin iloinen, Muriel? En ole ollut
näin onnellinen vielä milloinkaan."
Blaken lupaus.
"En tiennyt, että olin niin kiintynyt tähän paikkaan", sanoi hän.
"Eikö olekin ihmeellistä? Olen tosiaankin ollut onnellinen täällä,
vaikka en ole sitä ennen ymmärtänyt."
Muriel huoahti:
"En minä aina ajattele tällä tavoin", sanoi hän. "Pelästyin kovin,
kun kuulin Nick'in tulevan kotiin. Mutta kai minä vähitellen totun
siihen ajatukseen. Älkää enää muistelko sanojani. Ehkäpä viisastun
vuosien kuluessa."
Muriel yritti nauraa, mutta ei voinut.
"Muriel, minun on niin vaikea puhua. Minä voin vain iskeä suoraan
asiaan. Te tarvitsette jonkun, joka teitä suojelee! Ettekö soisi minun
rupeavan sellaiseksi? Tahdotteko, antautua minun hoivaani?"
"Tule siis turviini, Muriel", sanoi hän hellästi. "Minä lupaan olla
turvanasi, niin että ei kenkään saa sinua pelottaa."
Sama hirveä pelko valtasi hänet taasen kuin silloinkin, sama raju
pakenemisen halu heräsi hänessä ja hän painautui nyyhkien Grangen
rintaa vasten.
Serkut.
Grange katseli kauan hänen peräänsä. Kun hän sitten meni Daisyn
luo, oli hymy kadonnut hänen huuliltaan.
"Olet oikeassa, Daisy", sanoi hän. "Tätä asiaa emme voi sinulta
salata."
"Mutta, Blake", sanoi hän sitten, "se ei ole oikein. Hän kuului
Nick'ille jo kauan ennen, kuin sinä häntä ajattelitkaan. En olisi
uskonut, että sinä käyttäytyisit tällä tavoin ja asettuisit Nick'in tielle,
juuri kun häntä odotetaan kotiin saapuvaksi. Miten se on
mahdollista? Se ei suinkaan vielä ole päätetty asia, vai miten,
Blake?"
Grange ei enää karttanut hänen katsettaan. Hän oli varman ja
samalla suuttuneen näköinen.
"En ole tehnyt mitään sellaista, jota minun tulisi hävetä", sanoi
hän lyhyesti. "Olen kosinut häntä ja hän on suostunut. Mitä Nick
Ratcliffeen tulee, niin on hän mielestäni käyttänyt väärin asemaansa
Murieliin nähden. Muriel vihaa ja inhoaa häntä. Nick on varmaan
hänet pelottanut. Hänellä ei ole mitään sananvaltaa Murielin
suhteen."
"Kerrohan minulle", jatkoi Daisy, "mistä johtui, että kosit häntä niin
odottamatta? Rakastatko häntä paljonkin?"
"Olet aivan oikeassa", vastasi Blake heti. "En ollut kyllin hyvä
sinullekaan, mutta olipa sentään aika, jolloin sinulle kelpasin."
Daisyn lapsi.
Muriel nousi hiljaa tulta kohentamaan. Hän tunsi, ettei enää voinut
katsoa Daisya, joka yhä tuuditti kuollutta lastaan sylissään, siksi
meni hän, yhä yöpuvussaan, ruokasaliin ja asettui akkunan luo
odottamaan lääkäriä.
Siinä kaikki, mitä hän sanoi, mutta nuo sanat tunkivat suoraan
Murielin sydämeen. Hän vapisi ne kuullessaan. Tuntui, kuin olisi Nick
ne sanat lausunut.
Eräs sähkösanoma.
"Älä lainkaan välitä minusta. Tee vain työsi valmiiksi", sanoi tulija.
"Ethän vain kuvittele, että tein sen sinun tähtesi?" sanoi hän. "En
voinut matkustaa yhtä mittaa rannikolle asti, ymmärrätkö? Siksi
poikkesin tänne."
Will nauroi.
"Voit ainakin sanoa Daisylle, että teen työtä kuin orja hänen ja
pojan hyväksi", sanoi hän. "Pahinta on, että poika on niin heikko,
kirjoittaa Daisy."
"Viime syksynäkö?"
"Sinä et tule elämään täällä koko ikääsi", sanoi Nick. "Sinä olet
edistysihminen, ystäväni. Mutta katsoppas, tuolla kuistilla seisoo
palveliasi. Meneppäs kysymään, mitä asiaa hänellä on."
Will meni kuistille ja Nick näki palvelijan ojentavan hänelle jotakin
pienellä tarjottimella. Sitten katosi Will näkyvistä mennen luultavasti
pöydän ääreen, jolla lamppu oli. Oli aivan hiljaista, sakaalin ulvonta
vain kuului jostakin kaukaa.
Nick kuuli paperin rapinaa ja sitten oli kaikki taasen hiljaa. Lopulta
hermostui hän ja huusi:
Pöydän ääressä oli Will polvillaan pää käsiin nojaten. Koko hänen
olentonsa ilmasi syvää toivottomuutta. Hän oli aivan hiljaa, olkapäät
vain nytkähtelivät. Toisessa kädessä piti hän rypistynyttä paperia.
"En sitä usko", vastasi Will syvään huoaten. "Hän ei tule enää
milloinkaan minun luokseni, sen tiedän."
"Älä ole noin lapsekas. Tietysti hän tulee. Jos sinä sitä toivot, niin
hän tulee."
Tulevaisuustuumia.
Aluksi ei hän tietänyt, voisiko luottaa Murieliin, mutta siitä sai hän
piankin varmuuden. Unohtaen kokonaan itsensä tuo nuori tyttö
osoitti suurta uhrautuvaisuutta ja itsensä hillitsemistä.
Vapaaehtoisesti asettautui hän Daisyn vuoteen ääreen ja oli
tohtorille yhtä suureksi avuksi, kuin varsinainen sairaanhoitajatar.
Daisy ei puhunut paljon, mutta hän tunsi kuin lohtua Murielin
läsnäolosta ja siten heidän ystävyytensä yhä lujittuivat.
"Sinä et saa alituisesti olla minun luonani", sanoi hän. "Olen ollut
niin itsekäs. Mene hänen luokseen Muriel, sillä hän on varmaankin
ikävissään. On parempi teille kummallekin, että olette enemmän
toistenne seurassa. Minäkin koetan tulla ulos huomenna, jos tohtori
sen sallii. Tänäänhän on hockey-päivä, eikö olekin? Mene Blaken
kanssa hockey-kentälle."