comparison rgClustalw.py @ 0:de3662385a52 draft

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