repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1 value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
pybel/pybel | src/pybel/struct/filters/node_filters.py | invert_node_predicate | def invert_node_predicate(node_predicate: NodePredicate) -> NodePredicate: # noqa: D202
"""Build a node predicate that is the inverse of the given node predicate."""
def inverse_predicate(graph: BELGraph, node: BaseEntity) -> bool:
"""Return the inverse of the enclosed node predicate applied to the graph and node."""
return not node_predicate(graph, node)
return inverse_predicate | python | def invert_node_predicate(node_predicate: NodePredicate) -> NodePredicate: # noqa: D202
"""Build a node predicate that is the inverse of the given node predicate."""
def inverse_predicate(graph: BELGraph, node: BaseEntity) -> bool:
"""Return the inverse of the enclosed node predicate applied to the graph and node."""
return not node_predicate(graph, node)
return inverse_predicate | [
"def",
"invert_node_predicate",
"(",
"node_predicate",
":",
"NodePredicate",
")",
"->",
"NodePredicate",
":",
"# noqa: D202",
"def",
"inverse_predicate",
"(",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"bool",
":",
"\"\"\"Return the inverse... | Build a node predicate that is the inverse of the given node predicate. | [
"Build",
"a",
"node",
"predicate",
"that",
"is",
"the",
"inverse",
"of",
"the",
"given",
"node",
"predicate",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_filters.py#L29-L36 | train | 29,500 |
pybel/pybel | src/pybel/struct/filters/node_filters.py | concatenate_node_predicates | def concatenate_node_predicates(node_predicates: NodePredicates) -> NodePredicate:
"""Concatenate multiple node predicates to a new predicate that requires all predicates to be met.
Example usage:
>>> from pybel.dsl import protein, gene
>>> from pybel.struct.filters.node_predicates import not_pathology, node_exclusion_predicate_builder
>>> app_protein = protein(name='APP', namespace='HGNC')
>>> app_gene = gene(name='APP', namespace='HGNC')
>>> app_predicate = node_exclusion_predicate_builder([app_protein, app_gene])
>>> my_predicate = concatenate_node_predicates([not_pathology, app_predicate])
"""
# If a predicate outside a list is given, just return it
if not isinstance(node_predicates, Iterable):
return node_predicates
node_predicates = tuple(node_predicates)
# If only one predicate is given, don't bother wrapping it
if 1 == len(node_predicates):
return node_predicates[0]
def concatenated_node_predicate(graph: BELGraph, node: BaseEntity) -> bool:
"""Pass only for a nodes that pass all enclosed predicates."""
return all(
node_predicate(graph, node)
for node_predicate in node_predicates
)
return concatenated_node_predicate | python | def concatenate_node_predicates(node_predicates: NodePredicates) -> NodePredicate:
"""Concatenate multiple node predicates to a new predicate that requires all predicates to be met.
Example usage:
>>> from pybel.dsl import protein, gene
>>> from pybel.struct.filters.node_predicates import not_pathology, node_exclusion_predicate_builder
>>> app_protein = protein(name='APP', namespace='HGNC')
>>> app_gene = gene(name='APP', namespace='HGNC')
>>> app_predicate = node_exclusion_predicate_builder([app_protein, app_gene])
>>> my_predicate = concatenate_node_predicates([not_pathology, app_predicate])
"""
# If a predicate outside a list is given, just return it
if not isinstance(node_predicates, Iterable):
return node_predicates
node_predicates = tuple(node_predicates)
# If only one predicate is given, don't bother wrapping it
if 1 == len(node_predicates):
return node_predicates[0]
def concatenated_node_predicate(graph: BELGraph, node: BaseEntity) -> bool:
"""Pass only for a nodes that pass all enclosed predicates."""
return all(
node_predicate(graph, node)
for node_predicate in node_predicates
)
return concatenated_node_predicate | [
"def",
"concatenate_node_predicates",
"(",
"node_predicates",
":",
"NodePredicates",
")",
"->",
"NodePredicate",
":",
"# If a predicate outside a list is given, just return it",
"if",
"not",
"isinstance",
"(",
"node_predicates",
",",
"Iterable",
")",
":",
"return",
"node_pr... | Concatenate multiple node predicates to a new predicate that requires all predicates to be met.
Example usage:
>>> from pybel.dsl import protein, gene
>>> from pybel.struct.filters.node_predicates import not_pathology, node_exclusion_predicate_builder
>>> app_protein = protein(name='APP', namespace='HGNC')
>>> app_gene = gene(name='APP', namespace='HGNC')
>>> app_predicate = node_exclusion_predicate_builder([app_protein, app_gene])
>>> my_predicate = concatenate_node_predicates([not_pathology, app_predicate]) | [
"Concatenate",
"multiple",
"node",
"predicates",
"to",
"a",
"new",
"predicate",
"that",
"requires",
"all",
"predicates",
"to",
"be",
"met",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_filters.py#L39-L68 | train | 29,501 |
pybel/pybel | src/pybel/struct/filters/node_filters.py | filter_nodes | def filter_nodes(graph: BELGraph, node_predicates: NodePredicates) -> Iterable[BaseEntity]:
"""Apply a set of predicates to the nodes iterator of a BEL graph."""
concatenated_predicate = concatenate_node_predicates(node_predicates=node_predicates)
for node in graph:
if concatenated_predicate(graph, node):
yield node | python | def filter_nodes(graph: BELGraph, node_predicates: NodePredicates) -> Iterable[BaseEntity]:
"""Apply a set of predicates to the nodes iterator of a BEL graph."""
concatenated_predicate = concatenate_node_predicates(node_predicates=node_predicates)
for node in graph:
if concatenated_predicate(graph, node):
yield node | [
"def",
"filter_nodes",
"(",
"graph",
":",
"BELGraph",
",",
"node_predicates",
":",
"NodePredicates",
")",
"->",
"Iterable",
"[",
"BaseEntity",
"]",
":",
"concatenated_predicate",
"=",
"concatenate_node_predicates",
"(",
"node_predicates",
"=",
"node_predicates",
")",
... | Apply a set of predicates to the nodes iterator of a BEL graph. | [
"Apply",
"a",
"set",
"of",
"predicates",
"to",
"the",
"nodes",
"iterator",
"of",
"a",
"BEL",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_filters.py#L71-L76 | train | 29,502 |
pybel/pybel | src/pybel/struct/filters/node_filters.py | get_nodes | def get_nodes(graph: BELGraph, node_predicates: NodePredicates) -> Set[BaseEntity]:
"""Get the set of all nodes that pass the predicates."""
return set(filter_nodes(graph, node_predicates=node_predicates)) | python | def get_nodes(graph: BELGraph, node_predicates: NodePredicates) -> Set[BaseEntity]:
"""Get the set of all nodes that pass the predicates."""
return set(filter_nodes(graph, node_predicates=node_predicates)) | [
"def",
"get_nodes",
"(",
"graph",
":",
"BELGraph",
",",
"node_predicates",
":",
"NodePredicates",
")",
"->",
"Set",
"[",
"BaseEntity",
"]",
":",
"return",
"set",
"(",
"filter_nodes",
"(",
"graph",
",",
"node_predicates",
"=",
"node_predicates",
")",
")"
] | Get the set of all nodes that pass the predicates. | [
"Get",
"the",
"set",
"of",
"all",
"nodes",
"that",
"pass",
"the",
"predicates",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_filters.py#L79-L81 | train | 29,503 |
pybel/pybel | src/pybel/struct/filters/node_filters.py | count_passed_node_filter | def count_passed_node_filter(graph: BELGraph, node_predicates: NodePredicates) -> int:
"""Count how many nodes pass a given set of node predicates."""
return sum(1 for _ in filter_nodes(graph, node_predicates=node_predicates)) | python | def count_passed_node_filter(graph: BELGraph, node_predicates: NodePredicates) -> int:
"""Count how many nodes pass a given set of node predicates."""
return sum(1 for _ in filter_nodes(graph, node_predicates=node_predicates)) | [
"def",
"count_passed_node_filter",
"(",
"graph",
":",
"BELGraph",
",",
"node_predicates",
":",
"NodePredicates",
")",
"->",
"int",
":",
"return",
"sum",
"(",
"1",
"for",
"_",
"in",
"filter_nodes",
"(",
"graph",
",",
"node_predicates",
"=",
"node_predicates",
"... | Count how many nodes pass a given set of node predicates. | [
"Count",
"how",
"many",
"nodes",
"pass",
"a",
"given",
"set",
"of",
"node",
"predicates",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_filters.py#L84-L86 | train | 29,504 |
pybel/pybel | src/pybel/struct/mutation/deletion/protein_rna_origins.py | get_gene_leaves | def get_gene_leaves(graph) -> Iterable[BaseEntity]:
"""Iterate over all genes who have only one connection, that's a transcription to its RNA.
:param pybel.BELGraph graph: A BEL graph
"""
for node in get_nodes_by_function(graph, GENE):
if graph.in_degree(node) != 0:
continue
if graph.out_degree(node) != 1:
continue
_, _, d = list(graph.out_edges(node, data=True))[0]
if d[RELATION] == TRANSCRIBED_TO:
yield node | python | def get_gene_leaves(graph) -> Iterable[BaseEntity]:
"""Iterate over all genes who have only one connection, that's a transcription to its RNA.
:param pybel.BELGraph graph: A BEL graph
"""
for node in get_nodes_by_function(graph, GENE):
if graph.in_degree(node) != 0:
continue
if graph.out_degree(node) != 1:
continue
_, _, d = list(graph.out_edges(node, data=True))[0]
if d[RELATION] == TRANSCRIBED_TO:
yield node | [
"def",
"get_gene_leaves",
"(",
"graph",
")",
"->",
"Iterable",
"[",
"BaseEntity",
"]",
":",
"for",
"node",
"in",
"get_nodes_by_function",
"(",
"graph",
",",
"GENE",
")",
":",
"if",
"graph",
".",
"in_degree",
"(",
"node",
")",
"!=",
"0",
":",
"continue",
... | Iterate over all genes who have only one connection, that's a transcription to its RNA.
:param pybel.BELGraph graph: A BEL graph | [
"Iterate",
"over",
"all",
"genes",
"who",
"have",
"only",
"one",
"connection",
"that",
"s",
"a",
"transcription",
"to",
"its",
"RNA",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/deletion/protein_rna_origins.py#L17-L32 | train | 29,505 |
pybel/pybel | src/pybel/struct/mutation/deletion/protein_rna_origins.py | get_rna_leaves | def get_rna_leaves(graph) -> Iterable[BaseEntity]:
"""Iterate over all RNAs who have only one connection, that's a translation to its protein.
:param pybel.BELGraph graph: A BEL graph
"""
for node in get_nodes_by_function(graph, RNA):
if graph.in_degree(node) != 0:
continue
if graph.out_degree(node) != 1:
continue
_, _, d = list(graph.out_edges(node, data=True))[0]
if d[RELATION] == TRANSLATED_TO:
yield node | python | def get_rna_leaves(graph) -> Iterable[BaseEntity]:
"""Iterate over all RNAs who have only one connection, that's a translation to its protein.
:param pybel.BELGraph graph: A BEL graph
"""
for node in get_nodes_by_function(graph, RNA):
if graph.in_degree(node) != 0:
continue
if graph.out_degree(node) != 1:
continue
_, _, d = list(graph.out_edges(node, data=True))[0]
if d[RELATION] == TRANSLATED_TO:
yield node | [
"def",
"get_rna_leaves",
"(",
"graph",
")",
"->",
"Iterable",
"[",
"BaseEntity",
"]",
":",
"for",
"node",
"in",
"get_nodes_by_function",
"(",
"graph",
",",
"RNA",
")",
":",
"if",
"graph",
".",
"in_degree",
"(",
"node",
")",
"!=",
"0",
":",
"continue",
... | Iterate over all RNAs who have only one connection, that's a translation to its protein.
:param pybel.BELGraph graph: A BEL graph | [
"Iterate",
"over",
"all",
"RNAs",
"who",
"have",
"only",
"one",
"connection",
"that",
"s",
"a",
"translation",
"to",
"its",
"protein",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/deletion/protein_rna_origins.py#L35-L50 | train | 29,506 |
pybel/pybel | src/pybel/dsl/node_classes.py | _entity_list_as_bel | def _entity_list_as_bel(entities: Iterable[BaseEntity]) -> str:
"""Stringify a list of BEL entities."""
return ', '.join(
e.as_bel()
for e in entities
) | python | def _entity_list_as_bel(entities: Iterable[BaseEntity]) -> str:
"""Stringify a list of BEL entities."""
return ', '.join(
e.as_bel()
for e in entities
) | [
"def",
"_entity_list_as_bel",
"(",
"entities",
":",
"Iterable",
"[",
"BaseEntity",
"]",
")",
"->",
"str",
":",
"return",
"', '",
".",
"join",
"(",
"e",
".",
"as_bel",
"(",
")",
"for",
"e",
"in",
"entities",
")"
] | Stringify a list of BEL entities. | [
"Stringify",
"a",
"list",
"of",
"BEL",
"entities",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/node_classes.py#L629-L634 | train | 29,507 |
pybel/pybel | src/pybel/dsl/node_classes.py | CentralDogma.get_parent | def get_parent(self) -> Optional['CentralDogma']:
"""Get the parent, or none if it's already a reference node.
:rtype: Optional[CentralDogma]
Example usage:
>>> ab42 = Protein(name='APP', namespace='HGNC', variants=[Fragment(start=672, stop=713)])
>>> app = ab42.get_parent()
>>> assert 'p(HGNC:APP)' == app.as_bel()
"""
if VARIANTS not in self:
return
return self.__class__(namespace=self.namespace, name=self.name, identifier=self.identifier) | python | def get_parent(self) -> Optional['CentralDogma']:
"""Get the parent, or none if it's already a reference node.
:rtype: Optional[CentralDogma]
Example usage:
>>> ab42 = Protein(name='APP', namespace='HGNC', variants=[Fragment(start=672, stop=713)])
>>> app = ab42.get_parent()
>>> assert 'p(HGNC:APP)' == app.as_bel()
"""
if VARIANTS not in self:
return
return self.__class__(namespace=self.namespace, name=self.name, identifier=self.identifier) | [
"def",
"get_parent",
"(",
"self",
")",
"->",
"Optional",
"[",
"'CentralDogma'",
"]",
":",
"if",
"VARIANTS",
"not",
"in",
"self",
":",
"return",
"return",
"self",
".",
"__class__",
"(",
"namespace",
"=",
"self",
".",
"namespace",
",",
"name",
"=",
"self",... | Get the parent, or none if it's already a reference node.
:rtype: Optional[CentralDogma]
Example usage:
>>> ab42 = Protein(name='APP', namespace='HGNC', variants=[Fragment(start=672, stop=713)])
>>> app = ab42.get_parent()
>>> assert 'p(HGNC:APP)' == app.as_bel() | [
"Get",
"the",
"parent",
"or",
"none",
"if",
"it",
"s",
"already",
"a",
"reference",
"node",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/node_classes.py#L258-L272 | train | 29,508 |
pybel/pybel | src/pybel/dsl/node_classes.py | CentralDogma.with_variants | def with_variants(self, variants: Union['Variant', List['Variant']]) -> 'CentralDogma':
"""Create a new entity with the given variants.
:param variants: An optional variant or list of variants
Example Usage:
>>> app = Protein(name='APP', namespace='HGNC')
>>> ab42 = app.with_variants([Fragment(start=672, stop=713)])
>>> assert 'p(HGNC:APP, frag(672_713))' == ab42.as_bel()
"""
return self.__class__(
namespace=self.namespace,
name=self.name,
identifier=self.identifier,
variants=variants,
) | python | def with_variants(self, variants: Union['Variant', List['Variant']]) -> 'CentralDogma':
"""Create a new entity with the given variants.
:param variants: An optional variant or list of variants
Example Usage:
>>> app = Protein(name='APP', namespace='HGNC')
>>> ab42 = app.with_variants([Fragment(start=672, stop=713)])
>>> assert 'p(HGNC:APP, frag(672_713))' == ab42.as_bel()
"""
return self.__class__(
namespace=self.namespace,
name=self.name,
identifier=self.identifier,
variants=variants,
) | [
"def",
"with_variants",
"(",
"self",
",",
"variants",
":",
"Union",
"[",
"'Variant'",
",",
"List",
"[",
"'Variant'",
"]",
"]",
")",
"->",
"'CentralDogma'",
":",
"return",
"self",
".",
"__class__",
"(",
"namespace",
"=",
"self",
".",
"namespace",
",",
"na... | Create a new entity with the given variants.
:param variants: An optional variant or list of variants
Example Usage:
>>> app = Protein(name='APP', namespace='HGNC')
>>> ab42 = app.with_variants([Fragment(start=672, stop=713)])
>>> assert 'p(HGNC:APP, frag(672_713))' == ab42.as_bel() | [
"Create",
"a",
"new",
"entity",
"with",
"the",
"given",
"variants",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/node_classes.py#L274-L290 | train | 29,509 |
pybel/pybel | src/pybel/dsl/node_classes.py | ProteinModification.as_bel | def as_bel(self) -> str:
"""Return this protein modification variant as a BEL string."""
return 'pmod({}{})'.format(
str(self[IDENTIFIER]),
''.join(', {}'.format(self[x]) for x in PMOD_ORDER[2:] if x in self)
) | python | def as_bel(self) -> str:
"""Return this protein modification variant as a BEL string."""
return 'pmod({}{})'.format(
str(self[IDENTIFIER]),
''.join(', {}'.format(self[x]) for x in PMOD_ORDER[2:] if x in self)
) | [
"def",
"as_bel",
"(",
"self",
")",
"->",
"str",
":",
"return",
"'pmod({}{})'",
".",
"format",
"(",
"str",
"(",
"self",
"[",
"IDENTIFIER",
"]",
")",
",",
"''",
".",
"join",
"(",
"', {}'",
".",
"format",
"(",
"self",
"[",
"x",
"]",
")",
"for",
"x",... | Return this protein modification variant as a BEL string. | [
"Return",
"this",
"protein",
"modification",
"variant",
"as",
"a",
"BEL",
"string",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/node_classes.py#L359-L364 | train | 29,510 |
pybel/pybel | src/pybel/dsl/node_classes.py | Fragment.range | def range(self) -> str:
"""Get the range of this fragment."""
if FRAGMENT_MISSING in self:
return '?'
return '{}_{}'.format(self[FRAGMENT_START], self[FRAGMENT_STOP]) | python | def range(self) -> str:
"""Get the range of this fragment."""
if FRAGMENT_MISSING in self:
return '?'
return '{}_{}'.format(self[FRAGMENT_START], self[FRAGMENT_STOP]) | [
"def",
"range",
"(",
"self",
")",
"->",
"str",
":",
"if",
"FRAGMENT_MISSING",
"in",
"self",
":",
"return",
"'?'",
"return",
"'{}_{}'",
".",
"format",
"(",
"self",
"[",
"FRAGMENT_START",
"]",
",",
"self",
"[",
"FRAGMENT_STOP",
"]",
")"
] | Get the range of this fragment. | [
"Get",
"the",
"range",
"of",
"this",
"fragment",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/node_classes.py#L485-L490 | train | 29,511 |
pybel/pybel | src/pybel/dsl/node_classes.py | Fragment.as_bel | def as_bel(self) -> str:
"""Return this fragment variant as a BEL string."""
res = '"{}"'.format(self.range)
if FRAGMENT_DESCRIPTION in self:
res += ', "{}"'.format(self[FRAGMENT_DESCRIPTION])
return 'frag({})'.format(res) | python | def as_bel(self) -> str:
"""Return this fragment variant as a BEL string."""
res = '"{}"'.format(self.range)
if FRAGMENT_DESCRIPTION in self:
res += ', "{}"'.format(self[FRAGMENT_DESCRIPTION])
return 'frag({})'.format(res) | [
"def",
"as_bel",
"(",
"self",
")",
"->",
"str",
":",
"res",
"=",
"'\"{}\"'",
".",
"format",
"(",
"self",
".",
"range",
")",
"if",
"FRAGMENT_DESCRIPTION",
"in",
"self",
":",
"res",
"+=",
"', \"{}\"'",
".",
"format",
"(",
"self",
"[",
"FRAGMENT_DESCRIPTION... | Return this fragment variant as a BEL string. | [
"Return",
"this",
"fragment",
"variant",
"as",
"a",
"BEL",
"string",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/node_classes.py#L492-L499 | train | 29,512 |
pybel/pybel | src/pybel/dsl/node_classes.py | _Transcribable.get_gene | def get_gene(self) -> Gene:
"""Get the corresponding gene or raise an exception if it's not the reference node.
:raises: InferCentralDogmaException
"""
if self.variants:
raise InferCentralDogmaException('can not get gene for variant')
return Gene(
namespace=self.namespace,
name=self.name,
identifier=self.identifier
) | python | def get_gene(self) -> Gene:
"""Get the corresponding gene or raise an exception if it's not the reference node.
:raises: InferCentralDogmaException
"""
if self.variants:
raise InferCentralDogmaException('can not get gene for variant')
return Gene(
namespace=self.namespace,
name=self.name,
identifier=self.identifier
) | [
"def",
"get_gene",
"(",
"self",
")",
"->",
"Gene",
":",
"if",
"self",
".",
"variants",
":",
"raise",
"InferCentralDogmaException",
"(",
"'can not get gene for variant'",
")",
"return",
"Gene",
"(",
"namespace",
"=",
"self",
".",
"namespace",
",",
"name",
"=",
... | Get the corresponding gene or raise an exception if it's not the reference node.
:raises: InferCentralDogmaException | [
"Get",
"the",
"corresponding",
"gene",
"or",
"raise",
"an",
"exception",
"if",
"it",
"s",
"not",
"the",
"reference",
"node",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/node_classes.py#L520-L532 | train | 29,513 |
pybel/pybel | src/pybel/dsl/node_classes.py | Protein.get_rna | def get_rna(self) -> Rna:
"""Get the corresponding RNA or raise an exception if it's not the reference node.
:raises: InferCentralDogmaException
"""
if self.variants:
raise InferCentralDogmaException('can not get rna for variant')
return Rna(
namespace=self.namespace,
name=self.name,
identifier=self.identifier
) | python | def get_rna(self) -> Rna:
"""Get the corresponding RNA or raise an exception if it's not the reference node.
:raises: InferCentralDogmaException
"""
if self.variants:
raise InferCentralDogmaException('can not get rna for variant')
return Rna(
namespace=self.namespace,
name=self.name,
identifier=self.identifier
) | [
"def",
"get_rna",
"(",
"self",
")",
"->",
"Rna",
":",
"if",
"self",
".",
"variants",
":",
"raise",
"InferCentralDogmaException",
"(",
"'can not get rna for variant'",
")",
"return",
"Rna",
"(",
"namespace",
"=",
"self",
".",
"namespace",
",",
"name",
"=",
"s... | Get the corresponding RNA or raise an exception if it's not the reference node.
:raises: InferCentralDogmaException | [
"Get",
"the",
"corresponding",
"RNA",
"or",
"raise",
"an",
"exception",
"if",
"it",
"s",
"not",
"the",
"reference",
"node",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/node_classes.py#L614-L626 | train | 29,514 |
pybel/pybel | src/pybel/dsl/node_classes.py | EnumeratedFusionRange.as_bel | def as_bel(self) -> str:
"""Return this fusion range as a BEL string."""
return '{reference}.{start}_{stop}'.format(
reference=self[FUSION_REFERENCE],
start=self[FUSION_START],
stop=self[FUSION_STOP],
) | python | def as_bel(self) -> str:
"""Return this fusion range as a BEL string."""
return '{reference}.{start}_{stop}'.format(
reference=self[FUSION_REFERENCE],
start=self[FUSION_START],
stop=self[FUSION_STOP],
) | [
"def",
"as_bel",
"(",
"self",
")",
"->",
"str",
":",
"return",
"'{reference}.{start}_{stop}'",
".",
"format",
"(",
"reference",
"=",
"self",
"[",
"FUSION_REFERENCE",
"]",
",",
"start",
"=",
"self",
"[",
"FUSION_START",
"]",
",",
"stop",
"=",
"self",
"[",
... | Return this fusion range as a BEL string. | [
"Return",
"this",
"fusion",
"range",
"as",
"a",
"BEL",
"string",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/node_classes.py#L836-L842 | train | 29,515 |
pybel/pybel | src/pybel/dsl/node_classes.py | FusionBase.as_bel | def as_bel(self) -> str:
"""Return this fusion as a BEL string."""
return '{}(fus({}:{}, "{}", {}:{}, "{}"))'.format(
self._func,
self.partner_5p.namespace,
self.partner_5p._priority_id,
self.range_5p.as_bel(),
self.partner_3p.namespace,
self.partner_3p._priority_id,
self.range_3p.as_bel(),
) | python | def as_bel(self) -> str:
"""Return this fusion as a BEL string."""
return '{}(fus({}:{}, "{}", {}:{}, "{}"))'.format(
self._func,
self.partner_5p.namespace,
self.partner_5p._priority_id,
self.range_5p.as_bel(),
self.partner_3p.namespace,
self.partner_3p._priority_id,
self.range_3p.as_bel(),
) | [
"def",
"as_bel",
"(",
"self",
")",
"->",
"str",
":",
"return",
"'{}(fus({}:{}, \"{}\", {}:{}, \"{}\"))'",
".",
"format",
"(",
"self",
".",
"_func",
",",
"self",
".",
"partner_5p",
".",
"namespace",
",",
"self",
".",
"partner_5p",
".",
"_priority_id",
",",
"s... | Return this fusion as a BEL string. | [
"Return",
"this",
"fusion",
"as",
"a",
"BEL",
"string",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/node_classes.py#L891-L901 | train | 29,516 |
pybel/pybel | src/pybel/struct/summary/edge_summary.py | iter_annotation_values | def iter_annotation_values(graph, annotation: str) -> Iterable[str]:
"""Iterate over all of the values for an annotation used in the graph.
:param pybel.BELGraph graph: A BEL graph
:param str annotation: The annotation to grab
"""
return (
value
for _, _, data in graph.edges(data=True)
if edge_has_annotation(data, annotation)
for value in data[ANNOTATIONS][annotation]
) | python | def iter_annotation_values(graph, annotation: str) -> Iterable[str]:
"""Iterate over all of the values for an annotation used in the graph.
:param pybel.BELGraph graph: A BEL graph
:param str annotation: The annotation to grab
"""
return (
value
for _, _, data in graph.edges(data=True)
if edge_has_annotation(data, annotation)
for value in data[ANNOTATIONS][annotation]
) | [
"def",
"iter_annotation_values",
"(",
"graph",
",",
"annotation",
":",
"str",
")",
"->",
"Iterable",
"[",
"str",
"]",
":",
"return",
"(",
"value",
"for",
"_",
",",
"_",
",",
"data",
"in",
"graph",
".",
"edges",
"(",
"data",
"=",
"True",
")",
"if",
... | Iterate over all of the values for an annotation used in the graph.
:param pybel.BELGraph graph: A BEL graph
:param str annotation: The annotation to grab | [
"Iterate",
"over",
"all",
"of",
"the",
"values",
"for",
"an",
"annotation",
"used",
"in",
"the",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/edge_summary.py#L38-L49 | train | 29,517 |
pybel/pybel | src/pybel/struct/summary/edge_summary.py | _group_dict_set | def _group_dict_set(iterator):
"""Make a dict that accumulates the values for each key in an iterator of doubles.
:param iter[tuple[A,B]] iterator: An iterator
:rtype: dict[A,set[B]]
"""
d = defaultdict(set)
for key, value in iterator:
d[key].add(value)
return dict(d) | python | def _group_dict_set(iterator):
"""Make a dict that accumulates the values for each key in an iterator of doubles.
:param iter[tuple[A,B]] iterator: An iterator
:rtype: dict[A,set[B]]
"""
d = defaultdict(set)
for key, value in iterator:
d[key].add(value)
return dict(d) | [
"def",
"_group_dict_set",
"(",
"iterator",
")",
":",
"d",
"=",
"defaultdict",
"(",
"set",
")",
"for",
"key",
",",
"value",
"in",
"iterator",
":",
"d",
"[",
"key",
"]",
".",
"add",
"(",
"value",
")",
"return",
"dict",
"(",
"d",
")"
] | Make a dict that accumulates the values for each key in an iterator of doubles.
:param iter[tuple[A,B]] iterator: An iterator
:rtype: dict[A,set[B]] | [
"Make",
"a",
"dict",
"that",
"accumulates",
"the",
"values",
"for",
"each",
"key",
"in",
"an",
"iterator",
"of",
"doubles",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/edge_summary.py#L52-L61 | train | 29,518 |
pybel/pybel | src/pybel/struct/summary/edge_summary.py | get_annotation_values | def get_annotation_values(graph, annotation: str) -> Set[str]:
"""Get all values for the given annotation.
:param pybel.BELGraph graph: A BEL graph
:param annotation: The annotation to summarize
:return: A set of all annotation values
"""
return set(iter_annotation_values(graph, annotation)) | python | def get_annotation_values(graph, annotation: str) -> Set[str]:
"""Get all values for the given annotation.
:param pybel.BELGraph graph: A BEL graph
:param annotation: The annotation to summarize
:return: A set of all annotation values
"""
return set(iter_annotation_values(graph, annotation)) | [
"def",
"get_annotation_values",
"(",
"graph",
",",
"annotation",
":",
"str",
")",
"->",
"Set",
"[",
"str",
"]",
":",
"return",
"set",
"(",
"iter_annotation_values",
"(",
"graph",
",",
"annotation",
")",
")"
] | Get all values for the given annotation.
:param pybel.BELGraph graph: A BEL graph
:param annotation: The annotation to summarize
:return: A set of all annotation values | [
"Get",
"all",
"values",
"for",
"the",
"given",
"annotation",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/edge_summary.py#L73-L80 | train | 29,519 |
pybel/pybel | src/pybel/struct/summary/edge_summary.py | count_relations | def count_relations(graph) -> Counter:
"""Return a histogram over all relationships in a graph.
:param pybel.BELGraph graph: A BEL graph
:return: A Counter from {relation type: frequency}
"""
return Counter(
data[RELATION]
for _, _, data in graph.edges(data=True)
) | python | def count_relations(graph) -> Counter:
"""Return a histogram over all relationships in a graph.
:param pybel.BELGraph graph: A BEL graph
:return: A Counter from {relation type: frequency}
"""
return Counter(
data[RELATION]
for _, _, data in graph.edges(data=True)
) | [
"def",
"count_relations",
"(",
"graph",
")",
"->",
"Counter",
":",
"return",
"Counter",
"(",
"data",
"[",
"RELATION",
"]",
"for",
"_",
",",
"_",
",",
"data",
"in",
"graph",
".",
"edges",
"(",
"data",
"=",
"True",
")",
")"
] | Return a histogram over all relationships in a graph.
:param pybel.BELGraph graph: A BEL graph
:return: A Counter from {relation type: frequency} | [
"Return",
"a",
"histogram",
"over",
"all",
"relationships",
"in",
"a",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/edge_summary.py#L83-L92 | train | 29,520 |
pybel/pybel | src/pybel/struct/summary/edge_summary.py | _annotation_iter_helper | def _annotation_iter_helper(graph) -> Iterable[str]:
"""Iterate over the annotation keys.
:param pybel.BELGraph graph: A BEL graph
"""
return (
key
for _, _, data in graph.edges(data=True)
if ANNOTATIONS in data
for key in data[ANNOTATIONS]
) | python | def _annotation_iter_helper(graph) -> Iterable[str]:
"""Iterate over the annotation keys.
:param pybel.BELGraph graph: A BEL graph
"""
return (
key
for _, _, data in graph.edges(data=True)
if ANNOTATIONS in data
for key in data[ANNOTATIONS]
) | [
"def",
"_annotation_iter_helper",
"(",
"graph",
")",
"->",
"Iterable",
"[",
"str",
"]",
":",
"return",
"(",
"key",
"for",
"_",
",",
"_",
",",
"data",
"in",
"graph",
".",
"edges",
"(",
"data",
"=",
"True",
")",
"if",
"ANNOTATIONS",
"in",
"data",
"for"... | Iterate over the annotation keys.
:param pybel.BELGraph graph: A BEL graph | [
"Iterate",
"over",
"the",
"annotation",
"keys",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/edge_summary.py#L122-L132 | train | 29,521 |
pybel/pybel | src/pybel/struct/summary/edge_summary.py | get_unused_list_annotation_values | def get_unused_list_annotation_values(graph) -> Mapping[str, Set[str]]:
"""Get all of the unused values for list annotations.
:param pybel.BELGraph graph: A BEL graph
:return: A dictionary of {str annotation: set of str values that aren't used}
"""
result = {}
for annotation, values in graph.annotation_list.items():
used_values = get_annotation_values(graph, annotation)
if len(used_values) == len(values): # all values have been used
continue
result[annotation] = set(values) - used_values
return result | python | def get_unused_list_annotation_values(graph) -> Mapping[str, Set[str]]:
"""Get all of the unused values for list annotations.
:param pybel.BELGraph graph: A BEL graph
:return: A dictionary of {str annotation: set of str values that aren't used}
"""
result = {}
for annotation, values in graph.annotation_list.items():
used_values = get_annotation_values(graph, annotation)
if len(used_values) == len(values): # all values have been used
continue
result[annotation] = set(values) - used_values
return result | [
"def",
"get_unused_list_annotation_values",
"(",
"graph",
")",
"->",
"Mapping",
"[",
"str",
",",
"Set",
"[",
"str",
"]",
"]",
":",
"result",
"=",
"{",
"}",
"for",
"annotation",
",",
"values",
"in",
"graph",
".",
"annotation_list",
".",
"items",
"(",
")",... | Get all of the unused values for list annotations.
:param pybel.BELGraph graph: A BEL graph
:return: A dictionary of {str annotation: set of str values that aren't used} | [
"Get",
"all",
"of",
"the",
"unused",
"values",
"for",
"list",
"annotations",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/edge_summary.py#L135-L147 | train | 29,522 |
pybel/pybel | src/pybel/io/lines.py | from_lines | def from_lines(lines: Iterable[str], **kwargs) -> BELGraph:
"""Load a BEL graph from an iterable over the lines of a BEL script.
:param lines: An iterable of strings (the lines in a BEL script)
The remaining keyword arguments are passed to :func:`pybel.io.line_utils.parse_lines`.
"""
graph = BELGraph()
parse_lines(graph=graph, lines=lines, **kwargs)
return graph | python | def from_lines(lines: Iterable[str], **kwargs) -> BELGraph:
"""Load a BEL graph from an iterable over the lines of a BEL script.
:param lines: An iterable of strings (the lines in a BEL script)
The remaining keyword arguments are passed to :func:`pybel.io.line_utils.parse_lines`.
"""
graph = BELGraph()
parse_lines(graph=graph, lines=lines, **kwargs)
return graph | [
"def",
"from_lines",
"(",
"lines",
":",
"Iterable",
"[",
"str",
"]",
",",
"*",
"*",
"kwargs",
")",
"->",
"BELGraph",
":",
"graph",
"=",
"BELGraph",
"(",
")",
"parse_lines",
"(",
"graph",
"=",
"graph",
",",
"lines",
"=",
"lines",
",",
"*",
"*",
"kwa... | Load a BEL graph from an iterable over the lines of a BEL script.
:param lines: An iterable of strings (the lines in a BEL script)
The remaining keyword arguments are passed to :func:`pybel.io.line_utils.parse_lines`. | [
"Load",
"a",
"BEL",
"graph",
"from",
"an",
"iterable",
"over",
"the",
"lines",
"of",
"a",
"BEL",
"script",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/lines.py#L23-L32 | train | 29,523 |
pybel/pybel | src/pybel/io/lines.py | from_url | def from_url(url: str, **kwargs) -> BELGraph:
"""Load a BEL graph from a URL resource.
:param url: A valid URL pointing to a BEL document
The remaining keyword arguments are passed to :func:`pybel.io.line_utils.parse_lines`.
"""
log.info('Loading from url: %s', url)
res = download(url)
lines = (line.decode('utf-8') for line in res.iter_lines())
graph = BELGraph(path=url)
parse_lines(graph=graph, lines=lines, **kwargs)
return graph | python | def from_url(url: str, **kwargs) -> BELGraph:
"""Load a BEL graph from a URL resource.
:param url: A valid URL pointing to a BEL document
The remaining keyword arguments are passed to :func:`pybel.io.line_utils.parse_lines`.
"""
log.info('Loading from url: %s', url)
res = download(url)
lines = (line.decode('utf-8') for line in res.iter_lines())
graph = BELGraph(path=url)
parse_lines(graph=graph, lines=lines, **kwargs)
return graph | [
"def",
"from_url",
"(",
"url",
":",
"str",
",",
"*",
"*",
"kwargs",
")",
"->",
"BELGraph",
":",
"log",
".",
"info",
"(",
"'Loading from url: %s'",
",",
"url",
")",
"res",
"=",
"download",
"(",
"url",
")",
"lines",
"=",
"(",
"line",
".",
"decode",
"... | Load a BEL graph from a URL resource.
:param url: A valid URL pointing to a BEL document
The remaining keyword arguments are passed to :func:`pybel.io.line_utils.parse_lines`. | [
"Load",
"a",
"BEL",
"graph",
"from",
"a",
"URL",
"resource",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/lines.py#L52-L65 | train | 29,524 |
pybel/pybel | src/pybel/struct/mutation/expansion/neighborhood.py | expand_node_predecessors | def expand_node_predecessors(universe, graph, node: BaseEntity) -> None:
"""Expand around the predecessors of the given node in the result graph.
:param pybel.BELGraph universe: The graph containing the stuff to add
:param pybel.BELGraph graph: The graph to add stuff to
:param node: A BEL node
"""
skip_successors = set()
for successor in universe.successors(node):
if successor in graph:
skip_successors.add(successor)
continue
graph.add_node(successor, **universe.nodes[successor])
graph.add_edges_from(
(source, successor, key, data)
for source, successor, key, data in universe.out_edges(node, data=True, keys=True)
if successor not in skip_successors
)
update_node_helper(universe, graph)
update_metadata(universe, graph) | python | def expand_node_predecessors(universe, graph, node: BaseEntity) -> None:
"""Expand around the predecessors of the given node in the result graph.
:param pybel.BELGraph universe: The graph containing the stuff to add
:param pybel.BELGraph graph: The graph to add stuff to
:param node: A BEL node
"""
skip_successors = set()
for successor in universe.successors(node):
if successor in graph:
skip_successors.add(successor)
continue
graph.add_node(successor, **universe.nodes[successor])
graph.add_edges_from(
(source, successor, key, data)
for source, successor, key, data in universe.out_edges(node, data=True, keys=True)
if successor not in skip_successors
)
update_node_helper(universe, graph)
update_metadata(universe, graph) | [
"def",
"expand_node_predecessors",
"(",
"universe",
",",
"graph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"None",
":",
"skip_successors",
"=",
"set",
"(",
")",
"for",
"successor",
"in",
"universe",
".",
"successors",
"(",
"node",
")",
":",
"if",
"succes... | Expand around the predecessors of the given node in the result graph.
:param pybel.BELGraph universe: The graph containing the stuff to add
:param pybel.BELGraph graph: The graph to add stuff to
:param node: A BEL node | [
"Expand",
"around",
"the",
"predecessors",
"of",
"the",
"given",
"node",
"in",
"the",
"result",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/expansion/neighborhood.py#L22-L44 | train | 29,525 |
pybel/pybel | src/pybel/struct/mutation/expansion/neighborhood.py | expand_node_successors | def expand_node_successors(universe, graph, node: BaseEntity) -> None:
"""Expand around the successors of the given node in the result graph.
:param pybel.BELGraph universe: The graph containing the stuff to add
:param pybel.BELGraph graph: The graph to add stuff to
:param node: A BEL node
"""
skip_predecessors = set()
for predecessor in universe.predecessors(node):
if predecessor in graph:
skip_predecessors.add(predecessor)
continue
graph.add_node(predecessor, **universe.nodes[predecessor])
graph.add_edges_from(
(predecessor, target, key, data)
for predecessor, target, key, data in universe.in_edges(node, data=True, keys=True)
if predecessor not in skip_predecessors
)
update_node_helper(universe, graph)
update_metadata(universe, graph) | python | def expand_node_successors(universe, graph, node: BaseEntity) -> None:
"""Expand around the successors of the given node in the result graph.
:param pybel.BELGraph universe: The graph containing the stuff to add
:param pybel.BELGraph graph: The graph to add stuff to
:param node: A BEL node
"""
skip_predecessors = set()
for predecessor in universe.predecessors(node):
if predecessor in graph:
skip_predecessors.add(predecessor)
continue
graph.add_node(predecessor, **universe.nodes[predecessor])
graph.add_edges_from(
(predecessor, target, key, data)
for predecessor, target, key, data in universe.in_edges(node, data=True, keys=True)
if predecessor not in skip_predecessors
)
update_node_helper(universe, graph)
update_metadata(universe, graph) | [
"def",
"expand_node_successors",
"(",
"universe",
",",
"graph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"None",
":",
"skip_predecessors",
"=",
"set",
"(",
")",
"for",
"predecessor",
"in",
"universe",
".",
"predecessors",
"(",
"node",
")",
":",
"if",
"pr... | Expand around the successors of the given node in the result graph.
:param pybel.BELGraph universe: The graph containing the stuff to add
:param pybel.BELGraph graph: The graph to add stuff to
:param node: A BEL node | [
"Expand",
"around",
"the",
"successors",
"of",
"the",
"given",
"node",
"in",
"the",
"result",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/expansion/neighborhood.py#L48-L70 | train | 29,526 |
pybel/pybel | src/pybel/struct/mutation/expansion/neighborhood.py | expand_all_node_neighborhoods | def expand_all_node_neighborhoods(universe, graph, filter_pathologies: bool = False) -> None:
"""Expand the neighborhoods of all nodes in the given graph.
:param pybel.BELGraph universe: The graph containing the stuff to add
:param pybel.BELGraph graph: The graph to add stuff to
:param filter_pathologies: Should expansion take place around pathologies?
"""
for node in list(graph):
if filter_pathologies and is_pathology(node):
continue
expand_node_neighborhood(universe, graph, node) | python | def expand_all_node_neighborhoods(universe, graph, filter_pathologies: bool = False) -> None:
"""Expand the neighborhoods of all nodes in the given graph.
:param pybel.BELGraph universe: The graph containing the stuff to add
:param pybel.BELGraph graph: The graph to add stuff to
:param filter_pathologies: Should expansion take place around pathologies?
"""
for node in list(graph):
if filter_pathologies and is_pathology(node):
continue
expand_node_neighborhood(universe, graph, node) | [
"def",
"expand_all_node_neighborhoods",
"(",
"universe",
",",
"graph",
",",
"filter_pathologies",
":",
"bool",
"=",
"False",
")",
"->",
"None",
":",
"for",
"node",
"in",
"list",
"(",
"graph",
")",
":",
"if",
"filter_pathologies",
"and",
"is_pathology",
"(",
... | Expand the neighborhoods of all nodes in the given graph.
:param pybel.BELGraph universe: The graph containing the stuff to add
:param pybel.BELGraph graph: The graph to add stuff to
:param filter_pathologies: Should expansion take place around pathologies? | [
"Expand",
"the",
"neighborhoods",
"of",
"all",
"nodes",
"in",
"the",
"given",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/expansion/neighborhood.py#L98-L109 | train | 29,527 |
pybel/pybel | src/pybel/io/line_utils.py | parse_lines | def parse_lines(graph: BELGraph,
lines: Iterable[str],
manager: Optional[Manager] = None,
allow_nested: bool = False,
citation_clearing: bool = True,
use_tqdm: bool = False,
tqdm_kwargs: Optional[Mapping[str, Any]] = None,
no_identifier_validation: bool = False,
disallow_unqualified_translocations: bool = False,
allow_redefinition: bool = False,
allow_definition_failures: bool = False,
allow_naked_names: bool = False,
required_annotations: Optional[List[str]] = None,
):
"""Parse an iterable of lines into this graph.
Delegates to :func:`parse_document`, :func:`parse_definitions`, and :func:`parse_statements`.
:param graph: A BEL graph
:param lines: An iterable over lines of BEL script
:param manager: A PyBEL database manager
:param allow_nested: If true, turns off nested statement failures
:param citation_clearing: Should :code:`SET Citation` statements clear evidence and all annotations?
Delegated to :class:`pybel.parser.ControlParser`
:param use_tqdm: Use :mod:`tqdm` to show a progress bar?
:param tqdm_kwargs: Keywords to pass to ``tqdm``
:param disallow_unqualified_translocations: If true, allow translocations without TO and FROM clauses.
:param required_annotations: Annotations that are required for all statements
.. warning::
These options allow concessions for parsing BEL that is either **WRONG** or **UNSCIENTIFIC**. Use them at
risk to reproducibility and validity of your results.
:param no_identifier_validation: If true, turns off namespace validation
:param allow_naked_names: If true, turns off naked namespace failures
:param allow_redefinition: If true, doesn't fail on second definition of same name or annotation
:param allow_definition_failures: If true, allows parsing to continue if a terminology file download/parse fails
"""
docs, definitions, statements = split_file_to_annotations_and_definitions(lines)
if manager is None:
manager = Manager()
metadata_parser = MetadataParser(
manager,
allow_redefinition=allow_redefinition,
skip_validation=no_identifier_validation,
)
parse_document(
graph,
docs,
metadata_parser,
)
parse_definitions(
graph,
definitions,
metadata_parser,
allow_failures=allow_definition_failures,
use_tqdm=use_tqdm,
tqdm_kwargs=tqdm_kwargs,
)
bel_parser = BELParser(
graph=graph,
# terminologies
namespace_to_term=metadata_parser.namespace_to_term,
namespace_to_pattern=metadata_parser.namespace_to_pattern,
annotation_to_term=metadata_parser.annotation_to_term,
annotation_to_pattern=metadata_parser.annotation_to_pattern,
annotation_to_local=metadata_parser.annotation_to_local,
# language settings
allow_nested=allow_nested,
citation_clearing=citation_clearing,
skip_validation=no_identifier_validation,
allow_naked_names=allow_naked_names,
disallow_unqualified_translocations=disallow_unqualified_translocations,
required_annotations=required_annotations,
)
parse_statements(
graph,
statements,
bel_parser,
use_tqdm=use_tqdm,
tqdm_kwargs=tqdm_kwargs,
)
log.info('Network has %d nodes and %d edges', graph.number_of_nodes(), graph.number_of_edges()) | python | def parse_lines(graph: BELGraph,
lines: Iterable[str],
manager: Optional[Manager] = None,
allow_nested: bool = False,
citation_clearing: bool = True,
use_tqdm: bool = False,
tqdm_kwargs: Optional[Mapping[str, Any]] = None,
no_identifier_validation: bool = False,
disallow_unqualified_translocations: bool = False,
allow_redefinition: bool = False,
allow_definition_failures: bool = False,
allow_naked_names: bool = False,
required_annotations: Optional[List[str]] = None,
):
"""Parse an iterable of lines into this graph.
Delegates to :func:`parse_document`, :func:`parse_definitions`, and :func:`parse_statements`.
:param graph: A BEL graph
:param lines: An iterable over lines of BEL script
:param manager: A PyBEL database manager
:param allow_nested: If true, turns off nested statement failures
:param citation_clearing: Should :code:`SET Citation` statements clear evidence and all annotations?
Delegated to :class:`pybel.parser.ControlParser`
:param use_tqdm: Use :mod:`tqdm` to show a progress bar?
:param tqdm_kwargs: Keywords to pass to ``tqdm``
:param disallow_unqualified_translocations: If true, allow translocations without TO and FROM clauses.
:param required_annotations: Annotations that are required for all statements
.. warning::
These options allow concessions for parsing BEL that is either **WRONG** or **UNSCIENTIFIC**. Use them at
risk to reproducibility and validity of your results.
:param no_identifier_validation: If true, turns off namespace validation
:param allow_naked_names: If true, turns off naked namespace failures
:param allow_redefinition: If true, doesn't fail on second definition of same name or annotation
:param allow_definition_failures: If true, allows parsing to continue if a terminology file download/parse fails
"""
docs, definitions, statements = split_file_to_annotations_and_definitions(lines)
if manager is None:
manager = Manager()
metadata_parser = MetadataParser(
manager,
allow_redefinition=allow_redefinition,
skip_validation=no_identifier_validation,
)
parse_document(
graph,
docs,
metadata_parser,
)
parse_definitions(
graph,
definitions,
metadata_parser,
allow_failures=allow_definition_failures,
use_tqdm=use_tqdm,
tqdm_kwargs=tqdm_kwargs,
)
bel_parser = BELParser(
graph=graph,
# terminologies
namespace_to_term=metadata_parser.namespace_to_term,
namespace_to_pattern=metadata_parser.namespace_to_pattern,
annotation_to_term=metadata_parser.annotation_to_term,
annotation_to_pattern=metadata_parser.annotation_to_pattern,
annotation_to_local=metadata_parser.annotation_to_local,
# language settings
allow_nested=allow_nested,
citation_clearing=citation_clearing,
skip_validation=no_identifier_validation,
allow_naked_names=allow_naked_names,
disallow_unqualified_translocations=disallow_unqualified_translocations,
required_annotations=required_annotations,
)
parse_statements(
graph,
statements,
bel_parser,
use_tqdm=use_tqdm,
tqdm_kwargs=tqdm_kwargs,
)
log.info('Network has %d nodes and %d edges', graph.number_of_nodes(), graph.number_of_edges()) | [
"def",
"parse_lines",
"(",
"graph",
":",
"BELGraph",
",",
"lines",
":",
"Iterable",
"[",
"str",
"]",
",",
"manager",
":",
"Optional",
"[",
"Manager",
"]",
"=",
"None",
",",
"allow_nested",
":",
"bool",
"=",
"False",
",",
"citation_clearing",
":",
"bool",... | Parse an iterable of lines into this graph.
Delegates to :func:`parse_document`, :func:`parse_definitions`, and :func:`parse_statements`.
:param graph: A BEL graph
:param lines: An iterable over lines of BEL script
:param manager: A PyBEL database manager
:param allow_nested: If true, turns off nested statement failures
:param citation_clearing: Should :code:`SET Citation` statements clear evidence and all annotations?
Delegated to :class:`pybel.parser.ControlParser`
:param use_tqdm: Use :mod:`tqdm` to show a progress bar?
:param tqdm_kwargs: Keywords to pass to ``tqdm``
:param disallow_unqualified_translocations: If true, allow translocations without TO and FROM clauses.
:param required_annotations: Annotations that are required for all statements
.. warning::
These options allow concessions for parsing BEL that is either **WRONG** or **UNSCIENTIFIC**. Use them at
risk to reproducibility and validity of your results.
:param no_identifier_validation: If true, turns off namespace validation
:param allow_naked_names: If true, turns off naked namespace failures
:param allow_redefinition: If true, doesn't fail on second definition of same name or annotation
:param allow_definition_failures: If true, allows parsing to continue if a terminology file download/parse fails | [
"Parse",
"an",
"iterable",
"of",
"lines",
"into",
"this",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/line_utils.py#L36-L126 | train | 29,528 |
pybel/pybel | src/pybel/io/line_utils.py | parse_document | def parse_document(graph: BELGraph,
enumerated_lines: Iterable[Tuple[int, str]],
metadata_parser: MetadataParser,
) -> None:
"""Parse the lines in the document section of a BEL script."""
parse_document_start_time = time.time()
for line_number, line in enumerated_lines:
try:
metadata_parser.parseString(line, line_number=line_number)
except VersionFormatWarning as exc:
_log_parse_exception(graph, exc)
graph.add_warning(exc)
except Exception as e:
exc = MalformedMetadataException(line_number, line, 0)
_log_parse_exception(graph, exc)
raise exc from e
for required in REQUIRED_METADATA:
required_metadatum = metadata_parser.document_metadata.get(required)
if required_metadatum is not None:
continue
required_metadatum_key = INVERSE_DOCUMENT_KEYS[required]
# This has to be insert since it needs to go on the front!
exc = MissingMetadataException.make(required_metadatum_key)
graph.warnings.insert(0, (None, exc, {}))
_log_parse_exception(graph, exc)
graph.document.update(metadata_parser.document_metadata)
log.info('Finished parsing document section in %.02f seconds', time.time() - parse_document_start_time) | python | def parse_document(graph: BELGraph,
enumerated_lines: Iterable[Tuple[int, str]],
metadata_parser: MetadataParser,
) -> None:
"""Parse the lines in the document section of a BEL script."""
parse_document_start_time = time.time()
for line_number, line in enumerated_lines:
try:
metadata_parser.parseString(line, line_number=line_number)
except VersionFormatWarning as exc:
_log_parse_exception(graph, exc)
graph.add_warning(exc)
except Exception as e:
exc = MalformedMetadataException(line_number, line, 0)
_log_parse_exception(graph, exc)
raise exc from e
for required in REQUIRED_METADATA:
required_metadatum = metadata_parser.document_metadata.get(required)
if required_metadatum is not None:
continue
required_metadatum_key = INVERSE_DOCUMENT_KEYS[required]
# This has to be insert since it needs to go on the front!
exc = MissingMetadataException.make(required_metadatum_key)
graph.warnings.insert(0, (None, exc, {}))
_log_parse_exception(graph, exc)
graph.document.update(metadata_parser.document_metadata)
log.info('Finished parsing document section in %.02f seconds', time.time() - parse_document_start_time) | [
"def",
"parse_document",
"(",
"graph",
":",
"BELGraph",
",",
"enumerated_lines",
":",
"Iterable",
"[",
"Tuple",
"[",
"int",
",",
"str",
"]",
"]",
",",
"metadata_parser",
":",
"MetadataParser",
",",
")",
"->",
"None",
":",
"parse_document_start_time",
"=",
"t... | Parse the lines in the document section of a BEL script. | [
"Parse",
"the",
"lines",
"in",
"the",
"document",
"section",
"of",
"a",
"BEL",
"script",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/line_utils.py#L129-L160 | train | 29,529 |
pybel/pybel | src/pybel/io/line_utils.py | parse_definitions | def parse_definitions(graph: BELGraph,
enumerated_lines: Iterable[Tuple[int, str]],
metadata_parser: MetadataParser,
allow_failures: bool = False,
use_tqdm: bool = False,
tqdm_kwargs: Optional[Mapping[str, Any]] = None,
) -> None:
"""Parse the lines in the definitions section of a BEL script.
:param graph: A BEL graph
:param enumerated_lines: An enumerated iterable over the lines in the definitions section of a BEL script
:param metadata_parser: A metadata parser
:param allow_failures: If true, allows parser to continue past strange failures
:param use_tqdm: Use :mod:`tqdm` to show a progress bar?
:param tqdm_kwargs: Keywords to pass to ``tqdm``
:raises: pybel.parser.parse_exceptions.InconsistentDefinitionError
:raises: pybel.resources.exc.ResourceError
:raises: sqlalchemy.exc.OperationalError
"""
parse_definitions_start_time = time.time()
if use_tqdm:
_tqdm_kwargs = dict(desc='Definitions', leave=False)
if tqdm_kwargs:
_tqdm_kwargs.update(tqdm_kwargs)
enumerated_lines = tqdm(list(enumerated_lines), **_tqdm_kwargs)
for line_number, line in enumerated_lines:
try:
metadata_parser.parseString(line, line_number=line_number)
except (InconsistentDefinitionError, ResourceError) as e:
parse_log.exception(LOG_FMT, line_number, 0, e.__class__.__name__, line)
raise e
except OperationalError as e:
parse_log.warning('Need to upgrade database. See '
'http://pybel.readthedocs.io/en/latest/installation.html#upgrading')
raise e
except Exception as e:
if not allow_failures:
exc = MalformedMetadataException(line_number, line, 0)
_log_parse_exception(graph, exc)
raise exc from e
graph.namespace_url.update(metadata_parser.namespace_url_dict)
graph.namespace_pattern.update({
keyword: pattern.pattern
for keyword, pattern in metadata_parser.namespace_to_pattern.items()
})
graph.annotation_url.update(metadata_parser.annotation_url_dict)
graph.annotation_pattern.update({
keyword: pattern.pattern
for keyword, pattern in metadata_parser.annotation_to_pattern.items()
})
graph.annotation_list.update(metadata_parser.annotation_to_local)
graph.uncached_namespaces.update(metadata_parser.uncachable_namespaces)
log.info('Finished parsing definitions section in %.02f seconds', time.time() - parse_definitions_start_time) | python | def parse_definitions(graph: BELGraph,
enumerated_lines: Iterable[Tuple[int, str]],
metadata_parser: MetadataParser,
allow_failures: bool = False,
use_tqdm: bool = False,
tqdm_kwargs: Optional[Mapping[str, Any]] = None,
) -> None:
"""Parse the lines in the definitions section of a BEL script.
:param graph: A BEL graph
:param enumerated_lines: An enumerated iterable over the lines in the definitions section of a BEL script
:param metadata_parser: A metadata parser
:param allow_failures: If true, allows parser to continue past strange failures
:param use_tqdm: Use :mod:`tqdm` to show a progress bar?
:param tqdm_kwargs: Keywords to pass to ``tqdm``
:raises: pybel.parser.parse_exceptions.InconsistentDefinitionError
:raises: pybel.resources.exc.ResourceError
:raises: sqlalchemy.exc.OperationalError
"""
parse_definitions_start_time = time.time()
if use_tqdm:
_tqdm_kwargs = dict(desc='Definitions', leave=False)
if tqdm_kwargs:
_tqdm_kwargs.update(tqdm_kwargs)
enumerated_lines = tqdm(list(enumerated_lines), **_tqdm_kwargs)
for line_number, line in enumerated_lines:
try:
metadata_parser.parseString(line, line_number=line_number)
except (InconsistentDefinitionError, ResourceError) as e:
parse_log.exception(LOG_FMT, line_number, 0, e.__class__.__name__, line)
raise e
except OperationalError as e:
parse_log.warning('Need to upgrade database. See '
'http://pybel.readthedocs.io/en/latest/installation.html#upgrading')
raise e
except Exception as e:
if not allow_failures:
exc = MalformedMetadataException(line_number, line, 0)
_log_parse_exception(graph, exc)
raise exc from e
graph.namespace_url.update(metadata_parser.namespace_url_dict)
graph.namespace_pattern.update({
keyword: pattern.pattern
for keyword, pattern in metadata_parser.namespace_to_pattern.items()
})
graph.annotation_url.update(metadata_parser.annotation_url_dict)
graph.annotation_pattern.update({
keyword: pattern.pattern
for keyword, pattern in metadata_parser.annotation_to_pattern.items()
})
graph.annotation_list.update(metadata_parser.annotation_to_local)
graph.uncached_namespaces.update(metadata_parser.uncachable_namespaces)
log.info('Finished parsing definitions section in %.02f seconds', time.time() - parse_definitions_start_time) | [
"def",
"parse_definitions",
"(",
"graph",
":",
"BELGraph",
",",
"enumerated_lines",
":",
"Iterable",
"[",
"Tuple",
"[",
"int",
",",
"str",
"]",
"]",
",",
"metadata_parser",
":",
"MetadataParser",
",",
"allow_failures",
":",
"bool",
"=",
"False",
",",
"use_tq... | Parse the lines in the definitions section of a BEL script.
:param graph: A BEL graph
:param enumerated_lines: An enumerated iterable over the lines in the definitions section of a BEL script
:param metadata_parser: A metadata parser
:param allow_failures: If true, allows parser to continue past strange failures
:param use_tqdm: Use :mod:`tqdm` to show a progress bar?
:param tqdm_kwargs: Keywords to pass to ``tqdm``
:raises: pybel.parser.parse_exceptions.InconsistentDefinitionError
:raises: pybel.resources.exc.ResourceError
:raises: sqlalchemy.exc.OperationalError | [
"Parse",
"the",
"lines",
"in",
"the",
"definitions",
"section",
"of",
"a",
"BEL",
"script",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/line_utils.py#L163-L220 | train | 29,530 |
pybel/pybel | src/pybel/io/line_utils.py | parse_statements | def parse_statements(graph: BELGraph,
enumerated_lines: Iterable[Tuple[int, str]],
bel_parser: BELParser,
use_tqdm: bool = False,
tqdm_kwargs: Optional[Mapping[str, Any]] = None,
) -> None:
"""Parse a list of statements from a BEL Script.
:param graph: A BEL graph
:param enumerated_lines: An enumerated iterable over the lines in the statements section of a BEL script
:param bel_parser: A BEL parser
:param use_tqdm: Use :mod:`tqdm` to show a progress bar? Requires reading whole file to memory.
:param tqdm_kwargs: Keywords to pass to ``tqdm``
"""
parse_statements_start_time = time.time()
if use_tqdm:
_tqdm_kwargs = dict(desc='Statements')
if tqdm_kwargs:
_tqdm_kwargs.update(tqdm_kwargs)
enumerated_lines = tqdm(list(enumerated_lines), **_tqdm_kwargs)
for line_number, line in enumerated_lines:
try:
bel_parser.parseString(line, line_number=line_number)
except ParseException as e:
exc = BELSyntaxError(line_number, line, e.loc)
_log_parse_exception(graph, exc)
graph.add_warning(exc, bel_parser.get_annotations())
except PlaceholderAminoAcidWarning as exc:
exc.line_number = line_number
_log_parse_exception(graph, exc)
graph.add_warning(exc, bel_parser.get_annotations())
except BELParserWarning as exc:
_log_parse_exception(graph, exc)
graph.add_warning(exc, bel_parser.get_annotations())
except Exception:
parse_log.exception(LOG_FMT, line_number, 0, 'General Failure', line)
raise
log.info('Parsed statements section in %.02f seconds with %d warnings', time.time() - parse_statements_start_time,
len(graph.warnings)) | python | def parse_statements(graph: BELGraph,
enumerated_lines: Iterable[Tuple[int, str]],
bel_parser: BELParser,
use_tqdm: bool = False,
tqdm_kwargs: Optional[Mapping[str, Any]] = None,
) -> None:
"""Parse a list of statements from a BEL Script.
:param graph: A BEL graph
:param enumerated_lines: An enumerated iterable over the lines in the statements section of a BEL script
:param bel_parser: A BEL parser
:param use_tqdm: Use :mod:`tqdm` to show a progress bar? Requires reading whole file to memory.
:param tqdm_kwargs: Keywords to pass to ``tqdm``
"""
parse_statements_start_time = time.time()
if use_tqdm:
_tqdm_kwargs = dict(desc='Statements')
if tqdm_kwargs:
_tqdm_kwargs.update(tqdm_kwargs)
enumerated_lines = tqdm(list(enumerated_lines), **_tqdm_kwargs)
for line_number, line in enumerated_lines:
try:
bel_parser.parseString(line, line_number=line_number)
except ParseException as e:
exc = BELSyntaxError(line_number, line, e.loc)
_log_parse_exception(graph, exc)
graph.add_warning(exc, bel_parser.get_annotations())
except PlaceholderAminoAcidWarning as exc:
exc.line_number = line_number
_log_parse_exception(graph, exc)
graph.add_warning(exc, bel_parser.get_annotations())
except BELParserWarning as exc:
_log_parse_exception(graph, exc)
graph.add_warning(exc, bel_parser.get_annotations())
except Exception:
parse_log.exception(LOG_FMT, line_number, 0, 'General Failure', line)
raise
log.info('Parsed statements section in %.02f seconds with %d warnings', time.time() - parse_statements_start_time,
len(graph.warnings)) | [
"def",
"parse_statements",
"(",
"graph",
":",
"BELGraph",
",",
"enumerated_lines",
":",
"Iterable",
"[",
"Tuple",
"[",
"int",
",",
"str",
"]",
"]",
",",
"bel_parser",
":",
"BELParser",
",",
"use_tqdm",
":",
"bool",
"=",
"False",
",",
"tqdm_kwargs",
":",
... | Parse a list of statements from a BEL Script.
:param graph: A BEL graph
:param enumerated_lines: An enumerated iterable over the lines in the statements section of a BEL script
:param bel_parser: A BEL parser
:param use_tqdm: Use :mod:`tqdm` to show a progress bar? Requires reading whole file to memory.
:param tqdm_kwargs: Keywords to pass to ``tqdm`` | [
"Parse",
"a",
"list",
"of",
"statements",
"from",
"a",
"BEL",
"Script",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/line_utils.py#L223-L264 | train | 29,531 |
pybel/pybel | src/pybel/manager/database_io.py | to_database | def to_database(graph, manager: Optional[Manager] = None, store_parts: bool = True, use_tqdm: bool = False):
"""Store a graph in a database.
:param BELGraph graph: A BEL graph
:param store_parts: Should the graph be stored in the edge store?
:return: If successful, returns the network object from the database.
:rtype: Optional[Network]
"""
if manager is None:
manager = Manager()
try:
return manager.insert_graph(graph, store_parts=store_parts, use_tqdm=use_tqdm)
except (IntegrityError, OperationalError):
manager.session.rollback()
log.exception('Error storing graph')
except Exception as e:
manager.session.rollback()
raise e | python | def to_database(graph, manager: Optional[Manager] = None, store_parts: bool = True, use_tqdm: bool = False):
"""Store a graph in a database.
:param BELGraph graph: A BEL graph
:param store_parts: Should the graph be stored in the edge store?
:return: If successful, returns the network object from the database.
:rtype: Optional[Network]
"""
if manager is None:
manager = Manager()
try:
return manager.insert_graph(graph, store_parts=store_parts, use_tqdm=use_tqdm)
except (IntegrityError, OperationalError):
manager.session.rollback()
log.exception('Error storing graph')
except Exception as e:
manager.session.rollback()
raise e | [
"def",
"to_database",
"(",
"graph",
",",
"manager",
":",
"Optional",
"[",
"Manager",
"]",
"=",
"None",
",",
"store_parts",
":",
"bool",
"=",
"True",
",",
"use_tqdm",
":",
"bool",
"=",
"False",
")",
":",
"if",
"manager",
"is",
"None",
":",
"manager",
... | Store a graph in a database.
:param BELGraph graph: A BEL graph
:param store_parts: Should the graph be stored in the edge store?
:return: If successful, returns the network object from the database.
:rtype: Optional[Network] | [
"Store",
"a",
"graph",
"in",
"a",
"database",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/database_io.py#L20-L38 | train | 29,532 |
pybel/pybel | src/pybel/manager/database_io.py | from_database | def from_database(name: str, version: Optional[str] = None, manager: Optional[Manager] = None):
"""Load a BEL graph from a database.
If name and version are given, finds it exactly with
:meth:`pybel.manager.Manager.get_network_by_name_version`. If just the name is given, finds most recent
with :meth:`pybel.manager.Manager.get_network_by_name_version`
:param name: The name of the graph
:param version: The version string of the graph. If not specified, loads most recent graph added with this name
:return: A BEL graph loaded from the database
:rtype: Optional[BELGraph]
"""
if manager is None:
manager = Manager()
if version is None:
return manager.get_graph_by_most_recent(name)
return manager.get_graph_by_name_version(name, version) | python | def from_database(name: str, version: Optional[str] = None, manager: Optional[Manager] = None):
"""Load a BEL graph from a database.
If name and version are given, finds it exactly with
:meth:`pybel.manager.Manager.get_network_by_name_version`. If just the name is given, finds most recent
with :meth:`pybel.manager.Manager.get_network_by_name_version`
:param name: The name of the graph
:param version: The version string of the graph. If not specified, loads most recent graph added with this name
:return: A BEL graph loaded from the database
:rtype: Optional[BELGraph]
"""
if manager is None:
manager = Manager()
if version is None:
return manager.get_graph_by_most_recent(name)
return manager.get_graph_by_name_version(name, version) | [
"def",
"from_database",
"(",
"name",
":",
"str",
",",
"version",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"manager",
":",
"Optional",
"[",
"Manager",
"]",
"=",
"None",
")",
":",
"if",
"manager",
"is",
"None",
":",
"manager",
"=",
"Manager"... | Load a BEL graph from a database.
If name and version are given, finds it exactly with
:meth:`pybel.manager.Manager.get_network_by_name_version`. If just the name is given, finds most recent
with :meth:`pybel.manager.Manager.get_network_by_name_version`
:param name: The name of the graph
:param version: The version string of the graph. If not specified, loads most recent graph added with this name
:return: A BEL graph loaded from the database
:rtype: Optional[BELGraph] | [
"Load",
"a",
"BEL",
"graph",
"from",
"a",
"database",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/database_io.py#L41-L59 | train | 29,533 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | _node_has_variant | def _node_has_variant(node: BaseEntity, variant: str) -> bool:
"""Return true if the node has at least one of the given variant.
:param variant: :data:`PMOD`, :data:`HGVS`, :data:`GMOD`, or :data:`FRAGMENT`
"""
return VARIANTS in node and any(
variant_dict[KIND] == variant
for variant_dict in node[VARIANTS]
) | python | def _node_has_variant(node: BaseEntity, variant: str) -> bool:
"""Return true if the node has at least one of the given variant.
:param variant: :data:`PMOD`, :data:`HGVS`, :data:`GMOD`, or :data:`FRAGMENT`
"""
return VARIANTS in node and any(
variant_dict[KIND] == variant
for variant_dict in node[VARIANTS]
) | [
"def",
"_node_has_variant",
"(",
"node",
":",
"BaseEntity",
",",
"variant",
":",
"str",
")",
"->",
"bool",
":",
"return",
"VARIANTS",
"in",
"node",
"and",
"any",
"(",
"variant_dict",
"[",
"KIND",
"]",
"==",
"variant",
"for",
"variant_dict",
"in",
"node",
... | Return true if the node has at least one of the given variant.
:param variant: :data:`PMOD`, :data:`HGVS`, :data:`GMOD`, or :data:`FRAGMENT` | [
"Return",
"true",
"if",
"the",
"node",
"has",
"at",
"least",
"one",
"of",
"the",
"given",
"variant",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L117-L125 | train | 29,534 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | _node_has_modifier | def _node_has_modifier(graph: BELGraph, node: BaseEntity, modifier: str) -> bool:
"""Return true if over any of a nodes edges, it has a given modifier.
Modifier can be one of:
- :data:`pybel.constants.ACTIVITY`,
- :data:`pybel.constants.DEGRADATION`
- :data:`pybel.constants.TRANSLOCATION`.
:param modifier: One of :data:`pybel.constants.ACTIVITY`, :data:`pybel.constants.DEGRADATION`, or
:data:`pybel.constants.TRANSLOCATION`
"""
modifier_in_subject = any(
part_has_modifier(d, SUBJECT, modifier)
for _, _, d in graph.out_edges(node, data=True)
)
modifier_in_object = any(
part_has_modifier(d, OBJECT, modifier)
for _, _, d in graph.in_edges(node, data=True)
)
return modifier_in_subject or modifier_in_object | python | def _node_has_modifier(graph: BELGraph, node: BaseEntity, modifier: str) -> bool:
"""Return true if over any of a nodes edges, it has a given modifier.
Modifier can be one of:
- :data:`pybel.constants.ACTIVITY`,
- :data:`pybel.constants.DEGRADATION`
- :data:`pybel.constants.TRANSLOCATION`.
:param modifier: One of :data:`pybel.constants.ACTIVITY`, :data:`pybel.constants.DEGRADATION`, or
:data:`pybel.constants.TRANSLOCATION`
"""
modifier_in_subject = any(
part_has_modifier(d, SUBJECT, modifier)
for _, _, d in graph.out_edges(node, data=True)
)
modifier_in_object = any(
part_has_modifier(d, OBJECT, modifier)
for _, _, d in graph.in_edges(node, data=True)
)
return modifier_in_subject or modifier_in_object | [
"def",
"_node_has_modifier",
"(",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
",",
"modifier",
":",
"str",
")",
"->",
"bool",
":",
"modifier_in_subject",
"=",
"any",
"(",
"part_has_modifier",
"(",
"d",
",",
"SUBJECT",
",",
"modifier",
")",
"f... | Return true if over any of a nodes edges, it has a given modifier.
Modifier can be one of:
- :data:`pybel.constants.ACTIVITY`,
- :data:`pybel.constants.DEGRADATION`
- :data:`pybel.constants.TRANSLOCATION`.
:param modifier: One of :data:`pybel.constants.ACTIVITY`, :data:`pybel.constants.DEGRADATION`, or
:data:`pybel.constants.TRANSLOCATION` | [
"Return",
"true",
"if",
"over",
"any",
"of",
"a",
"nodes",
"edges",
"it",
"has",
"a",
"given",
"modifier",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L152-L174 | train | 29,535 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | has_activity | def has_activity(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if over any of the node's edges, it has a molecular activity."""
return _node_has_modifier(graph, node, ACTIVITY) | python | def has_activity(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if over any of the node's edges, it has a molecular activity."""
return _node_has_modifier(graph, node, ACTIVITY) | [
"def",
"has_activity",
"(",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"bool",
":",
"return",
"_node_has_modifier",
"(",
"graph",
",",
"node",
",",
"ACTIVITY",
")"
] | Return true if over any of the node's edges, it has a molecular activity. | [
"Return",
"true",
"if",
"over",
"any",
"of",
"the",
"node",
"s",
"edges",
"it",
"has",
"a",
"molecular",
"activity",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L177-L179 | train | 29,536 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | is_degraded | def is_degraded(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if over any of the node's edges, it is degraded."""
return _node_has_modifier(graph, node, DEGRADATION) | python | def is_degraded(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if over any of the node's edges, it is degraded."""
return _node_has_modifier(graph, node, DEGRADATION) | [
"def",
"is_degraded",
"(",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"bool",
":",
"return",
"_node_has_modifier",
"(",
"graph",
",",
"node",
",",
"DEGRADATION",
")"
] | Return true if over any of the node's edges, it is degraded. | [
"Return",
"true",
"if",
"over",
"any",
"of",
"the",
"node",
"s",
"edges",
"it",
"is",
"degraded",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L182-L184 | train | 29,537 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | is_translocated | def is_translocated(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if over any of the node's edges, it is translocated."""
return _node_has_modifier(graph, node, TRANSLOCATION) | python | def is_translocated(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if over any of the node's edges, it is translocated."""
return _node_has_modifier(graph, node, TRANSLOCATION) | [
"def",
"is_translocated",
"(",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"bool",
":",
"return",
"_node_has_modifier",
"(",
"graph",
",",
"node",
",",
"TRANSLOCATION",
")"
] | Return true if over any of the node's edges, it is translocated. | [
"Return",
"true",
"if",
"over",
"any",
"of",
"the",
"node",
"s",
"edges",
"it",
"is",
"translocated",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L187-L189 | train | 29,538 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | has_causal_in_edges | def has_causal_in_edges(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if the node contains any in_edges that are causal."""
return any(
data[RELATION] in CAUSAL_RELATIONS
for _, _, data in graph.in_edges(node, data=True)
) | python | def has_causal_in_edges(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if the node contains any in_edges that are causal."""
return any(
data[RELATION] in CAUSAL_RELATIONS
for _, _, data in graph.in_edges(node, data=True)
) | [
"def",
"has_causal_in_edges",
"(",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"bool",
":",
"return",
"any",
"(",
"data",
"[",
"RELATION",
"]",
"in",
"CAUSAL_RELATIONS",
"for",
"_",
",",
"_",
",",
"data",
"in",
"graph",
".",
"i... | Return true if the node contains any in_edges that are causal. | [
"Return",
"true",
"if",
"the",
"node",
"contains",
"any",
"in_edges",
"that",
"are",
"causal",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L192-L197 | train | 29,539 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | has_causal_out_edges | def has_causal_out_edges(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if the node contains any out_edges that are causal."""
return any(
data[RELATION] in CAUSAL_RELATIONS
for _, _, data in graph.out_edges(node, data=True)
) | python | def has_causal_out_edges(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if the node contains any out_edges that are causal."""
return any(
data[RELATION] in CAUSAL_RELATIONS
for _, _, data in graph.out_edges(node, data=True)
) | [
"def",
"has_causal_out_edges",
"(",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"bool",
":",
"return",
"any",
"(",
"data",
"[",
"RELATION",
"]",
"in",
"CAUSAL_RELATIONS",
"for",
"_",
",",
"_",
",",
"data",
"in",
"graph",
".",
"... | Return true if the node contains any out_edges that are causal. | [
"Return",
"true",
"if",
"the",
"node",
"contains",
"any",
"out_edges",
"that",
"are",
"causal",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L200-L205 | train | 29,540 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | node_exclusion_predicate_builder | def node_exclusion_predicate_builder(nodes: Iterable[BaseEntity]) -> NodePredicate:
"""Build a node predicate that returns false for the given nodes."""
nodes = set(nodes)
@node_predicate
def node_exclusion_predicate(node: BaseEntity) -> bool:
"""Return true if the node is not in the given set of nodes."""
return node not in nodes
return node_exclusion_predicate | python | def node_exclusion_predicate_builder(nodes: Iterable[BaseEntity]) -> NodePredicate:
"""Build a node predicate that returns false for the given nodes."""
nodes = set(nodes)
@node_predicate
def node_exclusion_predicate(node: BaseEntity) -> bool:
"""Return true if the node is not in the given set of nodes."""
return node not in nodes
return node_exclusion_predicate | [
"def",
"node_exclusion_predicate_builder",
"(",
"nodes",
":",
"Iterable",
"[",
"BaseEntity",
"]",
")",
"->",
"NodePredicate",
":",
"nodes",
"=",
"set",
"(",
"nodes",
")",
"@",
"node_predicate",
"def",
"node_exclusion_predicate",
"(",
"node",
":",
"BaseEntity",
"... | Build a node predicate that returns false for the given nodes. | [
"Build",
"a",
"node",
"predicate",
"that",
"returns",
"false",
"for",
"the",
"given",
"nodes",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L208-L217 | train | 29,541 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | node_inclusion_predicate_builder | def node_inclusion_predicate_builder(nodes: Iterable[BaseEntity]) -> NodePredicate:
"""Build a function that returns true for the given nodes."""
nodes = set(nodes)
@node_predicate
def node_inclusion_predicate(node: BaseEntity) -> bool:
"""Return true if the node is in the given set of nodes."""
return node in nodes
return node_inclusion_predicate | python | def node_inclusion_predicate_builder(nodes: Iterable[BaseEntity]) -> NodePredicate:
"""Build a function that returns true for the given nodes."""
nodes = set(nodes)
@node_predicate
def node_inclusion_predicate(node: BaseEntity) -> bool:
"""Return true if the node is in the given set of nodes."""
return node in nodes
return node_inclusion_predicate | [
"def",
"node_inclusion_predicate_builder",
"(",
"nodes",
":",
"Iterable",
"[",
"BaseEntity",
"]",
")",
"->",
"NodePredicate",
":",
"nodes",
"=",
"set",
"(",
"nodes",
")",
"@",
"node_predicate",
"def",
"node_inclusion_predicate",
"(",
"node",
":",
"BaseEntity",
"... | Build a function that returns true for the given nodes. | [
"Build",
"a",
"function",
"that",
"returns",
"true",
"for",
"the",
"given",
"nodes",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L220-L229 | train | 29,542 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | is_causal_source | def is_causal_source(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true of the node is a causal source.
- Doesn't have any causal in edge(s)
- Does have causal out edge(s)
"""
# TODO reimplement to be faster
return not has_causal_in_edges(graph, node) and has_causal_out_edges(graph, node) | python | def is_causal_source(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true of the node is a causal source.
- Doesn't have any causal in edge(s)
- Does have causal out edge(s)
"""
# TODO reimplement to be faster
return not has_causal_in_edges(graph, node) and has_causal_out_edges(graph, node) | [
"def",
"is_causal_source",
"(",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"bool",
":",
"# TODO reimplement to be faster",
"return",
"not",
"has_causal_in_edges",
"(",
"graph",
",",
"node",
")",
"and",
"has_causal_out_edges",
"(",
"graph"... | Return true of the node is a causal source.
- Doesn't have any causal in edge(s)
- Does have causal out edge(s) | [
"Return",
"true",
"of",
"the",
"node",
"is",
"a",
"causal",
"source",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L232-L239 | train | 29,543 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | is_causal_sink | def is_causal_sink(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if the node is a causal sink.
- Does have causal in edge(s)
- Doesn't have any causal out edge(s)
"""
return has_causal_in_edges(graph, node) and not has_causal_out_edges(graph, node) | python | def is_causal_sink(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if the node is a causal sink.
- Does have causal in edge(s)
- Doesn't have any causal out edge(s)
"""
return has_causal_in_edges(graph, node) and not has_causal_out_edges(graph, node) | [
"def",
"is_causal_sink",
"(",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"bool",
":",
"return",
"has_causal_in_edges",
"(",
"graph",
",",
"node",
")",
"and",
"not",
"has_causal_out_edges",
"(",
"graph",
",",
"node",
")"
] | Return true if the node is a causal sink.
- Does have causal in edge(s)
- Doesn't have any causal out edge(s) | [
"Return",
"true",
"if",
"the",
"node",
"is",
"a",
"causal",
"sink",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L242-L248 | train | 29,544 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | is_causal_central | def is_causal_central(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if the node is neither a causal sink nor a causal source.
- Does have causal in edges(s)
- Does have causal out edge(s)
"""
return has_causal_in_edges(graph, node) and has_causal_out_edges(graph, node) | python | def is_causal_central(graph: BELGraph, node: BaseEntity) -> bool:
"""Return true if the node is neither a causal sink nor a causal source.
- Does have causal in edges(s)
- Does have causal out edge(s)
"""
return has_causal_in_edges(graph, node) and has_causal_out_edges(graph, node) | [
"def",
"is_causal_central",
"(",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"bool",
":",
"return",
"has_causal_in_edges",
"(",
"graph",
",",
"node",
")",
"and",
"has_causal_out_edges",
"(",
"graph",
",",
"node",
")"
] | Return true if the node is neither a causal sink nor a causal source.
- Does have causal in edges(s)
- Does have causal out edge(s) | [
"Return",
"true",
"if",
"the",
"node",
"is",
"neither",
"a",
"causal",
"sink",
"nor",
"a",
"causal",
"source",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L251-L257 | train | 29,545 |
pybel/pybel | src/pybel/struct/filters/node_predicates.py | is_isolated_list_abundance | def is_isolated_list_abundance(graph: BELGraph, node: BaseEntity, cls: Type[ListAbundance] = ListAbundance) -> bool:
"""Return if the node is a list abundance but has no qualified edges."""
return (
isinstance(node, cls) and
0 == graph.in_degree(node) and
all(
data[RELATION] == HAS_COMPONENT
for _, __, data in graph.out_edges(node, data=True)
)
) | python | def is_isolated_list_abundance(graph: BELGraph, node: BaseEntity, cls: Type[ListAbundance] = ListAbundance) -> bool:
"""Return if the node is a list abundance but has no qualified edges."""
return (
isinstance(node, cls) and
0 == graph.in_degree(node) and
all(
data[RELATION] == HAS_COMPONENT
for _, __, data in graph.out_edges(node, data=True)
)
) | [
"def",
"is_isolated_list_abundance",
"(",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
",",
"cls",
":",
"Type",
"[",
"ListAbundance",
"]",
"=",
"ListAbundance",
")",
"->",
"bool",
":",
"return",
"(",
"isinstance",
"(",
"node",
",",
"cls",
")",... | Return if the node is a list abundance but has no qualified edges. | [
"Return",
"if",
"the",
"node",
"is",
"a",
"list",
"abundance",
"but",
"has",
"no",
"qualified",
"edges",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/node_predicates.py#L260-L269 | train | 29,546 |
pybel/pybel | src/pybel/struct/mutation/collapse/collapse.py | collapse_pair | def collapse_pair(graph, survivor: BaseEntity, victim: BaseEntity) -> None:
"""Rewire all edges from the synonymous node to the survivor node, then deletes the synonymous node.
Does not keep edges between the two nodes.
:param pybel.BELGraph graph: A BEL graph
:param survivor: The BEL node to collapse all edges on the synonym to
:param victim: The BEL node to collapse into the surviving node
"""
graph.add_edges_from(
(survivor, successor, key, data)
for _, successor, key, data in graph.out_edges(victim, keys=True, data=True)
if successor != survivor
)
graph.add_edges_from(
(predecessor, survivor, key, data)
for predecessor, _, key, data in graph.in_edges(victim, keys=True, data=True)
if predecessor != survivor
)
graph.remove_node(victim) | python | def collapse_pair(graph, survivor: BaseEntity, victim: BaseEntity) -> None:
"""Rewire all edges from the synonymous node to the survivor node, then deletes the synonymous node.
Does not keep edges between the two nodes.
:param pybel.BELGraph graph: A BEL graph
:param survivor: The BEL node to collapse all edges on the synonym to
:param victim: The BEL node to collapse into the surviving node
"""
graph.add_edges_from(
(survivor, successor, key, data)
for _, successor, key, data in graph.out_edges(victim, keys=True, data=True)
if successor != survivor
)
graph.add_edges_from(
(predecessor, survivor, key, data)
for predecessor, _, key, data in graph.in_edges(victim, keys=True, data=True)
if predecessor != survivor
)
graph.remove_node(victim) | [
"def",
"collapse_pair",
"(",
"graph",
",",
"survivor",
":",
"BaseEntity",
",",
"victim",
":",
"BaseEntity",
")",
"->",
"None",
":",
"graph",
".",
"add_edges_from",
"(",
"(",
"survivor",
",",
"successor",
",",
"key",
",",
"data",
")",
"for",
"_",
",",
"... | Rewire all edges from the synonymous node to the survivor node, then deletes the synonymous node.
Does not keep edges between the two nodes.
:param pybel.BELGraph graph: A BEL graph
:param survivor: The BEL node to collapse all edges on the synonym to
:param victim: The BEL node to collapse into the surviving node | [
"Rewire",
"all",
"edges",
"from",
"the",
"synonymous",
"node",
"to",
"the",
"survivor",
"node",
"then",
"deletes",
"the",
"synonymous",
"node",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/collapse/collapse.py#L33-L54 | train | 29,547 |
pybel/pybel | src/pybel/struct/mutation/collapse/collapse.py | collapse_nodes | def collapse_nodes(graph, survivor_mapping: Mapping[BaseEntity, Set[BaseEntity]]) -> None:
"""Collapse all nodes in values to the key nodes, in place.
:param pybel.BELGraph graph: A BEL graph
:param survivor_mapping: A dictionary with survivors as their keys, and iterables of the corresponding victims as
values.
"""
inconsistencies = surviors_are_inconsistent(survivor_mapping)
if inconsistencies:
raise ValueError('survivor mapping is inconsistent: {}'.format(inconsistencies))
for survivor, victims in survivor_mapping.items():
for victim in victims:
collapse_pair(graph, survivor=survivor, victim=victim)
_remove_self_edges(graph) | python | def collapse_nodes(graph, survivor_mapping: Mapping[BaseEntity, Set[BaseEntity]]) -> None:
"""Collapse all nodes in values to the key nodes, in place.
:param pybel.BELGraph graph: A BEL graph
:param survivor_mapping: A dictionary with survivors as their keys, and iterables of the corresponding victims as
values.
"""
inconsistencies = surviors_are_inconsistent(survivor_mapping)
if inconsistencies:
raise ValueError('survivor mapping is inconsistent: {}'.format(inconsistencies))
for survivor, victims in survivor_mapping.items():
for victim in victims:
collapse_pair(graph, survivor=survivor, victim=victim)
_remove_self_edges(graph) | [
"def",
"collapse_nodes",
"(",
"graph",
",",
"survivor_mapping",
":",
"Mapping",
"[",
"BaseEntity",
",",
"Set",
"[",
"BaseEntity",
"]",
"]",
")",
"->",
"None",
":",
"inconsistencies",
"=",
"surviors_are_inconsistent",
"(",
"survivor_mapping",
")",
"if",
"inconsis... | Collapse all nodes in values to the key nodes, in place.
:param pybel.BELGraph graph: A BEL graph
:param survivor_mapping: A dictionary with survivors as their keys, and iterables of the corresponding victims as
values. | [
"Collapse",
"all",
"nodes",
"in",
"values",
"to",
"the",
"key",
"nodes",
"in",
"place",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/collapse/collapse.py#L60-L75 | train | 29,548 |
pybel/pybel | src/pybel/struct/mutation/collapse/collapse.py | surviors_are_inconsistent | def surviors_are_inconsistent(survivor_mapping: Mapping[BaseEntity, Set[BaseEntity]]) -> Set[BaseEntity]:
"""Check that there's no transitive shit going on."""
victim_mapping = set()
for victim in itt.chain.from_iterable(survivor_mapping.values()):
if victim in survivor_mapping:
victim_mapping.add(victim)
return victim_mapping | python | def surviors_are_inconsistent(survivor_mapping: Mapping[BaseEntity, Set[BaseEntity]]) -> Set[BaseEntity]:
"""Check that there's no transitive shit going on."""
victim_mapping = set()
for victim in itt.chain.from_iterable(survivor_mapping.values()):
if victim in survivor_mapping:
victim_mapping.add(victim)
return victim_mapping | [
"def",
"surviors_are_inconsistent",
"(",
"survivor_mapping",
":",
"Mapping",
"[",
"BaseEntity",
",",
"Set",
"[",
"BaseEntity",
"]",
"]",
")",
"->",
"Set",
"[",
"BaseEntity",
"]",
":",
"victim_mapping",
"=",
"set",
"(",
")",
"for",
"victim",
"in",
"itt",
".... | Check that there's no transitive shit going on. | [
"Check",
"that",
"there",
"s",
"no",
"transitive",
"shit",
"going",
"on",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/collapse/collapse.py#L78-L84 | train | 29,549 |
pybel/pybel | src/pybel/struct/mutation/collapse/collapse.py | collapse_all_variants | def collapse_all_variants(graph) -> None:
"""Collapse all genes', RNAs', miRNAs', and proteins' variants to their parents.
:param pybel.BELGraph graph: A BEL Graph
"""
has_variant_predicate = build_relation_predicate(HAS_VARIANT)
edges = list(filter_edges(graph, has_variant_predicate))
for u, v, _ in edges:
collapse_pair(graph, survivor=u, victim=v)
_remove_self_edges(graph) | python | def collapse_all_variants(graph) -> None:
"""Collapse all genes', RNAs', miRNAs', and proteins' variants to their parents.
:param pybel.BELGraph graph: A BEL Graph
"""
has_variant_predicate = build_relation_predicate(HAS_VARIANT)
edges = list(filter_edges(graph, has_variant_predicate))
for u, v, _ in edges:
collapse_pair(graph, survivor=u, victim=v)
_remove_self_edges(graph) | [
"def",
"collapse_all_variants",
"(",
"graph",
")",
"->",
"None",
":",
"has_variant_predicate",
"=",
"build_relation_predicate",
"(",
"HAS_VARIANT",
")",
"edges",
"=",
"list",
"(",
"filter_edges",
"(",
"graph",
",",
"has_variant_predicate",
")",
")",
"for",
"u",
... | Collapse all genes', RNAs', miRNAs', and proteins' variants to their parents.
:param pybel.BELGraph graph: A BEL Graph | [
"Collapse",
"all",
"genes",
"RNAs",
"miRNAs",
"and",
"proteins",
"variants",
"to",
"their",
"parents",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/collapse/collapse.py#L88-L100 | train | 29,550 |
pybel/pybel | src/pybel/struct/utils.py | update_metadata | def update_metadata(source, target) -> None:
"""Update the namespace and annotation metadata in the target graph.
:param pybel.BELGraph source:
:param pybel.BELGraph target:
"""
target.namespace_url.update(source.namespace_url)
target.namespace_pattern.update(source.namespace_pattern)
target.annotation_url.update(source.annotation_url)
target.annotation_pattern.update(source.annotation_pattern)
for keyword, values in source.annotation_list.items():
if keyword not in target.annotation_list:
target.annotation_list[keyword] = values
else:
target.annotation_list[keyword].update(values) | python | def update_metadata(source, target) -> None:
"""Update the namespace and annotation metadata in the target graph.
:param pybel.BELGraph source:
:param pybel.BELGraph target:
"""
target.namespace_url.update(source.namespace_url)
target.namespace_pattern.update(source.namespace_pattern)
target.annotation_url.update(source.annotation_url)
target.annotation_pattern.update(source.annotation_pattern)
for keyword, values in source.annotation_list.items():
if keyword not in target.annotation_list:
target.annotation_list[keyword] = values
else:
target.annotation_list[keyword].update(values) | [
"def",
"update_metadata",
"(",
"source",
",",
"target",
")",
"->",
"None",
":",
"target",
".",
"namespace_url",
".",
"update",
"(",
"source",
".",
"namespace_url",
")",
"target",
".",
"namespace_pattern",
".",
"update",
"(",
"source",
".",
"namespace_pattern",... | Update the namespace and annotation metadata in the target graph.
:param pybel.BELGraph source:
:param pybel.BELGraph target: | [
"Update",
"the",
"namespace",
"and",
"annotation",
"metadata",
"in",
"the",
"target",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/utils.py#L13-L28 | train | 29,551 |
pybel/pybel | src/pybel/struct/utils.py | update_node_helper | def update_node_helper(source: nx.Graph, target: nx.Graph) -> None:
"""Update the nodes' data dictionaries in the target graph from the source graph.
:param source: The universe of all knowledge
:param target: The target BEL graph
"""
for node in target:
if node in source:
target.nodes[node].update(source.nodes[node]) | python | def update_node_helper(source: nx.Graph, target: nx.Graph) -> None:
"""Update the nodes' data dictionaries in the target graph from the source graph.
:param source: The universe of all knowledge
:param target: The target BEL graph
"""
for node in target:
if node in source:
target.nodes[node].update(source.nodes[node]) | [
"def",
"update_node_helper",
"(",
"source",
":",
"nx",
".",
"Graph",
",",
"target",
":",
"nx",
".",
"Graph",
")",
"->",
"None",
":",
"for",
"node",
"in",
"target",
":",
"if",
"node",
"in",
"source",
":",
"target",
".",
"nodes",
"[",
"node",
"]",
".... | Update the nodes' data dictionaries in the target graph from the source graph.
:param source: The universe of all knowledge
:param target: The target BEL graph | [
"Update",
"the",
"nodes",
"data",
"dictionaries",
"in",
"the",
"target",
"graph",
"from",
"the",
"source",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/utils.py#L31-L39 | train | 29,552 |
pybel/pybel | src/pybel/struct/summary/errors.py | get_syntax_errors | def get_syntax_errors(graph: BELGraph) -> List[WarningTuple]:
"""List the syntax errors encountered during compilation of a BEL script."""
return [
(path, exc, an)
for path, exc, an in graph.warnings
if isinstance(exc, BELSyntaxError)
] | python | def get_syntax_errors(graph: BELGraph) -> List[WarningTuple]:
"""List the syntax errors encountered during compilation of a BEL script."""
return [
(path, exc, an)
for path, exc, an in graph.warnings
if isinstance(exc, BELSyntaxError)
] | [
"def",
"get_syntax_errors",
"(",
"graph",
":",
"BELGraph",
")",
"->",
"List",
"[",
"WarningTuple",
"]",
":",
"return",
"[",
"(",
"path",
",",
"exc",
",",
"an",
")",
"for",
"path",
",",
"exc",
",",
"an",
"in",
"graph",
".",
"warnings",
"if",
"isinstan... | List the syntax errors encountered during compilation of a BEL script. | [
"List",
"the",
"syntax",
"errors",
"encountered",
"during",
"compilation",
"of",
"a",
"BEL",
"script",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/errors.py#L23-L29 | train | 29,553 |
pybel/pybel | src/pybel/struct/summary/errors.py | count_error_types | def count_error_types(graph: BELGraph) -> Counter:
"""Count the occurrence of each type of error in a graph.
:return: A Counter of {error type: frequency}
"""
return Counter(
exc.__class__.__name__
for _, exc, _ in graph.warnings
) | python | def count_error_types(graph: BELGraph) -> Counter:
"""Count the occurrence of each type of error in a graph.
:return: A Counter of {error type: frequency}
"""
return Counter(
exc.__class__.__name__
for _, exc, _ in graph.warnings
) | [
"def",
"count_error_types",
"(",
"graph",
":",
"BELGraph",
")",
"->",
"Counter",
":",
"return",
"Counter",
"(",
"exc",
".",
"__class__",
".",
"__name__",
"for",
"_",
",",
"exc",
",",
"_",
"in",
"graph",
".",
"warnings",
")"
] | Count the occurrence of each type of error in a graph.
:return: A Counter of {error type: frequency} | [
"Count",
"the",
"occurrence",
"of",
"each",
"type",
"of",
"error",
"in",
"a",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/errors.py#L32-L40 | train | 29,554 |
pybel/pybel | src/pybel/struct/summary/errors.py | _naked_names_iter | def _naked_names_iter(graph: BELGraph) -> Iterable[str]:
"""Iterate over naked name warnings from a graph."""
for _, exc, _ in graph.warnings:
if isinstance(exc, NakedNameWarning):
yield exc.name | python | def _naked_names_iter(graph: BELGraph) -> Iterable[str]:
"""Iterate over naked name warnings from a graph."""
for _, exc, _ in graph.warnings:
if isinstance(exc, NakedNameWarning):
yield exc.name | [
"def",
"_naked_names_iter",
"(",
"graph",
":",
"BELGraph",
")",
"->",
"Iterable",
"[",
"str",
"]",
":",
"for",
"_",
",",
"exc",
",",
"_",
"in",
"graph",
".",
"warnings",
":",
"if",
"isinstance",
"(",
"exc",
",",
"NakedNameWarning",
")",
":",
"yield",
... | Iterate over naked name warnings from a graph. | [
"Iterate",
"over",
"naked",
"name",
"warnings",
"from",
"a",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/errors.py#L43-L47 | train | 29,555 |
pybel/pybel | src/pybel/struct/summary/errors.py | calculate_incorrect_name_dict | def calculate_incorrect_name_dict(graph: BELGraph) -> Mapping[str, List[str]]:
"""Get missing names grouped by namespace."""
missing = defaultdict(list)
for namespace, name in _iterate_namespace_name(graph):
missing[namespace].append(name)
return dict(missing) | python | def calculate_incorrect_name_dict(graph: BELGraph) -> Mapping[str, List[str]]:
"""Get missing names grouped by namespace."""
missing = defaultdict(list)
for namespace, name in _iterate_namespace_name(graph):
missing[namespace].append(name)
return dict(missing) | [
"def",
"calculate_incorrect_name_dict",
"(",
"graph",
":",
"BELGraph",
")",
"->",
"Mapping",
"[",
"str",
",",
"List",
"[",
"str",
"]",
"]",
":",
"missing",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"namespace",
",",
"name",
"in",
"_iterate_namespace_name"... | Get missing names grouped by namespace. | [
"Get",
"missing",
"names",
"grouped",
"by",
"namespace",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/errors.py#L70-L77 | train | 29,556 |
pybel/pybel | src/pybel/struct/summary/errors.py | calculate_error_by_annotation | def calculate_error_by_annotation(graph: BELGraph, annotation: str) -> Mapping[str, List[str]]:
"""Group error names by a given annotation."""
results = defaultdict(list)
for _, exc, ctx in graph.warnings:
if not ctx or not edge_has_annotation(ctx, annotation):
continue
values = ctx[ANNOTATIONS][annotation]
if isinstance(values, str):
results[values].append(exc.__class__.__name__)
elif isinstance(values, Iterable):
for value in values:
results[value].append(exc.__class__.__name__)
return dict(results) | python | def calculate_error_by_annotation(graph: BELGraph, annotation: str) -> Mapping[str, List[str]]:
"""Group error names by a given annotation."""
results = defaultdict(list)
for _, exc, ctx in graph.warnings:
if not ctx or not edge_has_annotation(ctx, annotation):
continue
values = ctx[ANNOTATIONS][annotation]
if isinstance(values, str):
results[values].append(exc.__class__.__name__)
elif isinstance(values, Iterable):
for value in values:
results[value].append(exc.__class__.__name__)
return dict(results) | [
"def",
"calculate_error_by_annotation",
"(",
"graph",
":",
"BELGraph",
",",
"annotation",
":",
"str",
")",
"->",
"Mapping",
"[",
"str",
",",
"List",
"[",
"str",
"]",
"]",
":",
"results",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"_",
",",
"exc",
","... | Group error names by a given annotation. | [
"Group",
"error",
"names",
"by",
"a",
"given",
"annotation",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/errors.py#L80-L97 | train | 29,557 |
pybel/pybel | src/pybel/struct/mutation/induction/utils.py | get_subgraph_by_edge_filter | def get_subgraph_by_edge_filter(graph, edge_predicates: Optional[EdgePredicates] = None):
"""Induce a sub-graph on all edges that pass the given filters.
:param pybel.BELGraph graph: A BEL graph
:param edge_predicates: An edge predicate or list of edge predicates
:return: A BEL sub-graph induced over the edges passing the given filters
:rtype: pybel.BELGraph
"""
rv = graph.fresh_copy()
expand_by_edge_filter(graph, rv, edge_predicates=edge_predicates)
return rv | python | def get_subgraph_by_edge_filter(graph, edge_predicates: Optional[EdgePredicates] = None):
"""Induce a sub-graph on all edges that pass the given filters.
:param pybel.BELGraph graph: A BEL graph
:param edge_predicates: An edge predicate or list of edge predicates
:return: A BEL sub-graph induced over the edges passing the given filters
:rtype: pybel.BELGraph
"""
rv = graph.fresh_copy()
expand_by_edge_filter(graph, rv, edge_predicates=edge_predicates)
return rv | [
"def",
"get_subgraph_by_edge_filter",
"(",
"graph",
",",
"edge_predicates",
":",
"Optional",
"[",
"EdgePredicates",
"]",
"=",
"None",
")",
":",
"rv",
"=",
"graph",
".",
"fresh_copy",
"(",
")",
"expand_by_edge_filter",
"(",
"graph",
",",
"rv",
",",
"edge_predic... | Induce a sub-graph on all edges that pass the given filters.
:param pybel.BELGraph graph: A BEL graph
:param edge_predicates: An edge predicate or list of edge predicates
:return: A BEL sub-graph induced over the edges passing the given filters
:rtype: pybel.BELGraph | [
"Induce",
"a",
"sub",
"-",
"graph",
"on",
"all",
"edges",
"that",
"pass",
"the",
"given",
"filters",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/utils.py#L20-L30 | train | 29,558 |
pybel/pybel | src/pybel/struct/mutation/induction/utils.py | get_subgraph_by_induction | def get_subgraph_by_induction(graph, nodes: Iterable[BaseEntity]):
"""Induce a sub-graph over the given nodes or return None if none of the nodes are in the given graph.
:param pybel.BELGraph graph: A BEL graph
:param nodes: A list of BEL nodes in the graph
:rtype: Optional[pybel.BELGraph]
"""
nodes = tuple(nodes)
if all(node not in graph for node in nodes):
return
return subgraph(graph, nodes) | python | def get_subgraph_by_induction(graph, nodes: Iterable[BaseEntity]):
"""Induce a sub-graph over the given nodes or return None if none of the nodes are in the given graph.
:param pybel.BELGraph graph: A BEL graph
:param nodes: A list of BEL nodes in the graph
:rtype: Optional[pybel.BELGraph]
"""
nodes = tuple(nodes)
if all(node not in graph for node in nodes):
return
return subgraph(graph, nodes) | [
"def",
"get_subgraph_by_induction",
"(",
"graph",
",",
"nodes",
":",
"Iterable",
"[",
"BaseEntity",
"]",
")",
":",
"nodes",
"=",
"tuple",
"(",
"nodes",
")",
"if",
"all",
"(",
"node",
"not",
"in",
"graph",
"for",
"node",
"in",
"nodes",
")",
":",
"return... | Induce a sub-graph over the given nodes or return None if none of the nodes are in the given graph.
:param pybel.BELGraph graph: A BEL graph
:param nodes: A list of BEL nodes in the graph
:rtype: Optional[pybel.BELGraph] | [
"Induce",
"a",
"sub",
"-",
"graph",
"over",
"the",
"given",
"nodes",
"or",
"return",
"None",
"if",
"none",
"of",
"the",
"nodes",
"are",
"in",
"the",
"given",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/utils.py#L34-L46 | train | 29,559 |
pybel/pybel | src/pybel/struct/mutation/induction_expansion.py | get_multi_causal_upstream | def get_multi_causal_upstream(graph, nbunch: Union[BaseEntity, Iterable[BaseEntity]]):
"""Get the union of all the 2-level deep causal upstream subgraphs from the nbunch.
:param pybel.BELGraph graph: A BEL graph
:param nbunch: A BEL node or list of BEL nodes
:return: A subgraph of the original BEL graph
:rtype: pybel.BELGraph
"""
result = get_upstream_causal_subgraph(graph, nbunch)
expand_upstream_causal(graph, result)
return result | python | def get_multi_causal_upstream(graph, nbunch: Union[BaseEntity, Iterable[BaseEntity]]):
"""Get the union of all the 2-level deep causal upstream subgraphs from the nbunch.
:param pybel.BELGraph graph: A BEL graph
:param nbunch: A BEL node or list of BEL nodes
:return: A subgraph of the original BEL graph
:rtype: pybel.BELGraph
"""
result = get_upstream_causal_subgraph(graph, nbunch)
expand_upstream_causal(graph, result)
return result | [
"def",
"get_multi_causal_upstream",
"(",
"graph",
",",
"nbunch",
":",
"Union",
"[",
"BaseEntity",
",",
"Iterable",
"[",
"BaseEntity",
"]",
"]",
")",
":",
"result",
"=",
"get_upstream_causal_subgraph",
"(",
"graph",
",",
"nbunch",
")",
"expand_upstream_causal",
"... | Get the union of all the 2-level deep causal upstream subgraphs from the nbunch.
:param pybel.BELGraph graph: A BEL graph
:param nbunch: A BEL node or list of BEL nodes
:return: A subgraph of the original BEL graph
:rtype: pybel.BELGraph | [
"Get",
"the",
"union",
"of",
"all",
"the",
"2",
"-",
"level",
"deep",
"causal",
"upstream",
"subgraphs",
"from",
"the",
"nbunch",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction_expansion.py#L25-L35 | train | 29,560 |
pybel/pybel | src/pybel/struct/mutation/induction_expansion.py | get_multi_causal_downstream | def get_multi_causal_downstream(graph, nbunch: Union[BaseEntity, Iterable[BaseEntity]]):
"""Get the union of all of the 2-level deep causal downstream subgraphs from the nbunch.
:param pybel.BELGraph graph: A BEL graph
:param nbunch: A BEL node or list of BEL nodes
:return: A subgraph of the original BEL graph
:rtype: pybel.BELGraph
"""
result = get_downstream_causal_subgraph(graph, nbunch)
expand_downstream_causal(graph, result)
return result | python | def get_multi_causal_downstream(graph, nbunch: Union[BaseEntity, Iterable[BaseEntity]]):
"""Get the union of all of the 2-level deep causal downstream subgraphs from the nbunch.
:param pybel.BELGraph graph: A BEL graph
:param nbunch: A BEL node or list of BEL nodes
:return: A subgraph of the original BEL graph
:rtype: pybel.BELGraph
"""
result = get_downstream_causal_subgraph(graph, nbunch)
expand_downstream_causal(graph, result)
return result | [
"def",
"get_multi_causal_downstream",
"(",
"graph",
",",
"nbunch",
":",
"Union",
"[",
"BaseEntity",
",",
"Iterable",
"[",
"BaseEntity",
"]",
"]",
")",
":",
"result",
"=",
"get_downstream_causal_subgraph",
"(",
"graph",
",",
"nbunch",
")",
"expand_downstream_causal... | Get the union of all of the 2-level deep causal downstream subgraphs from the nbunch.
:param pybel.BELGraph graph: A BEL graph
:param nbunch: A BEL node or list of BEL nodes
:return: A subgraph of the original BEL graph
:rtype: pybel.BELGraph | [
"Get",
"the",
"union",
"of",
"all",
"of",
"the",
"2",
"-",
"level",
"deep",
"causal",
"downstream",
"subgraphs",
"from",
"the",
"nbunch",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction_expansion.py#L39-L49 | train | 29,561 |
pybel/pybel | src/pybel/struct/mutation/induction_expansion.py | get_subgraph_by_second_neighbors | def get_subgraph_by_second_neighbors(graph, nodes: Iterable[BaseEntity], filter_pathologies: bool = False):
"""Get a graph around the neighborhoods of the given nodes and expand to the neighborhood of those nodes.
Returns none if none of the nodes are in the graph.
:param pybel.BELGraph graph: A BEL graph
:param nodes: An iterable of BEL nodes
:param filter_pathologies: Should expansion take place around pathologies?
:return: A BEL graph induced around the neighborhoods of the given nodes
:rtype: Optional[pybel.BELGraph]
"""
result = get_subgraph_by_neighborhood(graph, nodes)
if result is None:
return
expand_all_node_neighborhoods(graph, result, filter_pathologies=filter_pathologies)
return result | python | def get_subgraph_by_second_neighbors(graph, nodes: Iterable[BaseEntity], filter_pathologies: bool = False):
"""Get a graph around the neighborhoods of the given nodes and expand to the neighborhood of those nodes.
Returns none if none of the nodes are in the graph.
:param pybel.BELGraph graph: A BEL graph
:param nodes: An iterable of BEL nodes
:param filter_pathologies: Should expansion take place around pathologies?
:return: A BEL graph induced around the neighborhoods of the given nodes
:rtype: Optional[pybel.BELGraph]
"""
result = get_subgraph_by_neighborhood(graph, nodes)
if result is None:
return
expand_all_node_neighborhoods(graph, result, filter_pathologies=filter_pathologies)
return result | [
"def",
"get_subgraph_by_second_neighbors",
"(",
"graph",
",",
"nodes",
":",
"Iterable",
"[",
"BaseEntity",
"]",
",",
"filter_pathologies",
":",
"bool",
"=",
"False",
")",
":",
"result",
"=",
"get_subgraph_by_neighborhood",
"(",
"graph",
",",
"nodes",
")",
"if",
... | Get a graph around the neighborhoods of the given nodes and expand to the neighborhood of those nodes.
Returns none if none of the nodes are in the graph.
:param pybel.BELGraph graph: A BEL graph
:param nodes: An iterable of BEL nodes
:param filter_pathologies: Should expansion take place around pathologies?
:return: A BEL graph induced around the neighborhoods of the given nodes
:rtype: Optional[pybel.BELGraph] | [
"Get",
"a",
"graph",
"around",
"the",
"neighborhoods",
"of",
"the",
"given",
"nodes",
"and",
"expand",
"to",
"the",
"neighborhood",
"of",
"those",
"nodes",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction_expansion.py#L53-L70 | train | 29,562 |
pybel/pybel | src/pybel/manager/cache_manager.py | _normalize_url | def _normalize_url(graph: BELGraph, keyword: str) -> Optional[str]: # FIXME move to utilities and unit test
"""Normalize a URL for the BEL graph."""
if keyword == BEL_DEFAULT_NAMESPACE and BEL_DEFAULT_NAMESPACE not in graph.namespace_url:
return BEL_DEFAULT_NAMESPACE_URL
return graph.namespace_url.get(keyword) | python | def _normalize_url(graph: BELGraph, keyword: str) -> Optional[str]: # FIXME move to utilities and unit test
"""Normalize a URL for the BEL graph."""
if keyword == BEL_DEFAULT_NAMESPACE and BEL_DEFAULT_NAMESPACE not in graph.namespace_url:
return BEL_DEFAULT_NAMESPACE_URL
return graph.namespace_url.get(keyword) | [
"def",
"_normalize_url",
"(",
"graph",
":",
"BELGraph",
",",
"keyword",
":",
"str",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"# FIXME move to utilities and unit test",
"if",
"keyword",
"==",
"BEL_DEFAULT_NAMESPACE",
"and",
"BEL_DEFAULT_NAMESPACE",
"not",
"in",
... | Normalize a URL for the BEL graph. | [
"Normalize",
"a",
"URL",
"for",
"the",
"BEL",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L108-L113 | train | 29,563 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.drop_namespaces | def drop_namespaces(self):
"""Drop all namespaces."""
self.session.query(NamespaceEntry).delete()
self.session.query(Namespace).delete()
self.session.commit() | python | def drop_namespaces(self):
"""Drop all namespaces."""
self.session.query(NamespaceEntry).delete()
self.session.query(Namespace).delete()
self.session.commit() | [
"def",
"drop_namespaces",
"(",
"self",
")",
":",
"self",
".",
"session",
".",
"query",
"(",
"NamespaceEntry",
")",
".",
"delete",
"(",
")",
"self",
".",
"session",
".",
"query",
"(",
"Namespace",
")",
".",
"delete",
"(",
")",
"self",
".",
"session",
... | Drop all namespaces. | [
"Drop",
"all",
"namespaces",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L131-L135 | train | 29,564 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.drop_namespace_by_url | def drop_namespace_by_url(self, url: str) -> None:
"""Drop the namespace at the given URL.
Won't work if the edge store is in use.
:param url: The URL of the namespace to drop
"""
namespace = self.get_namespace_by_url(url)
self.session.query(NamespaceEntry).filter(NamespaceEntry.namespace == namespace).delete()
self.session.delete(namespace)
self.session.commit() | python | def drop_namespace_by_url(self, url: str) -> None:
"""Drop the namespace at the given URL.
Won't work if the edge store is in use.
:param url: The URL of the namespace to drop
"""
namespace = self.get_namespace_by_url(url)
self.session.query(NamespaceEntry).filter(NamespaceEntry.namespace == namespace).delete()
self.session.delete(namespace)
self.session.commit() | [
"def",
"drop_namespace_by_url",
"(",
"self",
",",
"url",
":",
"str",
")",
"->",
"None",
":",
"namespace",
"=",
"self",
".",
"get_namespace_by_url",
"(",
"url",
")",
"self",
".",
"session",
".",
"query",
"(",
"NamespaceEntry",
")",
".",
"filter",
"(",
"Na... | Drop the namespace at the given URL.
Won't work if the edge store is in use.
:param url: The URL of the namespace to drop | [
"Drop",
"the",
"namespace",
"at",
"the",
"given",
"URL",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L137-L147 | train | 29,565 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.get_namespace_by_url | def get_namespace_by_url(self, url: str) -> Optional[Namespace]:
"""Look up a namespace by url."""
return self.session.query(Namespace).filter(Namespace.url == url).one_or_none() | python | def get_namespace_by_url(self, url: str) -> Optional[Namespace]:
"""Look up a namespace by url."""
return self.session.query(Namespace).filter(Namespace.url == url).one_or_none() | [
"def",
"get_namespace_by_url",
"(",
"self",
",",
"url",
":",
"str",
")",
"->",
"Optional",
"[",
"Namespace",
"]",
":",
"return",
"self",
".",
"session",
".",
"query",
"(",
"Namespace",
")",
".",
"filter",
"(",
"Namespace",
".",
"url",
"==",
"url",
")",... | Look up a namespace by url. | [
"Look",
"up",
"a",
"namespace",
"by",
"url",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L149-L151 | train | 29,566 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.get_namespace_by_keyword_version | def get_namespace_by_keyword_version(self, keyword: str, version: str) -> Optional[Namespace]:
"""Get a namespace with a given keyword and version."""
filt = and_(Namespace.keyword == keyword, Namespace.version == version)
return self.session.query(Namespace).filter(filt).one_or_none() | python | def get_namespace_by_keyword_version(self, keyword: str, version: str) -> Optional[Namespace]:
"""Get a namespace with a given keyword and version."""
filt = and_(Namespace.keyword == keyword, Namespace.version == version)
return self.session.query(Namespace).filter(filt).one_or_none() | [
"def",
"get_namespace_by_keyword_version",
"(",
"self",
",",
"keyword",
":",
"str",
",",
"version",
":",
"str",
")",
"->",
"Optional",
"[",
"Namespace",
"]",
":",
"filt",
"=",
"and_",
"(",
"Namespace",
".",
"keyword",
"==",
"keyword",
",",
"Namespace",
"."... | Get a namespace with a given keyword and version. | [
"Get",
"a",
"namespace",
"with",
"a",
"given",
"keyword",
"and",
"version",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L153-L156 | train | 29,567 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.ensure_default_namespace | def ensure_default_namespace(self) -> Namespace:
"""Get or create the BEL default namespace."""
namespace = self.get_namespace_by_keyword_version(BEL_DEFAULT_NAMESPACE, BEL_DEFAULT_NAMESPACE_VERSION)
if namespace is None:
namespace = Namespace(
name='BEL Default Namespace',
contact='charles.hoyt@scai.fraunhofer.de',
keyword=BEL_DEFAULT_NAMESPACE,
version=BEL_DEFAULT_NAMESPACE_VERSION,
url=BEL_DEFAULT_NAMESPACE_URL,
)
for name in set(chain(pmod_mappings, gmod_mappings, activity_mapping, compartment_mapping)):
entry = NamespaceEntry(name=name, namespace=namespace)
self.session.add(entry)
self.session.add(namespace)
self.session.commit()
return namespace | python | def ensure_default_namespace(self) -> Namespace:
"""Get or create the BEL default namespace."""
namespace = self.get_namespace_by_keyword_version(BEL_DEFAULT_NAMESPACE, BEL_DEFAULT_NAMESPACE_VERSION)
if namespace is None:
namespace = Namespace(
name='BEL Default Namespace',
contact='charles.hoyt@scai.fraunhofer.de',
keyword=BEL_DEFAULT_NAMESPACE,
version=BEL_DEFAULT_NAMESPACE_VERSION,
url=BEL_DEFAULT_NAMESPACE_URL,
)
for name in set(chain(pmod_mappings, gmod_mappings, activity_mapping, compartment_mapping)):
entry = NamespaceEntry(name=name, namespace=namespace)
self.session.add(entry)
self.session.add(namespace)
self.session.commit()
return namespace | [
"def",
"ensure_default_namespace",
"(",
"self",
")",
"->",
"Namespace",
":",
"namespace",
"=",
"self",
".",
"get_namespace_by_keyword_version",
"(",
"BEL_DEFAULT_NAMESPACE",
",",
"BEL_DEFAULT_NAMESPACE_VERSION",
")",
"if",
"namespace",
"is",
"None",
":",
"namespace",
... | Get or create the BEL default namespace. | [
"Get",
"or",
"create",
"the",
"BEL",
"default",
"namespace",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L158-L178 | train | 29,568 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.get_namespace_by_keyword_pattern | def get_namespace_by_keyword_pattern(self, keyword: str, pattern: str) -> Optional[Namespace]:
"""Get a namespace with a given keyword and pattern."""
filt = and_(Namespace.keyword == keyword, Namespace.pattern == pattern)
return self.session.query(Namespace).filter(filt).one_or_none() | python | def get_namespace_by_keyword_pattern(self, keyword: str, pattern: str) -> Optional[Namespace]:
"""Get a namespace with a given keyword and pattern."""
filt = and_(Namespace.keyword == keyword, Namespace.pattern == pattern)
return self.session.query(Namespace).filter(filt).one_or_none() | [
"def",
"get_namespace_by_keyword_pattern",
"(",
"self",
",",
"keyword",
":",
"str",
",",
"pattern",
":",
"str",
")",
"->",
"Optional",
"[",
"Namespace",
"]",
":",
"filt",
"=",
"and_",
"(",
"Namespace",
".",
"keyword",
"==",
"keyword",
",",
"Namespace",
"."... | Get a namespace with a given keyword and pattern. | [
"Get",
"a",
"namespace",
"with",
"a",
"given",
"keyword",
"and",
"pattern",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L223-L226 | train | 29,569 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.ensure_regex_namespace | def ensure_regex_namespace(self, keyword: str, pattern: str) -> Namespace:
"""Get or create a regular expression namespace.
:param keyword: The keyword of a regular expression namespace
:param pattern: The pattern for a regular expression namespace
"""
if pattern is None:
raise ValueError('cannot have null pattern')
namespace = self.get_namespace_by_keyword_pattern(keyword, pattern)
if namespace is None:
log.info('creating regex namespace: %s:%s', keyword, pattern)
namespace = Namespace(
keyword=keyword,
pattern=pattern
)
self.session.add(namespace)
self.session.commit()
return namespace | python | def ensure_regex_namespace(self, keyword: str, pattern: str) -> Namespace:
"""Get or create a regular expression namespace.
:param keyword: The keyword of a regular expression namespace
:param pattern: The pattern for a regular expression namespace
"""
if pattern is None:
raise ValueError('cannot have null pattern')
namespace = self.get_namespace_by_keyword_pattern(keyword, pattern)
if namespace is None:
log.info('creating regex namespace: %s:%s', keyword, pattern)
namespace = Namespace(
keyword=keyword,
pattern=pattern
)
self.session.add(namespace)
self.session.commit()
return namespace | [
"def",
"ensure_regex_namespace",
"(",
"self",
",",
"keyword",
":",
"str",
",",
"pattern",
":",
"str",
")",
"->",
"Namespace",
":",
"if",
"pattern",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'cannot have null pattern'",
")",
"namespace",
"=",
"self",
".... | Get or create a regular expression namespace.
:param keyword: The keyword of a regular expression namespace
:param pattern: The pattern for a regular expression namespace | [
"Get",
"or",
"create",
"a",
"regular",
"expression",
"namespace",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L228-L248 | train | 29,570 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.get_namespace_entry | def get_namespace_entry(self, url: str, name: str) -> Optional[NamespaceEntry]:
"""Get a given NamespaceEntry object.
:param url: The url of the namespace source
:param name: The value of the namespace from the given url's document
"""
entry_filter = and_(Namespace.url == url, NamespaceEntry.name == name)
result = self.session.query(NamespaceEntry).join(Namespace).filter(entry_filter).all()
if 0 == len(result):
return
if 1 < len(result):
log.warning('result for get_namespace_entry is too long. Returning first of %s', [str(r) for r in result])
return result[0] | python | def get_namespace_entry(self, url: str, name: str) -> Optional[NamespaceEntry]:
"""Get a given NamespaceEntry object.
:param url: The url of the namespace source
:param name: The value of the namespace from the given url's document
"""
entry_filter = and_(Namespace.url == url, NamespaceEntry.name == name)
result = self.session.query(NamespaceEntry).join(Namespace).filter(entry_filter).all()
if 0 == len(result):
return
if 1 < len(result):
log.warning('result for get_namespace_entry is too long. Returning first of %s', [str(r) for r in result])
return result[0] | [
"def",
"get_namespace_entry",
"(",
"self",
",",
"url",
":",
"str",
",",
"name",
":",
"str",
")",
"->",
"Optional",
"[",
"NamespaceEntry",
"]",
":",
"entry_filter",
"=",
"and_",
"(",
"Namespace",
".",
"url",
"==",
"url",
",",
"NamespaceEntry",
".",
"name"... | Get a given NamespaceEntry object.
:param url: The url of the namespace source
:param name: The value of the namespace from the given url's document | [
"Get",
"a",
"given",
"NamespaceEntry",
"object",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L250-L265 | train | 29,571 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.get_or_create_regex_namespace_entry | def get_or_create_regex_namespace_entry(self, namespace: str, pattern: str, name: str) -> NamespaceEntry:
"""Get a namespace entry from a regular expression.
Need to commit after!
:param namespace: The name of the namespace
:param pattern: The regular expression pattern for the namespace
:param name: The entry to get
"""
namespace = self.ensure_regex_namespace(namespace, pattern)
n_filter = and_(Namespace.pattern == pattern, NamespaceEntry.name == name)
name_model = self.session.query(NamespaceEntry).join(Namespace).filter(n_filter).one_or_none()
if name_model is None:
name_model = NamespaceEntry(
namespace=namespace,
name=name
)
self.session.add(name_model)
return name_model | python | def get_or_create_regex_namespace_entry(self, namespace: str, pattern: str, name: str) -> NamespaceEntry:
"""Get a namespace entry from a regular expression.
Need to commit after!
:param namespace: The name of the namespace
:param pattern: The regular expression pattern for the namespace
:param name: The entry to get
"""
namespace = self.ensure_regex_namespace(namespace, pattern)
n_filter = and_(Namespace.pattern == pattern, NamespaceEntry.name == name)
name_model = self.session.query(NamespaceEntry).join(Namespace).filter(n_filter).one_or_none()
if name_model is None:
name_model = NamespaceEntry(
namespace=namespace,
name=name
)
self.session.add(name_model)
return name_model | [
"def",
"get_or_create_regex_namespace_entry",
"(",
"self",
",",
"namespace",
":",
"str",
",",
"pattern",
":",
"str",
",",
"name",
":",
"str",
")",
"->",
"NamespaceEntry",
":",
"namespace",
"=",
"self",
".",
"ensure_regex_namespace",
"(",
"namespace",
",",
"pat... | Get a namespace entry from a regular expression.
Need to commit after!
:param namespace: The name of the namespace
:param pattern: The regular expression pattern for the namespace
:param name: The entry to get | [
"Get",
"a",
"namespace",
"entry",
"from",
"a",
"regular",
"expression",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L272-L294 | train | 29,572 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.list_annotations | def list_annotations(self) -> List[Namespace]:
"""List all annotations."""
return self.session.query(Namespace).filter(Namespace.is_annotation).all() | python | def list_annotations(self) -> List[Namespace]:
"""List all annotations."""
return self.session.query(Namespace).filter(Namespace.is_annotation).all() | [
"def",
"list_annotations",
"(",
"self",
")",
"->",
"List",
"[",
"Namespace",
"]",
":",
"return",
"self",
".",
"session",
".",
"query",
"(",
"Namespace",
")",
".",
"filter",
"(",
"Namespace",
".",
"is_annotation",
")",
".",
"all",
"(",
")"
] | List all annotations. | [
"List",
"all",
"annotations",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L296-L298 | train | 29,573 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.count_annotations | def count_annotations(self) -> int:
"""Count the number of annotations in the database."""
return self.session.query(Namespace).filter(Namespace.is_annotation).count() | python | def count_annotations(self) -> int:
"""Count the number of annotations in the database."""
return self.session.query(Namespace).filter(Namespace.is_annotation).count() | [
"def",
"count_annotations",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"session",
".",
"query",
"(",
"Namespace",
")",
".",
"filter",
"(",
"Namespace",
".",
"is_annotation",
")",
".",
"count",
"(",
")"
] | Count the number of annotations in the database. | [
"Count",
"the",
"number",
"of",
"annotations",
"in",
"the",
"database",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L300-L302 | train | 29,574 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.count_annotation_entries | def count_annotation_entries(self) -> int:
"""Count the number of annotation entries in the database."""
return self.session.query(NamespaceEntry).filter(NamespaceEntry.is_annotation).count() | python | def count_annotation_entries(self) -> int:
"""Count the number of annotation entries in the database."""
return self.session.query(NamespaceEntry).filter(NamespaceEntry.is_annotation).count() | [
"def",
"count_annotation_entries",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"session",
".",
"query",
"(",
"NamespaceEntry",
")",
".",
"filter",
"(",
"NamespaceEntry",
".",
"is_annotation",
")",
".",
"count",
"(",
")"
] | Count the number of annotation entries in the database. | [
"Count",
"the",
"number",
"of",
"annotation",
"entries",
"in",
"the",
"database",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L304-L306 | train | 29,575 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.get_annotation_entry_names | def get_annotation_entry_names(self, url: str) -> Set[str]:
"""Return a dict of annotations and their labels for the given annotation file.
:param url: the location of the annotation file
"""
annotation = self.get_or_create_annotation(url)
return {
x.name
for x in self.session.query(NamespaceEntry.name).filter(NamespaceEntry.namespace == annotation)
} | python | def get_annotation_entry_names(self, url: str) -> Set[str]:
"""Return a dict of annotations and their labels for the given annotation file.
:param url: the location of the annotation file
"""
annotation = self.get_or_create_annotation(url)
return {
x.name
for x in self.session.query(NamespaceEntry.name).filter(NamespaceEntry.namespace == annotation)
} | [
"def",
"get_annotation_entry_names",
"(",
"self",
",",
"url",
":",
"str",
")",
"->",
"Set",
"[",
"str",
"]",
":",
"annotation",
"=",
"self",
".",
"get_or_create_annotation",
"(",
"url",
")",
"return",
"{",
"x",
".",
"name",
"for",
"x",
"in",
"self",
".... | Return a dict of annotations and their labels for the given annotation file.
:param url: the location of the annotation file | [
"Return",
"a",
"dict",
"of",
"annotations",
"and",
"their",
"labels",
"for",
"the",
"given",
"annotation",
"file",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L341-L350 | train | 29,576 |
pybel/pybel | src/pybel/manager/cache_manager.py | NamespaceManager.get_annotation_entries_by_names | def get_annotation_entries_by_names(self, url: str, names: Iterable[str]) -> List[NamespaceEntry]:
"""Get annotation entries by URL and names.
:param url: The url of the annotation source
:param names: The names of the annotation entries from the given url's document
"""
annotation_filter = and_(Namespace.url == url, NamespaceEntry.name.in_(names))
return self.session.query(NamespaceEntry).join(Namespace).filter(annotation_filter).all() | python | def get_annotation_entries_by_names(self, url: str, names: Iterable[str]) -> List[NamespaceEntry]:
"""Get annotation entries by URL and names.
:param url: The url of the annotation source
:param names: The names of the annotation entries from the given url's document
"""
annotation_filter = and_(Namespace.url == url, NamespaceEntry.name.in_(names))
return self.session.query(NamespaceEntry).join(Namespace).filter(annotation_filter).all() | [
"def",
"get_annotation_entries_by_names",
"(",
"self",
",",
"url",
":",
"str",
",",
"names",
":",
"Iterable",
"[",
"str",
"]",
")",
"->",
"List",
"[",
"NamespaceEntry",
"]",
":",
"annotation_filter",
"=",
"and_",
"(",
"Namespace",
".",
"url",
"==",
"url",
... | Get annotation entries by URL and names.
:param url: The url of the annotation source
:param names: The names of the annotation entries from the given url's document | [
"Get",
"annotation",
"entries",
"by",
"URL",
"and",
"names",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L357-L364 | train | 29,577 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.drop_networks | def drop_networks(self) -> None:
"""Drop all networks."""
for network in self.session.query(Network).all():
self.drop_network(network) | python | def drop_networks(self) -> None:
"""Drop all networks."""
for network in self.session.query(Network).all():
self.drop_network(network) | [
"def",
"drop_networks",
"(",
"self",
")",
"->",
"None",
":",
"for",
"network",
"in",
"self",
".",
"session",
".",
"query",
"(",
"Network",
")",
".",
"all",
"(",
")",
":",
"self",
".",
"drop_network",
"(",
"network",
")"
] | Drop all networks. | [
"Drop",
"all",
"networks",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L403-L406 | train | 29,578 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.drop_network_by_id | def drop_network_by_id(self, network_id: int) -> None:
"""Drop a network by its database identifier."""
network = self.session.query(Network).get(network_id)
self.drop_network(network) | python | def drop_network_by_id(self, network_id: int) -> None:
"""Drop a network by its database identifier."""
network = self.session.query(Network).get(network_id)
self.drop_network(network) | [
"def",
"drop_network_by_id",
"(",
"self",
",",
"network_id",
":",
"int",
")",
"->",
"None",
":",
"network",
"=",
"self",
".",
"session",
".",
"query",
"(",
"Network",
")",
".",
"get",
"(",
"network_id",
")",
"self",
".",
"drop_network",
"(",
"network",
... | Drop a network by its database identifier. | [
"Drop",
"a",
"network",
"by",
"its",
"database",
"identifier",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L408-L411 | train | 29,579 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.drop_network | def drop_network(self, network: Network) -> None:
"""Drop a network, while also cleaning up any edges that are no longer part of any network."""
# get the IDs of the edges that will be orphaned by deleting this network
# FIXME: this list could be a problem if it becomes very large; possible optimization is a temporary table in DB
edge_ids = [result.edge_id for result in self.query_singleton_edges_from_network(network)]
# delete the network-to-node mappings for this network
self.session.query(network_node).filter(network_node.c.network_id == network.id).delete(
synchronize_session=False)
# delete the edge-to-property mappings for the to-be-orphaned edges
self.session.query(edge_property).filter(edge_property.c.edge_id.in_(edge_ids)).delete(
synchronize_session=False)
# delete the edge-to-annotation mappings for the to-be-orphaned edges
self.session.query(edge_annotation).filter(edge_annotation.c.edge_id.in_(edge_ids)).delete(
synchronize_session=False)
# delete the edge-to-network mappings for this network
self.session.query(network_edge).filter(network_edge.c.network_id == network.id).delete(
synchronize_session=False)
# delete the now-orphaned edges
self.session.query(Edge).filter(Edge.id.in_(edge_ids)).delete(synchronize_session=False)
# delete the network
self.session.query(Network).filter(Network.id == network.id).delete(synchronize_session=False)
# commit it!
self.session.commit() | python | def drop_network(self, network: Network) -> None:
"""Drop a network, while also cleaning up any edges that are no longer part of any network."""
# get the IDs of the edges that will be orphaned by deleting this network
# FIXME: this list could be a problem if it becomes very large; possible optimization is a temporary table in DB
edge_ids = [result.edge_id for result in self.query_singleton_edges_from_network(network)]
# delete the network-to-node mappings for this network
self.session.query(network_node).filter(network_node.c.network_id == network.id).delete(
synchronize_session=False)
# delete the edge-to-property mappings for the to-be-orphaned edges
self.session.query(edge_property).filter(edge_property.c.edge_id.in_(edge_ids)).delete(
synchronize_session=False)
# delete the edge-to-annotation mappings for the to-be-orphaned edges
self.session.query(edge_annotation).filter(edge_annotation.c.edge_id.in_(edge_ids)).delete(
synchronize_session=False)
# delete the edge-to-network mappings for this network
self.session.query(network_edge).filter(network_edge.c.network_id == network.id).delete(
synchronize_session=False)
# delete the now-orphaned edges
self.session.query(Edge).filter(Edge.id.in_(edge_ids)).delete(synchronize_session=False)
# delete the network
self.session.query(Network).filter(Network.id == network.id).delete(synchronize_session=False)
# commit it!
self.session.commit() | [
"def",
"drop_network",
"(",
"self",
",",
"network",
":",
"Network",
")",
"->",
"None",
":",
"# get the IDs of the edges that will be orphaned by deleting this network",
"# FIXME: this list could be a problem if it becomes very large; possible optimization is a temporary table in DB",
"ed... | Drop a network, while also cleaning up any edges that are no longer part of any network. | [
"Drop",
"a",
"network",
"while",
"also",
"cleaning",
"up",
"any",
"edges",
"that",
"are",
"no",
"longer",
"part",
"of",
"any",
"network",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L413-L442 | train | 29,580 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.query_singleton_edges_from_network | def query_singleton_edges_from_network(self, network: Network) -> sqlalchemy.orm.query.Query:
"""Return a query selecting all edge ids that only belong to the given network."""
ne1 = aliased(network_edge, name='ne1')
ne2 = aliased(network_edge, name='ne2')
singleton_edge_ids_for_network = (
self.session
.query(ne1.c.edge_id)
.outerjoin(ne2, and_(
ne1.c.edge_id == ne2.c.edge_id,
ne1.c.network_id != ne2.c.network_id
))
.filter(and_(
ne1.c.network_id == network.id,
ne2.c.edge_id == None # noqa: E711
))
)
return singleton_edge_ids_for_network | python | def query_singleton_edges_from_network(self, network: Network) -> sqlalchemy.orm.query.Query:
"""Return a query selecting all edge ids that only belong to the given network."""
ne1 = aliased(network_edge, name='ne1')
ne2 = aliased(network_edge, name='ne2')
singleton_edge_ids_for_network = (
self.session
.query(ne1.c.edge_id)
.outerjoin(ne2, and_(
ne1.c.edge_id == ne2.c.edge_id,
ne1.c.network_id != ne2.c.network_id
))
.filter(and_(
ne1.c.network_id == network.id,
ne2.c.edge_id == None # noqa: E711
))
)
return singleton_edge_ids_for_network | [
"def",
"query_singleton_edges_from_network",
"(",
"self",
",",
"network",
":",
"Network",
")",
"->",
"sqlalchemy",
".",
"orm",
".",
"query",
".",
"Query",
":",
"ne1",
"=",
"aliased",
"(",
"network_edge",
",",
"name",
"=",
"'ne1'",
")",
"ne2",
"=",
"aliased... | Return a query selecting all edge ids that only belong to the given network. | [
"Return",
"a",
"query",
"selecting",
"all",
"edge",
"ids",
"that",
"only",
"belong",
"to",
"the",
"given",
"network",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L444-L460 | train | 29,581 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.get_network_versions | def get_network_versions(self, name: str) -> Set[str]:
"""Return all of the versions of a network with the given name."""
return {
version
for version, in self.session.query(Network.version).filter(Network.name == name).all()
} | python | def get_network_versions(self, name: str) -> Set[str]:
"""Return all of the versions of a network with the given name."""
return {
version
for version, in self.session.query(Network.version).filter(Network.name == name).all()
} | [
"def",
"get_network_versions",
"(",
"self",
",",
"name",
":",
"str",
")",
"->",
"Set",
"[",
"str",
"]",
":",
"return",
"{",
"version",
"for",
"version",
",",
"in",
"self",
".",
"session",
".",
"query",
"(",
"Network",
".",
"version",
")",
".",
"filte... | Return all of the versions of a network with the given name. | [
"Return",
"all",
"of",
"the",
"versions",
"of",
"a",
"network",
"with",
"the",
"given",
"name",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L462-L467 | train | 29,582 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.get_network_by_name_version | def get_network_by_name_version(self, name: str, version: str) -> Optional[Network]:
"""Load the network with the given name and version if it exists."""
name_version_filter = and_(Network.name == name, Network.version == version)
network = self.session.query(Network).filter(name_version_filter).one_or_none()
return network | python | def get_network_by_name_version(self, name: str, version: str) -> Optional[Network]:
"""Load the network with the given name and version if it exists."""
name_version_filter = and_(Network.name == name, Network.version == version)
network = self.session.query(Network).filter(name_version_filter).one_or_none()
return network | [
"def",
"get_network_by_name_version",
"(",
"self",
",",
"name",
":",
"str",
",",
"version",
":",
"str",
")",
"->",
"Optional",
"[",
"Network",
"]",
":",
"name_version_filter",
"=",
"and_",
"(",
"Network",
".",
"name",
"==",
"name",
",",
"Network",
".",
"... | Load the network with the given name and version if it exists. | [
"Load",
"the",
"network",
"with",
"the",
"given",
"name",
"and",
"version",
"if",
"it",
"exists",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L469-L473 | train | 29,583 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.get_graph_by_name_version | def get_graph_by_name_version(self, name: str, version: str) -> Optional[BELGraph]:
"""Load the BEL graph with the given name, or allows for specification of version."""
network = self.get_network_by_name_version(name, version)
if network is None:
return
return network.as_bel() | python | def get_graph_by_name_version(self, name: str, version: str) -> Optional[BELGraph]:
"""Load the BEL graph with the given name, or allows for specification of version."""
network = self.get_network_by_name_version(name, version)
if network is None:
return
return network.as_bel() | [
"def",
"get_graph_by_name_version",
"(",
"self",
",",
"name",
":",
"str",
",",
"version",
":",
"str",
")",
"->",
"Optional",
"[",
"BELGraph",
"]",
":",
"network",
"=",
"self",
".",
"get_network_by_name_version",
"(",
"name",
",",
"version",
")",
"if",
"net... | Load the BEL graph with the given name, or allows for specification of version. | [
"Load",
"the",
"BEL",
"graph",
"with",
"the",
"given",
"name",
"or",
"allows",
"for",
"specification",
"of",
"version",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L475-L482 | train | 29,584 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.get_networks_by_name | def get_networks_by_name(self, name: str) -> List[Network]:
"""Get all networks with the given name. Useful for getting all versions of a given network."""
return self.session.query(Network).filter(Network.name.like(name)).all() | python | def get_networks_by_name(self, name: str) -> List[Network]:
"""Get all networks with the given name. Useful for getting all versions of a given network."""
return self.session.query(Network).filter(Network.name.like(name)).all() | [
"def",
"get_networks_by_name",
"(",
"self",
",",
"name",
":",
"str",
")",
"->",
"List",
"[",
"Network",
"]",
":",
"return",
"self",
".",
"session",
".",
"query",
"(",
"Network",
")",
".",
"filter",
"(",
"Network",
".",
"name",
".",
"like",
"(",
"name... | Get all networks with the given name. Useful for getting all versions of a given network. | [
"Get",
"all",
"networks",
"with",
"the",
"given",
"name",
".",
"Useful",
"for",
"getting",
"all",
"versions",
"of",
"a",
"given",
"network",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L484-L486 | train | 29,585 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.get_most_recent_network_by_name | def get_most_recent_network_by_name(self, name: str) -> Optional[Network]:
"""Get the most recently created network with the given name."""
return self.session.query(Network).filter(Network.name == name).order_by(Network.created.desc()).first() | python | def get_most_recent_network_by_name(self, name: str) -> Optional[Network]:
"""Get the most recently created network with the given name."""
return self.session.query(Network).filter(Network.name == name).order_by(Network.created.desc()).first() | [
"def",
"get_most_recent_network_by_name",
"(",
"self",
",",
"name",
":",
"str",
")",
"->",
"Optional",
"[",
"Network",
"]",
":",
"return",
"self",
".",
"session",
".",
"query",
"(",
"Network",
")",
".",
"filter",
"(",
"Network",
".",
"name",
"==",
"name"... | Get the most recently created network with the given name. | [
"Get",
"the",
"most",
"recently",
"created",
"network",
"with",
"the",
"given",
"name",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L488-L490 | train | 29,586 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.get_network_by_id | def get_network_by_id(self, network_id: int) -> Network:
"""Get a network from the database by its identifier."""
return self.session.query(Network).get(network_id) | python | def get_network_by_id(self, network_id: int) -> Network:
"""Get a network from the database by its identifier."""
return self.session.query(Network).get(network_id) | [
"def",
"get_network_by_id",
"(",
"self",
",",
"network_id",
":",
"int",
")",
"->",
"Network",
":",
"return",
"self",
".",
"session",
".",
"query",
"(",
"Network",
")",
".",
"get",
"(",
"network_id",
")"
] | Get a network from the database by its identifier. | [
"Get",
"a",
"network",
"from",
"the",
"database",
"by",
"its",
"identifier",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L501-L503 | train | 29,587 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.get_graph_by_id | def get_graph_by_id(self, network_id: int) -> BELGraph:
"""Get a network from the database by its identifier and converts it to a BEL graph."""
network = self.get_network_by_id(network_id)
log.debug('converting network [id=%d] %s to bel graph', network_id, network)
return network.as_bel() | python | def get_graph_by_id(self, network_id: int) -> BELGraph:
"""Get a network from the database by its identifier and converts it to a BEL graph."""
network = self.get_network_by_id(network_id)
log.debug('converting network [id=%d] %s to bel graph', network_id, network)
return network.as_bel() | [
"def",
"get_graph_by_id",
"(",
"self",
",",
"network_id",
":",
"int",
")",
"->",
"BELGraph",
":",
"network",
"=",
"self",
".",
"get_network_by_id",
"(",
"network_id",
")",
"log",
".",
"debug",
"(",
"'converting network [id=%d] %s to bel graph'",
",",
"network_id",... | Get a network from the database by its identifier and converts it to a BEL graph. | [
"Get",
"a",
"network",
"from",
"the",
"database",
"by",
"its",
"identifier",
"and",
"converts",
"it",
"to",
"a",
"BEL",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L505-L509 | train | 29,588 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.get_networks_by_ids | def get_networks_by_ids(self, network_ids: Iterable[int]) -> List[Network]:
"""Get a list of networks with the given identifiers.
Note: order is not necessarily preserved.
"""
log.debug('getting networks by identifiers: %s', network_ids)
return self.session.query(Network).filter(Network.id_in(network_ids)).all() | python | def get_networks_by_ids(self, network_ids: Iterable[int]) -> List[Network]:
"""Get a list of networks with the given identifiers.
Note: order is not necessarily preserved.
"""
log.debug('getting networks by identifiers: %s', network_ids)
return self.session.query(Network).filter(Network.id_in(network_ids)).all() | [
"def",
"get_networks_by_ids",
"(",
"self",
",",
"network_ids",
":",
"Iterable",
"[",
"int",
"]",
")",
"->",
"List",
"[",
"Network",
"]",
":",
"log",
".",
"debug",
"(",
"'getting networks by identifiers: %s'",
",",
"network_ids",
")",
"return",
"self",
".",
"... | Get a list of networks with the given identifiers.
Note: order is not necessarily preserved. | [
"Get",
"a",
"list",
"of",
"networks",
"with",
"the",
"given",
"identifiers",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L511-L517 | train | 29,589 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.get_graphs_by_ids | def get_graphs_by_ids(self, network_ids: Iterable[int]) -> List[BELGraph]:
"""Get a list of networks with the given identifiers and converts to BEL graphs."""
rv = [
self.get_graph_by_id(network_id)
for network_id in network_ids
]
log.debug('returning graphs for network identifiers: %s', network_ids)
return rv | python | def get_graphs_by_ids(self, network_ids: Iterable[int]) -> List[BELGraph]:
"""Get a list of networks with the given identifiers and converts to BEL graphs."""
rv = [
self.get_graph_by_id(network_id)
for network_id in network_ids
]
log.debug('returning graphs for network identifiers: %s', network_ids)
return rv | [
"def",
"get_graphs_by_ids",
"(",
"self",
",",
"network_ids",
":",
"Iterable",
"[",
"int",
"]",
")",
"->",
"List",
"[",
"BELGraph",
"]",
":",
"rv",
"=",
"[",
"self",
".",
"get_graph_by_id",
"(",
"network_id",
")",
"for",
"network_id",
"in",
"network_ids",
... | Get a list of networks with the given identifiers and converts to BEL graphs. | [
"Get",
"a",
"list",
"of",
"networks",
"with",
"the",
"given",
"identifiers",
"and",
"converts",
"to",
"BEL",
"graphs",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L519-L526 | train | 29,590 |
pybel/pybel | src/pybel/manager/cache_manager.py | NetworkManager.get_graph_by_ids | def get_graph_by_ids(self, network_ids: List[int]) -> BELGraph:
"""Get a combine BEL Graph from a list of network identifiers."""
if len(network_ids) == 1:
return self.get_graph_by_id(network_ids[0])
log.debug('getting graph by identifiers: %s', network_ids)
graphs = self.get_graphs_by_ids(network_ids)
log.debug('getting union of graphs: %s', network_ids)
rv = union(graphs)
return rv | python | def get_graph_by_ids(self, network_ids: List[int]) -> BELGraph:
"""Get a combine BEL Graph from a list of network identifiers."""
if len(network_ids) == 1:
return self.get_graph_by_id(network_ids[0])
log.debug('getting graph by identifiers: %s', network_ids)
graphs = self.get_graphs_by_ids(network_ids)
log.debug('getting union of graphs: %s', network_ids)
rv = union(graphs)
return rv | [
"def",
"get_graph_by_ids",
"(",
"self",
",",
"network_ids",
":",
"List",
"[",
"int",
"]",
")",
"->",
"BELGraph",
":",
"if",
"len",
"(",
"network_ids",
")",
"==",
"1",
":",
"return",
"self",
".",
"get_graph_by_id",
"(",
"network_ids",
"[",
"0",
"]",
")"... | Get a combine BEL Graph from a list of network identifiers. | [
"Get",
"a",
"combine",
"BEL",
"Graph",
"from",
"a",
"list",
"of",
"network",
"identifiers",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L528-L539 | train | 29,591 |
pybel/pybel | src/pybel/manager/cache_manager.py | InsertManager.insert_graph | def insert_graph(self, graph: BELGraph, store_parts: bool = True, use_tqdm: bool = False) -> Network:
"""Insert a graph in the database and returns the corresponding Network model.
:raises: pybel.resources.exc.ResourceError
"""
if not graph.name:
raise ValueError('Can not upload a graph without a name')
if not graph.version:
raise ValueError('Can not upload a graph without a version')
log.debug('inserting %s v%s', graph.name, graph.version)
t = time.time()
self.ensure_default_namespace()
namespace_urls = graph.namespace_url.values()
if use_tqdm:
namespace_urls = tqdm(namespace_urls, desc='namespaces')
for namespace_url in namespace_urls:
if namespace_url not in graph.uncached_namespaces:
self.get_or_create_namespace(namespace_url)
for keyword, pattern in graph.namespace_pattern.items():
self.ensure_regex_namespace(keyword, pattern)
annotation_urls = graph.annotation_url.values()
if use_tqdm:
annotation_urls = tqdm(annotation_urls, desc='annotations')
for annotation_url in annotation_urls:
self.get_or_create_annotation(annotation_url)
network = Network(**{
key: value
for key, value in graph.document.items()
if key in METADATA_INSERT_KEYS
})
network.store_bel(graph)
if store_parts:
network.nodes, network.edges = self._store_graph_parts(graph, use_tqdm=use_tqdm)
self.session.add(network)
self.session.commit()
log.info('inserted %s v%s in %.2f seconds', graph.name, graph.version, time.time() - t)
return network | python | def insert_graph(self, graph: BELGraph, store_parts: bool = True, use_tqdm: bool = False) -> Network:
"""Insert a graph in the database and returns the corresponding Network model.
:raises: pybel.resources.exc.ResourceError
"""
if not graph.name:
raise ValueError('Can not upload a graph without a name')
if not graph.version:
raise ValueError('Can not upload a graph without a version')
log.debug('inserting %s v%s', graph.name, graph.version)
t = time.time()
self.ensure_default_namespace()
namespace_urls = graph.namespace_url.values()
if use_tqdm:
namespace_urls = tqdm(namespace_urls, desc='namespaces')
for namespace_url in namespace_urls:
if namespace_url not in graph.uncached_namespaces:
self.get_or_create_namespace(namespace_url)
for keyword, pattern in graph.namespace_pattern.items():
self.ensure_regex_namespace(keyword, pattern)
annotation_urls = graph.annotation_url.values()
if use_tqdm:
annotation_urls = tqdm(annotation_urls, desc='annotations')
for annotation_url in annotation_urls:
self.get_or_create_annotation(annotation_url)
network = Network(**{
key: value
for key, value in graph.document.items()
if key in METADATA_INSERT_KEYS
})
network.store_bel(graph)
if store_parts:
network.nodes, network.edges = self._store_graph_parts(graph, use_tqdm=use_tqdm)
self.session.add(network)
self.session.commit()
log.info('inserted %s v%s in %.2f seconds', graph.name, graph.version, time.time() - t)
return network | [
"def",
"insert_graph",
"(",
"self",
",",
"graph",
":",
"BELGraph",
",",
"store_parts",
":",
"bool",
"=",
"True",
",",
"use_tqdm",
":",
"bool",
"=",
"False",
")",
"->",
"Network",
":",
"if",
"not",
"graph",
".",
"name",
":",
"raise",
"ValueError",
"(",
... | Insert a graph in the database and returns the corresponding Network model.
:raises: pybel.resources.exc.ResourceError | [
"Insert",
"a",
"graph",
"in",
"the",
"database",
"and",
"returns",
"the",
"corresponding",
"Network",
"model",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L557-L608 | train | 29,592 |
pybel/pybel | src/pybel/manager/cache_manager.py | InsertManager._store_graph_parts | def _store_graph_parts(self, graph: BELGraph, use_tqdm: bool = False) -> Tuple[List[Node], List[Edge]]:
"""Store the given graph into the edge store.
:raises: pybel.resources.exc.ResourceError
:raises: EdgeAddError
"""
log.debug('inserting %s into edge store', graph)
log.debug('building node models')
node_model_build_start = time.time()
nodes = list(graph)
if use_tqdm:
nodes = tqdm(nodes, total=graph.number_of_nodes(), desc='nodes')
node_model = {}
for node in nodes:
namespace = node.get(NAMESPACE)
if graph.skip_storing_namespace(namespace):
continue # already know this node won't be cached
node_object = self.get_or_create_node(graph, node)
if node_object is None:
log.warning('can not add node %s', node)
continue
node_model[node] = node_object
node_models = list(node_model.values())
log.debug('built %d node models in %.2f seconds', len(node_models), time.time() - node_model_build_start)
node_model_commit_start = time.time()
self.session.add_all(node_models)
self.session.commit()
log.debug('stored %d node models in %.2f seconds', len(node_models), time.time() - node_model_commit_start)
log.debug('building edge models')
edge_model_build_start = time.time()
edges = graph.edges(keys=True, data=True)
if use_tqdm:
edges = tqdm(edges, total=graph.number_of_edges(), desc='edges')
edge_models = list(self._get_edge_models(graph, node_model, edges))
log.debug('built %d edge models in %.2f seconds', len(edge_models), time.time() - edge_model_build_start)
edge_model_commit_start = time.time()
self.session.add_all(edge_models)
self.session.commit()
log.debug('stored %d edge models in %.2f seconds', len(edge_models), time.time() - edge_model_commit_start)
return node_models, edge_models | python | def _store_graph_parts(self, graph: BELGraph, use_tqdm: bool = False) -> Tuple[List[Node], List[Edge]]:
"""Store the given graph into the edge store.
:raises: pybel.resources.exc.ResourceError
:raises: EdgeAddError
"""
log.debug('inserting %s into edge store', graph)
log.debug('building node models')
node_model_build_start = time.time()
nodes = list(graph)
if use_tqdm:
nodes = tqdm(nodes, total=graph.number_of_nodes(), desc='nodes')
node_model = {}
for node in nodes:
namespace = node.get(NAMESPACE)
if graph.skip_storing_namespace(namespace):
continue # already know this node won't be cached
node_object = self.get_or_create_node(graph, node)
if node_object is None:
log.warning('can not add node %s', node)
continue
node_model[node] = node_object
node_models = list(node_model.values())
log.debug('built %d node models in %.2f seconds', len(node_models), time.time() - node_model_build_start)
node_model_commit_start = time.time()
self.session.add_all(node_models)
self.session.commit()
log.debug('stored %d node models in %.2f seconds', len(node_models), time.time() - node_model_commit_start)
log.debug('building edge models')
edge_model_build_start = time.time()
edges = graph.edges(keys=True, data=True)
if use_tqdm:
edges = tqdm(edges, total=graph.number_of_edges(), desc='edges')
edge_models = list(self._get_edge_models(graph, node_model, edges))
log.debug('built %d edge models in %.2f seconds', len(edge_models), time.time() - edge_model_build_start)
edge_model_commit_start = time.time()
self.session.add_all(edge_models)
self.session.commit()
log.debug('stored %d edge models in %.2f seconds', len(edge_models), time.time() - edge_model_commit_start)
return node_models, edge_models | [
"def",
"_store_graph_parts",
"(",
"self",
",",
"graph",
":",
"BELGraph",
",",
"use_tqdm",
":",
"bool",
"=",
"False",
")",
"->",
"Tuple",
"[",
"List",
"[",
"Node",
"]",
",",
"List",
"[",
"Edge",
"]",
"]",
":",
"log",
".",
"debug",
"(",
"'inserting %s ... | Store the given graph into the edge store.
:raises: pybel.resources.exc.ResourceError
:raises: EdgeAddError | [
"Store",
"the",
"given",
"graph",
"into",
"the",
"edge",
"store",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L610-L663 | train | 29,593 |
pybel/pybel | src/pybel/manager/cache_manager.py | InsertManager._get_annotation_entries_from_data | def _get_annotation_entries_from_data(self, graph: BELGraph, data: EdgeData) -> Optional[List[NamespaceEntry]]:
"""Get the annotation entries from an edge data dictionary."""
annotations_dict = data.get(ANNOTATIONS)
if annotations_dict is not None:
return [
entry
for url, names in self._iter_from_annotations_dict(graph, annotations_dict=annotations_dict)
for entry in self.get_annotation_entries_by_names(url, names)
] | python | def _get_annotation_entries_from_data(self, graph: BELGraph, data: EdgeData) -> Optional[List[NamespaceEntry]]:
"""Get the annotation entries from an edge data dictionary."""
annotations_dict = data.get(ANNOTATIONS)
if annotations_dict is not None:
return [
entry
for url, names in self._iter_from_annotations_dict(graph, annotations_dict=annotations_dict)
for entry in self.get_annotation_entries_by_names(url, names)
] | [
"def",
"_get_annotation_entries_from_data",
"(",
"self",
",",
"graph",
":",
"BELGraph",
",",
"data",
":",
"EdgeData",
")",
"->",
"Optional",
"[",
"List",
"[",
"NamespaceEntry",
"]",
"]",
":",
"annotations_dict",
"=",
"data",
".",
"get",
"(",
"ANNOTATIONS",
"... | Get the annotation entries from an edge data dictionary. | [
"Get",
"the",
"annotation",
"entries",
"from",
"an",
"edge",
"data",
"dictionary",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L741-L749 | train | 29,594 |
pybel/pybel | src/pybel/manager/cache_manager.py | InsertManager._add_qualified_edge | def _add_qualified_edge(self, graph: BELGraph, source: Node, target: Node, key: str, bel: str, data: EdgeData):
"""Add a qualified edge to the network."""
citation_dict = data[CITATION]
citation = self.get_or_create_citation(
type=citation_dict.get(CITATION_TYPE),
reference=citation_dict.get(CITATION_REFERENCE),
name=citation_dict.get(CITATION_NAME),
title=citation_dict.get(CITATION_TITLE),
volume=citation_dict.get(CITATION_VOLUME),
issue=citation_dict.get(CITATION_ISSUE),
pages=citation_dict.get(CITATION_PAGES),
date=citation_dict.get(CITATION_DATE),
first=citation_dict.get(CITATION_FIRST_AUTHOR),
last=citation_dict.get(CITATION_LAST_AUTHOR),
authors=citation_dict.get(CITATION_AUTHORS),
)
evidence = self.get_or_create_evidence(citation, data[EVIDENCE])
properties = self.get_or_create_properties(graph, data)
if properties is None:
return
annotations = self._get_annotation_entries_from_data(graph, data)
return self.get_or_create_edge(
source=source,
target=target,
relation=data[RELATION],
bel=bel,
sha512=key,
data=data,
evidence=evidence,
properties=properties,
annotations=annotations,
) | python | def _add_qualified_edge(self, graph: BELGraph, source: Node, target: Node, key: str, bel: str, data: EdgeData):
"""Add a qualified edge to the network."""
citation_dict = data[CITATION]
citation = self.get_or_create_citation(
type=citation_dict.get(CITATION_TYPE),
reference=citation_dict.get(CITATION_REFERENCE),
name=citation_dict.get(CITATION_NAME),
title=citation_dict.get(CITATION_TITLE),
volume=citation_dict.get(CITATION_VOLUME),
issue=citation_dict.get(CITATION_ISSUE),
pages=citation_dict.get(CITATION_PAGES),
date=citation_dict.get(CITATION_DATE),
first=citation_dict.get(CITATION_FIRST_AUTHOR),
last=citation_dict.get(CITATION_LAST_AUTHOR),
authors=citation_dict.get(CITATION_AUTHORS),
)
evidence = self.get_or_create_evidence(citation, data[EVIDENCE])
properties = self.get_or_create_properties(graph, data)
if properties is None:
return
annotations = self._get_annotation_entries_from_data(graph, data)
return self.get_or_create_edge(
source=source,
target=target,
relation=data[RELATION],
bel=bel,
sha512=key,
data=data,
evidence=evidence,
properties=properties,
annotations=annotations,
) | [
"def",
"_add_qualified_edge",
"(",
"self",
",",
"graph",
":",
"BELGraph",
",",
"source",
":",
"Node",
",",
"target",
":",
"Node",
",",
"key",
":",
"str",
",",
"bel",
":",
"str",
",",
"data",
":",
"EdgeData",
")",
":",
"citation_dict",
"=",
"data",
"[... | Add a qualified edge to the network. | [
"Add",
"a",
"qualified",
"edge",
"to",
"the",
"network",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L751-L787 | train | 29,595 |
pybel/pybel | src/pybel/manager/cache_manager.py | InsertManager._add_unqualified_edge | def _add_unqualified_edge(self, source: Node, target: Node, key: str, bel: str, data: EdgeData) -> Edge:
"""Add an unqualified edge to the network."""
return self.get_or_create_edge(
source=source,
target=target,
relation=data[RELATION],
bel=bel,
sha512=key,
data=data,
) | python | def _add_unqualified_edge(self, source: Node, target: Node, key: str, bel: str, data: EdgeData) -> Edge:
"""Add an unqualified edge to the network."""
return self.get_or_create_edge(
source=source,
target=target,
relation=data[RELATION],
bel=bel,
sha512=key,
data=data,
) | [
"def",
"_add_unqualified_edge",
"(",
"self",
",",
"source",
":",
"Node",
",",
"target",
":",
"Node",
",",
"key",
":",
"str",
",",
"bel",
":",
"str",
",",
"data",
":",
"EdgeData",
")",
"->",
"Edge",
":",
"return",
"self",
".",
"get_or_create_edge",
"(",... | Add an unqualified edge to the network. | [
"Add",
"an",
"unqualified",
"edge",
"to",
"the",
"network",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L789-L798 | train | 29,596 |
pybel/pybel | src/pybel/manager/cache_manager.py | InsertManager.get_or_create_evidence | def get_or_create_evidence(self, citation: Citation, text: str) -> Evidence:
"""Create an entry and object for given evidence if it does not exist."""
sha512 = hash_evidence(text=text, type=str(citation.type), reference=str(citation.reference))
if sha512 in self.object_cache_evidence:
evidence = self.object_cache_evidence[sha512]
self.session.add(evidence)
return evidence
evidence = self.get_evidence_by_hash(sha512)
if evidence is not None:
self.object_cache_evidence[sha512] = evidence
return evidence
evidence = Evidence(
text=text,
citation=citation,
sha512=sha512,
)
self.session.add(evidence)
self.object_cache_evidence[sha512] = evidence
return evidence | python | def get_or_create_evidence(self, citation: Citation, text: str) -> Evidence:
"""Create an entry and object for given evidence if it does not exist."""
sha512 = hash_evidence(text=text, type=str(citation.type), reference=str(citation.reference))
if sha512 in self.object_cache_evidence:
evidence = self.object_cache_evidence[sha512]
self.session.add(evidence)
return evidence
evidence = self.get_evidence_by_hash(sha512)
if evidence is not None:
self.object_cache_evidence[sha512] = evidence
return evidence
evidence = Evidence(
text=text,
citation=citation,
sha512=sha512,
)
self.session.add(evidence)
self.object_cache_evidence[sha512] = evidence
return evidence | [
"def",
"get_or_create_evidence",
"(",
"self",
",",
"citation",
":",
"Citation",
",",
"text",
":",
"str",
")",
"->",
"Evidence",
":",
"sha512",
"=",
"hash_evidence",
"(",
"text",
"=",
"text",
",",
"type",
"=",
"str",
"(",
"citation",
".",
"type",
")",
"... | Create an entry and object for given evidence if it does not exist. | [
"Create",
"an",
"entry",
"and",
"object",
"for",
"given",
"evidence",
"if",
"it",
"does",
"not",
"exist",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L800-L823 | train | 29,597 |
pybel/pybel | src/pybel/manager/cache_manager.py | InsertManager.get_or_create_node | def get_or_create_node(self, graph: BELGraph, node: BaseEntity) -> Optional[Node]:
"""Create an entry and object for given node if it does not exist."""
sha512 = node.as_sha512()
if sha512 in self.object_cache_node:
return self.object_cache_node[sha512]
node_model = self.get_node_by_hash(sha512)
if node_model is not None:
self.object_cache_node[sha512] = node_model
return node_model
node_model = Node._start_from_base_entity(node)
namespace = node.get(NAMESPACE)
if namespace is None:
pass
elif namespace in graph.namespace_url:
url = graph.namespace_url[namespace]
name = node[NAME]
entry = self.get_namespace_entry(url, name)
if entry is None:
log.debug('skipping node with identifier %s: %s', url, name)
return
self.session.add(entry)
node_model.namespace_entry = entry
elif namespace in graph.namespace_pattern:
name = node[NAME]
pattern = graph.namespace_pattern[namespace]
entry = self.get_or_create_regex_namespace_entry(namespace, pattern, name)
self.session.add(entry)
node_model.namespace_entry = entry
else:
log.warning("No reference in BELGraph for namespace: {}".format(node[NAMESPACE]))
return
if VARIANTS in node or FUSION in node:
node_model.is_variant = True
node_model.has_fusion = FUSION in node
modifications = self.get_or_create_modification(graph, node)
if modifications is None:
log.warning('could not create %s because had an uncachable modification', node.as_bel())
return
node_model.modifications = modifications
self.session.add(node_model)
self.object_cache_node[sha512] = node_model
return node_model | python | def get_or_create_node(self, graph: BELGraph, node: BaseEntity) -> Optional[Node]:
"""Create an entry and object for given node if it does not exist."""
sha512 = node.as_sha512()
if sha512 in self.object_cache_node:
return self.object_cache_node[sha512]
node_model = self.get_node_by_hash(sha512)
if node_model is not None:
self.object_cache_node[sha512] = node_model
return node_model
node_model = Node._start_from_base_entity(node)
namespace = node.get(NAMESPACE)
if namespace is None:
pass
elif namespace in graph.namespace_url:
url = graph.namespace_url[namespace]
name = node[NAME]
entry = self.get_namespace_entry(url, name)
if entry is None:
log.debug('skipping node with identifier %s: %s', url, name)
return
self.session.add(entry)
node_model.namespace_entry = entry
elif namespace in graph.namespace_pattern:
name = node[NAME]
pattern = graph.namespace_pattern[namespace]
entry = self.get_or_create_regex_namespace_entry(namespace, pattern, name)
self.session.add(entry)
node_model.namespace_entry = entry
else:
log.warning("No reference in BELGraph for namespace: {}".format(node[NAMESPACE]))
return
if VARIANTS in node or FUSION in node:
node_model.is_variant = True
node_model.has_fusion = FUSION in node
modifications = self.get_or_create_modification(graph, node)
if modifications is None:
log.warning('could not create %s because had an uncachable modification', node.as_bel())
return
node_model.modifications = modifications
self.session.add(node_model)
self.object_cache_node[sha512] = node_model
return node_model | [
"def",
"get_or_create_node",
"(",
"self",
",",
"graph",
":",
"BELGraph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"Optional",
"[",
"Node",
"]",
":",
"sha512",
"=",
"node",
".",
"as_sha512",
"(",
")",
"if",
"sha512",
"in",
"self",
".",
"object_cache_nod... | Create an entry and object for given node if it does not exist. | [
"Create",
"an",
"entry",
"and",
"object",
"for",
"given",
"node",
"if",
"it",
"does",
"not",
"exist",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L825-L881 | train | 29,598 |
pybel/pybel | src/pybel/manager/cache_manager.py | InsertManager.drop_nodes | def drop_nodes(self) -> None:
"""Drop all nodes in the database."""
t = time.time()
self.session.query(Node).delete()
self.session.commit()
log.info('dropped all nodes in %.2f seconds', time.time() - t) | python | def drop_nodes(self) -> None:
"""Drop all nodes in the database."""
t = time.time()
self.session.query(Node).delete()
self.session.commit()
log.info('dropped all nodes in %.2f seconds', time.time() - t) | [
"def",
"drop_nodes",
"(",
"self",
")",
"->",
"None",
":",
"t",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"session",
".",
"query",
"(",
"Node",
")",
".",
"delete",
"(",
")",
"self",
".",
"session",
".",
"commit",
"(",
")",
"log",
".",
"in... | Drop all nodes in the database. | [
"Drop",
"all",
"nodes",
"in",
"the",
"database",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/cache_manager.py#L883-L890 | train | 29,599 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.