bl2seq.py
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:3k
- #!/usr/bin/python
- # $Id: bl2seq.py,v 1000.0 2003/10/31 21:37:46 gouriano Exp $
- #
- # Author: Josh Cherry
- #
- # align two nucleotide sequences using bl2seq
- # (from gbench)
- import sys
- import cgi
- import os
- import tempfile
- def writefasta(seq, fname, seqname):
- s = ">" + seqname + "n"
- 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 "bl2seq.py",
- menu-item "Alignments/Align two sequences using blast",
- tooltip "Align two sequences using blast (bl2seq)",
- commands algo {
- {
- command 3,
- args {
- {
- name "locs",
- desc "Locations to evaluate",
- data array {
- object {
- docaddr "(nil)",
- objaddr "(nil)",
- subtype "Seq-loc"
- }
- }
- }
- }
- }
- }
- }
- '''
- sys.exit(0)
- # otherwise, run
- locs = args['locs']
- if len(locs) != 2:
- sys.stderr.write("need exactly 2 sequences; you supplied %dn" % len(locs))
- sys.exit(1)
- # write temporary fasta files contining the sequences
- fname0 = tempfile.mktemp('.fasta')
- fname1 = tempfile.mktemp('.fasta')
- loc0 = cgi.parse_qs(locs[0]);
- loc1 = cgi.parse_qs(locs[1]);
- writefasta(loc0['seq'][0], fname0, loc0['title'][0])
- writefasta(loc1['seq'][0], fname1, loc1['title'][0])
- # run bl2seq, which must be on path
- os.system('bl2seq -p blastn -i %s -j %s' % (fname0, fname1))
- # then delete temporary fasta files
- os.system('rm %s %s' % (fname0, fname1))
- # ===========================================================================
- # $Log: bl2seq.py,v $
- # Revision 1000.0 2003/10/31 21:37:46 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 19:12:25 jcherry
- # Reflected change of PluginURL to PluginValue (changed addr to
- # value in asn.1)
- #
- # Revision 1.2 2003/10/07 13:47:01 dicuccio
- # Renamed CPluginURL* to CPluginValue*
- #
- # Revision 1.1 2003/07/28 18:24:31 jcherry
- # Initial version
- #
- # ===========================================================================
- #
- # ===========================================================================
- # PRODUCTION $Log: bl2seq.py,v $
- # PRODUCTION Revision 1000.0 2003/10/31 21:37:46 gouriano
- # PRODUCTION PRODUCTION: IMPORTED [ORIGINAL] Dev-tree R1.4
- # PRODUCTION
- # ===========================================================================
- #