annotate commons/core/parsing/multifastaParserLauncher.py @ 31:0ab839023fe4

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