annotate tools/rgenetics/rgClustalw.py @ 1:cdcb0ce84a1b

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:45:15 -0500
parents 9071e359b9a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2 rgclustalw.py
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 wrapper for clustalw necessitated by bad choice of output path for .dnd file based on input file. Naughty.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 Copyright ross lazarus march 2011
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 All rights reserved
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 Licensed under the LGPL
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 import sys,optparse,os,subprocess,tempfile,shutil
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 class Clustrunner:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 def __init__(self,opts=None):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 self.opts = opts
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 self.iname = 'infile_copy'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 shutil.copy(self.opts.input,self.iname)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 def run(self):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 tlf = open(self.opts.outlog,'w')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 cl = ['clustalw2 -INFILE=%s -OUTFILE=%s -OUTORDER=%s -TYPE=%s -OUTPUT=%s' % (self.iname,self.opts.output,self.opts.out_order,self.opts.dnarna,self.opts.outform)]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 if self.opts.seq_range_end <> None and self.opts.seq_range_start <> None:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 cl.append('-RANGE=%s,%s' % (self.opts.seq_range_start,self.opts.seq_range_end))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 if self.opts.outform=='CLUSTAL' and self.opts.outseqnos <> None:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 cl.append('-SEQNOS=ON')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 process = subprocess.Popen(' '.join(cl), shell=True, stderr=tlf, stdout=tlf)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 rval = process.wait()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 dndf = '%s.dnd' % self.iname
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 if os.path.exists(dndf):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 tlf.write('\nClustal created the following dnd file for your information:\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 dnds = open('%s.dnd' % self.iname,'r').readlines()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 for row in dnds:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 tlf.write(row)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 tlf.write('\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 tlf.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 os.unlink(self.iname)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 if __name__ == "__main__":
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 op = optparse.OptionParser()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 op.add_option('-i', '--input', default=None)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 op.add_option('-o', '--output', default=None)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 op.add_option('-t', '--outname', default="rgClustal")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 op.add_option('-s', '--out_order', default='ALIGNMENT')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 op.add_option('-f', '--outform', default='CLUSTAL')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 op.add_option('-e', '--seq_range_end',default=None)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 op.add_option('-b', '--seq_range_start',default=None)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 op.add_option('-l','--outlog',default='rgClustalw.log')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 op.add_option('-q', '--outseqnos',default=None)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51 op.add_option('-d', '--dnarna',default='DNA')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53 opts, args = op.parse_args()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 assert opts.input <> None
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 assert os.path.isfile(opts.input)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56 c = Clustrunner(opts)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57 c.run()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
58
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
59
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
60