Search is not available for this dataset
text
stringlengths
75
104k
def cmdclass(path, enable=None, user=None): """Build nbextension cmdclass dict for the setuptools.setup method. Parameters ---------- path: str Directory relative to the setup file that the nbextension code lives in. enable: [str=None] Extension to "enable". Enabling an ext...
def count_subgraph_sizes(graph: BELGraph, annotation: str = 'Subgraph') -> Counter[int]: """Count the number of nodes in each subgraph induced by an annotation. :param annotation: The annotation to group by and compare. Defaults to 'Subgraph' :return: A dictionary from {annotation value: number of nodes} ...
def calculate_subgraph_edge_overlap( graph: BELGraph, annotation: str = 'Subgraph' ) -> Tuple[ Mapping[str, EdgeSet], Mapping[str, Mapping[str, EdgeSet]], Mapping[str, Mapping[str, EdgeSet]], Mapping[str, Mapping[str, float]], ]: """Build a DatafFame to show the overlap between diffe...
def summarize_subgraph_edge_overlap(graph: BELGraph, annotation: str = 'Subgraph') -> Mapping[str, Mapping[str, float]]: """Return a similarity matrix between all subgraphs (or other given annotation). :param annotation: The annotation to group by and compare. Defaults to :code:`"Subgraph"` :return: A simi...
def summarize_subgraph_node_overlap(graph: BELGraph, node_predicates=None, annotation: str = 'Subgraph'): """Calculate the subgraph similarity tanimoto similarity in nodes passing the given filter. Provides an alternate view on subgraph similarity, from a more node-centric view """ r1 = group_nodes_by_...
def rank_subgraph_by_node_filter(graph: BELGraph, node_predicates: Union[NodePredicate, Iterable[NodePredicate]], annotation: str = 'Subgraph', reverse: bool = True, ) -> List[Tuple[str, i...
def to_jupyter(graph: BELGraph, chart: Optional[str] = None) -> Javascript: """Render the graph as JavaScript in a Jupyter Notebook.""" with open(os.path.join(HERE, 'render_with_javascript.js'), 'rt') as f: js_template = Template(f.read()) return Javascript(js_template.render(**_get_context(graph, ...
def to_html(graph: BELGraph, chart: Optional[str] = None) -> str: """Render the graph as an HTML string. Common usage may involve writing to a file like: >>> from pybel.examples import sialic_acid_graph >>> with open('ideogram_output.html', 'w') as file: ... print(to_html(sialic_acid_graph), f...
def prerender(graph: BELGraph) -> Mapping[str, Mapping[str, Any]]: """Generate the annotations JSON for Ideogram.""" import bio2bel_hgnc from bio2bel_hgnc.models import HumanGene graph: BELGraph = graph.copy() enrich_protein_and_rna_origins(graph) collapse_all_variants(graph) genes: Set[Gen...
def plot_summary_axes(graph: BELGraph, lax, rax, logx=True): """Plots your graph summary statistics on the given axes. After, you should run :func:`plt.tight_layout` and you must run :func:`plt.show` to view. Shows: 1. Count of nodes, grouped by function type 2. Count of edges, grouped by relation...
def plot_summary(graph: BELGraph, plt, logx=True, **kwargs): """Plots your graph summary statistics. This function is a thin wrapper around :func:`plot_summary_axis`. It automatically takes care of building figures given matplotlib's pyplot module as an argument. After, you need to run :func:`plt.show`. ...
def remove_nodes_by_function_namespace(graph: BELGraph, func: str, namespace: Strings) -> None: """Remove nodes with the given function and namespace. This might be useful to exclude information learned about distant species, such as excluding all information from MGI and RGD in diseases where mice and rat...
def preprocessing_excel(path): """Preprocess the excel sheet :param filepath: filepath of the excel data :return: df: pandas dataframe with excel data :rtype: pandas.DataFrame """ if not os.path.exists(path): raise ValueError("Error: %s file not found" % path) # Import Models from ...
def preprocessing_br_projection_excel(path: str) -> pd.DataFrame: """Preprocess the excel file. Parameters ---------- path : Filepath of the excel sheet """ if not os.path.exists(path): raise ValueError("Error: %s file not found" % path) return pd.read_excel(path, sheetname=0, head...
def get_nift_values() -> Mapping[str, str]: """Extract the list of NIFT names from the BEL resource and builds a dictionary mapping from the lowercased version to the uppercase version. """ r = get_bel_resource(NIFT) return { name.lower(): name for name in r['Values'] }
def write_neurommsig_bel(file, df: pd.DataFrame, disease: str, nift_values: Mapping[str, str], ): """Writes the NeuroMMSigDB excel sheet to BEL :param file: a file or file-like that can be writen to :param d...
def get_contradiction_summary(graph: BELGraph) -> Iterable[Tuple[BaseEntity, BaseEntity, str]]: """Yield triplets of (source node, target node, set of relations) for (source node, target node) pairs that have multiple, contradictory relations. """ for u, v in set(graph.edges()): relations = {dat...
def get_regulatory_pairs(graph: BELGraph) -> Set[NodePair]: """Find pairs of nodes that have mutual causal edges that are regulating each other such that ``A -> B`` and ``B -| A``. :return: A set of pairs of nodes with mutual causal edges """ cg = get_causal_subgraph(graph) results = set() ...
def get_chaotic_pairs(graph: BELGraph) -> SetOfNodePairs: """Find pairs of nodes that have mutual causal edges that are increasing each other such that ``A -> B`` and ``B -> A``. :return: A set of pairs of nodes with mutual causal edges """ cg = get_causal_subgraph(graph) results = set() ...
def get_correlation_graph(graph: BELGraph) -> Graph: """Extract an undirected graph of only correlative relationships.""" result = Graph() for u, v, d in graph.edges(data=True): if d[RELATION] not in CORRELATIVE_RELATIONS: continue if not result.has_edge(u, v): resu...
def get_correlation_triangles(graph: BELGraph) -> SetOfNodeTriples: """Return a set of all triangles pointed by the given node.""" return { tuple(sorted([n, u, v], key=str)) for n in graph for u, v in itt.combinations(graph[n], 2) if graph.has_edge(u, v) }
def get_triangles(graph: DiGraph) -> SetOfNodeTriples: """Get a set of triples representing the 3-cycles from a directional graph. Each 3-cycle is returned once, with nodes in sorted order. """ return { tuple(sorted([a, b, c], key=str)) for a, b in graph.edges() for c in graph.s...
def get_separate_unstable_correlation_triples(graph: BELGraph) -> Iterable[NodeTriple]: """Yield all triples of nodes A, B, C such that ``A pos B``, ``A pos C``, and ``B neg C``. :return: An iterator over triples of unstable graphs, where the second two are negative """ cg = get_correlation_graph(graph...
def get_mutually_unstable_correlation_triples(graph: BELGraph) -> Iterable[NodeTriple]: """Yield triples of nodes (A, B, C) such that ``A neg B``, ``B neg C``, and ``C neg A``.""" cg = get_correlation_graph(graph) for a, b, c in get_correlation_triangles(cg): if all(NEGATIVE_CORRELATION in x for x ...
def jens_transformation_alpha(graph: BELGraph) -> DiGraph: """Apply Jens' transformation (Type 1) to the graph. 1. Induce a sub-graph over causal + correlative edges 2. Transform edges by the following rules: - increases => increases - decreases => backwards increases - positive cor...
def jens_transformation_beta(graph: BELGraph) -> DiGraph: """Apply Jens' Transformation (Type 2) to the graph. 1. Induce a sub-graph over causal and correlative relations 2. Transform edges with the following rules: - increases => backwards decreases - decreases => decreases - posit...
def get_jens_unstable(graph: BELGraph) -> Iterable[NodeTriple]: """Yield triples of nodes (A, B, C) where ``A -> B``, ``A -| C``, and ``C positiveCorrelation A``. Calculated efficiently using the Jens Transformation. """ r = jens_transformation_alpha(graph) return get_triangles(r)
def summarize_stability(graph: BELGraph) -> Mapping[str, int]: """Summarize the stability of the graph.""" regulatory_pairs = get_regulatory_pairs(graph) chaotic_pairs = get_chaotic_pairs(graph) dampened_pairs = get_dampened_pairs(graph) contraditory_pairs = get_contradiction_summary(graph) sepa...
def flatten_list_abundance(node: ListAbundance) -> ListAbundance: """Flattens the complex or composite abundance.""" return node.__class__(list(chain.from_iterable( ( flatten_list_abundance(member).members if isinstance(member, ListAbundance) else [member] ) ...
def list_abundance_expansion(graph: BELGraph) -> None: """Flatten list abundances.""" mapping = { node: flatten_list_abundance(node) for node in graph if isinstance(node, ListAbundance) } relabel_nodes(graph, mapping, copy=False)
def list_abundance_cartesian_expansion(graph: BELGraph) -> None: """Expand all list abundances to simple subject-predicate-object networks.""" for u, v, k, d in list(graph.edges(keys=True, data=True)): if CITATION not in d: continue if isinstance(u, ListAbundance) and isinstance(v, ...
def _reaction_cartesion_expansion_unqualified_helper( graph: BELGraph, u: BaseEntity, v: BaseEntity, d: dict, ) -> None: """Helper to deal with cartension expansion in unqualified edges.""" if isinstance(u, Reaction) and isinstance(v, Reaction): enzymes = _get_catalysts_i...
def _get_catalysts_in_reaction(reaction: Reaction) -> Set[BaseAbundance]: """Return nodes that are both in reactants and reactions in a reaction.""" return { reactant for reactant in reaction.reactants if reactant in reaction.products }
def reaction_cartesian_expansion(graph: BELGraph, accept_unqualified_edges: bool = True) -> None: """Expand all reactions to simple subject-predicate-object networks.""" for u, v, d in list(graph.edges(data=True)): # Deal with unqualified edges if CITATION not in d and accept_unqualified_edges: ...
def insert_graph(self, graph: BELGraph, **_kwargs) -> Network: """Insert a graph and return the resulting ORM object (mocked).""" result = _Namespace() result.id = len(self.networks) self.networks[result.id] = graph return result
def get_graphs_by_ids(self, network_ids: Iterable[int]) -> List[BELGraph]: """Get several graphs by their identifiers.""" return [ self.networks[network_id] for network_id in network_ids ]
def _generate_citation_dict(graph: BELGraph) -> Mapping[str, Mapping[Tuple[BaseEntity, BaseEntity], str]]: """Prepare a citation data dictionary from a graph. :return: A dictionary of dictionaries {citation type: {(source, target): citation reference} """ results = defaultdict(lambda: defaultdict(set))...
def get_pmid_by_keyword(keyword: str, graph: Optional[BELGraph] = None, pubmed_identifiers: Optional[Set[str]] = None, ) -> Set[str]: """Get the set of PubMed identifiers beginning with the given keyword string. :param keyword: The beg...
def count_citations(graph: BELGraph, **annotations) -> Counter: """Counts the citations in a graph based on a given filter :param graph: A BEL graph :param dict annotations: The annotation filters to use :return: A counter from {(citation type, citation reference): frequency} """ citations = de...
def count_citations_by_annotation(graph: BELGraph, annotation: str) -> Mapping[str, typing.Counter[str]]: """Group the citation counters by subgraphs induced by the annotation. :param graph: A BEL graph :param annotation: The annotation to use to group the graph :return: A dictionary of Counters {subgr...
def count_author_publications(graph: BELGraph) -> typing.Counter[str]: """Count the number of publications of each author to the given graph.""" authors = group_as_dict(_iter_author_publiations(graph)) return Counter(count_dict_values(count_defaultdict(authors)))
def get_authors_by_keyword(keyword: str, graph=None, authors=None) -> Set[str]: """Get authors for whom the search term is a substring. :param pybel.BELGraph graph: A BEL graph :param keyword: The keyword to search the author strings for :param set[str] authors: An optional set of pre-cached author...
def count_authors_by_annotation(graph: BELGraph, annotation: str = 'Subgraph') -> Mapping[str, typing.Counter[str]]: """Group the author counters by sub-graphs induced by the annotation. :param graph: A BEL graph :param annotation: The annotation to use to group the graph :return: A dictionary of Count...
def get_evidences_by_pmid(graph: BELGraph, pmids: Union[str, Iterable[str]]): """Get a dictionary from the given PubMed identifiers to the sets of all evidence strings associated with each in the graph. :param graph: A BEL graph :param pmids: An iterable of PubMed identifiers, as strings. Is consumed a...
def count_citation_years(graph: BELGraph) -> typing.Counter[int]: """Count the number of citations from each year.""" result = defaultdict(set) for _, _, data in graph.edges(data=True): if CITATION not in data or CITATION_DATE not in data[CITATION]: continue try: dt...
def get_citation_years(graph: BELGraph) -> List[Tuple[int, int]]: """Create a citation timeline counter from the graph.""" return create_timeline(count_citation_years(graph))
def create_timeline(year_counter: typing.Counter[int]) -> List[Tuple[int, int]]: """Complete the Counter timeline. :param Counter year_counter: counter dict for each year :return: complete timeline """ if not year_counter: return [] from_year = min(year_counter) - 1 until_year = da...
def count_confidences(graph: BELGraph) -> typing.Counter[str]: """Count the confidences in the graph.""" return Counter( ( 'None' if ANNOTATIONS not in data or 'Confidence' not in data[ANNOTATIONS] else list(data[ANNOTATIONS]['Confidence'])[0] ) for _,...
def enrich_pubmed_citations(graph: BELGraph, manager: Manager) -> Set[str]: """Overwrite all PubMed citations with values from NCBI's eUtils lookup service. :return: A set of PMIDs for which the eUtils service crashed """ pmids = get_pubmed_identifiers(graph) pmid_data, errors = get_citations_by_pm...
def update_context(universe: BELGraph, graph: BELGraph): """Update the context of a subgraph from the universe of all knowledge.""" for namespace in get_namespaces(graph): if namespace in universe.namespace_url: graph.namespace_url[namespace] = universe.namespace_url[namespace] elif ...
def highlight_nodes(graph: BELGraph, nodes: Optional[Iterable[BaseEntity]] = None, color: Optional[str]=None): """Adds a highlight tag to the given nodes. :param graph: A BEL graph :param nodes: The nodes to add a highlight tag on :param color: The color to highlight (use something that works with CSS)...
def is_node_highlighted(graph: BELGraph, node: BaseEntity) -> bool: """Returns if the given node is highlighted. :param graph: A BEL graph :param node: A BEL node :type node: tuple :return: Does the node contain highlight information? :rtype: bool """ return NODE_HIGHLIGHT in graph.node...
def remove_highlight_nodes(graph: BELGraph, nodes: Optional[Iterable[BaseEntity]]=None) -> None: """Removes the highlight from the given nodes, or all nodes if none given. :param graph: A BEL graph :param nodes: The list of nodes to un-highlight """ for node in graph if nodes is None else nodes: ...
def highlight_edges(graph: BELGraph, edges=None, color: Optional[str]=None) -> None: """Adds a highlight tag to the given edges. :param graph: A BEL graph :param edges: The edges (4-tuples of u, v, k, d) to add a highlight tag on :type edges: iter[tuple] :param str color: The color to highlight (us...
def is_edge_highlighted(graph: BELGraph, u, v, k) -> bool: """Returns if the given edge is highlighted. :param graph: A BEL graph :return: Does the edge contain highlight information? :rtype: bool """ return EDGE_HIGHLIGHT in graph[u][v][k]
def remove_highlight_edges(graph: BELGraph, edges=None): """Remove the highlight from the given edges, or all edges if none given. :param graph: A BEL graph :param edges: The edges (4-tuple of u,v,k,d) to remove the highlight from) :type edges: iter[tuple] """ for u, v, k, _ in graph.edges(keys...
def highlight_subgraph(universe: BELGraph, graph: BELGraph): """Highlight all nodes/edges in the universe that in the given graph. :param universe: The universe of knowledge :param graph: The BEL graph to mutate """ highlight_nodes(universe, graph) highlight_edges(universe, graph.edges())
def remove_highlight_subgraph(graph: BELGraph, subgraph: BELGraph): """Remove the highlight from all nodes/edges in the graph that are in the subgraph. :param graph: The BEL graph to mutate :param subgraph: The subgraph from which to remove the highlighting """ remove_highlight_nodes(graph, subgrap...
def get_causal_out_edges( graph: BELGraph, nbunch: Union[BaseEntity, Iterable[BaseEntity]], ) -> Set[Tuple[BaseEntity, BaseEntity]]: """Get the out-edges to the given node that are causal. :return: A set of (source, target) pairs where the source is the given node """ return { (...
def get_causal_source_nodes(graph: BELGraph, func: str) -> Set[BaseEntity]: """Return a set of all nodes that have an in-degree of 0. This likely means that it is an external perturbagen and is not known to have any causal origin from within the biological system. These nodes are useful to identify because...
def get_causal_central_nodes(graph: BELGraph, func: str) -> Set[BaseEntity]: """Return a set of all nodes that have both an in-degree > 0 and out-degree > 0. This means that they are an integral part of a pathway, since they are both produced and consumed. """ return { node for node in ...
def get_causal_sink_nodes(graph: BELGraph, func) -> Set[BaseEntity]: """Returns a set of all ABUNDANCE nodes that have an causal out-degree of 0. This likely means that the knowledge assembly is incomplete, or there is a curation error. """ return { node for node in graph if nod...
def count_top_centrality(graph: BELGraph, number: Optional[int] = 30) -> Mapping[BaseEntity, int]: """Get top centrality dictionary.""" dd = nx.betweenness_centrality(graph) dc = Counter(dd) return dict(dc.most_common(number))
def get_modifications_count(graph: BELGraph) -> Mapping[str, int]: """Get a modifications count dictionary.""" return remove_falsy_values({ 'Translocations': len(get_translocated(graph)), 'Degradations': len(get_degradations(graph)), 'Molecular Activities': len(get_activities(graph)), ...
def remove_falsy_values(counter: Mapping[Any, int]) -> Mapping[Any, int]: """Remove all values that are zero.""" return { label: count for label, count in counter.items() if count }
def _collapse_variants_by_function(graph: BELGraph, func: str) -> None: """Collapse all of the given functions' variants' edges to their parents, in-place.""" for parent_node, variant_node, data in graph.edges(data=True): if data[RELATION] == HAS_VARIANT and parent_node.function == func: col...
def rewire_variants_to_genes(graph: BELGraph) -> None: """Find all protein variants that are pointing to a gene and not a protein and fixes them by changing their function to be :data:`pybel.constants.GENE`, in place A use case is after running :func:`collapse_to_genes`. """ mapping = {} for n...
def _collapse_edge_passing_predicates(graph: BELGraph, edge_predicates: EdgePredicates = None) -> None: """Collapse all edges passing the given edge predicates.""" for u, v, _ in filter_edges(graph, edge_predicates=edge_predicates): collapse_pair(graph, survivor=u, victim=v)
def _collapse_edge_by_namespace(graph: BELGraph, victim_namespaces: Strings, survivor_namespaces: str, relations: Strings) -> None: """Collapse pairs of nodes with the given namespaces that have the given relationship. ...
def collapse_equivalencies_by_namespace(graph: BELGraph, victim_namespace: Strings, survivor_namespace: str) -> None: """Collapse pairs of nodes with the given namespaces that have equivalence relationships. :param graph: A BEL graph :param victim_namespace: The namespace(s) of the node to collapse ...
def collapse_orthologies_by_namespace(graph: BELGraph, victim_namespace: Strings, survivor_namespace: str) -> None: """Collapse pairs of nodes with the given namespaces that have orthology relationships. :param graph: A BEL Graph :param victim_namespace: The namespace(s) of the node to collapse :param ...
def collapse_entrez_equivalencies(graph: BELGraph): """Collapse all equivalence edges away from Entrez. Assumes well formed, 2-way equivalencies.""" relation_filter = build_relation_predicate(EQUIVALENT_TO) source_namespace_filter = build_source_namespace_filter(['EGID', 'EG', 'ENTREZ']) edge_predicate...
def collapse_consistent_edges(graph: BELGraph): """Collapse consistent edges together. .. warning:: This operation doesn't preserve evidences or other annotations """ for u, v in graph.edges(): relation = pair_is_consistent(graph, u, v) if not relation: continue ed...
def collapse_to_protein_interactions(graph: BELGraph) -> BELGraph: """Collapse to a graph made of only causal gene/protein edges.""" rv: BELGraph = graph.copy() collapse_to_genes(rv) def is_edge_ppi(_: BELGraph, u: BaseEntity, v: BaseEntity, __: str) -> bool: """Check if an edge is a PPI.""" ...
def collapse_nodes_with_same_names(graph: BELGraph) -> None: """Collapse all nodes with the same name, merging namespaces by picking first alphabetical one.""" survivor_mapping = defaultdict(set) # Collapse mapping dict victims = set() # Things already mapped while iterating it = tqdm(itt.combinations(...
def main(output): """Output the HBP knowledge graph to the desktop""" from hbp_knowledge import get_graph graph = get_graph() text = to_html(graph) print(text, file=output)
def node_is_upstream_leaf(graph: BELGraph, node: BaseEntity) -> bool: """Return if the node is an upstream leaf. An upstream leaf is defined as a node that has no in-edges, and exactly 1 out-edge. """ return 0 == len(graph.predecessors(node)) and 1 == len(graph.successors(node))
def get_unweighted_upstream_leaves(graph: BELGraph, key: Optional[str] = None) -> Iterable[BaseEntity]: """Get nodes with no incoming edges, one outgoing edge, and without the given key in its data dictionary. .. seealso :: :func:`data_does_not_contain_key_builder` :param graph: A BEL graph :param key...
def remove_unweighted_leaves(graph: BELGraph, key: Optional[str] = None) -> None: """Remove nodes that are leaves and that don't have a weight (or other key) attribute set. :param graph: A BEL graph :param key: The key in the node data dictionary representing the experimental data. Defaults to :data:`...
def is_unweighted_source(graph: BELGraph, node: BaseEntity, key: str) -> bool: """Check if the node is both a source and also has an annotation. :param graph: A BEL graph :param node: A BEL node :param key: The key in the node data dictionary representing the experimental data """ return graph....
def get_unweighted_sources(graph: BELGraph, key: Optional[str] = None) -> Iterable[BaseEntity]: """Get nodes on the periphery of the sub-graph that do not have a annotation for the given key. :param graph: A BEL graph :param key: The key in the node data dictionary representing the experimental data :r...
def remove_unweighted_sources(graph: BELGraph, key: Optional[str] = None) -> None: """Prune unannotated nodes on the periphery of the sub-graph. :param graph: A BEL graph :param key: The key in the node data dictionary representing the experimental data. Defaults to :data:`pybel_tools.constants.WEIGHT...
def prune_mechanism_by_data(graph, key: Optional[str] = None) -> None: """Remove all leaves and source nodes that don't have weights. Is a thin wrapper around :func:`remove_unweighted_leaves` and :func:`remove_unweighted_sources` :param graph: A BEL graph :param key: The key in the node data dictiona...
def generate_mechanism(graph: BELGraph, node: BaseEntity, key: Optional[str] = None) -> BELGraph: """Generate a mechanistic sub-graph upstream of the given node. :param graph: A BEL graph :param node: A BEL node :param key: The key in the node data dictionary representing the experimental data. :re...
def generate_bioprocess_mechanisms(graph, key: Optional[str] = None) -> Mapping[BiologicalProcess, BELGraph]: """Generate a mechanistic sub-graph for each biological process in the graph using :func:`generate_mechanism`. :param graph: A BEL graph :param key: The key in the node data dictionary representing...
def get_neurommsig_scores(graph: BELGraph, genes: List[Gene], annotation: str = 'Subgraph', ora_weight: Optional[float] = None, hub_weight: Optional[float] = None, top_percent: Optional[floa...
def get_neurommsig_scores_prestratified(subgraphs: Mapping[str, BELGraph], genes: List[Gene], ora_weight: Optional[float] = None, hub_weight: Optional[float] = None, ...
def get_neurommsig_score(graph: BELGraph, genes: List[Gene], ora_weight: Optional[float] = None, hub_weight: Optional[float] = None, top_percent: Optional[float] = None, topology_weight: Optional...
def neurommsig_gene_ora(graph: BELGraph, genes: List[Gene]) -> float: """Calculate the percentage of target genes mappable to the graph. Assume: graph central dogma inferred, collapsed to genes, collapsed variants """ graph_genes = set(get_nodes_by_function(graph, GENE)) return len(graph_genes...
def neurommsig_hubs(graph: BELGraph, genes: List[Gene], top_percent: Optional[float] = None) -> float: """Calculate the percentage of target genes mappable to the graph. Assume: graph central dogma inferred, collapsed to genes, collapsed variants, graph has more than 20 nodes :param graph: A BEL g...
def neurommsig_topology(graph: BELGraph, nodes: List[BaseEntity]) -> float: """Calculate the node neighbor score for a given list of nodes. - Doesn't consider self loops .. math:: \frac{\sum_i^n N_G[i]}{n*(n-1)} """ nodes = list(nodes) number_nodes = len(nodes) if n...
def bond_run(perc_graph_result, seed, ps, convolution_factors_tasks): """ Perform a single run (realization) over all microstates and return the canonical cluster statistics """ microcanonical_statistics = percolate.hpc.bond_microcanonical_statistics( seed=seed, **perc_graph_result ) ...
def bond_task( perc_graph_result, seeds, ps, convolution_factors_tasks_iterator ): """ Perform a number of runs The number of runs is the number of seeds convolution_factors_tasks_iterator needs to be an iterator We shield the convolution factors tasks from jug value/result mechanism by s...
def get_leaves_by_type(graph, func=None, prune_threshold=1): """Returns an iterable over all nodes in graph (in-place) with only a connection to one node. Useful for gene and RNA. Allows for optional filter by function type. :param pybel.BELGraph graph: A BEL graph :param func: If set, filters by the ...
def get_peripheral_successor_edges(graph: BELGraph, subgraph: BELGraph) -> EdgeIterator: """Get the set of possible successor edges peripheral to the sub-graph. The source nodes in this iterable are all inside the sub-graph, while the targets are outside. """ for u in subgraph: for _, v, k in g...
def get_peripheral_predecessor_edges(graph: BELGraph, subgraph: BELGraph) -> EdgeIterator: """Get the set of possible predecessor edges peripheral to the sub-graph. The target nodes in this iterable are all inside the sub-graph, while the sources are outside. """ for v in subgraph: for u, _, k ...
def count_sources(edge_iter: EdgeIterator) -> Counter: """Count the source nodes in an edge iterator with keys and data. :return: A counter of source nodes in the iterable """ return Counter(u for u, _, _ in edge_iter)
def count_targets(edge_iter: EdgeIterator) -> Counter: """Count the target nodes in an edge iterator with keys and data. :return: A counter of target nodes in the iterable """ return Counter(v for _, v, _ in edge_iter)
def get_subgraph_edges(graph: BELGraph, annotation: str, value: str, source_filter=None, target_filter=None, ): """Gets all edges from a given subgraph whose source and target nodes pass all of the giv...
def get_subgraph_peripheral_nodes(graph: BELGraph, subgraph: Iterable[BaseEntity], node_predicates: NodePredicates = None, edge_predicates: EdgePredicates = None, ): """Get a summa...