0
|
1 #!/usr/bin/env python
|
|
2
|
|
3 """
|
|
4 Author: George Weingart
|
|
5 Description: Prepare parameters to call micropita
|
|
6 """
|
|
7
|
|
8 #####################################################################################
|
|
9 #Copyright (C) <2012>
|
|
10 #
|
|
11 #Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
12 #this software and associated documentation files (the "Software"), to deal in the
|
|
13 #Software without restriction, including without limitation the rights to use, copy,
|
|
14 #modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
15 #and to permit persons to whom the Software is furnished to do so, subject to
|
|
16 #the following conditions:
|
|
17 #
|
|
18 #The above copyright notice and this permission notice shall be included in all copies
|
|
19 #or substantial portions of the Software.
|
|
20 #
|
|
21 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
22 #INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
23 #PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
24 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
25 #OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
26 #SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
27 #####################################################################################
|
|
28
|
|
29 __author__ = "George Weingart"
|
|
30 __copyright__ = "Copyright 2012"
|
|
31 __credits__ = ["George Weingart"]
|
|
32 __license__ = "MIT"
|
|
33 __maintainer__ = "George Weingart"
|
|
34 __email__ = "george.weingart@gmail.com"
|
|
35 __status__ = "Development"
|
|
36
|
|
37 import argparse
|
|
38 from cStringIO import StringIO
|
|
39 import sys,string,time
|
|
40 import os
|
|
41 from time import gmtime, strftime
|
|
42 from pprint import pprint
|
|
43
|
|
44 ##################################################################################
|
|
45 # Decode Parms #
|
|
46 ##################################################################################
|
|
47 def read_params(x):
|
|
48 parser = argparse.ArgumentParser(description='Micropita Annotate Argparser')
|
|
49 parser.add_argument('--input', action="store",dest='inputname')
|
|
50 parser.add_argument('--output', action="store",dest='outputname')
|
|
51 parser.add_argument('-m', action="store",dest='MParameter')
|
|
52 parser.add_argument('-n', action="store",dest='NSamples')
|
|
53 parser.add_argument('--lastmeta', action="store",dest='lastmeta')
|
|
54 parser.add_argument('--stratify_value', action="store",dest='stratify_value')
|
|
55
|
|
56
|
|
57 try:
|
|
58 parser.add_argument('--feature_method', action="store",dest='feature_method')
|
|
59 except:
|
|
60 pass
|
|
61 try:
|
|
62 parser.add_argument('--targets', action="store",dest='targets')
|
|
63 except:
|
|
64 pass
|
|
65 try:
|
|
66 parser.add_argument('--label_value', action="store",dest='label_value')
|
|
67 except:
|
|
68 pass
|
|
69
|
|
70
|
|
71
|
|
72 return parser
|
|
73
|
|
74
|
|
75 ##################################################################################
|
|
76 # Main Program #
|
|
77 ##################################################################################
|
|
78 parser = read_params( sys.argv )
|
|
79 results = parser.parse_args()
|
|
80 root_dir = os.environ.get('micropita_SCRIPT_PATH')
|
|
81
|
|
82
|
|
83 fname = results.inputname
|
|
84 input_file = open(fname,'rU')
|
|
85 input_lines = input_file.readlines()
|
|
86 input_file.close()
|
|
87 table_lines = []
|
|
88 for x in input_lines:
|
|
89 first_column = x.split('\t')[0]
|
|
90 table_lines.append(first_column)
|
|
91
|
|
92
|
|
93
|
|
94 FileTimeStamp = strftime("%Y%m%d%H%M%S", gmtime())
|
|
95 LastMetaInt = 0
|
|
96 if results.lastmeta and not results.lastmeta == "None":
|
|
97 LastMetaInt = int(results.lastmeta) - 1
|
|
98
|
|
99 StratifyValueInt = 0
|
|
100 if results.stratify_value and not results.stratify_value == "None":
|
|
101 StratifyValueInt = int(results.stratify_value) - 2
|
|
102
|
|
103 LabelValueInt = 0
|
|
104 if results.label_value and not results.label_value == "None":
|
|
105 LabelValueInt = int(results.label_value) - 1
|
|
106
|
|
107 stratify_string = ""
|
|
108 q = '"'
|
|
109 if not results.stratify_value == '1':
|
|
110 stratify_string = " --stratify " + q + table_lines[StratifyValueInt] + q + " "
|
|
111
|
|
112 if results.MParameter == "features":
|
|
113 TBTargets = list()
|
|
114 TableTargets = results.targets.split(',')
|
|
115 for t in TableTargets:
|
|
116 tb_entry = int(t) + LastMetaInt
|
|
117 TBTargets.append(int(tb_entry))
|
|
118
|
|
119
|
|
120 TempTargetsFileName = "/tmp/micropita_targets" + FileTimeStamp
|
|
121 OutTargetsFile = open(TempTargetsFileName,"w")
|
|
122 indx = -1
|
|
123 for c in table_lines:
|
|
124 indx+=1
|
|
125 if indx in TBTargets:
|
|
126 OutputString = table_lines[indx] + "\n"
|
|
127 OutTargetsFile.write(OutputString)
|
|
128 OutTargetsFile.close()
|
|
129
|
|
130 os_command = "python " + \
|
|
131 root_dir + "/" +\
|
|
132 "MicroPITA.py "+\
|
|
133 "--lastmeta " + table_lines[LastMetaInt]+ " " +\
|
|
134 "--feature_method " + results.feature_method + " " + \
|
|
135 "--target " + TempTargetsFileName + " " +\
|
|
136 "-m " + results.MParameter + " " + \
|
|
137 "-n " + results.NSamples + " " +\
|
|
138 stratify_string + " " +\
|
|
139 results.inputname + " " +\
|
|
140 results.outputname
|
|
141 #print os_command
|
|
142 os.system(os_command)
|
|
143
|
|
144 if results.MParameter == "representative"\
|
|
145 or results.MParameter == "diverse"\
|
|
146 or results.MParameter == "extreme":
|
|
147 os_command = "python " + \
|
|
148 root_dir + "/" +\
|
|
149 "MicroPITA.py "+\
|
|
150 "--lastmeta " + table_lines[LastMetaInt]+ " " +\
|
|
151 "-m " + results.MParameter + " " + \
|
|
152 "-n " + results.NSamples + " " +\
|
|
153 stratify_string + " " + \
|
|
154 results.inputname + " " +\
|
|
155 results.outputname
|
|
156 #print os_command
|
|
157 os.system(os_command)
|
|
158
|
|
159 if results.MParameter == "distinct"\
|
|
160 or results.MParameter == "discriminant":
|
|
161 os_command = "python " + \
|
|
162 root_dir + "/" +\
|
|
163 "MicroPITA.py "+\
|
|
164 "--lastmeta " + table_lines[LastMetaInt]+ " " +\
|
|
165 "--label " + table_lines[LastMetaInt]+ " " +\
|
|
166 "-m " + results.MParameter + " " + \
|
|
167 "-n " + results.NSamples + " " +\
|
|
168 stratify_string + " " + \
|
|
169 results.inputname + " " +\
|
|
170 results.outputname
|
|
171 #print os_command
|
|
172 os.system(os_command)
|