comparison commons/launcher/launchMafft.py @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -0400
parents 94ab73e8a190
children
comparison
equal deleted inserted replaced
30:5677346472b5 31:0ab839023fe4
1 #!/usr/bin/env python
2
3 # DEPRECATED
4
5 import user, os, sys, getopt, exceptions
6
7 if not os.environ.has_key( "REPET_PATH" ):
8 print "*** Error: no environment variable REPET_PATH"
9 sys.exit(1)
10 sys.path.append( os.environ["REPET_PATH"] )
11
12 import pyRepet.launcher.programLauncher
13 import pyRepet.seq.fastaDB
14 from pyRepet.seq.BioseqDB import *
15
16 #------------------------------------------------------------------------------
17
18 def help():
19
20 print
21 print "DEPRECATED"
22 print
23 print "usage: ",sys.argv[0],"[ options ]"
24 print "options:"
25 print " -h: this help"
26 print " -i: name of the input file (format='fasta')"
27 print " -o: name of the output file (default=inFileName+'.fa_aln')"
28 print " -v: verbose (default=0/1)"
29 print
30
31 #------------------------------------------------------------------------------
32
33 def main():
34
35 """
36 This program launches MAFFT to build a multiple sequence alignment.
37 """
38
39 inFileName = ""
40 outFileName = ""
41 verbose = 0
42
43 try:
44 opts,args=getopt.getopt(sys.argv[1:],"hi:o:v:")
45 except getopt.GetoptError:
46 help()
47 sys.exit(1)
48 for o,a in opts:
49 if o == "-h":
50 help()
51 sys.exit(0)
52 elif o == "-i":
53 inFileName = a
54 elif o == "-o":
55 outFileName = a
56 elif o == "-v":
57 verbose = int(a)
58
59 if inFileName == "":
60 print "*** Error: missing compulsory options"
61 help()
62 sys.exit(1)
63
64 if verbose > 0:
65 print "beginning of %s" % (sys.argv[0].split("/")[-1])
66 sys.stdout.flush()
67
68 if verbose > 0:
69 print "build a multiple alignment from '%s'..." % ( inFileName )
70 sys.stdout.flush()
71
72 pyRepet.seq.fastaDB.shortenSeqHeaders( inFileName )
73
74 bsDB = BioseqDB( inFileName+".shortH" )
75 bsDB.upCase()
76 bsDB.save( inFileName+".shortHtmp" )
77 del bsDB
78 os.rename( inFileName+".shortHtmp", inFileName+".shortH" )
79
80 pL = pyRepet.launcher.programLauncher.programLauncher( inFileName+".shortH" )
81 pL.launchMafft( outFileName=inFileName+".shortH.fa_aln", verbose=verbose )
82
83 pyRepet.seq.fastaDB.retrieveInitSeqHeaders( inFileName+".shortH.fa_aln",
84 inFileName+".shortHlink",
85 inFileName+".shortH.fa_aln.initH",
86 verbose-1 )
87
88 if outFileName == "":
89 outFileName = "%s.fa_aln" % ( inFileName )
90 os.system( "mv %s.shortH.fa_aln.initH %s" % ( inFileName, outFileName ) )
91
92 for f in [inFileName+".shortH",inFileName+".shortH.fa_aln",inFileName+".shortHlink"]:
93 os.remove( f )
94
95 if verbose > 0:
96 print "%s finished successfully" % (sys.argv[0].split("/")[-1])
97 sys.stdout.flush()
98
99 return 0
100
101 #------------------------------------------------------------------------------
102
103 if __name__ == '__main__':
104 main()