How to use sub_method method in autopy

Best Python code snippet using autopy

filterStatPandaMatrixByGroup.py

Source:filterStatPandaMatrixByGroup.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- coding: utf-8 -*-3#from __future__ import unicode_literals4from __future__ import division, with_statement5'''6Copyright 2015, 陈同 (chentong_biology@163.com). 7===========================================================8'''9__author__ = 'chentong & ct586[9]'10__author_email__ = 'chentong_biology@163.com'11#=========================================================12desc = '''13Program description:14 This is designed to extract part rows by given group, such as top 10 variable items in each group. 15'''16import sys17import os18from json import dumps as json_dumps19from time import localtime, strftime 20timeformat = "%Y-%m-%d %H:%M:%S"21from optparse import OptionParser as OP22import pandas as pd23import re24#from multiprocessing.dummy import Pool as ThreadPool25#from bs4 import BeautifulSoup26#reload(sys)27#sys.setdefaultencoding('utf8')28debug = 029def isfloat(x):30 try:31 a = float(x)32 except ValueError:33 return Fslse34 else:35 return True36#---------------------------------37def isint(x):38 try:39 a = float(x)40 b = int(a)41 except ValueError:42 return False43 else:44 return a == b45#-------------------------------------46def fprint(content):47 """ 48 This is a Google style docs.49 Args:50 param1(str): this is the first param51 param2(int, optional): this is a second param52 53 Returns:54 bool: This is a description of what is returned55 56 Raises:57 KeyError: raises an exception))58 """59 print json_dumps(content,indent=1)60def cmdparameter(argv):61 if len(argv) == 1:62 global desc63 print >>sys.stderr, desc64 cmd = 'python ' + argv[0] + ' -h'65 os.system(cmd)66 sys.exit(1)67 usages = "%prog -i file"68 parser = OP(usage=usages)69 parser.add_option("-i", "--input-file", dest="filein",70 metavar="FILEIN", help="A numerical matrix file")71 parser.add_option("-T", "--transpose-data", dest="transpose",72 default=False, action="store_true", 73 help="Transpose data before doing all stats, meaning doing all stats for columns.")74 parser.add_option("-H", "--header", dest="header",75 default=0, type='int', help="An integer to specify the header line. Default <O> represents using first line as header line. Give <-1> to specify no header line." )76 parser.add_option("-r", "--index-col", dest="index_col",77 default='0', help="Column to use as the row labels of the DataFrame (Default 0 represents the first column). If a sequence like <0,1,2> is given, a MultiIndex will be used. Supply <None> to turn off index_col. All none numerical columns should be used as index.")78 parser.add_option("-g", "--group-col", dest="group_col",79 help="The column name used for grouping. Normally this column should be used as index also.")80 parser.add_option("-c", "--usecols", dest="usecols",81 default="None", help="Return a subset of the columns. All elements in this array must either \82be positional (i.e. integer indices into the document columns) or strings \83that correspond to column names provided either by the user in `names` or \84inferred from the document header row(s). For example, a valid `usecols` \85parameter would be <0,1,2> or <foo,bar,baz>. Using this parameter \86results in much faster parsing time and lower memory usage. \87*******One important note, <index_col> should be also included in <usecols>. \88Default <None> to read in all columns.")89 #parser.add_option("-n", "--rename_cols", dest="rename_cols",90 # default="infer", help="Rename columns before merging. If only one column is \91#extracted (excluding row index), column name will be renamed with <file_label>; \92#If more than one columns are extracted, column names will be renamed with <file_label_original_name>. \93#If a list of names are given when extracting multiple columns, \94#column names will be renamed with <file_label_given_name>.\95#Supply <None> to disable rename.")96 parser.add_option("-m", "--method", dest="method",97 help="One or a list of statistics to be computed for each row, like <mad,std,mean,sum,median,min,max,var,skew,kurt,>")98 parser.add_option("-s", "--sort-values", dest="sort_values",99 help="One or a list of statistics to be used for sorting. Default using values given to <-m>.")100 parser.add_option("-a", "--ascending", dest="ascending",101 default=False, action="store_true", 102 help="Sort ascending vs. descending (default).")103 parser.add_option("-t", "--top", dest="top",104 default='10', 105 help="Screen given number of top items or given percentage of top items. Default 10 for each group.")106 parser.add_option("-O", "--statistics-only", dest="statistics_only", 107 default=False, action="store_true", help="[Uppercase O] Default output original matrix combined with computed statistics. Specify to output only computed statistics result.")108 parser.add_option("-o", "--outputfile", dest="output",109 help="[Lowercase o] Output file prefix. Default input file with suffix <.xls, .tsv, .csv, .txt removed if exists>. A suffix <xls.gz> will be added.")110 parser.add_option("-u", "--uncompressed", dest="uncompressed",111 default=False, action="store_true", help="Default output gzipped file. Specify to output uncompressed result.")112 parser.add_option("-v", "--verbose", dest="verbose",113 action="store_true", help="Show process information")114 parser.add_option("-D", "--debug", dest="debug",115 default=False, action="store_true", help="Debug the program")116 (options, args) = parser.parse_args(argv[1:])117 assert options.filein != None, "A filename needed for -i"118 return (options, args)119#--------------------------------------------------------------------120def main():121 options, args = cmdparameter(sys.argv)122 #-----------------------------------123 file = options.filein124 transpose = options.transpose125 statistics_only = options.statistics_only126 group_col = options.group_col127 #fileL = re.split(r'[, ]*', file.strip())128 #if options.rename_cols != "None":129 # label = options.label130 # labelL = re.split(r'[, ]*', label.strip())131 #else:132 # labelL = fileL133 header = options.header134 if header == -1:135 header = 'None'136 index_col = options.index_col.strip()137 if index_col != "None":138 index_col = [int(i) for i in re.split(r'[, ]*', index_col)]139 else:140 index_col = None141 #-----------------------------------------------------142 usecols = options.usecols143 #print >>sys.stderr, usecols144 if usecols != "None":145 usecols = usecols.split(',')146 usecols_2 = [int(i) for i in usecols if i.isdigit()]147 if len(usecols_2) == len(usecols):148 usecols = usecols_2149 else:150 usecols = None151 #print >>sys.stderr, usecols152 #---------------------------------------------------------153 #rename_cols = options.rename_cols154 #if rename_cols not in ["infer", "None"]:155 # rename_cols = re.split(r'[, ]*', rename_cols.strip())156 methodD = {"mad":1,"std":1,"mean":1,"sum":1,"median":1,157 "min":1,"max":1,"var":1,"skew":1,"kurt":1}158 method = options.method159 assert method, "-m/--method is missing"160 methods = re.split(r'[, ]*', method.strip())161 for i in methods:162 assert i in methodD, sys.exit("Un-supproted method "+i)163 #--------------------164 sort_values = options.sort_values165 if sort_values:166 sort_values = re.split(r'[, ]*', sort_values.strip())167 else:168 sort_values = methods169 #--------------------------------------------------170 ascending = options.ascending171 uncompressed = options.uncompressed172 if not options.output:173 suffix = ['xls', 'tsv', 'csv', 'txt']174 if file.find('.') != -1:175 file_name, suf = file.rsplit('.', 1)176 if suf not in suffix:177 file_name = file178 else:179 file_name = file180 output = file_name181 else:182 output = options.output183 output += '.' + '_'.join(methods)184 assert output, "-o/--outputfile should be supplied."185 verbose = options.verbose186 top = options.top187 global debug188 debug = options.debug189 #-----------------------------------190 matrix = pd.read_table(file, header=header, index_col=index_col, usecols=usecols)191 total_line = matrix.shape[0]192 if transpose:193 matrix = matrix.T194 matrix.index.name = "ID"195 statL = []196 for sub_method in methods:197 if sub_method == "mad":198 stat = matrix.mad(axis=1).to_frame(sub_method)199 elif sub_method == "std":200 stat = matrix.std(axis=1).to_frame(sub_method)201 elif sub_method == "mean":202 stat = matrix.mean(axis=1).to_frame(sub_method)203 elif sub_method == "sum":204 stat = matrix.sum(axis=1).to_frame(sub_method)205 elif sub_method == "median":206 stat = matrix.median(axis=1).to_frame(sub_method)207 elif sub_method == "min":208 stat = matrix.min(axis=1).to_frame(sub_method)209 elif sub_method == "max":210 stat = matrix.max(axis=1).to_frame(sub_method)211 elif sub_method == "var":212 stat = matrix.var(axis=1).to_frame(sub_method)213 elif sub_method == "skew":214 stat = matrix.skew(axis=1).to_frame(sub_method)215 elif sub_method == "kurt":216 stat = matrix.kurt(axis=1).to_frame(sub_method)217 else:218 assert 1==0, "%s unknown method" % sub_method219 continue220 statL.append(stat)221 #--------------------------------------------------------222 if statistics_only:223 matrix = statL[0].join(statL[1:])224 else:225 matrix = matrix.join(statL)226 matrix.sort_values(by=methods, axis=0, ascending=ascending, inplace=True)227 matrix.reset_index(inplace=True)228 if uncompressed:229 full = output + '.xls'230 matrix.to_csv(full, sep=b"\t")231 else:232 full = output + '.xls.gz'233 matrix.to_csv(full, sep=b"\t", compression='gzip')234 if top:235 top_old = top236 top = float(top)237 if top < 1:238 top = top * total_line239 top = int(top)240 #if top >= total_line:241 # if uncompressed:242 # file = output+'.xls'243 # top = output+'.'+str(top)+'.xls'244 # else:245 # file = output+'.xls.gz'246 # top = output+'.'+str(top)+'.xls.gz'247 # path_name, file_name = os.path.split(file)248 # path_name, top_name = os.path.split(top)249 # os.system("(cd {}; ln -sf {} {})".format(path_name, file_name, top_name))250 # return251 if statistics_only:252 #matrix = matrix[0:top]253 matrix = matrix.groupby(group_col).head(top)254 else:255 matrix = matrix.groupby(group_col).head(top)256 dropCl = methods[:]257 dropCl.append(group_col)258 matrix = matrix.drop(dropCl, axis=1)259 if uncompressed:260 matrix.to_csv(output+'.top'+top_old+'.xls', sep=b"\t", index=False)261 else:262 matrix.to_csv(output+'.top'+top_old+'.xls.gz', compression='gzip', sep=b"\t", index=False)263 ###--------multi-process------------------264 #pool = ThreadPool(5) # 5 represents thread_num265 #result = pool.map(func, iterable_object)266 #pool.close()267 #pool.join()268 ###--------multi-process------------------269 if verbose:270 print >>sys.stderr,\271 "--Successful %s" % strftime(timeformat, localtime())272if __name__ == '__main__':273 startTime = strftime(timeformat, localtime())274 main()275 endTime = strftime(timeformat, localtime())276 fh = open('python.log', 'a')277 print >>fh, "%s\n\tRun time : %s - %s " % \278 (' '.join(sys.argv), startTime, endTime)279 fh.close()280 ###---------profile the program---------281 #import profile282 #profile_output = sys.argv[0]+".prof.txt")283 #profile.run("main()", profile_output)284 #import pstats285 #p = pstats.Stats(profile_output)286 #p.sort_stats("time").print_stats()...

