Edited wiki page PhyloBioRuby through web user interface.
[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
17
18
19 = Multiple Sequence Alignments =
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  
47
48 === Writing a Multiple Sequence Alignment to a File ===
49
50
51 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').
52
53 {{{
54 #!/usr/bin/env ruby
55 require 'bio'
56
57 # Creates a new file named "outfile.fasta" and writes
58 # multiple sequence alignment 'msa' to it in fasta format.
59 File.open('outfile.fasta', 'w') do |f|
60   f.write(msa.output(:fasta))
61 end
62 }}}
63
64 ==== Setting the Output Format ====
65
66 The following constants determine the output format.
67
68   * ClustalW: `:clustal`
69   * FASTA:    `:fasta`
70   * PHYLIP interleaved (will truncate sequence names to no more than 10 characters): `:phylip`
71   * PHYLIP non-interleaved (will truncate sequence names to no more than 10 characters): `:phylipnon`
72   * MSF: `:msf`
73   * Molphy: `:molphy`
74
75
76 For example, the following writes PHYLIP's non-interleaved format:
77
78 {{{
79 f.write(align.output(:phylipnon))
80 }}}
81
82
83 == Formatting of Individual Sequences ==
84
85 _... to be done_
86
87 !BioRuby can format molecular sequences in a variety of formats.
88 Individual sequences can be formatted to (e.g.) Genbank format as shown in the following examples.
89
90 For Sequence objects:
91 {{{
92 seq.to_seq.output(:genbank)
93 }}}
94
95 For Bio::!FlatFile entries:
96 {{{
97 entry.to_biosequence.output(:genbank)
98 }}}
99
100 Constants for available formats are:
101   * Genbank :genbank
102
103
104 == Calculating Multiple Sequence Alignments ==
105
106 !BioRuby can be used to execute a variety of multiple sequence alignment
107 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]). 
108 In the following, examples for using the MAFFT and Muscle are shown.
109
110
111 === MAFFT ===
112
113 The following example uses the MAFFT program to align four sequences
114 and then prints the result to the screen.
115 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. 
116
117 {{{
118 #!/usr/bin/env ruby
119 require 'bio'
120
121 # 'seqs' is either an array of sequences or a multiple sequence 
122 # alignment. In general this is read in from a file as described in ?.
123 # For the purpose of this tutorial, it is generated in code.
124 seqs = ['MFQIPEFEPSEQEDSSSAER',
125         'MGTPKQPSLAPAHALGLRKS',
126         'PKQPSLAPAHALGLRKS',
127         'MCSTSGCDLE'] 
128
129
130 # Calculates the alignment using the MAFFT program on the local
131 # machine with options '--maxiterate 1000 --localpair'
132 # and stores the result in 'report'.
133 options = ['--maxiterate', '1000', '--localpair']
134 mafft = Bio::MAFFT.new('path/to/mafft', options)
135 report = mafft.query_align(seqs)
136
137 # Accesses the actual alignment.
138 align = report.alignment
139
140 # Prints each sequence to the console.
141 align.each { |s| puts s.to_s }
142
143 }}}
144
145 References:
146
147  * Katoh, Toh (2008) "Recent developments in the MAFFT multiple sequence alignment program" Briefings in Bioinformatics 9:286-298 
148
149  * Katoh, Toh 2010 (2010) "Parallelization of the MAFFT multiple sequence alignment program" Bioinformatics 26:1899-1900 
150
151
152
153 === Muscle ===
154
155 {{{
156 #!/usr/bin/env ruby
157 require 'bio'
158
159 # 'seqs' is either an array of sequences or a multiple sequence 
160 # alignment. In general this is read in from a file as described in ?.
161 # For the purpose of this tutorial, it is generated in code.
162 seqs = ['MFQIPEFEPSEQEDSSSAER',
163         'MGTPKQPSLAPAHALGLRKS',
164         'PKQPSLAPAHALGLRKS',
165         'MCSTSGCDLE']  
166
167 # Calculates the alignment using the Muscle program on the local
168 # machine with options '-quiet -maxiters 64'
169 # and stores the result in 'report'.
170 options = ['-quiet', '-maxiters', '64']
171 muscle = Bio::Muscle.new('path/to/muscle', options)
172 report = muscle.query_align(seqs)
173
174 # Accesses the actual alignment.
175 align = report.alignment
176
177 # Prints each sequence to the console.
178 align.each { |s| puts s.to_s }
179
180 }}}
181
182 References:
183
184  * Edgar, R.C. (2004) "MUSCLE: multiple sequence alignment with high accuracy and high throughput" Nucleic Acids Res 32(5):1792-1797
185
186 === Other Programs ===
187
188 _need more detail here..._
189
190 [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. 
191
192
193
194 == Manipulating Multiple Sequence Alignments ==
195
196 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.
197
198
199 _... to be done_
200
201 {{{
202 #!/usr/bin/env ruby
203 require 'bio'
204
205 }}}
206
207
208 ----
209
210 = Phylogenetic Trees =
211
212
213 == Phylogenetic Tree Input and Output ==
214
215
216 === Reading in of Phylogenetic Trees ===
217
218
219
220 ====Newick or New Hampshire Format====
221
222 _... to be done_
223
224 {{{
225 #!/usr/bin/env ruby
226 require 'bio'
227
228 }}}
229
230 ====phyloXML Format====
231
232 Partially copied from [https://www.nescent.org/wg_phyloinformatics/BioRuby_PhyloXML_HowTo_documentation Diana Jaunzeikare's documentation].
233
234 In addition to !BioRuby, a libxml Ruby binding is also required. This can be installed with the following command: 
235
236 {{{
237 % gem install -r libxml-ruby
238 }}}
239
240 This example reads file "example.xml" and stores its [http://www.phyloxml.org/ phyloXML]-formatted trees in variable 'trees'.
241
242 {{{
243 #!/usr/bin/env ruby
244 require 'bio'
245
246 # This creates new phyloXML parser.
247 trees = Bio::PhyloXML::Parser.new('example.xml')
248
249 # This prints the names of all trees in the file.
250 trees.each do |tree|
251   puts tree.name
252 end
253
254 # If there are several trees in the file, you can access the one you wish via index.
255 tree = trees[3]
256
257 }}}
258
259
260 ====Nexus  Format====
261
262 _... to be done_
263
264 {{{
265 #!/usr/bin/env ruby
266 require 'bio'
267
268 }}}
269
270 === Writing of Phylogenetic Trees ===
271
272 ====Newick or New Hampshire Format====
273
274 _... to be done_
275
276 {{{
277 #!/usr/bin/env ruby
278 require 'bio'
279
280 }}}
281
282 ====phyloXML Format====
283
284 Partially copied from [https://www.nescent.org/wg_phyloinformatics/BioRuby_PhyloXML_HowTo_documentation Diana Jaunzeikare's documentation].
285
286 In addition to !BioRuby, a libxml Ruby binding is also required. This can be installed with the following command: 
287
288 {{{
289 % gem install -r libxml-ruby
290 }}}
291
292 This example writes trees 'tree1' and 'tree2' to file "tree.xml" in [http://www.phyloxml.org/ phyloXML] format.
293
294 {{{
295 #!/usr/bin/env ruby
296 require 'bio'
297
298 # this creates new phyloXML writer.
299 writer = Bio::PhyloXML::Writer.new('tree.xml')
300
301 # Writes tree to the file "tree.xml".
302 writer.write(tree1)
303
304 # Adds another tree to the file.
305 writer.write(tree2)
306
307
308 }}}
309
310
311 ====Nexus  Format====
312
313 _... to be done_
314
315 {{{
316 #!/usr/bin/env ruby
317 require 'bio'
318
319 }}}
320
321
322 == Phylogenetic Inference ==
323
324 _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..._
325
326 _What about pairwise distance calculation?_
327
328
329
330 == Maximum Likelihood ==
331
332 === RAxML ===
333
334 _... to be done_
335
336 {{{
337 #!/usr/bin/env ruby
338 require 'bio'
339
340 }}}
341
342
343 === PhyML ===
344
345 _... to be done_
346
347 {{{
348 #!/usr/bin/env ruby
349 require 'bio'
350
351 }}}
352
353 == Pairwise Distance Based Methods ==
354
355 === FastME ===
356
357 _... to be done_
358
359 {{{
360 #!/usr/bin/env ruby
361 require 'bio'
362
363 }}}
364
365
366
367 === PHYLIP? ===
368
369
370
371 == Support Calculation? ==
372
373 === Bootstrap Resampling? ===
374
375
376 ----
377
378 = Analyzing Phylogenetic Trees =
379
380 == PAML ==
381
382
383 == Gene Duplication Inference ==
384
385 _need to further test and then import GSoC 'SDI' work..._
386
387
388 == Others? ==
389
390
391 ----
392
393 = Putting It All Together =
394
395 Example of a small "pipeline"-type program running a mininal phyogenetic analysis: starting with a set of sequences and ending with a phylogenetic tree.
396