annotate commons/launcher/launchMafft.py @ 18:94ab73e8a190

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