Full Screen

Full Screen

IntegrationModule_getTioSafeXMLDiff.py

Source:IntegrationModule_getTioSafeXMLDiff.py Github

copy

Full Screen

...30 try:31 pub_xml.append(getattr(ob, pub_xml_method)(context_document=im.getSourceSection()))32 except TypeError:33 pub_xml.append(getattr(ob, pub_xml_method)())34 sub_object = sub_method(context_document=im.getDestinationSectionValue())35 sub_object.sort(cmp=tiosafe_sort)36 for ob in sub_object:37 try:38 sub_xml.append(getattr(ob, sub_xml_method)(context_document=im.getDestinationSection()))39 except TypeError:40 sub_xml.append(getattr(ob, sub_xml_method)())41else:42 raise ValueError("Impossible to get method, pub_method = %s from %s, sub_method = %s from %s" %(pub_method, pub_list, sub_method, sub_list,))43pub_xml = '\n'.join(pub_xml)44sub_xml = '\n'.join(sub_xml)...

Full Screen

Full Screen

PSAppDesigner.py

Source:PSAppDesigner.py Github

copy

Full Screen

1import win32com.client2import pythoncom3ProgID = "Excel.Application"4com_object = win32com.client.Dispatch(ProgID)5# print dir(com_object)6for key in dir(com_object):7 method = getattr(com_object,key)8 if str(type(method)) == "<type 'instance'>":9 print key10 for sub_method in dir(method):11 if not sub_method.startswith("_") and not "clsid" in sub_method.lower():12 print "\t"+sub_method13 else: ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autopy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful