comparison commons/core/parsing/multifastaParserLauncher.py @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
children
comparison
equal deleted inserted replaced
5:ea3082881bf8 6:769e306b7933
1 #!/usr/bin/env python
2
3 """
4 Launcher for the multifasta parser.
5 @param b: Name of the batch of sequences
6 @param g: Name of the gene
7 @param t: Scientific name of the taxon concerned
8 @param f: Name of the multifasta input file
9 """
10
11
12 import os
13 import sys
14 import getopt
15 from commons.core.parsing.Multifasta2SNPFile import Multifasta2SNPFile
16
17 CURRENT_DIR = os.getcwd()
18
19 def help():
20
21 """
22 Give the list of the command-line options.
23 """
24
25 print "Usage: ",sys.argv[0],"[ options ]"
26 print " -h: this help"
27 print "Mandatory option:"
28 print " -t: Scientific name of the taxon concerned"
29 print "Exclusive options (use either the first or the second, one should be used)"
30 print " -f: Name of the multifasta input file in one batch mode"
31 print " -d: Name of the directory containing multifasta input file(s) in multi-batch mode"
32 print "Only in one batch mode: mandatory options (when -f is used):"
33 print " -b: Name of the batch of submitted sequences"
34 print " -g: Name of the gene"
35 print ""
36
37
38 def runOneInputFile(batchName, geneName, taxon, inputFileName):
39 print "Multifasta parseur launched:!\n"
40 print "-- Input File: " + inputFileName + "\n"
41 print "-- Batch name: " + batchName + "\n"
42 print "-- Gene name: " + geneName + "\n"
43 print "-- Taxon: " + taxon + "\n"
44 #TODO: gerer le delete des fichiers(mode append)
45 multifasta2SNPFile = Multifasta2SNPFile(taxon, batchName, geneName)
46 multifasta2SNPFile.runOneBatch(inputFileName)
47 print "OK: Files generated!"
48
49
50 def runSeveralInputFile(taxon, rootDirectoryName):
51 multifasta2SNPFile = Multifasta2SNPFile(taxon)
52 multifasta2SNPFile.runSeveralBatches(rootDirectoryName)
53
54 def main():
55 batchName = ""
56 geneName = ""
57 taxon = ""
58 inputFileName = ""
59 rootDirectoryName = ""
60
61
62 try:
63 opts,args = getopt.getopt(sys.argv[1:],"hb:g:t:f:d:")
64 except getopt.GetoptError:
65 print "Invalid options\n"
66 help()
67 sys.exit(2)
68
69 for o, a in opts:
70 if o == "-h":
71 help()
72 exit(0)
73 elif o == "-b":
74 batchName = a
75 elif o == "-g":
76 geneName = a
77 elif o == "-t":
78 taxon = a
79 elif o == "-f":
80 inputFileName = a
81 elif o == "-d":
82 rootDirectoryName = os.path.abspath(a)
83
84 if taxon == "":
85 print "*** Error: The mandatory option -t is missing"
86 help()
87 sys.exit(1)
88
89 if (inputFileName == "" and rootDirectoryName == "") or (inputFileName != "" and rootDirectoryName != ""):
90 print "*** Error: You have to specify the input mode: choose either -f (for one file) or -d (for one directory of several files)"
91 help()
92 sys.exit(1)
93
94 if(inputFileName != ""):
95 if batchName == "" or geneName == "":
96 print "*** Error: A mandatory option is missing in one batch mode (-b or -g)"
97 help()
98 sys.exit(1)
99
100 if(inputFileName != ""):
101 runOneInputFile(batchName, geneName, taxon, inputFileName)
102 else:
103 runSeveralInputFile(taxon, rootDirectoryName)
104
105
106 return 0
107
108 #------------------------------------------------------------------------------
109 if __name__ == "__main__":
110 main()