Best Python code snippet using localstack_python
geneSymbols.py
Source:geneSymbols.py
...72 raise Exception("Error: invalid field_type")73 gene_dict = {x[key_field]: x for x in genes}74 # Now, recursively crawl the gene association structure75 # and update all gene entries76 def update_association(assoc):77 if assoc.type == "gene":78 gene = assoc.gene79 if gene.name in gene_dict:80 gene_info = gene_dict[gene.name]81 gene.name = gene_info['symbol'].upper()82 if 'alias_symbol' in gene_info:83 gene.alt_symbols = [84 x.upper() for x in gene_info['alias_symbol']85 ]86 else:87 for child in assoc.children:88 update_association(child)89 for reaction in model.reactions.values():90 if reaction.gene_associations is not None:91 update_association(reaction.gene_associations)92def load_mgi():93 """94 Loads the ortho2human, ortho2mouse dictionaries95 from the MGI exported file96 """97 ortho2mouse = defaultdict(set)98 ortho2human = defaultdict(set)99 mgi_file = os.path.join(100 RESOURCE_DIR, "Genes", "HOM_MouseHumanSequence.rpt.gz")101 data = pd.read_csv(mgi_file, sep="\t")102 hgs = data.loc[data['Common Organism Name'] == 'human']103 mgs = data.loc[data['Common Organism Name'] == 'mouse, laboratory']104 for ortho_id, hg in zip(hgs['HomoloGene ID'], hgs['Symbol']):105 ortho2human[ortho_id].add(hg.upper())106 for ortho_id, mg in zip(mgs['HomoloGene ID'], mgs['Symbol']):107 ortho2mouse[ortho_id].add(mg.upper())108 return ortho2human, ortho2mouse109def convert_species(model, target_species):110 if target_species == "homo_sapiens":111 return # Nothing to do, assume input is human112 if target_species != "mus_musculus":113 raise NotImplementedError("Can only convert to mus_musculus")114 ortho2human, ortho2mouse = load_mgi()115 # Invert the human dictionary116 human2ortho = defaultdict(set)117 for ortho_id in ortho2human:118 for hg in ortho2human[ortho_id]:119 human2ortho[hg].add(ortho_id)120 # Now, recursively crawl the gene association structure121 # and update all gene entries122 def update_association(assoc):123 if assoc.type == "gene":124 gene = assoc.gene125 if gene.name in human2ortho:126 ortho_id = human2ortho[gene.name]127 mouse_genes = set()128 for oid in ortho_id:129 if oid in ortho2mouse:130 mouse_genes |= ortho2mouse[oid]131 if len(mouse_genes) == 0:132 gene.name = ""133 gene.alt_symbols = []134 return135 if len(mouse_genes) == 1:136 gene.name = list(mouse_genes)[0]137 gene.alt_symbols = []138 return139 # About 30 human genes map to multiple mouse genes140 # Replace them with an OR association141 assoc.type = 'or'142 assoc.gene = None143 assoc.children = []144 for mg in mouse_genes:145 new_gene = Gene()146 new_gene.id = mg147 new_gene.name = mg148 new_assoc = Association()149 new_assoc.type = 'gene'150 new_assoc.gene = new_gene151 assoc.children.append(new_assoc)152 else:153 for child in assoc.children:154 update_association(child)155 for reaction in model.reactions.values():156 if reaction.gene_associations is not None:...
lambda_function.py
Source:lambda_function.py
...42 else:43 if association_id is not None:44 if state == running:45 print("Updating SSM State Manager Association: {}".format(association_id))46 update_association(client, association_id, instance_association_name)47 elif state == terminated:48 print("Deleting SSM State Manager Association: {}".format(association_id))49 delete_association(client, association_id)50 else:51 print("Association does not exist: {}".format(instance_association_name))52def delete_association(client, association_id):53 response = client.delete_association(54 AssociationId=association_id55 )56 if response["ResponseMetadata"]["HTTPStatusCode"] == 200:57 print("AssociationId: {} was successfully deleted.".format(association_id))58 else:59 print("And error occurred while deleting the Association.")60def update_association(client, association_id, instance_association_name):61 response = client.update_association(62 AssociationId=association_id,63 AssociationName=instance_association_name,64 Parameters=ssm_params(os.environ['update_playbook'], os.environ['code_bucket'])65 )66 association_version = response["AssociationDescription"]["AssociationVersion"]67 print("AssociationId: {} update to version: {}".format(association_id, association_version))68def create_association(client, instance_id, instance_association_name):69 response = client.create_association(70 Name="AWS-ApplyAnsiblePlaybooks",71 AssociationName=instance_association_name,72 Targets=[73 {74 'Key': "InstanceIds",75 'Values': [...
zero_one_matrix.py
Source:zero_one_matrix.py
...16 update_recursive(start_row, start_col - 1, result[start_row][start_col] + 1)17 update_recursive(start_row, start_col + 1, result[start_row][start_col] + 1)18 update_recursive(start_row - 1, start_col, result[start_row][start_col] + 1)19 update_recursive(start_row + 1, start_col, result[start_row][start_col] + 1)20 def update_association(start_row: int, start_col: int):21 if 0 <= start_row < row_limit and 0 <= start_col < col_limit:22 if mat[start_row][start_col] == 0:23 return24 if enqueued[start_row][start_col]:25 return26 queue.append((start_row, start_col))27 result[start_row][start_col] = 128 enqueued[start_row][start_col] = True29 for row_index in range(row_limit):30 for col_index in range(col_limit):31 if mat[row_index][col_index] == 0:32 result[row_index][col_index] = 033 update_association(row_index, col_index - 1)34 update_association(row_index, col_index + 1)35 update_association(row_index - 1, col_index)36 update_association(row_index + 1, col_index)37 while queue:38 cell = queue.popleft()39 update_recursive(cell[0] + 1, cell[1], 2)40 update_recursive(cell[0] - 1, cell[1], 2)41 update_recursive(cell[0], cell[1] + 1, 2)42 update_recursive(cell[0], cell[1] - 1, 2)...
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!!