def update_graph(gene2graph, cog, signif_struct_info, struct, radius): """Updates the residue neighbor graph based on the current structure. Residues are linked by edges if they are within the provided radius and are on the same gene. Parameters ---------- gene2graph : dict dictionary with genes as keys pointing to significant hotspot residue neighbor graph signif_struct_info : dict identifies which residues are significant hotspots struct : Bio.PDB structure structure under consideration when populating the graph radius : float radius deemed close enough to add an edge between two residues Returns ------- gene2graph : dict updated graph based on the provided structure """ # get which residues are significant signif_pdb_pos = signif_struct_info.keys() possible_res = set(signif_pdb_pos) # find neighbor residues cog = {k: cog[k] for k in cog if (k[2], k[3][1]) in signif_pdb_pos} neighbors = pstruct.find_neighbors_1D(cog, radius) #struct_info = struct_chain[pdb_id] # add edge if residues are neighbors avail_models = [m.id for m in struct] for s in signif_pdb_pos: tmp_chain, tmp_res = s cur_res = signif_struct_info[s] cur_gene = cur_res[0] # update gene2graph gene2graph.setdefault(cur_gene, {}) gene2graph[cur_gene].setdefault(cur_res, set()) for m in avail_models: try: # get neighbors tmp_id = struct[m][tmp_chain][int(tmp_res)].get_full_id() tmp_neighbors = set([(n[2], n[3][1]) for n in neighbors[tmp_id]]) # get only neighbors that are significant and in the # same gene signif_neighbors = set([signif_struct_info[o] for o in (tmp_neighbors & possible_res)]) signif_neighbors_gene = set([s for s in signif_neighbors if s[0] == cur_gene]) # add result to the graph gene2graph[cur_gene][cur_res] = gene2graph[cur_gene][cur_res] | signif_neighbors_gene except KeyError: # skip deleted chains, or models without a chain # be careful this catches all keyerrors pass return gene2graph
def update_graph(struct2graph, all_cogs, signif_struct_info, non_signif_struct_info, struct, radius): """Updates the residue neighbor graph based on the current structure. Residues are linked by edges if they are within the provided radius and are on the same gene. Parameters ---------- gene2graph : dict dictionary with genes as keys pointing to significant hotspot residue neighbor graph signif_struct_info : dict identifies which residues are significant hotspots struct : Bio.PDB structure structure under consideration when populating the graph radius : float radius deemed close enough to add an edge between two residues Returns ------- gene2graph : dict updated graph based on the provided structure """ # get which residues are significant signif_pdb_pos = signif_struct_info.keys() non_signif_pdb_pos = non_signif_struct_info.keys() possible_signif_res = set(signif_pdb_pos) possible_non_signif_res = set(non_signif_pdb_pos) # find neighbor residues signif_cogs = {k: all_cogs[k] for k in all_cogs if (k[2], k[3][1]) in signif_pdb_pos} neighbors = pstruct.find_neighbors_1D(signif_cogs, radius) all_neighbors = pstruct.find_neighbors_for_1D(all_cogs, signif_cogs.keys(), radius) #struct_info = struct_chain[pdb_id] # add edge if residues are neighbors avail_models = [m.id for m in struct] signif_res_neighbors = {} for s in signif_pdb_pos: tmp_chain, tmp_res = s cur_res = signif_struct_info[s] cur_pdb = cur_res[0] # update struct2graph struct2graph.setdefault(cur_pdb, {}) for m in avail_models: cur_res = (m, tmp_chain, int(tmp_res)) struct2graph[cur_pdb].setdefault(cur_res, set()) try: # get neighbors tmp_id = struct[m][tmp_chain][int(tmp_res)].get_full_id() tmp_neighbors = set([(n[2], n[3][1]) for n in neighbors[tmp_id]]) all_tmp_neighbors = set([(n[2], n[3][1]) for n in all_neighbors[tmp_id]]) signif_neighbors = set(tmp_neighbors & possible_signif_res) signif_neighbors_struct = set([(m, o[0], o[1]) for o in signif_neighbors]) non_signif_neighbors = set(all_tmp_neighbors & possible_non_signif_res) non_signif_neighbors_struct = set([(m, o[0], o[1]) for o in non_signif_neighbors]) signif_res_neighbors[cur_res] = non_signif_neighbors_struct # add result to the graphs struct2graph[cur_pdb][cur_res] = struct2graph[cur_pdb][cur_res] | signif_neighbors_struct except KeyError: # skip deleted chains, or models without a chain # be careful this catches all keyerrors print cur_pdb pass return struct2graph, signif_res_neighbors
def update_graph(gene2graph, cog, signif_struct_info, struct, radius): """Updates the residue neighbor graph based on the current structure. Residues are linked by edges if they are within the provided radius and are on the same gene. Parameters ---------- gene2graph : dict dictionary with genes as keys pointing to significant hotspot residue neighbor graph signif_struct_info : dict identifies which residues are significant hotspots struct : Bio.PDB structure structure under consideration when populating the graph radius : float radius deemed close enough to add an edge between two residues Returns ------- gene2graph : dict updated graph based on the provided structure """ # get which residues are significant signif_pdb_pos = signif_struct_info.keys() possible_res = set(signif_pdb_pos) # find neighbor residues cog = {k: cog[k] for k in cog if (k[2], k[3][1]) in signif_pdb_pos} neighbors = pstruct.find_neighbors_1D(cog, radius) #struct_info = struct_chain[pdb_id] # add edge if residues are neighbors avail_models = [m.id for m in struct] for s in signif_pdb_pos: tmp_chain, tmp_res = s cur_res = signif_struct_info[s] cur_gene = cur_res[0] # update gene2graph gene2graph.setdefault(cur_gene, {}) gene2graph[cur_gene].setdefault(cur_res, set()) for m in avail_models: try: # get neighbors tmp_id = struct[m][tmp_chain][int(tmp_res)].get_full_id() tmp_neighbors = set([(n[2], n[3][1]) for n in neighbors[tmp_id]]) # get only neighbors that are significant and in the # same gene signif_neighbors = set([ signif_struct_info[o] for o in (tmp_neighbors & possible_res) ]) signif_neighbors_gene = set( [s for s in signif_neighbors if s[0] == cur_gene]) # add result to the graph gene2graph[cur_gene][cur_res] = gene2graph[cur_gene][ cur_res] | signif_neighbors_gene except KeyError: # skip deleted chains, or models without a chain # be careful this catches all keyerrors pass return gene2graph