def inbox_by_context_name(): import sys sys.error("Don't do this") for t in Thing.objects.all(): if t.context.name.lower().find(INBOX_CONTEXT_STR) >= 0: t.status = t.STATE_INBOX t.save()
def ippft( f , niter=6 , eps=1e-8 ): ## Check whether the input Pseudo Polar Grid is a 2D array ## and it is a square matrix if f.ndim != 2: sys.error('ERROR: input for inversePseudoPolarFT is not a 2D array!') if f.shape[0] != f.shape[1]: sys.error('WARNING: input for inversePseudoPolarFT is not a square matrix') ## Convert input Pseudo Polar Grid to myComplex format f = f.astype( myComplex ) ## Get size of the output object n = int( 0.5 * f.shape[0] ) ## Create preconditioning matrix to decrease the ## conditioning number of the Pseudo Polar Operator M = np.array( np.sqrt( abs( np.arange(-n,n)/myFloat(n) ) ) ) M[n] = np.sqrt( 1.0/myFloat(4*n) ) M = np.ones( ( 2*n , 1 ) ) * M; M[:,:] = M[:,:]**2; ## Initialization of the preconditioned conjugate method xk = ppft_adj( np.multiply( M , f ) ) pk = xk - ppft_adj( M * ppft( xk ) ) rk = np.empty( ( n , n ) , dtype=myComplex ) rk[:,:] = pk[:,:] f[:,:] = 0 ppAdj = np.zeros( ( n , n ) , dtype=myComplex ) ## Print setu-up parameters for the IPPFT print(' PCG-IPPFT: stopping threshold: ' , eps ) print(' PCG-IPPFT: max number of CG-iterations: ' , niter ) ## Start conjugate gradient iterations it = 0 while it < niter: err = np.linalg.norm( pk ) print(' Iter = ' , it , ' cost function = ' , err ) if err > eps: f[:,:] = ppft( pk ) f[:,:] = np.multiply( M , f ) ppAdj[:,:] = ppft_adj( f ) a0 = np.sum( np.abs(rk) * np.abs(rk) ) a1 = np.sum( np.conjugate(pk) * ppAdj ) a = a0 / myComplex( a1 ) xk[:,:] += a*pk rk[:,:] -= a * ppAdj bb = np.sum( np.abs(rk) * np.abs(rk) ) b = bb/a0 pk[:,:] = rk + b * pk else: break it += 1 ## Final informative prints print(' PCG-IPPFT: number of CG-iterations used: ' , it ) print(' PCG-IPPFT: cost function: ' , err ) print(' .... PCG for inverse PPFT done!') return xk
def ppft_adj( f ): if f.ndim != 2: sys.error('ERROR: input for adjointPseudoPolarFT is not a 2D array!') nx,ny = f.shape if nx != ny or nx % 2: n = int( np.ceil( max(nx,ny)/2. ) * 2 ) else: n = nx n = int( n/2 ) f_out = np.zeros( ( n , n ), dtype=myComplex ) f_aux = np.zeros( ( 2*n , n ) , dtype=myComplex ) ## Vertical hourglass f_aux[:,:] = np.transpose( f[:n,:] ) for i in range( -n , n ): f_aux[i+n,:] = frft_ctr( f_aux[i+n,:] , i/myFloat( n ) ) f_aux[:,:] = np.roll( f_aux , n , axis=0 ) f_aux[:,:] = 2 * n * scipy.fftpack.ifft( f_aux , 2*n , axis=0 , overwrite_x=True ) f_aux[:,:] = np.fft.fftshift( f_aux , axes=(0,) ) f_out[:,:] = f_aux[n/2:3*n/2,:] ## Horizontal hourglass f_aux = f_aux.reshape( n , 2*n ) f_aux[:,:] = f[n:,:] for i in range( -n , n ): f_aux[:,i+n] = frft_ctr( f_aux[:,i+n] , i/myFloat( n ) ) f_aux[:,:] = np.roll( f_aux , n , axis=1 ) f_aux[:,:] = scipy.fftpack.fft( f_aux , 2*n , axis=1 , overwrite_x=True ) f_aux[:,:] = scipy.fftpack.fftshift( f_aux , axes=(1,) ) f_out[:,:] = 1/(n*np.sqrt(2)) * ( f_out[:,:] + f_aux[:,n/2:3*n/2] ) return f_out
def readGenes (fname): """ Take a file name that is bed-like (needs at least 3 columns) - will conserve strand and name if they exist Name will be the dictionary key for the output coverages """ genes = {} i = 1 with open(fname) as fn: for line in fn: if line.startswith('#'): continue try: chrom,start,end,name,score,strand = line.strip().split('\t')[:6] except: try: a = line.strip().split('\t') length = len(a) ext = 6-length a.extend(['.'] * ext) chrom, start, end, name, score, strand = a except: sys.error(fname, 'Not a valid bed') if name == '.': name = 'peak'+str(i) else: name = os.path.basename(name) #macs puts the full path in this name field, if it hasn't been cleaned up yet this will if args.m: start = (int(start)+int(end)) / 2 end = int(start +1 ) iv = HTSeq.GenomicInterval(chrom, start, end, strand) genes[str(name)] = iv i += 1 return(genes)
def close(self, exit = False): """ close finishes socket sessions. Best used after each run. exit=True, shuts down labview; Not recommended""" # close the remote channel through labview try: self.tSock.sendto('0005,0010,r', (self.host, self.tPort)) except: raise sys.error("Could not close remote channel. Socket connection broken.") if exit: try: self.tSock.sendto('0005,0010,x', (self.host, self.tPort)) except: raise sys.error("Could not exit LabVIEW. Socket connection broken.") #end socket sessions self.rSock.shutdown(1) self.tSock.shutdown(1) #close sockets self.rSock.close() self.tSock.close()
def get(self, options, url): data = get_http_data(url) match = re.search("liveStationsRedundancy = ({.*});</script>", data) parse = urlparse(url) station = parse.path[1:] streams = None if match: data = json.loads(match.group(1)) for i in data["stations"]: if station == i["name"].lower().replace(" ", ""): streams = i["streams"] break else: log.error("Can't find any streams.") sys.exit(2) if streams: if options.hls: try: m3u8_url = streams["hls"] base_url = m3u8_url.rsplit("/", 1)[0] download_hls(options, m3u8_url, base_url) except KeyError: log.error("Can't find any streams.") sys.error(2) else: try: rtmp = streams["rtmp"] download_rtmp(options, rtmp) except KeyError: mp3 = streams["mp3"] download_http(options, mp3) else: log.error("Can't find any streams.") sys.exit(2)
def plot_volumes(volume_files): """ Use fslview to visualize image volume data. Inputs ------ volume_files : list of strings names of image volume files Examples -------- >>> import os >>> from mindboggle.utils.plots import plot_volumes >>> path = os.environ['MINDBOGGLE_DATA'] >>> volume_file1 = os.path.join(path, 'arno', 'mri', 't1weighted.nii.gz') >>> volume_file2 = os.path.join(path, 'arno', 'mri', 't1weighted_brain.nii.gz') >>> volume_files = [volume_file1, volume_file2] >>> plot_volumes(volume_files) """ from mindboggle.utils.utils import execute if isinstance(volume_files, str): volume_files = [volume_files] elif not isinstance(volume_files, list): import sys sys.error('plot_volumes() requires volume_files to be a list or string.') cmd = ["fslview"] cmd.extend(volume_files) cmd.extend('&') execute(cmd, 'os')
def main(args): lvl = _levels[max(0, min(args.verbose, len(_levels)-1))] logging.basicConfig(level=lvl) rundir = getrundir(user=args.user) info = '%s/procserv-%s/info'%(rundir, args.proc) try: with open(info) as F: for L in map(str.strip, F): if not L.startswith('tcp:'): continue _tcp, iface, port = L.split(':', 2) args = [telnet, iface, port]+args.extra _log.debug('exec: %s', ' '.join(args)) os.execv(telnet, args) sys.exit(1) # never reached sys.error('%s has no tcp control port') except OSError as e: if e.errno==errno.ENOENT: _log.error('%s is not an active %s procServ', args.name, 'user' if args.user else 'system') else: _log.exception("Can't open %s"%info) sys.exit(1)
def p_lAsigna(p): '''lAsigna : LB exp C exp RB PC''' global DT if(not DT): print "Dimension error" sys.error(0) else: DT = False
def readQ(filename): items, timesteps, c = read(filename) if not 'q' in items: sys.error('Error: q is not column in the lammps trajectory %s' % filename) index = items.index('q') cout = c[:, :, index] return cout
def p_idList(p): '''idList : ID''' variables_declaradas(p[1]) dimention = dimension(p[1]) if dimension(p[1]) == -1: print "Error en cuanto la dimension" sys.error(0) avail.OPila_push(dir_var(p[1])) avail.OPila_push(dimention)
def get_filepath(dirpath, filename): if(is_valid_dir(dirpath)): filepath = "%s/%s" %(dirpath, filename) if(is_valid_file(filepath)): return filepath else: sys.error("File not in directory") else: sys.error("Invalid path to file")
def updatePlatform(self, platform): self.platform = platform self.printVerbose("get cfg for platform: " + self.platform) if self.platform in list(self.mirrorCfg.keys()): self.platformCfg = self.mirrorCfg[self.platform] else: pError("Config: platform " + self.platform + " not found in cfg file " + self.cfgFile) sys.error(2)
def get_filepath(dirpath, filename): if (is_valid_dir(dirpath)): filepath = "%s/%s" % (dirpath, filename) if (is_valid_file(filepath)): return filepath else: sys.error("File not in directory") else: sys.error("Invalid path to file")
def compil(): try: # cd into the biuld directory os.chdir('build') # run make and make install os.system('make && make install') except: sys.error('build directory does not exist. You should \ run ./setup.py -e configure first.')
def query_depth_ontology(net, node, root='cl:0000000'): depth = 0 while node != root: if len(net[node]) == 0: print(node) node = sorted(list(net[node].keys()))[0] depth += 1 if depth > 100: sys.error('root not found') return depth
def openCustomCfg(self): # test that the file exists if not os.path.isfile(self.optCfg): pError("Config: custom cfg file " + self.optCfg + " does not exist.") sys.error(2) # open with open(self.optCfg) as cfgFileHandle: mirrorCfg = json.load(cfgFileHandle) # update mirror's cfg self.mirrorCfg = update(self.mirrorCfg, mirrorCfg)
def print_arguments(program, args): """ Run program specified by user (species, genes, or snps) """ if program == 'species': print_species_arguments(args) elif program == 'genes': print_gene_arguments(args) elif program == 'snps': print_snp_arguments(args) else: sys.error("Unrecognized program: '%s'" % program)
def addFromFileNames(cls, filenames): """The method, given a list of file names, creates an array of dataset objects.""" if len(filenames) == 0: sys.error( "Trying to create a Datasets object from an empty list of filenames" ) datasets = [] for filename in filenames: datasets.append(self.datasetFromFileName(filename)) return cls(Datasets.__init__(datasets))
def print_arguments(program, args): """ Run program specified by user (species, genes, or snps) """ if program == 'species': print_species_arguments(args) elif program == 'genes': print_genes_arguments(args) elif program == 'snps': print_snps_arguments(args) else: sys.error("Unrecognized program: '%s'" % program)
def openCfg(self): # get the standard cluster cfg self.stdCfg = os.path.join(self.commandPath, self.stdCfg) self.printVerbose("reading std cfg file: " + self.stdCfg) if not os.path.isfile(self.stdCfg): pError("Config: mirror cfg file " + self.stdCfg + " does not exist.") sys.error(2) with open(self.stdCfg) as cfgFileHandle: self.mirrorCfg = json.load(cfgFileHandle)
def readXYZ(filename): items, timesteps, c = read(filename) if (not 'x' in items) or (not 'y' in items) or (not 'z' in items): sys.error( 'Error: x,y,z are not columns in the lammps trajectory %s (only %s)' % (filename, items)) indices = [items.index('x'), items.index('y'), items.index('z')] cout = c[:, :, indices] return cout
def condicion(self): estCondic = self.OPila.pop() tipoCondicion = self.TPila.pop() if (tipoCondicion != "bool"): print "Error, el tipo no coincide" sys.error(0) else: cuads = ['GOTOF', estCondic, -1, -1] self.cuad.append(cuads) self.numCuad += 1 self.salto.push(self.numCuad)
def plotVertLine(self,Name='Curv', vCent=1, vY=[] ,Color=kBlack,Style=0,Width=2,Legend='None'): nP = len(vY) if nP == 0 : sys.error("plotHorizBand: ZERO size") obj = TGraph( nP , array('d',[vCent]*nP) , array('d',vY) ) obj.SetLineColor(Color) obj.SetMarkerColor(Color) obj.SetLineWidth(2) obj.SetLineStyle(Style) obj.SetMarkerStyle(0) obj.SetMarkerSize(0) self.Obj2Plot[Name] = { 'Obj' : obj , 'Type' : 'Curve' , 'Legend' : Legend }
def condicion(self): estCondic = self.OPila.pop() tipoCondicion = self.TPila.pop() if(tipoCondicion != "bool"): print "Error, el tipo no coincide" sys.error(0) else: cuads = ['GOTOF', estCondic, -1, -1] self.cuad.append(cuads) self.numCuad += 1 self.salto.push(self.numCuad)
def plotHorizCurve(self,Name='Curv',vX=[],vCent=[],Color=kBlack,Style=0,Width=2,Legend='None'): nP = len(vX) if nP == 0 : sys.error("plotHorizBand: ZERO size") if len(vCent) != nP : sys.error("plotHorizBand: size mismatch") obj = TGraph( nP , array('d',vX) ,array('d',vCent) ) obj.SetLineColor(Color) obj.SetMarkerColor(Color) obj.SetLineWidth(Width) obj.SetLineStyle(Style) obj.SetMarkerStyle(0) obj.SetMarkerSize(0) self.Obj2Plot[Name] = { 'Obj' : obj , 'Type' : 'Curve' , 'Legend' : Legend }
def check_arguments(program, args): """ Run program specified by user (species, genes, or snps) """ if program == 'species': check_species(args) elif program == 'genes': check_genes(args) elif program == 'snps': check_snps(args) else: sys.error("Unrecognized program: '%s'" % program) if platform.system() not in ['Linux', 'Darwin']: sys.exit("Operating system '%s' not supported" % system())
def get_arguments(program): """ Get arguments for specified program """ if program == 'species': args = species_arguments() elif program == 'genes': args = gene_arguments() elif program == 'snps': args = snp_arguments() else: sys.error("Unrecognized program: '%s'" % program) args = add_ref_db(args) return args
def estimateGaussianParametersCOM(self): #try to estimate first guess for fitting a Gaussian based on center of mass if self.__ip != []: bla = self.__ip.getStatistics() return [ bla.xCenterOfMass, bla.yCenterOfMass, self.__objSigma, self.__objSigma, bla.max, bla.min ] else: sys.error( 'Could not estimate centroid, ImageProcessor not defined!')
def get_arguments(program): """ Get arguments for specified program """ if program == 'species': args = species_arguments() elif program == 'genes': args = genes_arguments() elif program == 'snps': args = snps_arguments() else: sys.error("Unrecognized program: '%s'" % program) utility.add_ref_db(args) return args
def run_program(program, args): """ Run program specified by user (species, genes, or snps) """ if program == 'species': from midas.run import species species.estimate_abundance(args) elif program == 'genes': from midas.run import genes genes.run_pipeline(args) elif program == 'snps': from midas.run import snps snps.run_pipeline(args) else: sys.error("Unrecognized program: '%s'" % program)
def run_program(program, args): """ Run program specified by user (species, genes, or snps) """ if program == 'species': from phylo_cnv import species species.estimate_abundance(args) elif program == 'genes': from phylo_cnv import genes genes.run_pipeline(args) elif program == 'snps': from phylo_cnv import snps snps.run_pipeline(args) else: sys.error("Unrecognized program: '%s'" % program)
def run_program(program, args): """ Run program specified by user (species, genes, or snps) """ if program == 'species': from midas.merge import merge_species merge_species.run_pipeline(args) elif program == 'genes': from midas.merge import merge_genes merge_genes.run_pipeline(args) elif program == 'snps': from midas.merge import merge_snps merge_snps.run_pipeline(args) else: sys.error("Unrecognized program: '%s'" % program)
def correctPath(thepath,linesDeletedInCurrentId): s=thepath if s[-4:-3]=="#": n=int(s[-3:]) j=3 elif s[-3:-2]=="#": n=int(s[-2:]) j=2 elif s[-2:-1]=="#": n=int(s[-1:]) j=1 else: sys.error('this should not happen') return s[:-j]+str(n-linesDeletedInCurrentId)
def create_transformation(t, v): if t == 'rotation': # [0, 180] return {'rotation_range': int(v * 180)} if t == 'shift': # [0, 1] return {'width_shift_range': v, 'height_shift_range': v} if t == 'brightness': # [0.5, 2] if v == 0: return {'brightness_range': None} return {'brightness_range': (1 - v * 0.5, 1 + v * 1)} if t == 'shear': # [0, 60] return {'shear_range': v * 60} if t == 'channel': # [0, 50] return {'channel_shift_range': v * 50} sys.error('Unknown transformation: %s' % t)
def plotHorizBand(self, Name='Band', vX=[], vCent=[], vUp=[], vDown=[], Color=90, Style=1001, Legend='None'): nP = len(vX) if nP == 0: sys.error("plotHorizBand: ZERO size") if len(vCent) != nP: sys.error("plotHorizBand: size mismatch") if len(vUp) != nP: sys.error("plotHorizBand: size mismatch") if len(vDown) != nP: sys.error("plotHorizBand: size mismatch") obj = TGraphAsymmErrors( nP, array('d', vX), array('d', vCent), array('d', [0.] * nP), array('d', [0.] * nP), array('d', [vCent[i] - vDown[i] for i in range(nP)]), array('d', [vUp[i] - vCent[i] for i in range(nP)])) print obj.GetFillStyle() obj.SetFillStyle(Style) obj.SetFillColor(Color) obj.SetLineColor(Color) obj.SetLineWidth(2) self.Obj2Plot[Name] = {'Obj': obj, 'Type': 'Band', 'Legend': Legend}
def main(prog_args): parser = optparse.OptionParser(version=meta.__version__) extract_group = optparse.OptionGroup(parser, 'Extract Queries from psql log') extract_group.add_option('--extract-queries', action='store_true', help='extract queries from a log file') extract_group.add_option('--log-file', help='specify log file') parser.add_option_group(extract_group) analyze_group = optparse.OptionGroup(parser, 'Analyze extracted queries') analyze_group.add_option('--analyze-queries', action='store_true', help='analyze query file (or stdin)') analyze_group.add_option('--query-file', help='specify query file (file with queries delimited by %s or stdin)' % SEP) analyze_group.add_option('--dburl', help='sqlalchemy connection string (we do not use sa, just the style of it ie postgres://postgres:password@localhost:port/dbname)') analyze_group.add_option('--config-file', help='specify config file containing parameters for analyzing') parser.add_option_group(analyze_group) parser.add_option('--gen-config', action='store_true', help='generate a config file writeing work_mem and maintenance_work_mem') parser.add_option('--test', action='store_true', help='run doctests') opt, args = parser.parse_args(prog_args) if opt.extract_queries: if not opt.log_file: sys.error('Specify --log-file') return 1 fin = open(opt.log_file) fout = sys.stdout get_log_queries(fin, fout) fout.close() if opt.analyze_queries: if not opt.query_file: fin = sys.stdin else: fin = open(opt.query_file) if not opt.config_file: sys.error('Specify --config-file (--gen-config to generate sample)') analyze_queries(_get_qf_queries(fin), opt.dburl, open(opt.config_file), sys.stdout) if opt.gen_config: c = Config() c.add_setting('work_mem', ['1MB', '512MB']) c.add_setting('maintenance_work_mem', ['1MB', '512MB']) c.write(sys.stdout) if opt.test: import doctest doctest.testmod()
def fromString(s): line = s.split("\n") style = line[0][line[0].find("<BG"):line[0].find(">")] G = nx.DiGraph() attr = line[0][line[0].find(">")+2:].rstrip() if len(attr)>0: for k in attr.split(" "): kk,v = k.split("=") G.graph[kk] = v row = 1 numrows = len(line) while row < numrows and line[row][0]=="N": r = line[row].rstrip().split(" ") if len(r) < 2: sys.exit("ERROR: graph node index not found on line " + line[row]) G.add_node(int(r[1])+1) G.node[int(r[1])+1]['ind'] = int(r[1])+1 G.node[int(r[1])+1]['viewpoint'] = True G.node[int(r[1])+1]['childrenOrder']=[] if len(r) > 2: G.node[int(r[1])+1]['label'] = ("".join(r[2:]).encode('utf-8')) row += 1 while row < numrows and line[row][0]=="E": r = line[row].rstrip().split(" ") if len(r) < 3: sys.exit("ERROR: graph edge index not found on line " + line[row]) G.add_edge(int(r[1])+1, int(r[2])+1) if len(r) == 3: print "Error unordered edge!" if len(r) > 3: index=int(r[3])-2 #extend list if it is not long enough for the index G.node[int(r[1])+1]['childrenOrder'].extend([-1 for i in xrange(len(G.node[int(r[1])+1]['childrenOrder']),index+1)]) G.node[int(r[1])+1]['childrenOrder'][index]=int(r[2])+1 #print G.node[int(r[1])]['childrenOrder'] #childrenOrder sould be correct G.edge[int(r[1])+1][int(r[2])+1]['childindex'] = r[3] #G.edge[int(r[1])][r[2]]['label'] = r[3:] row += 1 #integrity check for i in G.nodes(): #print i,DAG.node[i]['childrenOrder'],DAG.out_degree(i) assert len(G.node[i]['childrenOrder'])==G.out_degree(i) if not line[row]=="<EG>": sys.error("ERROR: cannot find expected <EG> marker at the end of the graph") return G
def readGenes(fname): """ Take a file name that is bed-like (needs at least 3 columns) - will conserve strand and name if they exist Name will be the dictionary key for the output coverages """ genes = {} i = 1 fieldsep = getsep(fname) patt = re.compile(r'^chr$') with open(fname) as fn: for line in fn: if line.startswith('#'): continue try: chrom, start, end, name, score, strand = line.strip().split( fieldsep)[:6] except: try: a = line.strip().split(fieldsep) length = len(a) ext = 6 - length a.extend(['.'] * ext) chrom, start, end, name, score, strand = a except: sys.error(fname, 'Not a valid bed') if name == '.': name = 'peak' + str(i) else: name = os.path.basename( name ) #macs puts the full path in this name field, if it hasn't been cleaned up yet this will if strand not in ('+', '-', '.'): strand = '.' if args.m: try: start = (int(start) + int(end)) / 2 end = int(start + 1) except: continue else: #this should be used to deal with TSS start = int(start) end = int(start) + 1 iv = HTSeq.GenomicInterval(chrom.replace('"', ''), int(start), int(end), strand) genes[str(name)] = iv i += 1 return (genes)
def get_concat_contigs(dirpath, filename): filepath = get_filepath(dirpath, filename) if (is_valid_file(filepath)): count_contig = get_contig_count(filepath) if (count_contig > 1): file_org = open("%s" % filepath, "r") file_new = open("%s/concat-%s" % (dirpath, filename), "a") file_new.write(">%s\n" % (filename)) for line in file_org: if (line[0] != ">"): line = line.rstrip() file_new.write(line) file_org.close() file_new.close() else: sys.error("Invalid path")
def get_concat_contigs(dirpath, filename): filepath = get_filepath(dirpath, filename) if(is_valid_file(filepath)): count_contig = get_contig_count(filepath) if(count_contig > 1): file_org = open("%s" %filepath, "r") file_new = open("%s/concat-%s" %(dirpath, filename), "a") file_new.write(">%s\n" %(filename)) for line in file_org: if(line[0] != ">"): line = line.rstrip() file_new.write(line) file_org.close() file_new.close() else: sys.error("Invalid path")
def estimateGaussianParametersBinary(self): #try to estimate first guess for fitting a Gaussian based on largest binary particle if self.__ip != []: ip_binary = self.__ip.duplicate() ip_binary.setAutoThreshold( ij.process.AutoThresholder.Method.IsoData, True) #ip_binary.setAutoThreshold(ImageProcessor.ISODATA2, True) ip_binary.threshold(int(ip_binary.getMinThreshold())) imp = ImagePlus('temp', ip_binary) #not finished yet print 'Threshold: ', int(ip_binary.getMinThreshold()) #return [bla.xCenterOfMass, bla.yCenterOfMass, self.__objSigma, self.__objSigma, bla.max, bla.min] else: sys.error( 'Could not estimate centroid, ImageProcessor not defined!')
def p_Asignacion(p): '''Asignacion : faID Factor5 Asignacion2''' ID = avail.IDPila_pop() if(idF == "asig"): TDim = avail.DPila_pop() variables_declaradas(ID) if(avail.DPila_pop()): if(TDim): par = avail.OPila_pop() par2 = avail.OPila_pop() avail.OPila_push(par) avail.TPila_push(tipo_variable(ID, "var")) avail.OPila_push(dir_var(ID)) avail.OPila_push(par2) avail.dim(dimension(ID), avail.OPila_pop()) avail.asign(avail.OPila_pop()) else: par = avail.OPila_pop() par2 = avail.OPila_pop() par3 = avail.OPila_pop() avail.OPila_push(par) avail.OPila_push(par2) avail.TPila_push(tipo_variable(ID, "var")) avail.OPila_push(dir_var(ID)) avail.OPila_push(par3) avail.dmT(dimension(ID), avail.OPila_pop()) avail.asign(avail.OPila_pop()) avail.asign(avail.OPila_pop()) else: avail.asign(dir_var(ID)) else: if(ID not in direc): print "Funcion no declarada", ID sys.exit(0) else: if((len(direc[ID][0])) != len(CHF)): print "Error de llamada de funcion, ", ID sys.error(0) else: cont = 0 for key in direc[ID][0]: if(direc[ID][0][key][0] != CHF[cont]): print "Error de tipo de llamada de funcion" sys.error(0) cont += 1 CHF[:] = []
def p_Asignacion(p): '''Asignacion : faID Factor5 Asignacion2''' ID = avail.IDPila_pop() if (idF == "asig"): TDim = avail.DPila_pop() variables_declaradas(ID) if (avail.DPila_pop()): if (TDim): par = avail.OPila_pop() par2 = avail.OPila_pop() avail.OPila_push(par) avail.TPila_push(tipo_variable(ID, "var")) avail.OPila_push(dir_var(ID)) avail.OPila_push(par2) avail.dim(dimension(ID), avail.OPila_pop()) avail.asign(avail.OPila_pop()) else: par = avail.OPila_pop() par2 = avail.OPila_pop() par3 = avail.OPila_pop() avail.OPila_push(par) avail.OPila_push(par2) avail.TPila_push(tipo_variable(ID, "var")) avail.OPila_push(dir_var(ID)) avail.OPila_push(par3) avail.dmT(dimension(ID), avail.OPila_pop()) avail.asign(avail.OPila_pop()) avail.asign(avail.OPila_pop()) else: avail.asign(dir_var(ID)) else: if (ID not in direc): print "Funcion no declarada", ID sys.exit(0) else: if ((len(direc[ID][0])) != len(CHF)): print "Error de llamada de funcion, ", ID sys.error(0) else: cont = 0 for key in direc[ID][0]: if (direc[ID][0][key][0] != CHF[cont]): print "Error de tipo de llamada de funcion" sys.error(0) cont += 1 CHF[:] = []
def main(folder_input, type_input, output=None): folder_input = realpath(folder_input) if not isdir(folder_input): logger.error('Input is not a folder: %s' % folder_input) sys.error(0) if not output: fname = basename(normpath(folder_input)) output = join(folder_input, fname + '.json') if type_input.lower() == 'xml': convert_xml(folder_input, output) elif type_input.lower() == 'txt': convert_txt(folder_input, output) else: logger.error('Type of files is not correct: %s' % type_input) sys.error(0)
def main(): if not os.path.exists('poker.jpg'): print 'ERROR: This is a simple test meant to be run on local files. Please run from the subimage/test directory.' sys.exit(-1) img = cv2.imread('poker.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE) cards = ar.find_by_ar(img, 0.7, 0.02,min_height=100,min_width=50) if not cards: print 'Sorry, couldn\'t find any cards in the provided image.' sys.error(-1) for card in cards: #try to find what suit this card is subsection = img[card.box] subsection = subsection * card.mask suit = get_suit(subsection) value = get_value(subsection) print 'Card found at ' + str(card.x) +','+ str(card.y)+': ' + suit + ' ' + value
def mov_average(self, n=3, win='tri'): """ Apply moving average with specified window. Parameters: n: window width (truncated to be odd integer) win: window type. Available windows are: 'rec': rectangular 'tri': triangular """ n = np.int(n) # truncate to integer n = n - (1 - np.mod(n, 2)) # n is odd or will be decreased by 1 m = (n - 1) // 2 + 1 # window center W = np.ones(n) # default rectangular window if (win.lower() == 'rec'): pass elif (win.lower() == 'tri'): W[:m] = np.linspace(1 / m, 1., m) W[m - 1:] = np.linspace(1., 1 / m, m) else: sys.error('Averaging window type not available!') m = m - 1 W = W / W.sum() X = MRPy.copy(self) for kX in range(self.NX): for k in range(0, m): k0 = m - k W0 = W[k0:] / np.sum(W[k0:]) X[kX, k] = np.sum(W0 * self[kX, :k + m + 1]) for k in range(m, self.N - m - 1): X[kX, k] = np.sum(W * self[kX, k - m:k + m + 1]) for k in range(self.N - m - 1, self.N): k0 = m - k + self.N W0 = W[:k0] / np.sum(W[:k0]) X[kX, k] = np.sum(W0 * self[kX, k - m:]) return X
def main(): if not os.path.exists('poker.jpg'): print 'ERROR: This is a simple test meant to be run on local files. Please run from the subimage/test directory.' sys.exit(-1) img = cv2.imread('poker.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE) cards = ar.find_by_ar(img, 0.7, 0.02, min_height=100, min_width=50) if not cards: print 'Sorry, couldn\'t find any cards in the provided image.' sys.error(-1) for card in cards: #try to find what suit this card is subsection = img[card.box] subsection = subsection * card.mask suit = get_suit(subsection) value = get_value(subsection) print 'Card found at ' + str(card.x) + ',' + str( card.y) + ': ' + suit + ' ' + value
def plotVertLine(self, Name='Curv', vCent=1, vY=[], Color=kBlack, Style=0, Width=2, Legend='None'): nP = len(vY) if nP == 0: sys.error("plotHorizBand: ZERO size") obj = TGraph(nP, array('d', [vCent] * nP), array('d', vY)) obj.SetLineColor(Color) obj.SetMarkerColor(Color) obj.SetLineWidth(2) obj.SetLineStyle(Style) obj.SetMarkerStyle(0) obj.SetMarkerSize(0) self.Obj2Plot[Name] = {'Obj': obj, 'Type': 'Curve', 'Legend': Legend}
def readGenes (fname): """ Take a file name that is bed-like (needs at least 3 columns) - will conserve strand and name if they exist Name will be the dictionary key for the output coverages """ genes = {} i = 1 fieldsep = getsep(fname) patt = re.compile(r'^chr$') with open(fname) as fn: for line in fn: if line.startswith('#'): continue try: chrom,start,end,name,score,strand = line.strip().split(fieldsep)[:6] except: try: a = line.strip().split(fieldsep) length = len(a) ext = 6-length a.extend(['.'] * ext) chrom, start, end, name, score, strand = a except: sys.error(fname, 'Not a valid bed') if name == '.': name = 'peak'+str(i) else: name = os.path.basename(name) #macs puts the full path in this name field, if it hasn't been cleaned up yet this will if strand not in ('+', '-', '.'): strand = '.' if args.m: try: start = (int(start)+int(end)) / 2 end = int(start +1 ) except: continue else: #this should be used to deal with TSS start = int(start) end = int(start)+1 iv = HTSeq.GenomicInterval(chrom.replace('"',''), int(start), int(end), strand) genes[str(name)] = iv i += 1 return(genes)
def tag_insert(thing_id, tag_name): sql_i = "INSERT OR IGNORE INTO tag (name) VALUES (?)" c = conn.cursor() param = (tag_name,) c.execute(sql_i, param) conn.commit() sql_i = "SELECT id FROM tag WHERE name = ?" param = (tag_name,) c.execute(sql_i, param) tag_id = c.fetchone()[0] if tag_id: sql_i = "INSERT OR IGNORE INTO thing_tag (thing_id, tag_id) VALUES (?, ?)" param = (thing_id, tag_id) # print param c.execute(sql_i, param) conn.commit() else: sys.error("tag is not exisitng in database file") c.close()
def __init__(self, path): # Regex za <div> poruke. ri = re.compile( r'<div\s+class="_3-94 _2lem"\s*>.*?</div>\s*(?=<div\s+class="_3-94 _2lem)', re.MULTILINE | re.S) try: f = open(path, "r", encoding="utf8") except IOError: sys.error("Fajl ne postoji.") # U buf se ucitava cela html stranica, a match je kolekcija svih poruka. buf = f.read() match = ri.findall(buf) if match is None: sys.exit() else: self.msgs = match
def plotHorizCurve(self, Name='Curv', vX=[], vCent=[], Color=kBlack, Style=0, Width=2, Legend='None'): nP = len(vX) if nP == 0: sys.error("plotHorizBand: ZERO size") if len(vCent) != nP: sys.error("plotHorizBand: size mismatch") obj = TGraph(nP, array('d', vX), array('d', vCent)) obj.SetLineColor(Color) obj.SetMarkerColor(Color) obj.SetLineWidth(Width) obj.SetLineStyle(Style) obj.SetMarkerStyle(0) obj.SetMarkerSize(0) self.Obj2Plot[Name] = {'Obj': obj, 'Type': 'Curve', 'Legend': Legend}
def license_insert(thing_id, license_url): sql_i = "INSERT OR IGNORE INTO license (url) VALUES (?)" c = conn.cursor() param = (license_url,) c.execute(sql_i, param) conn.commit() sql_i = "SELECT id FROM license WHERE url = ?" param = (license_url,) c.execute(sql_i, param) license_id = c.fetchone() if license_id and license_id[0]: license_id = license_id[0] sql_i = "INSERT OR IGNORE INTO thing_license (thing_id, license_id) VALUES (?,?)" param = (thing_id, license_id) # print param c.execute(sql_i, param) conn.commit() else: sys.error("license error in database") c.close()
def plotHorizBand(self,Name='Band',vX=[],vCent=[],vUp=[],vDown=[],Color=90,Style=1001,Legend='None'): nP = len(vX) if nP == 0 : sys.error("plotHorizBand: ZERO size") if len(vCent) != nP : sys.error("plotHorizBand: size mismatch") if len(vUp) != nP : sys.error("plotHorizBand: size mismatch") if len(vDown) != nP : sys.error("plotHorizBand: size mismatch") obj = TGraphAsymmErrors( nP , array('d',vX) , array('d',vCent) , array('d',[0.]*nP), array('d',[0.]*nP) , array('d',[vCent[i]-vDown[i] for i in range(nP)]) , array('d',[vUp[i]-vCent[i] for i in range(nP)]) ) print obj.GetFillStyle() obj.SetFillStyle(Style) obj.SetFillColor(Color) obj.SetLineColor(Color) obj.SetLineWidth(2) self.Obj2Plot[Name] = { 'Obj' : obj , 'Type' : 'Band' , 'Legend' : Legend }
def file_insert(thing_id, file_type, file_url, file_date, file_name, file_download): sql_i = "INSERT OR IGNORE INTO file_type (type) VALUES (?)" c = conn.cursor() param = (file_type,) # print param c.execute(sql_i, param) conn.commit() sql_i = "SELECT id FROM file_type WHERE type=?" param = (file_type,) c.execute(sql_i, param) type_id = c.fetchone()[0] if type_id: sql_i = "INSERT INTO file (thing_id, date, type_id, download_count, url, name) VALUES (?, ?, ?, ?, ?, ?)" param = (thing_id, file_date, type_id, file_download, file_url, file_name) # print param c.execute(sql_i, param) conn.commit() else: sys.error("file type is not correct in database") c.close()
def copy_file(in_file): if 'release' in build_type.lower(): file_list = (in_file) elif 'debug' in build_type.lower(): base_fn, ext = os.path.splitext(in_file) file_list = (base_fn+'d'+ext, base_fn[:(len(base_fn)-1)]+'d'+base_fn[-1]+ext, in_file)#must be the last else: sys.error('unknown build type'+buildtype) for file in file_list: src = os.path.join(src_root_path, file) if os.path.isfile(src): dst = os.path.join(dst_root_path, file) dir = os.path.dirname(dst) if not os.path.exists(dir): os.makedirs(dir) sh.copy(src, dst) return for file in file_list: src = os.path.join(src_root_path, file) sys.stderr.write(src+" does not exist\n")