在好例子网,分享、交流、成长!
您当前所在位置:首页Python 开发实例Python语言基础 → Biopython Tutorial.pdf

Biopython Tutorial.pdf

Python语言基础

下载此实例
  • 开发语言:Python
  • 实例大小:3.73M
  • 下载次数:6
  • 浏览次数:116
  • 发布时间:2020-03-11
  • 实例类别:Python语言基础
  • 发 布 人:fanxuezhe
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: python Biopython

实例介绍

【实例简介】

【实例截图】

【核心代码】


Contents
1 Introduction 9
1.1 What is Biopython? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2 What can I find in the Biopython package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3 Installing Biopython . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.4 Frequently Asked Questions (FAQ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2 Quick Start – What can you do with Biopython? 15
2.1 General overview of what Biopython provides . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.2 Working with sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3 A usage example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.4 Parsing sequence file formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.4.1 Simple FASTA parsing example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.4.2 Simple GenBank parsing example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.4.3 I love parsing – please don’t stop talking about it! . . . . . . . . . . . . . . . . . . . . 18
2.5 Connecting with biological databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.6 What to do next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3 Sequence objects 20
3.1 Sequences and Alphabets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.2 Sequences act like strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.3 Slicing a sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.4 Turning Seq objects into strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.5 Concatenating or adding sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.6 Changing case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.7 Nucleotide sequences and (reverse) complements . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.8 Transcription . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.9 Translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.10 Translation Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.11 Comparing Seq objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.12 MutableSeq objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.13 UnknownSeq objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.14 Working with strings directly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4 Sequence annotation objects 35
4.1 The SeqRecord object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.2 Creating a SeqRecord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.2.1 SeqRecord objects from scratch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.2.2 SeqRecord objects from FASTA files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.2.3 SeqRecord objects from GenBank files . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.3 Feature, location and position objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1
4.3.1 SeqFeature objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.3.2 Positions and locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.3.3 Sequence described by a feature or location . . . . . . . . . . . . . . . . . . . . . . . . 43
4.4 Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.6 The format method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.7 Slicing a SeqRecord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.8 Adding SeqRecord objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.9 Reverse-complementing SeqRecord objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5 Sequence Input/Output 51
5.1 Parsing or Reading Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.1.1 Reading Sequence Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
5.1.2 Iterating over the records in a sequence file . . . . . . . . . . . . . . . . . . . . . . . . 52
5.1.3 Getting a list of the records in a sequence file . . . . . . . . . . . . . . . . . . . . . . . 53
5.1.4 Extracting data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.2 Parsing sequences from compressed files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5.3 Parsing sequences from the net . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.3.1 Parsing GenBank records from the net . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.3.2 Parsing SwissProt sequences from the net . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.4 Sequence files as Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.4.1 Sequence files as Dictionaries – In memory . . . . . . . . . . . . . . . . . . . . . . . . 59
5.4.2 Sequence files as Dictionaries – Indexed files . . . . . . . . . . . . . . . . . . . . . . . . 61
5.4.3 Sequence files as Dictionaries – Database indexed files . . . . . . . . . . . . . . . . . . 63
5.4.4 Indexing compressed files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.4.5 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.5 Writing Sequence Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
5.5.1 Round trips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.5.2 Converting between sequence file formats . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.5.3 Converting a file of sequences to their reverse complements . . . . . . . . . . . . . . . 68
5.5.4 Getting your SeqRecord objects as formatted strings . . . . . . . . . . . . . . . . . . . 69
5.6 Low level FASTA and FASTQ parsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
6 Multiple Sequence Alignment objects 71
6.1 Parsing or Reading Sequence Alignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.1.1 Single Alignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
6.1.2 Multiple Alignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
6.1.3 Ambiguous Alignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
6.2 Writing Alignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
6.2.1 Converting between sequence alignment file formats . . . . . . . . . . . . . . . . . . . 79
6.2.2 Getting your alignment objects as formatted strings . . . . . . . . . . . . . . . . . . . 81
6.3 Manipulating Alignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
6.3.1 Slicing alignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
6.3.2 Alignments as arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
6.4 Alignment Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
6.4.1 ClustalW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
6.4.2 MUSCLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
6.4.3 MUSCLE using stdout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
6.4.4 MUSCLE using stdin and stdout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
6.4.5 EMBOSS needle and water . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
6.4.6 Biopython’s pairwise2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
6.5 Pairwise sequence alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
2
6.5.1 Basic usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
6.5.2 The pairwise aligner object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
6.5.3 Match and mismatch scores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
6.5.4 Affine gap scores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
6.5.5 General gap scores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
6.5.6 Iterating over alignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
6.5.7 Alignment objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
6.5.8 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
7 BLAST 105
7.1 Running BLAST over the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
7.2 Running BLAST locally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.2.2 Standalone NCBI BLAST  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.2.3 Other versions of BLAST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
7.3 Parsing BLAST output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
7.4 The BLAST record class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
7.5 Deprecated BLAST parsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
7.5.1 Parsing plain-text BLAST output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
7.5.2 Parsing a plain-text BLAST file full of BLAST runs . . . . . . . . . . . . . . . . . . . 114
7.5.3 Finding a bad record somewhere in a huge plain-text BLAST file . . . . . . . . . . . . 115
7.6 Dealing with PSI-BLAST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
7.7 Dealing with RPS-BLAST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
8 BLAST and other sequence search tools 117
8.1 The SearchIO object model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
8.1.1 QueryResult . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
8.1.2 Hit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
8.1.3 HSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
8.1.4 HSPFragment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8.2 A note about standards and conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
8.3 Reading search output files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
8.4 Dealing with large search output files with indexing . . . . . . . . . . . . . . . . . . . . . . . 131
8.5 Writing and converting search output files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
9 Accessing NCBI’s Entrez databases 134
9.1 Entrez Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
9.2 EInfo: Obtaining information about the Entrez databases . . . . . . . . . . . . . . . . . . . . 136
9.3 ESearch: Searching the Entrez databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
9.4 EPost: Uploading a list of identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
9.5 ESummary: Retrieving summaries from primary IDs . . . . . . . . . . . . . . . . . . . . . . . 139
9.6 EFetch: Downloading full records from Entrez . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
9.7 ELink: Searching for related items in NCBI Entrez . . . . . . . . . . . . . . . . . . . . . . . . 143
9.8 EGQuery: Global Query - counts for search terms . . . . . . . . . . . . . . . . . . . . . . . . 144
9.9 ESpell: Obtaining spelling suggestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
9.10 Parsing huge Entrez XML files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
9.11 Handling errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
9.12 Specialized parsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
9.12.1 Parsing Medline records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
9.12.2 Parsing GEO records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
9.12.3 Parsing UniGene records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
9.13 Using a proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
3
9.14 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
9.14.1 PubMed and Medline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
9.14.2 Searching, downloading, and parsing Entrez Nucleotide records . . . . . . . . . . . . . 154
9.14.3 Searching, downloading, and parsing GenBank records . . . . . . . . . . . . . . . . . . 155
9.14.4 Finding the lineage of an organism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9.15 Using the history and WebEnv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
9.15.1 Searching for and downloading sequences using the history . . . . . . . . . . . . . . . 158
9.15.2 Searching for and downloading abstracts using the history . . . . . . . . . . . . . . . . 159
9.15.3 Searching for citations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
10 Swiss-Prot and ExPASy 162
10.1 Parsing Swiss-Prot files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
10.1.1 Parsing Swiss-Prot records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
10.1.2 Parsing the Swiss-Prot keyword and category list . . . . . . . . . . . . . . . . . . . . . 164
10.2 Parsing Prosite records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
10.3 Parsing Prosite documentation records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
10.4 Parsing Enzyme records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
10.5 Accessing the ExPASy server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
10.5.1 Retrieving a Swiss-Prot record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
10.5.2 Searching Swiss-Prot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
10.5.3 Retrieving Prosite and Prosite documentation records . . . . . . . . . . . . . . . . . . 169
10.6 Scanning the Prosite database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
11 Going 3D: The PDB module 172
11.1 Reading and writing crystal structure files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
11.1.1 Reading a PDB file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
11.1.2 Reading an mmCIF file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
11.1.3 Reading files in the MMTF format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
11.1.4 Reading files in the PDB XML format . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
11.1.5 Writing PDB files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
11.1.6 Writing mmCIF files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
11.2 Structure representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
11.2.1 Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
11.2.2 Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
11.2.3 Chain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
11.2.4 Residue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
11.2.5 Atom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.2.6 Extracting a specific Atom/Residue/Chain/Model from a Structure . . . . . . . . . . . 180
11.3 Disorder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
11.3.1 General approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
11.3.2 Disordered atoms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
11.3.3 Disordered residues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.4 Hetero residues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.4.1 Associated problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.4.2 Water residues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.4.3 Other hetero residues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5 Navigating through a Structure object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.6 Analyzing structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.1 Measuring distances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.2 Measuring angles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.3 Measuring torsion angles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.4 Determining atom-atom contacts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
4
11.6.5 Superimposing two structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.6 Mapping the residues of two related structures onto each other . . . . . . . . . . . . . 186
11.6.7 Calculating the Half Sphere Exposure . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.8 Determining the secondary structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.9 Calculating the residue depth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.7 Common problems in PDB files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.7.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
11.7.2 Automatic correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
11.7.3 Fatal errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
11.8 Accessing the Protein Data Bank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
11.8.1 Downloading structures from the Protein Data Bank . . . . . . . . . . . . . . . . . . . 189
11.8.2 Downloading the entire PDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
11.8.3 Keeping a local copy of the PDB up to date . . . . . . . . . . . . . . . . . . . . . . . . 190
11.9 General questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
11.9.1 How well tested is Bio.PDB? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
11.9.2 How fast is it? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
11.9.3 Is there support for molecular graphics? . . . . . . . . . . . . . . . . . . . . . . . . . . 190
11.9.4 Who’s using Bio.PDB? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
12 Bio.PopGen: Population genetics 192
12.1 GenePop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
13 Phylogenetics with Bio.Phylo 194
13.1 Demo: What’s in a Tree? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
13.1.1 Coloring branches within a tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
13.2 I/O functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
13.3 View and export trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
13.4 Using Tree and Clade objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
13.4.1 Search and traversal methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
13.4.2 Information methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
13.4.3 Modification methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
13.4.4 Features of PhyloXML trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
13.5 Running external applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
13.6 PAML integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
13.7 Future plans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
14 Sequence motif analysis using Bio.motifs 209
14.1 Motif objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
14.1.1 Creating a motif from instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
14.1.2 Creating a sequence logo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
14.2 Reading motifs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
14.2.1 JASPAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
14.2.2 MEME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
14.2.3 TRANSFAC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
14.3 Writing motifs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
14.4 Position-Weight Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
14.5 Position-Specific Scoring Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
14.6 Searching for instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
14.6.1 Searching for exact matches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
14.6.2 Searching for matches using the PSSM score . . . . . . . . . . . . . . . . . . . . . . . 228
14.6.3 Selecting a score threshold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
14.7 Each motif object has an associated Position-Specific Scoring Matrix . . . . . . . . . . . . . . 229
5
14.8 Comparing motifs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
14.9 De novo motif finding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
14.9.1 MEME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
14.10Useful links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
15 Cluster analysis 235
15.1 Distance functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
15.2 Calculating cluster properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
15.3 Partitioning algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
15.4 Hierarchical clustering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
15.5 Self-Organizing Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
15.6 Principal Component Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
15.7 Handling Cluster/TreeView-type files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
15.8 Example calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
16 Supervised learning methods 258
16.1 The Logistic Regression Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
16.1.1 Background and Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
16.1.2 Training the logistic regression model . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
16.1.3 Using the logistic regression model for classification . . . . . . . . . . . . . . . . . . . 261
16.1.4 Logistic Regression, Linear Discriminant Analysis, and Support Vector Machines . . . 263
16.2 k-Nearest Neighbors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
16.2.1 Background and purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
16.2.2 Initializing a k-nearest neighbors model . . . . . . . . . . . . . . . . . . . . . . . . . . 264
16.2.3 Using a k-nearest neighbors model for classification . . . . . . . . . . . . . . . . . . . . 264
16.3 Na¨ıve Bayes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
16.4 Maximum Entropy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
16.5 Markov Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
17 Graphics including GenomeDiagram 267
17.1 GenomeDiagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
17.1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
17.1.2 Diagrams, tracks, feature-sets and features . . . . . . . . . . . . . . . . . . . . . . . . 267
17.1.3 A top down example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
17.1.4 A bottom up example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
17.1.5 Features without a SeqFeature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
17.1.6 Feature captions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
17.1.7 Feature sigils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
17.1.8 Arrow sigils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
17.1.9 A nice example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
17.1.10Multiple tracks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
17.1.11 Cross-Links between tracks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
17.1.12 Further options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
17.1.13 Converting old code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
17.2 Chromosomes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
17.2.1 Simple Chromosomes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
17.2.2 Annotated Chromosomes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
18 KEGG 291
18.1 Parsing KEGG records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
18.2 Querying the KEGG API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
6
19 Bio.phenotype: analyse phenotypic data 294
19.1 Phenotype Microarrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
19.1.1 Parsing Phenotype Microarray data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
19.1.2 Manipulating Phenotype Microarray data . . . . . . . . . . . . . . . . . . . . . . . . . 295
19.1.3 Writing Phenotype Microarray data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
20 Cookbook – Cool things to do with it 299
20.1 Working with sequence files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
20.1.1 Filtering a sequence file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
20.1.2 Producing randomised genomes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
20.1.3 Translating a FASTA file of CDS entries . . . . . . . . . . . . . . . . . . . . . . . . . . 302
20.1.4 Making the sequences in a FASTA file upper case . . . . . . . . . . . . . . . . . . . . . 302
20.1.5 Sorting a sequence file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
20.1.6 Simple quality filtering for FASTQ files . . . . . . . . . . . . . . . . . . . . . . . . . . 304
20.1.7 Trimming off primer sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
20.1.8 Trimming off adaptor sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
20.1.9 Converting FASTQ files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
20.1.10 Converting FASTA and QUAL files into FASTQ files . . . . . . . . . . . . . . . . . . . 309
20.1.11 Indexing a FASTQ file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
20.1.12 Converting SFF files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
20.1.13 Identifying open reading frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
20.2 Sequence parsing plus simple plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
20.2.1 Histogram of sequence lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
20.2.2 Plot of sequence GC% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
20.2.3 Nucleotide dot plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
20.2.4 Plotting the quality scores of sequencing read data . . . . . . . . . . . . . . . . . . . . 317
20.3 Dealing with alignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
20.3.1 Calculating summary information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
20.3.2 Calculating a quick consensus sequence . . . . . . . . . . . . . . . . . . . . . . . . . . 319
20.3.3 Position Specific Score Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
20.3.4 Information Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
20.4 Substitution Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
20.4.1 Using common substitution matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
20.4.2 Creating your own substitution matrix from an alignment . . . . . . . . . . . . . . . . 323
20.5 BioSQL – storing sequences in a relational database . . . . . . . . . . . . . . . . . . . . . . . 325
21 The Biopython testing framework 326
21.1 Running the tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
21.1.1 Running the tests using Tox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
21.2 Writing tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
21.2.1 Writing a print-and-compare test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
21.2.2 Writing a unittest-based test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
21.3 Writing doctests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
21.4 Writing doctests in the Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
22 Advanced 334
22.1 Parser Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
22.2 Substitution Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
22.2.1 SubsMat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
22.2.2 FreqTable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
7
23 Where to go from here – contributing to Biopython 339
23.1 Bug Reports   Feature Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
23.2 Mailing lists and helping newcomers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
23.3 Contributing Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
23.4 Contributing cookbook examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
23.5 Maintaining a distribution for a platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
23.6 Contributing Unit Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
23.7 Contributing Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
24 Appendix: Useful stuff about Python 342
24.1 What the heck is a handle? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
24.1.1 Creating a handle from a string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343


标签: python Biopython

实例下载地址

Biopython Tutorial.pdf

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警