clustalw.py
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:8k
- #!/usr/bin/python
- # $Id: clustalw.py,v 1000.0 2003/10/31 21:37:53 gouriano Exp $
- #
- # Author: Josh Cherry
- #
- # align sequences using clustalw (from gbench)
- import sys
- import cgi
- import os
- import tempfile
- # take a list of Seq-locs encoded as CGI strings,
- # and write out a multi-sequence fasta file
- def FastaFromCGI(locs, fname):
- s = ""
- for qs in locs:
- loc = cgi.parse_qs(qs)
- s += ">" + loc['short_title'][0] + " " + loc['title'][0] + "n"
- seq = loc['seq'][0]
- for pos in range(0, len(seq), 60):
- s += seq[pos:pos+60]
- s += 'n'
- f = open(fname, "w")
- f.write(s)
- f.close()
- input = sys.stdin.read()
- args = cgi.parse_qs(input)
- action = args['action'][0]
- # if a get info call ...
- if action == 'info':
- print '''
- PluginInfo ::= {
- ver-major 0,
- ver-minor 0,
- ver-revision 0,
- ver-build-date "",
- class-name "clustalw.py",
- menu-item "Alignments/Multiple alignment using clustalw",
- tooltip "Multiple alignment using clustalw",
- commands algo {
- {
- command 3,
- args {
- {
- name "locs",
- desc "Locations to evaluate",
- data array {
- object {
- docaddr "(nil)",
- objaddr "(nil)",
- subtype "Seq-loc"
- }
- }
- },
- {
- name "output",
- desc "Output format",
- default TRUE,
- data single string "clustal",
- constraint {
- set {
- "clustal",
- "phylip",
- "gcg",
- "gde",
- "pir",
- "nexus"
- }
- }
- },
- {
- name "alignment",
- desc "Alignment",
- default TRUE,
- data single string "full",
- constraint {
- set {
- "full",
- "fast"
- }
- }
- },
- {
- name "outorder",
- desc "Output order",
- default TRUE,
- data single string "aligned",
- constraint {
- set {
- "aligned",
- "input"
- }
- }
- },
- {
- name "ktuple",
- desc "ktuple (word size)",
- default TRUE,
- data single string "def",
- constraint {
- set {
- "def",
- "1",
- "2",
- "3",
- "4",
- "5"
- }
- }
- },
- {
- name "window",
- desc "Window length",
- default TRUE,
- data single string "def",
- constraint {
- set {
- "def",
- "10",
- "9",
- "8",
- "7",
- "6",
- "5",
- "4",
- "3",
- "2",
- "1",
- "0"
- }
- }
- },
- {
- name "topdiags",
- desc "Top diagonals",
- default TRUE,
- data single string "def",
- constraint {
- set {
- "def",
- "10",
- "9",
- "8",
- "7",
- "6",
- "5",
- "4",
- "3",
- "2",
- "1",
- "0"
- }
- }
- },
- {
- name "matrix",
- desc "Matrix (protein)",
- default TRUE,
- data single string "def",
- constraint {
- set {
- "def",
- "blosum",
- "pam",
- "gonnet",
- "id"
- }
- }
- },
- {
- name "gapopen",
- desc "Gap open penalty",
- default TRUE,
- data single string "def",
- constraint {
- set {
- "def",
- "100",
- "50",
- "25",
- "10",
- "5",
- "2",
- "1"
- }
- }
- },
- {
- name "gapext",
- desc "Gap extension penalty",
- default TRUE,
- data single string "def",
- constraint {
- set {
- "def",
- "0.05",
- "0.5",
- "1",
- "2.5",
- "5",
- "7.5",
- "10"
- }
- }
- },
- {
- name "gapdist",
- desc "Gap separation pen. range",
- default TRUE,
- data single string "def",
- constraint {
- set {
- "def",
- "10",
- "9",
- "8",
- "7",
- "6",
- "5",
- "4",
- "3",
- "2",
- "1"
- }
- }
- }
- }
- }
- }
- }
- '''
- sys.exit(0)
- # otherwise, run
- # write a temporary fasta file containing the sequences
- infile = tempfile.mktemp('.fasta')
- FastaFromCGI(args['locs'], infile)
- # get the arguments
- switches = []
- params = {}
- output = args['output'][0]
- if (output != 'clustal'):
- params['output'] = output
-
- if (args['alignment'][0] == 'fast'):
- switches.append('quicktree')
- params['outorder'] = args['outorder'][0]
- # things that could be 'def', otherwise need to be passed
- # on command line
- for name in ['ktuple', 'window', 'topdiags',
- 'matrix', 'gapopen', 'gapext', 'gapdist']:
- value = args[name][0]
- if (value != 'def'):
- params[name] = value
- params['infile'] = infile
- outfile = tempfile.mktemp() # temp file for output
- params['outfile'] = outfile
- # build the command line
- arglist = ''
- for switch in switches:
- arglist += ' -' + switch
- for param in params.keys():
- arglist += ' -' + param + '=' + params[param]
- cline = 'clustalw' + arglist
- print cline + 'n'
- sys.stdout.flush()
- # run clustalw, which must be on path
- os.system(cline)
- os.system('cat %s' % outfile)
- # then delete the temporary files
- os.system('rm %s %s' % (infile, outfile))
- # ===========================================================================
- # $Log: clustalw.py,v $
- # Revision 1000.0 2003/10/31 21:37:53 gouriano
- # PRODUCTION: IMPORTED [ORIGINAL] Dev-tree R1.4
- #
- # Revision 1.4 2003/10/29 20:12:05 jcherry
- # Reflect new spec for plugin args
- #
- # Revision 1.3 2003/10/07 13:47:02 dicuccio
- # Renamed CPluginURL* to CPluginValue*
- #
- # Revision 1.2 2003/07/30 19:38:20 jcherry
- # Added a bunch of parameters for the alignment
- #
- # Revision 1.1 2003/07/28 22:34:39 jcherry
- # Initial version
- #
- # ===========================================================================
- #
- # ===========================================================================
- # PRODUCTION $Log: clustalw.py,v $
- # PRODUCTION Revision 1000.0 2003/10/31 21:37:53 gouriano
- # PRODUCTION PRODUCTION: IMPORTED [ORIGINAL] Dev-tree R1.4
- # PRODUCTION
- # ===========================================================================
- #