annotate commons/launcher/LaunchRefalign_old.py @ 19:9bcfa7936eec

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:23:29 -0400
parents 94ab73e8a190
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 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 import sys
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5 import getopt
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 import pyRepet.launcher.programLauncher
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 from commons.core.seq.BioseqDB import BioseqDB
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9 from commons.tools.ChangeSequenceHeaders import ChangeSequenceHeaders
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 def help():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 print
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 print "usage: launchRefalign.py [ options ]"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 print "options:"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 print " -h: this help"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 print " -i: name of the input file (refseq is first, format='fasta')"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 print " -r: keep the reference sequence"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 print " -o: name of the output file (default=inFileName+'.fa_aln')"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 print " -v: verbose (default=0)"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 print
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 def main():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 """
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 Launch 'refalign' to build a master-slave multiple sequence alignment.
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 """
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 inFileName = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 keepRefseq = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 outFileName = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 verbose = 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 try:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 opts,args=getopt.getopt(sys.argv[1:],"hi:ro:v:")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 except getopt.GetoptError, err:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 print str(err); help(); sys.exit(1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 for o,a in opts:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 if o == "-h":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 help()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 sys.exit(0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 elif o == "-i":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 inFileName = a
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 elif o == "-r":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 keepRefseq = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 elif o == "-o":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 outFileName = a
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 elif o == "-v":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 verbose = int(a)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 if inFileName == "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 print "ERROR: missing compulsory options"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 help()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 sys.exit(1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 if verbose > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 print "START %s" % (sys.argv[0].split("/")[-1])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 sys.stdout.flush()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 if verbose > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 print "build a multiple alignment from '%s'..." % ( inFileName )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 sys.stdout.flush()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61 if outFileName == "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 outFileName = "%s.fa_aln" % ( inFileName )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 csh = ChangeSequenceHeaders()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 csh.setInputFile( inFileName )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 csh.setFormat( "fasta" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 csh.setStep( 1 )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 csh.setPrefix( "seq" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 csh.setLinkFile( inFileName+".shortHlink" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 csh.setOutputFile( inFileName+".shortH" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 csh.setVerbosityLevel( verbose - 1 )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 csh.run()
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 if keepRefseq:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 pL.launchRefalign( outFileName=inFileName+".shortH.fa_aln", refseqName="seq1", verbose=verbose )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84 pL.launchRefalign( outFileName=inFileName+".shortH.fa_aln", verbose=verbose )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 csh.setInputFile( inFileName+".shortH.fa_aln" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87 csh.setFormat( "fasta" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88 csh.setStep( 2 )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 csh.setLinkFile( inFileName+".shortHlink" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90 csh.setOutputFile( outFileName )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91 csh.setVerbosityLevel( verbose - 1 )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 csh.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 for f in [ inFileName+".shortH", inFileName+".shortHlink", inFileName+".shortH.fa_aln" ]:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
95 os.remove( f )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97 if verbose > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98 print "END %s" % (sys.argv[0].split("/")[-1])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99 sys.stdout.flush()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 return 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
102
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
103
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
104 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
105 main()