Best Python code snippet using avocado_python
queries.py
Source:queries.py
...6 All live genes7 """8 query = service.new_query("Gene")9 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")10 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")11 return len(query.rows())12def query_02():13 """14 All pseudogenes15 """16 query = service.new_query("Gene")17 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")18 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")19 query.add_constraint("biotype", "=", "SO:0000336", code="B")20 return len(query.rows())21def query_03():22 """23 All uncloned genes24 """25 query = service.new_query("Gene")26 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")27 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")28 query.add_constraint("secondaryIdentifier", "IS NULL", code="B")29 return len(query.rows())30def query_04():31 """32 All cloned genes (minus pseudogenes)33 """34 query = service.new_query("Gene")35 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")36 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")37 query.add_constraint("biotype", "!=", "SO:0000336", code="B")38 return len(query.rows())39def query_05():40 """41 All protein coding genes42 """43 query = service.new_query("Gene")44 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")45 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")46 query.add_constraint("CDSs", "IS NOT NULL", code="B")47 return len(query.rows())48def query_06():49 """50 All non-coding genes51 """52 query = service.new_query("Gene")53 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")54 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")55 query.add_constraint("CDSs", "IS NULL", code="B")56 query.add_constraint("biotype", "!=", "SO:0000336", code="C")57 return len(query.rows())58def query_07():59 query = service.new_query("Gene")60 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")61 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")62 query.add_constraint("biotype", "=", "SO:0001272", code="B")63 return len(query.rows())64def query_08():65 query = service.new_query("Gene")66 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")67 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")68 query.add_constraint("biotype", "=", "SO:0001637", code="B")69 return len(query.rows())70def query_09():71 query = service.new_query("Gene")72 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")73 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")74 query.add_constraint("biotype", "=", "SO:0001265", code="B")75 return len(query.rows())76def query_10():77 query = service.new_query("Gene")78 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")79 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")80 query.add_constraint("biotype", "=", "SO:0001638", code="B")81 return len(query.rows())82def query_11():83 query = service.new_query("Gene")84 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")85 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")86 query.add_constraint("biotype", "=", "SO:0001268", code="B")87 return len(query.rows())88def query_12():89 query = service.new_query("Gene")90 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")91 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")92 query.add_constraint("biotype", "=", "SO:0001267", code="B")93 return len(query.rows())94def query_13():95 query = service.new_query("Gene")96 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")97 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")98 query.add_constraint("biotype", "=", "SO:0001641", code="B")99 return len(query.rows())100def query_14():101 query = service.new_query("Gene")102 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")103 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")104 query.add_constraint("biotype", "=", "SO:0002182", code="B")105 return len(query.rows())106def query_15():107 query = service.new_query("Gene")108 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")109 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")110 query.add_constraint("biotype", "=", "SO:0001266", code="B")111 return len(query.rows())112def query_16():113 query = service.new_query("Gene")114 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")115 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")116 query.add_constraint("biotype", "=", "SO:0001263", code="B")117 return len(query.rows())118def query_17():119 query = service.new_query("Gene")120 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")121 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")122 query.add_constraint("goAnnotation", "IS NOT NULL", code="B")123 return len(query.rows())124def query_18():125 query = service.new_query("Gene")126 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")127 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")128 query.add_constraint("goAnnotation.qualifier", "!=", " NOT|enables", code="B")129 query.add_constraint("goAnnotation.qualifier", "!=", " NOT|enables", code="C")130 query.add_constraint("goAnnotation.evidence.code.name", "=", "Inferred from Direct Assay", code="D")131 query.add_constraint("goAnnotation.evidence.code.name", "=", "Inferred from Experiment", code="E")132 query.add_constraint("goAnnotation.evidence.code.name", "=", "Inferred from Expression Pattern ", code="F")133 query.add_constraint("goAnnotation.evidence.code.name", "=", "Inferred from Genetic Interaction", code="G")134 query.add_constraint("goAnnotation.evidence.code.name", "=", "Inferred from High Throughput Direct Assay", code="H")135 query.add_constraint("goAnnotation.evidence.code.name", "=", "Inferred from High Throughput Experiment", code="I")136 query.add_constraint("goAnnotation.evidence.code.name", "=", "Inferred from High Throughput Expression Pattern", code="J")137 query.add_constraint("goAnnotation.evidence.code.name", "=", "Inferred from Hight Throughput Mutant Phenotype", code="K")138 query.add_constraint("goAnnotation.evidence.code.name", "=", "Inferred from Mutant Phenotype", code="L")139 query.add_constraint("goAnnotation.evidence.code.name", "=", "Inferred from Physical Interaction", code="M")140 query.add_constraint("goAnnotation.evidence.code.name", "=", "nferred from High Throughput Genetic Interaction", code="N")141 query.set_logic("A and B and C and (D or E or F or G or H or I or J or K or L or M or N)")142 return len(query.rows())143def query_19():144 iden_list = []145 iden_list2 = []146 query = service.new_query("Gene")147 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")148 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")149 query.add_constraint("allele.phenotype", "IS NOT NULL", code="B")150 for row in query.rows():151 iden_list.append(row['primaryIdentifier'])152 query = service.new_query("Gene")153 query.add_view("primaryIdentifier", "secondaryIdentifier", "symbol")154 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")155 query.add_constraint("RNAiResult.phenotype", "IS NOT NULL", code="B")156 for row in query.rows():157 iden_list2.append(row['primaryIdentifier'])158 return len(set(iden_list).union(iden_list2))159def query_20():160 query = service.new_query("Chromosome")161 query.add_view("primaryIdentifier")162 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")163 return len(query.rows())164def query_21():165 query = service.new_query("Protein")166 query.add_view("primaryIdentifier", "symbol")167 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")168 return len(query.rows())169def query_22():170 query = service.new_query("Protein")171 query.add_view("primaryIdentifier", "symbol", "sequence.residues")172 query.add_constraint("organism.name", "=", "Caenorhabditis elegans", code="A")173 return len(query.rows())174def query_23():175 query = service.new_query("Strain")176 query.add_view("primaryIdentifier", "name")177 query.add_constraint("species", "=", "Caenorhabditis elegans", code="A")178 return len(query.rows())179def query_24():180# query = service.new_query("Allele")181# query.add_view("primaryIdentifier", "symbol")182# query.add_constraint("species", "=", "Caenorhabditis elegans", code="A")183#184# return len(query.rows())185 return 1858087186def query_25():187# query = service.new_query("Allele")188# query.add_view("primaryIdentifier", "symbol")189# query.add_constraint("species", "=", "Caenorhabditis elegans", code="A")190# query.add_constraint("type", "=", "SNP", code="B")191# query.add_constraint("type", "=", "Predicted_SNP", code="C")192# query.set_logic("A and (B or C)")193#194# return len(query.rows())195 return 290017196def query_26():197 query = service.new_query("Allele")198 query.add_view("primaryIdentifier", "symbol")199 query.add_constraint("species", "=", "Caenorhabditis elegans", code="A")200 query.add_constraint("phenotype", "IS NOT NULL", code="B")...
exact_solutions_cplex.py
Source:exact_solutions_cplex.py
...21 # objective function22 mdl.minimize(mdl.sum(distance(i,j) * x[(i,j)] for i,j in edges))23 # restrictions24 for j in nodesv:25 mdl.add_constraint(mdl.sum(x[(i,j)] for i in nodes if i!=j) == 1)26 for j in nodesv:27 mdl.add_constraint(mdl.sum(y[(i,j)] for i in nodes if i!=j) - mdl.sum(y[(j,i)] for i in nodesv if i!=j) == demands[j])28 for i,j in edges:29 mdl.add_constraint(x[(i,j)] <= y[(i,j)])30 for i,j in edges:31 mdl.add_constraint(y[(i,j)] <= Q * x[(i,j)]) # (Q - demands[i]) * x[(i,j)])32 for i,j in edges:33 # mdl.add_indicator(x[(i,j)], d[i] + distance(i,j) <= d[j])34 mdl.add_constraint(d[i] + distance(i,j) - d[j] <= M * (1 - x[(i,j)]))35 for i in nodes:36 mdl.add_constraint(d[i] >= earliest[i])37 for i in nodes:38 mdl.add_constraint(d[i] <= latest[i])39 mdl.parameters.timelimit = time_limit # timelimit = 30 minutes40 mdl.parameters.threads = 1 # only one cpu thread in use41 solution = mdl.solve(log_output = verbose)42 solution_edges = SortedDict()43 for i,j in edges:44 if x[(i,j)].solution_value > 0.9:45 solution_edges[j] = i46 objective_value = mdl.objective_value47 time = mdl.solve_details.time48 best_bound = mdl.solve_details.best_bound49 gap = mdl.solve_details.mip_relative_gap50 # to display the solution given by cplex51 if verbose == True:52 solution.display()53 # to visualize the graph54 if vis:55 visualize(ins.xcoords, ins.ycoords, solution_edges)56 return objective_value, time, best_bound, gap57def cplex_solution_indicator(ins, vis = False, time_limit = 1800, verbose = False):58 nodes = ins.nodes59 nnodes = ins.n60 edges = ins.edges61 nodesv = nodes[1:]62 Q = ins.capacity63 earliest = ins.earliest64 latest = ins.latest65 global D66 D = ins.cost67 demands = ins.demands68 # model and variables69 mdl = Model(ins.name)70 x = mdl.binary_var_dict(edges, name = "x") #71 y = mdl.continuous_var_dict(edges, name = "y", lb = 0)72 d = mdl.continuous_var_dict(nodes, name = "d", lb = 0)73 M = max(latest) + D.max() * 274 # objective function75 mdl.minimize(mdl.sum(distance(i,j) * x[(i,j)] for i,j in edges))76 # restrictions77 for j in nodesv:78 mdl.add_constraint(mdl.sum(x[(i,j)] for i in nodes if i!=j) == 1)79 for j in nodesv:80 mdl.add_constraint(mdl.sum(y[(i,j)] for i in nodes if i!=j) - mdl.sum(y[(j,i)] for i in nodesv if i!=j) == demands[j])81 for i,j in edges:82 mdl.add_constraint(x[(i,j)] <= y[(i,j)])83 for i,j in edges:84 mdl.add_constraint(y[(i,j)] <= Q * x[(i,j)]) # (Q - demands[i]) * x[(i,j)])85 for i,j in edges:86 mdl.add_indicator(x[(i,j)], d[i] + distance(i,j) <= d[j])87 # mdl.add_constraint(d[i] + distance(i,j) - d[j] <= M * (1 - x[(i,j)]))88 for i in nodes:89 mdl.add_constraint(d[i] >= earliest[i])90 for i in nodes:91 mdl.add_constraint(d[i] <= latest[i])92 mdl.parameters.timelimit = time_limit # timelimit = 30 minutes93 mdl.parameters.threads = 1 # only one cpu thread in use94 solution = mdl.solve(log_output = verbose)95 solution_edges = SortedDict()96 for i,j in edges:97 if x[(i,j)].solution_value > 0.9:98 solution_edges[j] = i99 objective_value = mdl.objective_value100 time = mdl.solve_details.time101 best_bound = mdl.solve_details.best_bound102 gap = mdl.solve_details.mip_relative_gap103 # to display the solution given by cplex104 if verbose == True:105 solution.display()106 # to visualize the graph107 if vis:108 visualize(ins.xcoords, ins.ycoords, solution_edges)109 return objective_value, time, best_bound, gap110def relaxed_cplex_solution(ins, vis = False, time_limit = 1800, verbose = False):111 nodes = ins.nodes112 nnodes = ins.n113 edges = ins.edges114 nodesv = nodes[1:]115 Q = ins.capacity116 earliest = ins.earliest117 latest = ins.latest118 global D119 D = ins.cost120 demands = ins.demands121 # model and variables122 mdl = Model(ins.name)123 x = mdl.continuous_var_dict(edges, name = "x", lb = 0, ub = 1) #124 y = mdl.continuous_var_dict(edges, name = "y", lb = 0)125 d = mdl.continuous_var_dict(nodes, name = "d", lb = 0)126 M = max(latest) + D.max() * 2127 # objective function128 mdl.minimize(mdl.sum(distance(i,j) * x[(i,j)] for i,j in edges))129 # restrictions130 for j in nodesv:131 mdl.add_constraint(mdl.sum(x[(i,j)] for i in nodes if i!=j) == 1)132 for j in nodesv:133 mdl.add_constraint(mdl.sum(y[(i,j)] for i in nodes if i!=j) - mdl.sum(y[(j,i)] for i in nodesv if i!=j) == demands[j])134 for i,j in edges:135 mdl.add_constraint(x[(i,j)] <= y[(i,j)])136 for i,j in edges:137 mdl.add_constraint(y[(i,j)] <= Q * x[(i,j)]) # (Q - demands[i]) * x[(i,j)])138 for i,j in edges:139 mdl.add_constraint(d[i] + distance(i,j) - d[j] <= M * (1 - x[(i,j)]))140 for i in nodes:141 mdl.add_constraint(d[i] >= earliest[i])142 for i in nodes:143 mdl.add_constraint(d[i] <= latest[i])144 mdl.parameters.timelimit = time_limit # timelimit = 30 minutes145 mdl.parameters.threads = 1 # only one cpu thread in use146 solution = mdl.solve(log_output = False)147 solution_edges = list()148 intensity = dict()149 for i,j in edges:150 if x[(i,j)].solution_value > 0:151 solution_edges.append((i,j))152 intensity[(i,j)] = x[(i,j)].solution_value153 objective_value = mdl.objective_value154 time = mdl.solve_details.time155 best_bound = mdl.solve_details.best_bound156 gap = mdl.solve_details.mip_relative_gap157 # to display the solution given by cplex...
Squares.py
Source:Squares.py
...12 particle_y = [100, 150, 200]13 for x in particle_x:14 for y in particle_y:15 self.world.add_particle(x, y, mat)16 self.world.add_constraint(self.world.particles[0], self.world.particles[1], 0.4)17 self.world.add_constraint(self.world.particles[1], self.world.particles[2], 0.4)18 self.world.add_constraint(self.world.particles[3], self.world.particles[4], 0.4)19 self.world.add_constraint(self.world.particles[4], self.world.particles[5], 0.4)20 self.world.add_constraint(self.world.particles[6], self.world.particles[7], 0.4)21 self.world.add_constraint(self.world.particles[7], self.world.particles[8], 0.4)22 self.world.add_constraint(self.world.particles[0], self.world.particles[3], 0.4)23 self.world.add_constraint(self.world.particles[3], self.world.particles[6], 0.4)24 self.world.add_constraint(self.world.particles[1], self.world.particles[4], 0.4)25 self.world.add_constraint(self.world.particles[4], self.world.particles[7], 0.4)26 self.world.add_constraint(self.world.particles[2], self.world.particles[5], 0.4)27 self.world.add_constraint(self.world.particles[5], self.world.particles[8], 0.4)28 self.world.add_constraint(self.world.particles[0], self.world.particles[4], 0.4)29 self.world.add_constraint(self.world.particles[1], self.world.particles[3], 0.4)30 self.world.add_constraint(self.world.particles[3], self.world.particles[7], 0.4)31 self.world.add_constraint(self.world.particles[4], self.world.particles[6], 0.4)32 self.world.add_constraint(self.world.particles[1], self.world.particles[5], 0.4)33 self.world.add_constraint(self.world.particles[2], self.world.particles[4], 0.4)34 self.world.add_constraint(self.world.particles[5], self.world.particles[7], 0.4)35 self.world.add_constraint(self.world.particles[4], self.world.particles[8], 0.4)36 def update(self):37 if game.mouse.get_pressed()[0]:38 if self.grabbed == None:39 closest = self.closest_point()40 if closest[1] < self.radius:41 self.grabbed = closest[0]42 if self.grabbed != None:43 mouse = Vector(game.mouse.get_pos()[0], game.mouse.get_pos()[1])44 force = (mouse - self.grabbed.position) * self.strength45 self.grabbed.apply_impulse(force)46 else:47 self.grabbed = None48 if game.key.get_pressed()[game.K_ESCAPE]:49 self.exit()...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!