annotate rgClustalw.py @ 0:de3662385a52 draft

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