PICASO.kgraph ============= .. py:module:: PICASO.kgraph Classes ------- .. autoapisummary:: PICASO.kgraph.MidpointNormalize PICASO.kgraph.KGraph PICASO.kgraph.NetworkScorer PICASO.kgraph.MeanNetworkScorer PICASO.kgraph.NetworkExtender PICASO.kgraph.CommunityTool PICASO.kgraph.DifferentialCommunityIdentifier PICASO.kgraph.GenesetAnnotator PICASO.kgraph.DifferentialKG PICASO.kgraph.NETSIM PICASO.kgraph.ModuleCompare PICASO.kgraph.CRankExplorer PICASO.kgraph.DefaultDict PICASO.kgraph.TwoLevelDifferentialAnalysis PICASO.kgraph.AIDescriptor Functions --------- .. autoapisummary:: PICASO.kgraph.sjoined Module Contents --------------- .. py:class:: MidpointNormalize(vmin=None, vmax=None, midpoint=None, clip=False) Bases: :py:obj:`matplotlib.colors.Normalize` .. py:attribute:: midpoint .. py:method:: __call__(value, clip=None) .. py:function:: sjoined(inlist) .. py:class:: KGraph(random_state=42, kgraph_name='KGraph') .. py:attribute:: kg .. py:attribute:: random_state .. py:attribute:: kgraph_name .. py:attribute:: logger .. py:method:: is_score_field(x) .. py:method:: get_node_attributes() .. py:method:: get_edge_attributes() .. py:method:: __repr__() .. py:method:: copy(suffix=None) .. py:method:: print_kg_info() .. py:method:: load_kgraph_base(data_dir, go=True, TFs=True, omnipath=True, opentargets=True, reactome=True, kegg=True, uniprot_loc=True, STRING=True, NPINTER=False, ot_min_disease_assoc_score=0.8, hallmark_genesets='kegg_gmts/human/c1.all.v2023.2.Hs.symbols.gmt', curated_genesets='kegg_gmts/human/c2.all.v2023.2.Hs.symbols.gmt') .. py:method:: load_kgraph(infile) .. py:method:: save_kgraph(outfile) .. py:method:: get_node_data(node) .. py:method:: get_node_edges(node, src_types=None, tgt_types=None) .. py:method:: get_nodes(nodetype=None) .. py:method:: get_nodes_with_highest_scores(n=3000, nodetype=None, score_accessor=lambda x: x['score'], node_filter=None) .. py:method:: get_edges_with_highest_scores(n=3000, src_types=None, tgt_types=None, score_accessor=lambda x: x['score']) .. py:method:: node_types(node, single=False) .. py:method:: get_node_types(single=False) .. py:method:: plot_node_types(show_threshold=0.02) .. py:method:: plot_node_children(node_types=None) .. py:method:: plot_child_distribution(plot=True) .. py:method:: plot_edge_types(field='type', show_threshold=0.02) .. py:method:: plot_edge_between_types(show_threshold=0.02) .. py:method:: _plot_pie(counteritems, show_threshold=0.02) .. py:method:: get_edge_types(field='type') .. py:method:: get_edge_node_types(edge, field='type') .. py:method:: get_edge_edge_types(src_types=None, tgt_types=None, type_accessor='type', ignore_edge_types=None) .. py:method:: get_edge_between_type() .. py:method:: add_gene_expression(exprDF, mean_column='mean', sd_column='sd', perc_expr_column='perc_expr', median_column='median', num_column='num', allnum_column='group_cells') .. py:method:: get_node_type(node) .. py:method:: get_edges_to_type(node, otype) .. py:method:: get_edges_between_ntypes(src_types, tgt_types) .. py:method:: _get_predecessors(start_node, ntype, n=10) .. py:method:: score_nodes_hierarchically(ntype='geneset', target_ntype='gene', relevance_threshold=0, child_score_accessor=lambda x: x.get('score', 0)) .. py:method:: node_type_overlap(node, types) .. py:method:: get_node_scores(score_accessor=lambda x: x.get('score', 0), nodes=None) .. py:method:: get_edge_scores(score_accessor=lambda x: x.get('score', 0), edge_types=None, nodes=None) .. py:method:: get_edge_scores_per_type(score_accessor=lambda x: x.get('score', 0), edge_types=None, single=False) .. py:method:: plot_score_histogram(edge_types=None, score_accessor=lambda x: x.get('score', 0)) .. py:method:: plot_edge_attribute_distribution(edge_types=None, score_accessor=lambda x: x.get('score', 0), ax=None, title=None) .. py:method:: plot_node_attribute_distribution(attribute_accessor, node_types=None, ax=None, title=None) .. py:method:: plot_node_attribute_histogram(attribute_accessor, nodes=None, node_type=None, ax=None, title=None) .. py:method:: plot_score_violin(per_edge_type=False, single_edge_types=False, edge_types=None, score_accessor=lambda x: x.get('score', 0), figsize=None) .. py:method:: plot_subgraph_scores(scores) .. py:method:: filter_nodes(filter_function) .. py:method:: filter_edges(filter_function) .. py:method:: subset_kg(retainedNodes, suffix='subset') .. py:method:: induce_kg(retainedNodes, suffix='subset', radius=1) .. py:method:: to_gene_kgraph() .. py:method:: _filter_edge_score(score_field, minEdgeScore=3.0, undirected=True) .. py:method:: get_communities_connectedcomponent(minEdgeScore=3.0, resolution=5, prefix='Community', sep='_', score_field='score') .. py:method:: get_communities_greedymodularity(minEdgeScore=3.0, resolution=0.5, prefix='Community', sep='_', score_field='score') .. py:method:: get_communities_asyn_label_propagation(minEdgeScore=3.0, prefix='Community', sep='_', score_field='score', seed=None) .. py:method:: get_communities(minEdgeScore=3.0, resolution=5, prefix='Community', sep='_', score_field='score') .. py:method:: get_communities_ecg(minEdgeScore=3.0, resolution=5, ens_size=16, prefix='Community', sep='_', score_field='score') .. py:method:: get_communities_negpos(max_comm_size=50, prefix='Community', sep='_', score_field='score') .. py:method:: get_communities_infomap(prefix='Community', sep=',') Partition network with the Infomap algorithm. Annotates nodes with 'community' id and return number of communities found. .. py:method:: get_communities_markovclustering(prefix='cluster', inflation=1.4) .. py:method:: get_communities_link(minEdgeScore=3.0, threshold=0.15, score_field='score', prefix='Community', sep='_') .. py:method:: describe_communities(comms) .. py:method:: get_kg_subgraph(genes) .. py:method:: plot_graph_network(outfile=None, notebook=False) .. py:method:: get_nx_subgraph(genes) .. py:method:: plot_graph(ax=None, figsize=(6, 6), title='', pos=None, close=True, font_size=8, edge_score_normalizer=None, node_score_normalizer=None, edge_cmap=plt.cm.Reds, max_node_size=200, nodetype2color={'gene': '#239756', 'geneset': '#3fc37e', 'disease': '#5047ee', 'drug': '#3026c1', 'NA': '#f37855'}, nodecolors={'gene': '#239756', 'geneset': '#3fc37e', 'disease': '#5047ee', 'drug': '#e600e6', 'NA': '#f37855'}, nodeshapes={'gene': 'o', 'geneset': 's', 'disease': '^', 'drug': 'p', 'NA': 'o'}, edge_score_accessor=lambda x: x.get('score', 0), node_score_accessor=lambda x: x.get('score', 0), legend=True) .. py:method:: get_node_degrees(intype, connecttype=None) .. py:class:: NetworkScorer(random_state=42) _summary_ Interface class for any network scoring class. Hint: All scores must have their minimum at 0 ! This is required such that differential KGs can be successfully generated! .. py:attribute:: random_state .. py:attribute:: logger .. py:method:: score() .. py:class:: MeanNetworkScorer(random_state=42) Bases: :py:obj:`NetworkScorer` _summary_ Interface class for any network scoring class. Hint: All scores must have their minimum at 0 ! This is required such that differential KGs can be successfully generated! .. py:attribute:: scoring_gene_gene_expression .. py:attribute:: scoring_interactions .. py:method:: score_edges(kgraph, value_accessor, edge_accessor, scorers, src_types=None, tgt_types=None, ignore_edge_types=None) .. py:method:: score_nodes_from_properties(kgraph, ntypes=['measured_expression'], scoring_function=lambda x: x['mean'] * x['perc_expr'], property_accessor=lambda x: x.get('expression', None)) .. py:method:: score_nodes_from_edges(kgraph, ntype='geneset', consider_edge_type=[('gene', 'geneset')], scoring_function=None, overwrite_score=False) .. py:method:: score_nx(kg: networkx.DiGraph) .. py:method:: score(kgraph: KGraph) .. py:method:: calculate_edge_zscores(kgraph, score_accessor, edge_accessor, src_types=None, tgt_types=None, ignore_edge_types=None) .. py:class:: NetworkExtender .. py:method:: extend_network(nodes, fullKG: KGraph, radius=1, scorer: NetworkScorer = None, min_children_gs=2, max_size_gs=100, minFraction_small=0.4, minFraction_large=0.5, node_types=['geneset', 'disease', 'ncRNA'], minGeneSpec={'geneset': 0.8, 'disease': 0.6}, min_edge_score=1.0, score_field='score', verbose=False) .. py:method:: extend_network_force(eKG: KGraph, fullKG: KGraph, nodetype, acceptor=None, edge_acceptor=None, minSpec=0.5) .. py:method:: extend_nodetypes(eKG: KGraph, fullKG: KGraph, nodetype, node_score_accessor=None, edge_score_accessor=None, min_node_score=0.5, verbose=False) .. py:class:: CommunityTool .. py:method:: scatter_community_scores(module_detail) .. py:method:: visualize_communities(details, title, subsetOrderFunc=None, field='median', show_values=True) .. py:method:: sort_communities(comm_details, details=False) .. py:method:: plot_community(KGs, communityNodes, own, main_net=None, num_columns=4, title=None, nodecolors={'gene': '#239756', 'geneset': '#3fc37e', 'disease': '#5047ee', 'drug': '#3026c1', 'NA': '#f37855'}, outfile=None, dpi=500, show=True, edge_score_accessor=lambda x: x.get('score', 0), node_score_accessor=lambda x: x.get('score', 0), verbose=False) .. py:method:: compare_modules(comms, figsize=(16, 12)) .. py:class:: DifferentialCommunityIdentifier .. py:method:: cohend(d1, d2) :classmethod: .. py:method:: calculate_scores(allKGs, ref_kg, nodes, score_field) .. py:method:: identify_differential_communities(communities, ref_kg, KGs, sort_function=None, score_field='score', use_statistic='cohend', min_nodes=10, min_enriched=0.5, min_effect_size=0.2, all_verbose=False, verbose=False) .. py:method:: score_subgraphs_for_subnet(KGs, subnet, score_field='score') .. py:method:: score_subgraphs(Gs, score_field='score', default_score=0) .. py:class:: GenesetAnnotator .. py:method:: annotate_genesets(kg: KGraph, settype='disease', targettype='gene') .. py:class:: DifferentialKG(pseudocount=0.01) .. py:attribute:: pseudocount .. py:method:: _get_edge_fold_changes(kg1: KGraph, kg2: KGraph) .. py:method:: _get_log_foldchange(node1Score, node2Score, log2=True) .. py:method:: _get_node_fold_changes(kg1: KGraph, kg2: KGraph) .. py:method:: get_differential_graph(kg1: KGraph, kg2: KGraph, field='fc', rescoring=['geneset', 'disease']) .. py:method:: calculate_diffkg_list(exprKGs, base_case, cases) .. py:class:: NETSIM(kg: KGraph, conf_score_accessor=lambda x: 1) .. py:attribute:: kg .. py:attribute:: orig_kg .. py:attribute:: conf_score_accessor .. py:attribute:: kg_rev .. py:attribute:: undirected_x .. py:attribute:: max_go_level :value: 10 .. py:attribute:: precalculated_term_genes .. py:method:: get_annotated_genes(ta) .. py:method:: confidence(gi, gj) .. py:method:: dij(gi, gj) .. py:method:: functional_distance_genesets(ta, tb, ga, gb) .. py:method:: get_lca(ta, tb) .. py:method:: get_shortest_path(ta, tb) .. py:method:: get_path_constrained_annotation(ta, tb, p, verbose=False) .. py:method:: get_node_name(node) .. py:method:: functional_similarity(ta, tb, verbose=False) .. py:method:: get_go_level(ta) .. py:method:: lca_similarity(ta, tb, verbose=False) .. py:method:: get_relevant_goterms(groupKG, max_terms=None, verbose=False) .. py:method:: compare_modules_lca(skg1, skg2, max_terms=None, verbose=True) .. py:method:: compare_modules(skg1, skg2, max_terms=None, verbose=True) .. py:class:: ModuleCompare .. py:method:: makeProgressBar() -> progressbar.ProgressBar :classmethod: .. py:method:: draw_network(G, title=None, borderWeightQuantile=0.8) .. py:method:: module_similarities_to_df(modSims) .. py:method:: network_compare_modules(inKGs, measure='jaccard', borderWeightQuantile=0.8) .. py:method:: network_compare_lca(inKGs, max_terms=None, fullKG=None, ns=None, borderWeightQuantile=0.8) .. py:method:: network_compare_netsim(inKGs, borderWeightQuantile=0.8, max_terms=None, fullKG=None, ns=None) .. py:method:: module_pca(sigKG, kg: KGraph) .. py:method:: plot_dendrogram(simDict, figsize=(8, 6), color_threshold=1) .. py:class:: CRankExplorer .. py:method:: calculate_connectivity(kg: KGraph) .. py:method:: calculate_density(communityKG: KGraph, edge_score_accessor) .. py:method:: calculate_boundary(community, fullKG: KGraph, edge_score_accessor, density) .. py:method:: calculate_allegiance(community, fullKG: KGraph) .. py:method:: evaluate_community(community, fullKG: KGraph, edge_score_accessor=lambda x: x['score']) .. py:method:: evaluate_communities(sigKGs, fullKGs, mod_sep='_mod_') .. py:method:: plot_scores(scoreDF) .. py:class:: DefaultDict Bases: :py:obj:`dict` dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) .. py:method:: __missing__(key) .. py:class:: TwoLevelDifferentialAnalysis(tlDict, sorted_zones, output_folder_formatter, fullKG=None) .. py:attribute:: tldict .. py:attribute:: sorted_zones .. py:attribute:: name_sep :value: '_mod_' .. py:attribute:: cellgroupdata .. py:attribute:: output_folder_formatter .. py:attribute:: recalc_warning :value: False .. py:method:: calculate_modules(relevant_cellgroups=None, cg_zone_formatter='{}_{}', reference_formatter='{}_Ref', diffkg=DifferentialKG(), overwrite=False) .. py:method:: _get_diff_comms(tkgs, min_effect_size=1.0, resolution=4, minEdgeScore=1, min_node_scores={'drug': 1.0, 'ncRNA': 0.7}, network_extend_spec={'geneset': {'min_gene_spec': 0.5, 'max_size_gs': 200, 'min_fraction_large': 0.6, 'min_fraction_small': 0.5}, 'disease': {'min_gene_spec': 0.8, 'max_size_gs': 100, 'min_fraction_large': 0.7, 'min_fraction_small': 0.6}}) .. py:method:: plot_module_comparisons(plot_communities=False, ct=CommunityTool()) .. py:method:: _geneset_filter(n, kg) .. py:method:: _filter_empty_genesets(n, kg) .. py:method:: _filter_singletons(n, kg) .. py:method:: _combined_filter(n, kg) .. py:property:: communities .. py:method:: get_community(cid) .. py:method:: get_community_details(cid) .. py:method:: get_community_kg(cid) .. py:method:: get_community_representation(cid, key='communities') .. py:method:: plot_module_description(nrow=4, figsize=(10, 10), dcolors=None) .. py:method:: _describe_kg(kg, name) .. py:method:: describe_modules(relevant_cellgroups=None, non_verbose=False) .. py:method:: create_overlap_df(nodetype) .. py:method:: _calculate_gs_overlap(gsType, gsDict, moduleKG) .. py:method:: _toShortName(x) .. py:method:: describe_module_scrna(adata, sc_celltype_column, sc_condition_column, show_plot=True, plot_folder=None, plot_prefix='overview_plot_{}', module_names=None, gsTypes=['disease', 'geneset', 'drug'], numGenesThreshold=3, numElemsBarPlot=10, hue_colors={'gene': '#239756', 'geneset': '#3fc37e', 'disease': '#5047ee', 'drug': '#e600e6', 'NA': '#f37855'}) .. py:method:: available_cellgroups() .. py:class:: AIDescriptor(model_name='LoneStriker/BioMistral-7B-DARE-GGUF', model_file='BioMistral-7B-DARE-Q4_K_M.gguf', local_dir='../llm_addon/model/') .. py:attribute:: model_name .. py:attribute:: model_file .. py:attribute:: local_dir .. py:attribute:: model_path .. py:attribute:: llm .. py:method:: query_genelist(gene_list, context=None, verbose=False, word_cloud=False) .. py:method:: _plot_wordcloud(text) .. py:method:: query_wordcloud(gene_list, context)