File: _Clustalw.py

package info (click to toggle)
python-biopython 1.68%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 46,860 kB
  • ctags: 13,237
  • sloc: python: 160,306; xml: 93,216; ansic: 9,118; sql: 1,208; makefile: 155; sh: 63
file content (333 lines) | stat: -rw-r--r-- 19,629 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# Copyright 2009 by Cymon J. Cox.  All rights reserved.
# This code is part of the Biopython distribution and governed by its
# license.  Please see the LICENSE file that should have been included
# as part of this package.
"""Command line wrapper for the multiple alignment program Clustal W.
"""

from __future__ import print_function

import os
from Bio.Application import _Option, _Switch, AbstractCommandline


class ClustalwCommandline(AbstractCommandline):
    """Command line wrapper for clustalw (version one or two).

    http://www.clustal.org/

    Example:
    --------

    >>> from Bio.Align.Applications import ClustalwCommandline
    >>> in_file = "unaligned.fasta"
    >>> clustalw_cline = ClustalwCommandline("clustalw2", infile=in_file)
    >>> print(clustalw_cline)
    clustalw2 -infile=unaligned.fasta

    You would typically run the command line with clustalw_cline() or via
    the Python subprocess module, as described in the Biopython tutorial.

    Citation:
    ---------

    Larkin MA, Blackshields G, Brown NP, Chenna R, McGettigan PA,
    McWilliam H, Valentin F, Wallace IM, Wilm A, Lopez R, Thompson JD,
    Gibson TJ, Higgins DG. (2007). Clustal W and Clustal X version 2.0.
    Bioinformatics, 23, 2947-2948.

    Last checked against versions: 1.83 and 2.1
    """
    # TODO - Should we default to cmd="clustalw2" now?
    def __init__(self, cmd="clustalw", **kwargs):
        self.parameters = \
            [
            _Option(["-infile", "-INFILE", "INFILE", "infile"],
                    "Input sequences.",
                    filename=True),
            _Option(["-profile1", "-PROFILE1", "PROFILE1", "profile1"],
                    "Profiles (old alignment).",
                    filename=True),
            _Option(["-profile2", "-PROFILE2", "PROFILE2", "profile2"],
                    "Profiles (old alignment).",
                    filename=True),
            # ################# VERBS (do things) #############################
            _Switch(["-options", "-OPTIONS", "OPTIONS", "options"],
                    "List the command line parameters"),
            _Switch(["-help", "-HELP", "HELP", "help"],
                    "Outline the command line params."),
            _Switch(["-check", "-CHECK", "CHECK", "check"],
                    "Outline the command line params."),
            _Switch(["-fullhelp", "-FULLHELP", "FULLHELP", "fullhelp"],
                    "Output full help content."),
            _Switch(["-align", "-ALIGN", "ALIGN", "align"],
                    "Do full multiple alignment."),
            _Switch(["-tree", "-TREE", "TREE", "tree"],
                    "Calculate NJ tree."),
            _Switch(["-pim", "-PIM", "PIM", "pim"],
                    "Output percent identity matrix (while calculating the tree)."),
            _Option(["-bootstrap", "-BOOTSTRAP", "BOOTSTRAP", "bootstrap"],
                    "Bootstrap a NJ tree (n= number of bootstraps; def. = 1000).",
                    checker_function=lambda x: isinstance(x, int)),
            _Switch(["-convert", "-CONVERT", "CONVERT", "convert"],
                    "Output the input sequences in a different file format."),
            # #################### PARAMETERS (set things) #########################
            # ***General settings:****
            # Makes no sense in biopython
            # _Option(["-interactive", "-INTERACTIVE", "INTERACTIVE", "interactive"],
            #        [],
            #        lambda x: 0, # Does not take value
            #        False,
            #        "read command line, then enter normal interactive menus",
            #        False),
            _Switch(["-quicktree", "-QUICKTREE", "QUICKTREE", "quicktree"],
                    "Use FAST algorithm for the alignment guide tree"),
            _Option(["-type", "-TYPE", "TYPE", "type"],
                    "PROTEIN or DNA sequences",
                    checker_function=lambda x: x in ["PROTEIN", "DNA",
                                                     "protein", "dna"]),
            _Switch(["-negative", "-NEGATIVE", "NEGATIVE", "negative"],
                    "Protein alignment with negative values in matrix"),
            _Option(["-outfile", "-OUTFILE", "OUTFILE", "outfile"],
                    "Output sequence alignment file name",
                    filename=True),
            _Option(["-output", "-OUTPUT", "OUTPUT", "output"],
                    "Output format: CLUSTAL(default), GCG, GDE, PHYLIP, PIR, NEXUS and FASTA",
                    checker_function=lambda x: x in ["CLUSTAL", "GCG", "GDE", "PHYLIP",
                                                     "PIR", "NEXUS", "FASTA",
                                                     "clustal", "gcg", "gde", "phylip",
                                                     "pir", "nexus", "fasta"]),
            _Option(["-outorder", "-OUTORDER", "OUTORDER", "outorder"],
                    "Output taxon order: INPUT or ALIGNED",
                    checker_function=lambda x: x in ["INPUT", "input",
                                                     "ALIGNED", "aligned"]),
            _Option(["-case", "-CASE", "CASE", "case"],
                    "LOWER or UPPER (for GDE output only)",
                    checker_function=lambda x: x in ["UPPER", "upper",
                                                     "LOWER", "lower"]),
            _Option(["-seqnos", "-SEQNOS", "SEQNOS", "seqnos"],
                    "OFF or ON (for Clustal output only)",
                    checker_function=lambda x: x in ["ON", "on",
                                                     "OFF", "off"]),
            _Option(["-seqno_range", "-SEQNO_RANGE", "SEQNO_RANGE", "seqno_range"],
                    "OFF or ON (NEW- for all output formats)",
                    checker_function=lambda x: x in ["ON", "on",
                                                     "OFF", "off"]),
            _Option(["-range", "-RANGE", "RANGE", "range"],
                    "Sequence range to write starting m to m+n. "
                    "Input as string eg. '24,200'"),
            _Option(["-maxseqlen", "-MAXSEQLEN", "MAXSEQLEN", "maxseqlen"],
                    "Maximum allowed input sequence length",
                    checker_function=lambda x: isinstance(x, int)),
            _Switch(["-quiet", "-QUIET", "QUIET", "quiet"],
                    "Reduce console output to minimum"),
            _Option(["-stats", "-STATS", "STATS", "stats"],
                    "Log some alignment statistics to file",
                    filename=True),
            # ***Fast Pairwise Alignments:***
            _Option(["-ktuple", "-KTUPLE", "KTUPLE", "ktuple"],
                    "Word size",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Option(["-topdiags", "-TOPDIAGS", "TOPDIAGS", "topdiags"],
                    "Number of best diags.",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Option(["-window", "-WINDOW", "WINDOW", "window"],
                    "Window around best diags.",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Option(["-pairgap", "-PAIRGAP", "PAIRGAP", "pairgap"],
                    "Gap penalty",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Option(["-score", "-SCORE", "SCORE", "score"],
                    "Either: PERCENT or ABSOLUTE",
                    checker_function=lambda x: x in ["percent", "PERCENT",
                                                     "absolute", "ABSOLUTE"]),
            # ***Slow Pairwise Alignments:***
            _Option(["-pwmatrix", "-PWMATRIX", "PWMATRIX", "pwmatrix"],
                    "Protein weight matrix=BLOSUM, PAM, GONNET, ID or filename",
                    checker_function=lambda x: x in ["BLOSUM", "PAM",
                                                     "GONNET", "ID",
                                                     "blosum", "pam",
                                                     "gonnet", "id"] or
                                                os.path.exists(x),
                    filename=True),
            _Option(["-pwdnamatrix", "-PWDNAMATRIX", "PWDNAMATRIX", "pwdnamatrix"],
                    "DNA weight matrix=IUB, CLUSTALW or filename",
                    checker_function=lambda x: x in ["IUB", "CLUSTALW",
                                                     "iub", "clustalw"] or
                                               os.path.exists(x),
                    filename=True),
            _Option(["-pwgapopen", "-PWGAPOPEN", "PWGAPOPEN", "pwgapopen"],
                    "Gap opening penalty",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Option(["-pwgapext", "-PWGAPEXT", "PWGAPEXT", "pwgapext"],
                    "Gap extension penalty",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            # ***Multiple Alignments:***
            _Option(["-newtree", "-NEWTREE", "NEWTREE", "newtree"],
                    "Output file name for newly created guide tree",
                    filename=True),
            _Option(["-usetree", "-USETREE", "USETREE", "usetree"],
                    "File name of guide tree",
                    checker_function=lambda x: os.path.exists,
                    filename=True),
            _Option(["-matrix", "-MATRIX", "MATRIX", "matrix"],
                    "Protein weight matrix=BLOSUM, PAM, GONNET, ID or filename",
                    checker_function=lambda x: x in ["BLOSUM", "PAM",
                                                     "GONNET", "ID",
                                                     "blosum", "pam",
                                                     "gonnet", "id"] or
                                               os.path.exists(x),
                    filename=True),
            _Option(["-dnamatrix", "-DNAMATRIX", "DNAMATRIX", "dnamatrix"],
                    "DNA weight matrix=IUB, CLUSTALW or filename",
                    checker_function=lambda x: x in ["IUB", "CLUSTALW",
                                                     "iub", "clustalw"] or
                                               os.path.exists(x),
                    filename=True),
            _Option(["-gapopen", "-GAPOPEN", "GAPOPEN", "gapopen"],
                    "Gap opening penalty",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Option(["-gapext", "-GAPEXT", "GAPEXT", "gapext"],
                    "Gap extension penalty",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Switch(["-endgaps", "-ENDGAPS", "ENDGAPS", "endgaps"],
                    "No end gap separation pen."),
            _Option(["-gapdist", "-GAPDIST", "GAPDIST", "gapdist"],
                    "Gap separation pen. range",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Switch(["-nopgap", "-NOPGAP", "NOPGAP", "nopgap"],
                    "Residue-specific gaps off"),
            _Switch(["-nohgap", "-NOHGAP", "NOHGAP", "nohgap"],
                    "Hydrophilic gaps off"),
            _Switch(["-hgapresidues", "-HGAPRESIDUES", "HGAPRESIDUES", "hgapresidues"],
                    "List hydrophilic res."),
            _Option(["-maxdiv", "-MAXDIV", "MAXDIV", "maxdiv"],
                    "% ident. for delay",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            # Already handled in General Settings section, but appears a second
            # time under Multiple Alignments in the help
            # _Option(["-type", "-TYPE", "TYPE", "type"],
            #        "PROTEIN or DNA",
            #        checker_function=lambda x: x in ["PROTEIN", "DNA",
            #                                         "protein", "dna"]),
            _Option(["-transweight", "-TRANSWEIGHT", "TRANSWEIGHT", "transweight"],
                    "Transitions weighting",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Option(["-iteration", "-ITERATION", "ITERATION", "iteration"],
                    "NONE or TREE or ALIGNMENT",
                    checker_function=lambda x: x in ["NONE", "TREE",
                                                     "ALIGNMENT",
                                                     "none", "tree",
                                                     "alignment"]),
            _Option(["-numiter", "-NUMITER", "NUMITER", "numiter"],
                    "maximum number of iterations to perform",
                    checker_function=lambda x: isinstance(x, int)),
            _Switch(["-noweights", "-NOWEIGHTS", "NOWEIGHTS", "noweights"],
                    "Disable sequence weighting"),
            # ***Profile Alignments:***
            _Switch(["-profile", "-PROFILE", "PROFILE", "profile"],
                    "Merge two alignments by profile alignment"),
            _Option(["-newtree1", "-NEWTREE1", "NEWTREE1", "newtree1"],
                    "Output file name for new guide tree of profile1",
                    filename=True),
            _Option(["-newtree2", "-NEWTREE2", "NEWTREE2", "newtree2"],
                    "Output file for new guide tree of profile2",
                    filename=True),
            _Option(["-usetree1", "-USETREE1", "USETREE1", "usetree1"],
                    "File name of guide tree for profile1",
                    checker_function=lambda x: os.path.exists,
                    filename=True),
            _Option(["-usetree2", "-USETREE2", "USETREE2", "usetree2"],
                    "File name of guide tree for profile2",
                    checker_function=lambda x: os.path.exists,
                    filename=True),
            # ***Sequence to Profile Alignments:***
            _Switch(["-sequences", "-SEQUENCES", "SEQUENCES", "sequences"],
                    "Sequentially add profile2 sequences to profile1 alignment"),
            # These are already handled in the Multiple Alignments section,
            # but appear a second time here in the help.
            # _Option(["-newtree", "-NEWTREE", "NEWTREE", "newtree"],
            #        "File for new guide tree",
            #        filename=True),
            # _Option(["-usetree", "-USETREE", "USETREE", "usetree"],
            #        "File for old guide tree",
            #        checker_function=lambda x: os.path.exists,
            #        filename=True),
            # ***Structure Alignments:***
            _Switch(["-nosecstr1", "-NOSECSTR1", "NOSECSTR1", "nosecstr1"],
                    "Do not use secondary structure-gap penalty mask for profile 1"),
            _Switch(["-nosecstr2", "-NOSECSTR2", "NOSECSTR2", "nosecstr2"],
                    "Do not use secondary structure-gap penalty mask for profile 2"),
            _Option(["-secstrout", "-SECSTROUT", "SECSTROUT", "secstrout"],
                    "STRUCTURE or MASK or BOTH or NONE output in alignment file",
                    checker_function=lambda x: x in ["STRUCTURE", "MASK",
                                                     "BOTH", "NONE",
                                                     "structure", "mask",
                                                     "both", "none"]),
            _Option(["-helixgap", "-HELIXGAP", "HELIXGAP", "helixgap"],
                    "Gap penalty for helix core residues",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Option(["-strandgap", "-STRANDGAP", "STRANDGAP", "strandgap"],
                    "gap penalty for strand core residues",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Option(["-loopgap", "-LOOPGAP", "LOOPGAP", "loopgap"],
                    "Gap penalty for loop regions",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Option(["-terminalgap", "-TERMINALGAP", "TERMINALGAP", "terminalgap"],
                    "Gap penalty for structure termini",
                    checker_function=lambda x: isinstance(x, int) or
                                               isinstance(x, float)),
            _Option(["-helixendin", "-HELIXENDIN", "HELIXENDIN", "helixendin"],
                    "Number of residues inside helix to be treated as terminal",
                    checker_function=lambda x: isinstance(x, int)),
            _Option(["-helixendout", "-HELIXENDOUT", "HELIXENDOUT", "helixendout"],
                    "Number of residues outside helix to be treated as terminal",
                    checker_function=lambda x: isinstance(x, int)),
            _Option(["-strandendin", "-STRANDENDIN", "STRANDENDIN", "strandendin"],
                    "Number of residues inside strand to be treated as terminal",
                    checker_function=lambda x: isinstance(x, int)),
            _Option(["-strandendout", "-STRANDENDOUT", "STRANDENDOUT", "strandendout"],
                    "Number of residues outside strand to be treated as terminal",
                    checker_function=lambda x: isinstance(x, int)),
            # ***Trees:***
            _Option(["-outputtree", "-OUTPUTTREE", "OUTPUTTREE", "outputtree"],
                    "nj OR phylip OR dist OR nexus",
                    checker_function=lambda x: x in ["NJ", "PHYLIP",
                                                     "DIST", "NEXUS",
                                                     "nj", "phylip",
                                                     "dist", "nexus"]),
            _Option(["-seed", "-SEED", "SEED", "seed"],
                    "Seed number for bootstraps.",
                    checker_function=lambda x: isinstance(x, int)),
            _Switch(["-kimura", "-KIMURA", "KIMURA", "kimura"],
                    "Use Kimura's correction."),
            _Switch(["-tossgaps", "-TOSSGAPS", "TOSSGAPS", "tossgaps"],
                    "Ignore positions with gaps."),
            _Option(["-bootlabels", "-BOOTLABELS", "BOOTLABELS", "bootlabels"],
                    "Node OR branch position of bootstrap values in tree display",
                    checker_function=lambda x: x in ["NODE", "BRANCH",
                                                     "node", "branch"]),
            _Option(["-clustering", "-CLUSTERING", "CLUSTERING", "clustering"],
                    "NJ or UPGMA",
                    checker_function=lambda x: x in ["NJ", "UPGMA", "nj", "upgma"])
            ]
        AbstractCommandline.__init__(self, cmd, **kwargs)


if __name__ == "__main__":
    from Bio._utils import run_doctest
    run_doctest()