381ae70105689256d7cdbd308586a69121711b44
[jalview.git] / wiki / PhyloBioRuby.wiki
1 #summary Tutorial for multiple sequence alignments and phylogenetic methods in BioRuby -- under development!
2
3
4
5 = Introduction =
6
7 Under development!
8
9 Tutorial for multiple sequence alignments and phylogenetic methods in [http://bioruby.open-bio.org/ BioRuby].
10
11 Eventually, this is expected to be placed on the official !BioRuby page.
12
13 Author: [http://www.cmzmasek.net/ Christian M Zmasek], Sanford-Burnham Medical Research Institute
14
15  
16 Copyright (C) 2011 Christian M Zmasek. All rights reserved.
17
18
19 = Multiple Sequence Alignment =
20
21
22 == Multiple Sequence Alignment Input and Output ==
23
24 === Reading in a Multiple Sequence Alignment from a File ===
25
26 The following example shows how to read in a *ClustalW*-formatted multiple sequence alignment.
27
28 {{{
29 #!/usr/bin/env ruby
30 require 'bio'
31
32 # Reads in a ClustalW-formatted multiple sequence alignment
33 # from a file named "infile_clustalw.aln" and stores it in 'report'.
34 report = Bio::ClustalW::Report.new(File.read('infile_clustalw.aln'))
35
36 # Accesses the actual alignment.
37 msa = report.alignment
38
39 # Goes through all sequences in 'msa' and prints the
40 # actual molecular sequence.
41 msa.each do |entry|
42   puts entry.seq
43 end
44 }}}
45
46 Relevant API documentation
47
48  * [http://bioruby.open-bio.org/rdoc/classes/Bio/ClustalW/Report.html Bio::ClustalW::Report]
49  * 
50  
51
52 === Writing a Multiple Sequence Alignment to a File ===
53
54
55 The following example shows how to write a multiple sequence alignment in *FASTA*-format. It first creates a file named "outfile.fasta" for writing ('w') and then writes the multiple sequence alignment referred to by variable 'msa' to it in FASTA-format (':fasta').
56
57 {{{
58 #!/usr/bin/env ruby
59 require 'bio'
60
61 # Creates a new file named "outfile.fasta" and writes
62 # multiple sequence alignment 'msa' to it in fasta format.
63 File.open('outfile.fasta', 'w') do |f|
64   f.write(msa.output(:fasta))
65 end
66 }}}
67
68 ==== Setting the Output Format ====
69
70 The following symbols determine the output format:
71
72   * `:clustal` for ClustalW
73   * `:fasta` for FASTA
74   * `:phylip` for PHYLIP interleaved (will truncate sequence names to no more than 10 characters)
75   * `:phylipnon` for PHYLIP non-interleaved (will truncate sequence names to no more than 10 characters)
76   * `:msf` for MSF
77   * `:molphy` for Molphy
78
79
80 For example, the following writes in PHYLIP's non-interleaved format:
81
82 {{{
83 f.write(align.output(:phylipnon))
84 }}}
85
86
87 === Formatting of Individual Sequences ===
88
89 !BioRuby can format molecular sequences in a variety of formats.
90 Individual sequences can be formatted to (e.g.) Genbank format as shown in the following examples.
91
92 For Sequence objects:
93 {{{
94 seq.to_seq.output(:genbank)
95 }}}
96
97 For Bio::!FlatFile entries:
98 {{{
99 entry.to_biosequence.output(:genbank)
100 }}}
101
102 The following symbols determine the output format:
103   * `:genbank` for Genbank
104   * `:embl` for EMBL
105   * `:fasta` for FASTA
106   * `:fasta_ncbi` for NCBI-type FASTA
107   * `:raw` for raw sequence
108   * `:fastq` for FASTQ (includes quality scores)
109   * `:fastq_sanger` for Sanger-type FASTQ 
110   * `:fastq_solexa` for Solexa-type FASTQ 
111   * `:fastq_illumina` for Illumina-type FASTQ 
112
113 == Calculating Multiple Sequence Alignments ==
114
115 !BioRuby can be used to execute a variety of multiple sequence alignment
116 programs (such as [http://mafft.cbrc.jp/alignment/software/ MAFFT], [http://probcons.stanford.edu/ Probcons], [http://www.clustal.org/ ClustalW], [http://www.drive5.com/muscle/ Muscle], and [http://www.tcoffee.org/Projects_home_page/t_coffee_home_page.html T-Coffee]). 
117 In the following, examples for using the MAFFT and Muscle are shown.
118
119
120 === MAFFT ===
121
122 The following example uses the MAFFT program to align four sequences
123 and then prints the result to the screen.
124 Please note that if the path to the MAFFT executable is properly set `mafft=Bio::MAFFT.new(options)` can be used instead of explicitly indicating the path as in the example. 
125
126 {{{
127 #!/usr/bin/env ruby
128 require 'bio'
129
130 # 'seqs' is either an array of sequences or a multiple sequence 
131 # alignment. In general this is read in from a file as described in ?.
132 # For the purpose of this tutorial, it is generated in code.
133 seqs = ['MFQIPEFEPSEQEDSSSAER',
134         'MGTPKQPSLAPAHALGLRKS',
135         'PKQPSLAPAHALGLRKS',
136         'MCSTSGCDLE'] 
137
138
139 # Calculates the alignment using the MAFFT program on the local
140 # machine with options '--maxiterate 1000 --localpair'
141 # and stores the result in 'report'.
142 options = ['--maxiterate', '1000', '--localpair']
143 mafft = Bio::MAFFT.new('path/to/mafft', options)
144 report = mafft.query_align(seqs)
145
146 # Accesses the actual alignment.
147 align = report.alignment
148
149 # Prints each sequence to the console.
150 align.each { |s| puts s.to_s }
151
152 }}}
153
154 References:
155
156  * Katoh, Toh (2008) "Recent developments in the MAFFT multiple sequence alignment program" Briefings in Bioinformatics 9:286-298 
157
158  * Katoh, Toh 2010 (2010) "Parallelization of the MAFFT multiple sequence alignment program" Bioinformatics 26:1899-1900 
159
160
161
162 === Muscle ===
163
164 {{{
165 #!/usr/bin/env ruby
166 require 'bio'
167
168 # 'seqs' is either an array of sequences or a multiple sequence 
169 # alignment. In general this is read in from a file as described in ?.
170 # For the purpose of this tutorial, it is generated in code.
171 seqs = ['MFQIPEFEPSEQEDSSSAER',
172         'MGTPKQPSLAPAHALGLRKS',
173         'PKQPSLAPAHALGLRKS',
174         'MCSTSGCDLE']  
175
176 # Calculates the alignment using the Muscle program on the local
177 # machine with options '-quiet -maxiters 64'
178 # and stores the result in 'report'.
179 options = ['-quiet', '-maxiters', '64']
180 muscle = Bio::Muscle.new('path/to/muscle', options)
181 report = muscle.query_align(seqs)
182
183 # Accesses the actual alignment.
184 align = report.alignment
185
186 # Prints each sequence to the console.
187 align.each { |s| puts s.to_s }
188
189 }}}
190
191 References:
192
193  * Edgar, R.C. (2004) "MUSCLE: multiple sequence alignment with high accuracy and high throughput" Nucleic Acids Res 32(5):1792-1797
194
195 === Other Programs ===
196
197 _need more detail here..._
198
199 [http://probcons.stanford.edu/ Probcons], [http://www.clustal.org/ ClustalW], and [http://www.tcoffee.org/Projects_home_page/t_coffee_home_page.html T-Coffee] can be used in the same manner as the programs above. 
200
201
202
203 == Manipulating Multiple Sequence Alignments ==
204
205 Oftentimes, multiple sequence to be used for phylogenetic inference are 'cleaned up' in some manner. For instance, some researchers prefer to delete columns with more than 50% gaps. The following code is an example of how to do that in !BioRuby.
206
207
208 _... to be done_
209
210 {{{
211 #!/usr/bin/env ruby
212 require 'bio'
213
214 }}}
215
216
217 ----
218
219 = Phylogenetic Trees =
220
221
222 == Phylogenetic Tree Input and Output ==
223
224
225 === Reading in of Phylogenetic Trees ===
226
227
228
229 ====Newick or New Hampshire Format====
230
231 _... to be done_
232
233 {{{
234 #!/usr/bin/env ruby
235 require 'bio'
236
237 }}}
238
239 ====phyloXML Format====
240
241 Partially copied from [https://www.nescent.org/wg_phyloinformatics/BioRuby_PhyloXML_HowTo_documentation Diana Jaunzeikare's documentation].
242
243 In addition to !BioRuby, a libxml Ruby binding is also required. This can be installed with the following command: 
244
245 {{{
246 % gem install -r libxml-ruby
247 }}}
248
249 This example reads file "example.xml" and stores its [http://www.phyloxml.org/ phyloXML]-formatted trees in variable 'trees'.
250
251 {{{
252 #!/usr/bin/env ruby
253 require 'bio'
254
255 # This creates new phyloXML parser.
256 trees = Bio::PhyloXML::Parser.new('example.xml')
257
258 # This prints the names of all trees in the file.
259 trees.each do |tree|
260   puts tree.name
261 end
262
263 # If there are several trees in the file, you can access the one you wish via index.
264 tree = trees[3]
265
266 }}}
267
268
269 ====Nexus  Format====
270
271 _... to be done_
272
273 {{{
274 #!/usr/bin/env ruby
275 require 'bio'
276
277 }}}
278
279 === Writing of Phylogenetic Trees ===
280
281 ====Newick or New Hampshire Format====
282
283 _... to be done_
284
285 {{{
286 #!/usr/bin/env ruby
287 require 'bio'
288
289 }}}
290
291 ====phyloXML Format====
292
293 Partially copied from [https://www.nescent.org/wg_phyloinformatics/BioRuby_PhyloXML_HowTo_documentation Diana Jaunzeikare's documentation].
294
295 In addition to !BioRuby, a libxml Ruby binding is also required. This can be installed with the following command: 
296
297 {{{
298 % gem install -r libxml-ruby
299 }}}
300
301 This example writes trees 'tree1' and 'tree2' to file "tree.xml" in [http://www.phyloxml.org/ phyloXML] format.
302
303 {{{
304 #!/usr/bin/env ruby
305 require 'bio'
306
307 # this creates new phyloXML writer.
308 writer = Bio::PhyloXML::Writer.new('tree.xml')
309
310 # Writes tree to the file "tree.xml".
311 writer.write(tree1)
312
313 # Adds another tree to the file.
314 writer.write(tree2)
315
316
317 }}}
318
319
320 ====Nexus  Format====
321
322 _... to be done_
323
324 {{{
325 #!/usr/bin/env ruby
326 require 'bio'
327
328 }}}
329
330
331 = Phylogenetic Inference =
332
333 _Currently !BioRuby does not contain wrappers for phylogenetic inference programs, thus I am progress of writing a RAxML wrapper followed by a wrapper for FastME..._
334
335 == Optimality Criteria Based on Character Data ==
336
337 Character data based methods work directly on molecular sequences and thus do not require the calculation of pairwise distances but tend to be time consuming and sensitive to errors in the multiple sequence alignment.
338
339 === Maximum Likelihood ===
340
341 ==== RAxML ====
342
343 _... to be done_
344
345 {{{
346 #!/usr/bin/env ruby
347 require 'bio'
348
349 }}}
350
351
352 ==== PhyML ====
353
354 _... to be done_
355
356 {{{
357 #!/usr/bin/env ruby
358 require 'bio'
359
360 }}}
361
362 === Maximum Parsimony ===
363
364 Currently no direct support in !BioRuby.
365
366
367 === Bayesian Inference ===
368
369 Currently no direct support in !BioRuby.
370
371
372 == Pairwise Distance Based Methods ==
373
374 === Pairwise Sequence Distance Estimation ===
375
376 _... to be done_
377
378 {{{
379 #!/usr/bin/env ruby
380 require 'bio'
381
382 }}}
383
384
385 === Optimality Criteria Based on Pairwise Distances ===
386
387
388 ==== Minimal Evolution: FastME ====
389
390 _... to be done_
391
392 {{{
393 #!/usr/bin/env ruby
394 require 'bio'
395
396 }}}
397
398 === Algorithmic Methods Based on Pairwise Distances ===
399
400 ==== Neighbor Joining and Related Methods ====
401
402 _... to be done_
403
404 {{{
405 #!/usr/bin/env ruby
406 require 'bio'
407
408 }}}
409
410
411
412
413
414
415
416 == Support Calculation? ==
417
418 === Bootstrap Resampling? ===
419
420
421 ----
422
423 = Analyzing Phylogenetic Trees =
424
425 == PAML ==
426
427
428 == Gene Duplication Inference ==
429
430 _need to further test and then import GSoC 'SDI' work..._
431
432
433 == Others? ==
434
435
436 ----
437
438 = Putting It All Together =
439
440 Example of a small "pipeline"-type program running a mininal phyogenetic analysis: starting with a set of sequences and ending with a phylogenetic tree.
441