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/io/nodelink.py | to_json_path | def to_json_path(graph: BELGraph, path: str, **kwargs) -> None:
"""Write this graph to the given path as a Node-Link JSON."""
with open(os.path.expanduser(path), 'w') as f:
to_json_file(graph, file=f, **kwargs) | python | def to_json_path(graph: BELGraph, path: str, **kwargs) -> None:
"""Write this graph to the given path as a Node-Link JSON."""
with open(os.path.expanduser(path), 'w') as f:
to_json_file(graph, file=f, **kwargs) | [
"def",
"to_json_path",
"(",
"graph",
":",
"BELGraph",
",",
"path",
":",
"str",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
",",
"'w'",
")",
"as",
"f",
":",
"to_json... | Write this graph to the given path as a Node-Link JSON. | [
"Write",
"this",
"graph",
"to",
"the",
"given",
"path",
"as",
"a",
"Node",
"-",
"Link",
"JSON",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/nodelink.py#L47-L50 | train | 29,700 |
pybel/pybel | src/pybel/io/nodelink.py | to_json_file | def to_json_file(graph: BELGraph, file: TextIO, **kwargs) -> None:
"""Write this graph as Node-Link JSON to a file."""
graph_json_dict = to_json(graph)
json.dump(graph_json_dict, file, ensure_ascii=False, **kwargs) | python | def to_json_file(graph: BELGraph, file: TextIO, **kwargs) -> None:
"""Write this graph as Node-Link JSON to a file."""
graph_json_dict = to_json(graph)
json.dump(graph_json_dict, file, ensure_ascii=False, **kwargs) | [
"def",
"to_json_file",
"(",
"graph",
":",
"BELGraph",
",",
"file",
":",
"TextIO",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"graph_json_dict",
"=",
"to_json",
"(",
"graph",
")",
"json",
".",
"dump",
"(",
"graph_json_dict",
",",
"file",
",",
"ens... | Write this graph as Node-Link JSON to a file. | [
"Write",
"this",
"graph",
"as",
"Node",
"-",
"Link",
"JSON",
"to",
"a",
"file",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/nodelink.py#L53-L56 | train | 29,701 |
pybel/pybel | src/pybel/io/nodelink.py | to_jsons | def to_jsons(graph: BELGraph, **kwargs) -> str:
"""Dump this graph as a Node-Link JSON object to a string."""
graph_json_str = to_json(graph)
return json.dumps(graph_json_str, ensure_ascii=False, **kwargs) | python | def to_jsons(graph: BELGraph, **kwargs) -> str:
"""Dump this graph as a Node-Link JSON object to a string."""
graph_json_str = to_json(graph)
return json.dumps(graph_json_str, ensure_ascii=False, **kwargs) | [
"def",
"to_jsons",
"(",
"graph",
":",
"BELGraph",
",",
"*",
"*",
"kwargs",
")",
"->",
"str",
":",
"graph_json_str",
"=",
"to_json",
"(",
"graph",
")",
"return",
"json",
".",
"dumps",
"(",
"graph_json_str",
",",
"ensure_ascii",
"=",
"False",
",",
"*",
"... | Dump this graph as a Node-Link JSON object to a string. | [
"Dump",
"this",
"graph",
"as",
"a",
"Node",
"-",
"Link",
"JSON",
"object",
"to",
"a",
"string",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/nodelink.py#L59-L62 | train | 29,702 |
pybel/pybel | src/pybel/io/nodelink.py | from_json | def from_json(graph_json_dict: Mapping[str, Any], check_version=True) -> BELGraph:
"""Build a graph from Node-Link JSON Object."""
graph = node_link_graph(graph_json_dict)
return ensure_version(graph, check_version=check_version) | python | def from_json(graph_json_dict: Mapping[str, Any], check_version=True) -> BELGraph:
"""Build a graph from Node-Link JSON Object."""
graph = node_link_graph(graph_json_dict)
return ensure_version(graph, check_version=check_version) | [
"def",
"from_json",
"(",
"graph_json_dict",
":",
"Mapping",
"[",
"str",
",",
"Any",
"]",
",",
"check_version",
"=",
"True",
")",
"->",
"BELGraph",
":",
"graph",
"=",
"node_link_graph",
"(",
"graph_json_dict",
")",
"return",
"ensure_version",
"(",
"graph",
",... | Build a graph from Node-Link JSON Object. | [
"Build",
"a",
"graph",
"from",
"Node",
"-",
"Link",
"JSON",
"Object",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/nodelink.py#L65-L68 | train | 29,703 |
pybel/pybel | src/pybel/io/nodelink.py | from_json_path | def from_json_path(path: str, check_version: bool = True) -> BELGraph:
"""Build a graph from a file containing Node-Link JSON."""
with open(os.path.expanduser(path)) as f:
return from_json_file(f, check_version=check_version) | python | def from_json_path(path: str, check_version: bool = True) -> BELGraph:
"""Build a graph from a file containing Node-Link JSON."""
with open(os.path.expanduser(path)) as f:
return from_json_file(f, check_version=check_version) | [
"def",
"from_json_path",
"(",
"path",
":",
"str",
",",
"check_version",
":",
"bool",
"=",
"True",
")",
"->",
"BELGraph",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
")",
"as",
"f",
":",
"return",
"from_json_file",
... | Build a graph from a file containing Node-Link JSON. | [
"Build",
"a",
"graph",
"from",
"a",
"file",
"containing",
"Node",
"-",
"Link",
"JSON",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/nodelink.py#L71-L74 | train | 29,704 |
pybel/pybel | src/pybel/io/nodelink.py | from_json_file | def from_json_file(file: TextIO, check_version=True) -> BELGraph:
"""Build a graph from the Node-Link JSON contained in the given file."""
graph_json_dict = json.load(file)
return from_json(graph_json_dict, check_version=check_version) | python | def from_json_file(file: TextIO, check_version=True) -> BELGraph:
"""Build a graph from the Node-Link JSON contained in the given file."""
graph_json_dict = json.load(file)
return from_json(graph_json_dict, check_version=check_version) | [
"def",
"from_json_file",
"(",
"file",
":",
"TextIO",
",",
"check_version",
"=",
"True",
")",
"->",
"BELGraph",
":",
"graph_json_dict",
"=",
"json",
".",
"load",
"(",
"file",
")",
"return",
"from_json",
"(",
"graph_json_dict",
",",
"check_version",
"=",
"chec... | Build a graph from the Node-Link JSON contained in the given file. | [
"Build",
"a",
"graph",
"from",
"the",
"Node",
"-",
"Link",
"JSON",
"contained",
"in",
"the",
"given",
"file",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/nodelink.py#L77-L80 | train | 29,705 |
pybel/pybel | src/pybel/io/nodelink.py | from_jsons | def from_jsons(graph_json_str: str, check_version: bool = True) -> BELGraph:
"""Read a BEL graph from a Node-Link JSON string."""
graph_json_dict = json.loads(graph_json_str)
return from_json(graph_json_dict, check_version=check_version) | python | def from_jsons(graph_json_str: str, check_version: bool = True) -> BELGraph:
"""Read a BEL graph from a Node-Link JSON string."""
graph_json_dict = json.loads(graph_json_str)
return from_json(graph_json_dict, check_version=check_version) | [
"def",
"from_jsons",
"(",
"graph_json_str",
":",
"str",
",",
"check_version",
":",
"bool",
"=",
"True",
")",
"->",
"BELGraph",
":",
"graph_json_dict",
"=",
"json",
".",
"loads",
"(",
"graph_json_str",
")",
"return",
"from_json",
"(",
"graph_json_dict",
",",
... | Read a BEL graph from a Node-Link JSON string. | [
"Read",
"a",
"BEL",
"graph",
"from",
"a",
"Node",
"-",
"Link",
"JSON",
"string",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/nodelink.py#L83-L86 | train | 29,706 |
pybel/pybel | src/pybel/io/nodelink.py | node_link_data | def node_link_data(graph: BELGraph) -> Mapping[str, Any]:
"""Convert a BEL graph to a node-link format.
Adapted from :func:`networkx.readwrite.json_graph.node_link_data`
"""
nodes = sorted(graph, key=methodcaller('as_bel'))
mapping = dict(zip(nodes, count()))
return {
'directed': True... | python | def node_link_data(graph: BELGraph) -> Mapping[str, Any]:
"""Convert a BEL graph to a node-link format.
Adapted from :func:`networkx.readwrite.json_graph.node_link_data`
"""
nodes = sorted(graph, key=methodcaller('as_bel'))
mapping = dict(zip(nodes, count()))
return {
'directed': True... | [
"def",
"node_link_data",
"(",
"graph",
":",
"BELGraph",
")",
"->",
"Mapping",
"[",
"str",
",",
"Any",
"]",
":",
"nodes",
"=",
"sorted",
"(",
"graph",
",",
"key",
"=",
"methodcaller",
"(",
"'as_bel'",
")",
")",
"mapping",
"=",
"dict",
"(",
"zip",
"(",... | Convert a BEL graph to a node-link format.
Adapted from :func:`networkx.readwrite.json_graph.node_link_data` | [
"Convert",
"a",
"BEL",
"graph",
"to",
"a",
"node",
"-",
"link",
"format",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/nodelink.py#L89-L113 | train | 29,707 |
pybel/pybel | src/pybel/io/nodelink.py | _augment_node | def _augment_node(node: BaseEntity) -> BaseEntity:
"""Add the SHA-512 identifier to a node's dictionary."""
rv = node.copy()
rv['id'] = node.as_sha512()
rv['bel'] = node.as_bel()
for m in chain(node.get(MEMBERS, []), node.get(REACTANTS, []), node.get(PRODUCTS, [])):
m.update(_augment_node(m)... | python | def _augment_node(node: BaseEntity) -> BaseEntity:
"""Add the SHA-512 identifier to a node's dictionary."""
rv = node.copy()
rv['id'] = node.as_sha512()
rv['bel'] = node.as_bel()
for m in chain(node.get(MEMBERS, []), node.get(REACTANTS, []), node.get(PRODUCTS, [])):
m.update(_augment_node(m)... | [
"def",
"_augment_node",
"(",
"node",
":",
"BaseEntity",
")",
"->",
"BaseEntity",
":",
"rv",
"=",
"node",
".",
"copy",
"(",
")",
"rv",
"[",
"'id'",
"]",
"=",
"node",
".",
"as_sha512",
"(",
")",
"rv",
"[",
"'bel'",
"]",
"=",
"node",
".",
"as_bel",
... | Add the SHA-512 identifier to a node's dictionary. | [
"Add",
"the",
"SHA",
"-",
"512",
"identifier",
"to",
"a",
"node",
"s",
"dictionary",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/nodelink.py#L116-L123 | train | 29,708 |
pybel/pybel | src/pybel/parser/baseparser.py | BaseParser.parse_lines | def parse_lines(self, lines: Iterable[str]) -> List[ParseResults]:
"""Parse multiple lines in succession."""
return [
self.parseString(line, line_number)
for line_number, line in enumerate(lines)
] | python | def parse_lines(self, lines: Iterable[str]) -> List[ParseResults]:
"""Parse multiple lines in succession."""
return [
self.parseString(line, line_number)
for line_number, line in enumerate(lines)
] | [
"def",
"parse_lines",
"(",
"self",
",",
"lines",
":",
"Iterable",
"[",
"str",
"]",
")",
"->",
"List",
"[",
"ParseResults",
"]",
":",
"return",
"[",
"self",
".",
"parseString",
"(",
"line",
",",
"line_number",
")",
"for",
"line_number",
",",
"line",
"in... | Parse multiple lines in succession. | [
"Parse",
"multiple",
"lines",
"in",
"succession",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/baseparser.py#L36-L41 | train | 29,709 |
pybel/pybel | src/pybel/parser/baseparser.py | BaseParser.parseString | def parseString(self, line: str, line_number: int = 0) -> ParseResults: # noqa: N802
"""Parse a string with the language represented by this parser.
:param line: A string representing an instance of this parser's language
:param line_number: The current line number of the parser
"""
... | python | def parseString(self, line: str, line_number: int = 0) -> ParseResults: # noqa: N802
"""Parse a string with the language represented by this parser.
:param line: A string representing an instance of this parser's language
:param line_number: The current line number of the parser
"""
... | [
"def",
"parseString",
"(",
"self",
",",
"line",
":",
"str",
",",
"line_number",
":",
"int",
"=",
"0",
")",
"->",
"ParseResults",
":",
"# noqa: N802",
"self",
".",
"_line_number",
"=",
"line_number",
"return",
"self",
".",
"language",
".",
"parseString",
"(... | Parse a string with the language represented by this parser.
:param line: A string representing an instance of this parser's language
:param line_number: The current line number of the parser | [
"Parse",
"a",
"string",
"with",
"the",
"language",
"represented",
"by",
"this",
"parser",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/baseparser.py#L43-L50 | train | 29,710 |
pybel/pybel | src/pybel/parser/baseparser.py | BaseParser.streamline | def streamline(self):
"""Streamline the language represented by this parser to make queries run faster."""
t = time.time()
self.language.streamline()
log.info('streamlined %s in %.02f seconds', self.__class__.__name__, time.time() - t) | python | def streamline(self):
"""Streamline the language represented by this parser to make queries run faster."""
t = time.time()
self.language.streamline()
log.info('streamlined %s in %.02f seconds', self.__class__.__name__, time.time() - t) | [
"def",
"streamline",
"(",
"self",
")",
":",
"t",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"language",
".",
"streamline",
"(",
")",
"log",
".",
"info",
"(",
"'streamlined %s in %.02f seconds'",
",",
"self",
".",
"__class__",
".",
"__name__",
",",
... | Streamline the language represented by this parser to make queries run faster. | [
"Streamline",
"the",
"language",
"represented",
"by",
"this",
"parser",
"to",
"make",
"queries",
"run",
"faster",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/baseparser.py#L56-L60 | train | 29,711 |
pybel/pybel | src/pybel/struct/mutation/transfer.py | iter_children | def iter_children(graph, node: BaseEntity) -> Iterable[BaseEntity]:
"""Iterate over children of the node."""
return (
node
for node, _, d in graph.in_edges(node, data=True)
if d[RELATION] == IS_A
) | python | def iter_children(graph, node: BaseEntity) -> Iterable[BaseEntity]:
"""Iterate over children of the node."""
return (
node
for node, _, d in graph.in_edges(node, data=True)
if d[RELATION] == IS_A
) | [
"def",
"iter_children",
"(",
"graph",
",",
"node",
":",
"BaseEntity",
")",
"->",
"Iterable",
"[",
"BaseEntity",
"]",
":",
"return",
"(",
"node",
"for",
"node",
",",
"_",
",",
"d",
"in",
"graph",
".",
"in_edges",
"(",
"node",
",",
"data",
"=",
"True",... | Iterate over children of the node. | [
"Iterate",
"over",
"children",
"of",
"the",
"node",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/transfer.py#L15-L21 | train | 29,712 |
pybel/pybel | src/pybel/struct/mutation/transfer.py | transfer_causal_edges | def transfer_causal_edges(graph, source: BaseEntity, target: BaseEntity) -> Iterable[str]:
"""Transfer causal edges that the source has to the target and yield the resulting hashes."""
for _, v, data in graph.out_edges(source, data=True):
if data[RELATION] not in CAUSAL_RELATIONS:
continue
... | python | def transfer_causal_edges(graph, source: BaseEntity, target: BaseEntity) -> Iterable[str]:
"""Transfer causal edges that the source has to the target and yield the resulting hashes."""
for _, v, data in graph.out_edges(source, data=True):
if data[RELATION] not in CAUSAL_RELATIONS:
continue
... | [
"def",
"transfer_causal_edges",
"(",
"graph",
",",
"source",
":",
"BaseEntity",
",",
"target",
":",
"BaseEntity",
")",
"->",
"Iterable",
"[",
"str",
"]",
":",
"for",
"_",
",",
"v",
",",
"data",
"in",
"graph",
".",
"out_edges",
"(",
"source",
",",
"data... | Transfer causal edges that the source has to the target and yield the resulting hashes. | [
"Transfer",
"causal",
"edges",
"that",
"the",
"source",
"has",
"to",
"the",
"target",
"and",
"yield",
"the",
"resulting",
"hashes",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/transfer.py#L24-L54 | train | 29,713 |
pybel/pybel | src/pybel/struct/pipeline/pipeline.py | _get_protocol_tuple | def _get_protocol_tuple(data: Dict[str, Any]) -> Tuple[str, List, Dict]:
"""Convert a dictionary to a tuple."""
return data['function'], data.get('args', []), data.get('kwargs', {}) | python | def _get_protocol_tuple(data: Dict[str, Any]) -> Tuple[str, List, Dict]:
"""Convert a dictionary to a tuple."""
return data['function'], data.get('args', []), data.get('kwargs', {}) | [
"def",
"_get_protocol_tuple",
"(",
"data",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
")",
"->",
"Tuple",
"[",
"str",
",",
"List",
",",
"Dict",
"]",
":",
"return",
"data",
"[",
"'function'",
"]",
",",
"data",
".",
"get",
"(",
"'args'",
",",
"[",
"... | Convert a dictionary to a tuple. | [
"Convert",
"a",
"dictionary",
"to",
"a",
"tuple",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/pipeline.py#L25-L27 | train | 29,714 |
pybel/pybel | src/pybel/struct/pipeline/pipeline.py | Pipeline.from_functions | def from_functions(functions) -> 'Pipeline':
"""Build a pipeline from a list of functions.
:param functions: A list of functions or names of functions
:type functions: iter[((pybel.BELGraph) -> pybel.BELGraph) or ((pybel.BELGraph) -> None) or str]
Example with function:
>>> fr... | python | def from_functions(functions) -> 'Pipeline':
"""Build a pipeline from a list of functions.
:param functions: A list of functions or names of functions
:type functions: iter[((pybel.BELGraph) -> pybel.BELGraph) or ((pybel.BELGraph) -> None) or str]
Example with function:
>>> fr... | [
"def",
"from_functions",
"(",
"functions",
")",
"->",
"'Pipeline'",
":",
"result",
"=",
"Pipeline",
"(",
")",
"for",
"func",
"in",
"functions",
":",
"result",
".",
"append",
"(",
"func",
")",
"return",
"result"
] | Build a pipeline from a list of functions.
:param functions: A list of functions or names of functions
:type functions: iter[((pybel.BELGraph) -> pybel.BELGraph) or ((pybel.BELGraph) -> None) or str]
Example with function:
>>> from pybel.struct.pipeline import Pipeline
>>> fro... | [
"Build",
"a",
"pipeline",
"from",
"a",
"list",
"of",
"functions",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/pipeline.py#L60-L90 | train | 29,715 |
pybel/pybel | src/pybel/struct/pipeline/pipeline.py | Pipeline._get_function | def _get_function(self, name: str):
"""Wrap a function with the universe and in-place.
:param name: The name of the function
:rtype: types.FunctionType
:raises MissingPipelineFunctionError: If the functions is not registered
"""
f = mapped.get(name)
if f is None... | python | def _get_function(self, name: str):
"""Wrap a function with the universe and in-place.
:param name: The name of the function
:rtype: types.FunctionType
:raises MissingPipelineFunctionError: If the functions is not registered
"""
f = mapped.get(name)
if f is None... | [
"def",
"_get_function",
"(",
"self",
",",
"name",
":",
"str",
")",
":",
"f",
"=",
"mapped",
".",
"get",
"(",
"name",
")",
"if",
"f",
"is",
"None",
":",
"raise",
"MissingPipelineFunctionError",
"(",
"'{} is not registered as a pipeline function'",
".",
"format"... | Wrap a function with the universe and in-place.
:param name: The name of the function
:rtype: types.FunctionType
:raises MissingPipelineFunctionError: If the functions is not registered | [
"Wrap",
"a",
"function",
"with",
"the",
"universe",
"and",
"in",
"-",
"place",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/pipeline.py#L92-L113 | train | 29,716 |
pybel/pybel | src/pybel/struct/pipeline/pipeline.py | Pipeline.extend | def extend(self, protocol: Union[Iterable[Dict], 'Pipeline']) -> 'Pipeline':
"""Add another pipeline to the end of the current pipeline.
:param protocol: An iterable of dictionaries (or another Pipeline)
:return: This pipeline for fluid query building
Example:
>>> p1 = Pipelin... | python | def extend(self, protocol: Union[Iterable[Dict], 'Pipeline']) -> 'Pipeline':
"""Add another pipeline to the end of the current pipeline.
:param protocol: An iterable of dictionaries (or another Pipeline)
:return: This pipeline for fluid query building
Example:
>>> p1 = Pipelin... | [
"def",
"extend",
"(",
"self",
",",
"protocol",
":",
"Union",
"[",
"Iterable",
"[",
"Dict",
"]",
",",
"'Pipeline'",
"]",
")",
"->",
"'Pipeline'",
":",
"for",
"data",
"in",
"protocol",
":",
"name",
",",
"args",
",",
"kwargs",
"=",
"_get_protocol_tuple",
... | Add another pipeline to the end of the current pipeline.
:param protocol: An iterable of dictionaries (or another Pipeline)
:return: This pipeline for fluid query building
Example:
>>> p1 = Pipeline.from_functions(['enrich_protein_and_rna_origins'])
>>> p2 = Pipeline.from_func... | [
"Add",
"another",
"pipeline",
"to",
"the",
"end",
"of",
"the",
"current",
"pipeline",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/pipeline.py#L145-L161 | train | 29,717 |
pybel/pybel | src/pybel/struct/pipeline/pipeline.py | Pipeline._run_helper | def _run_helper(self, graph, protocol: Iterable[Dict]):
"""Help run the protocol.
:param pybel.BELGraph graph: A BEL graph
:param protocol: The protocol to run, as JSON
:rtype: pybel.BELGraph
"""
result = graph
for entry in protocol:
meta_entry = ent... | python | def _run_helper(self, graph, protocol: Iterable[Dict]):
"""Help run the protocol.
:param pybel.BELGraph graph: A BEL graph
:param protocol: The protocol to run, as JSON
:rtype: pybel.BELGraph
"""
result = graph
for entry in protocol:
meta_entry = ent... | [
"def",
"_run_helper",
"(",
"self",
",",
"graph",
",",
"protocol",
":",
"Iterable",
"[",
"Dict",
"]",
")",
":",
"result",
"=",
"graph",
"for",
"entry",
"in",
"protocol",
":",
"meta_entry",
"=",
"entry",
".",
"get",
"(",
"'meta'",
")",
"if",
"meta_entry"... | Help run the protocol.
:param pybel.BELGraph graph: A BEL graph
:param protocol: The protocol to run, as JSON
:rtype: pybel.BELGraph | [
"Help",
"run",
"the",
"protocol",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/pipeline.py#L163-L194 | train | 29,718 |
pybel/pybel | src/pybel/struct/pipeline/pipeline.py | Pipeline.run | def run(self, graph, universe=None):
"""Run the contained protocol on a seed graph.
:param pybel.BELGraph graph: The seed BEL graph
:param pybel.BELGraph universe: Allows just-in-time setting of the universe in case it wasn't set before.
Defaults to the g... | python | def run(self, graph, universe=None):
"""Run the contained protocol on a seed graph.
:param pybel.BELGraph graph: The seed BEL graph
:param pybel.BELGraph universe: Allows just-in-time setting of the universe in case it wasn't set before.
Defaults to the g... | [
"def",
"run",
"(",
"self",
",",
"graph",
",",
"universe",
"=",
"None",
")",
":",
"self",
".",
"universe",
"=",
"universe",
"or",
"graph",
".",
"copy",
"(",
")",
"return",
"self",
".",
"_run_helper",
"(",
"graph",
".",
"copy",
"(",
")",
",",
"self",... | Run the contained protocol on a seed graph.
:param pybel.BELGraph graph: The seed BEL graph
:param pybel.BELGraph universe: Allows just-in-time setting of the universe in case it wasn't set before.
Defaults to the given network.
:return: The new graph is ... | [
"Run",
"the",
"contained",
"protocol",
"on",
"a",
"seed",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/pipeline.py#L196-L206 | train | 29,719 |
pybel/pybel | src/pybel/struct/pipeline/pipeline.py | Pipeline._wrap_universe | def _wrap_universe(self, func): # noqa: D202
"""Take a function that needs a universe graph as the first argument and returns a wrapped one."""
@wraps(func)
def wrapper(graph, *args, **kwargs):
"""Apply the enclosed function with the universe given as the first argument."""
... | python | def _wrap_universe(self, func): # noqa: D202
"""Take a function that needs a universe graph as the first argument and returns a wrapped one."""
@wraps(func)
def wrapper(graph, *args, **kwargs):
"""Apply the enclosed function with the universe given as the first argument."""
... | [
"def",
"_wrap_universe",
"(",
"self",
",",
"func",
")",
":",
"# noqa: D202",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"graph",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Apply the enclosed function with the universe given as the fi... | Take a function that needs a universe graph as the first argument and returns a wrapped one. | [
"Take",
"a",
"function",
"that",
"needs",
"a",
"universe",
"graph",
"as",
"the",
"first",
"argument",
"and",
"returns",
"a",
"wrapped",
"one",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/pipeline.py#L229-L241 | train | 29,720 |
pybel/pybel | src/pybel/struct/pipeline/pipeline.py | Pipeline._wrap_in_place | def _wrap_in_place(func): # noqa: D202
"""Take a function that doesn't return the graph and returns the graph."""
@wraps(func)
def wrapper(graph, *args, **kwargs):
"""Apply the enclosed function and returns the graph."""
func(graph, *args, **kwargs)
return g... | python | def _wrap_in_place(func): # noqa: D202
"""Take a function that doesn't return the graph and returns the graph."""
@wraps(func)
def wrapper(graph, *args, **kwargs):
"""Apply the enclosed function and returns the graph."""
func(graph, *args, **kwargs)
return g... | [
"def",
"_wrap_in_place",
"(",
"func",
")",
":",
"# noqa: D202",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"graph",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Apply the enclosed function and returns the graph.\"\"\"",
"func",
"(",
... | Take a function that doesn't return the graph and returns the graph. | [
"Take",
"a",
"function",
"that",
"doesn",
"t",
"return",
"the",
"graph",
"and",
"returns",
"the",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/pipeline.py#L244-L253 | train | 29,721 |
pybel/pybel | src/pybel/struct/pipeline/pipeline.py | Pipeline.dump | def dump(self, file: TextIO, **kwargs) -> None:
"""Dump this protocol to a file in JSON."""
return json.dump(self.to_json(), file, **kwargs) | python | def dump(self, file: TextIO, **kwargs) -> None:
"""Dump this protocol to a file in JSON."""
return json.dump(self.to_json(), file, **kwargs) | [
"def",
"dump",
"(",
"self",
",",
"file",
":",
"TextIO",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"return",
"json",
".",
"dump",
"(",
"self",
".",
"to_json",
"(",
")",
",",
"file",
",",
"*",
"*",
"kwargs",
")"
] | Dump this protocol to a file in JSON. | [
"Dump",
"this",
"protocol",
"to",
"a",
"file",
"in",
"JSON",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/pipeline.py#L263-L265 | train | 29,722 |
pybel/pybel | src/pybel/struct/pipeline/pipeline.py | Pipeline._build_meta | def _build_meta(meta: str, pipelines: Iterable['Pipeline']) -> 'Pipeline':
"""Build a pipeline with a given meta-argument.
:param meta: either union or intersection
:param pipelines:
"""
return Pipeline(protocol=[
{
'meta': meta,
'pipe... | python | def _build_meta(meta: str, pipelines: Iterable['Pipeline']) -> 'Pipeline':
"""Build a pipeline with a given meta-argument.
:param meta: either union or intersection
:param pipelines:
"""
return Pipeline(protocol=[
{
'meta': meta,
'pipe... | [
"def",
"_build_meta",
"(",
"meta",
":",
"str",
",",
"pipelines",
":",
"Iterable",
"[",
"'Pipeline'",
"]",
")",
"->",
"'Pipeline'",
":",
"return",
"Pipeline",
"(",
"protocol",
"=",
"[",
"{",
"'meta'",
":",
"meta",
",",
"'pipelines'",
":",
"[",
"pipeline",... | Build a pipeline with a given meta-argument.
:param meta: either union or intersection
:param pipelines: | [
"Build",
"a",
"pipeline",
"with",
"a",
"given",
"meta",
"-",
"argument",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/pipeline.py#L295-L309 | train | 29,723 |
pybel/pybel | src/pybel/struct/summary/node_summary.py | get_names | def get_names(graph):
"""Get all names for each namespace.
:type graph: pybel.BELGraph
:rtype: dict[str,set[str]]
"""
rv = defaultdict(set)
for namespace, name in _identifier_filtered_iterator(graph):
rv[namespace].add(name)
return dict(rv) | python | def get_names(graph):
"""Get all names for each namespace.
:type graph: pybel.BELGraph
:rtype: dict[str,set[str]]
"""
rv = defaultdict(set)
for namespace, name in _identifier_filtered_iterator(graph):
rv[namespace].add(name)
return dict(rv) | [
"def",
"get_names",
"(",
"graph",
")",
":",
"rv",
"=",
"defaultdict",
"(",
"set",
")",
"for",
"namespace",
",",
"name",
"in",
"_identifier_filtered_iterator",
"(",
"graph",
")",
":",
"rv",
"[",
"namespace",
"]",
".",
"add",
"(",
"name",
")",
"return",
... | Get all names for each namespace.
:type graph: pybel.BELGraph
:rtype: dict[str,set[str]] | [
"Get",
"all",
"names",
"for",
"each",
"namespace",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/node_summary.py#L101-L110 | train | 29,724 |
pybel/pybel | src/pybel/struct/summary/node_summary.py | count_variants | def count_variants(graph):
"""Count how many of each type of variant a graph has.
:param pybel.BELGraph graph: A BEL graph
:rtype: Counter
"""
return Counter(
variant_data[KIND]
for data in graph
if has_variant(graph, data)
for variant_data in data[VARIANTS]
) | python | def count_variants(graph):
"""Count how many of each type of variant a graph has.
:param pybel.BELGraph graph: A BEL graph
:rtype: Counter
"""
return Counter(
variant_data[KIND]
for data in graph
if has_variant(graph, data)
for variant_data in data[VARIANTS]
) | [
"def",
"count_variants",
"(",
"graph",
")",
":",
"return",
"Counter",
"(",
"variant_data",
"[",
"KIND",
"]",
"for",
"data",
"in",
"graph",
"if",
"has_variant",
"(",
"graph",
",",
"data",
")",
"for",
"variant_data",
"in",
"data",
"[",
"VARIANTS",
"]",
")"... | Count how many of each type of variant a graph has.
:param pybel.BELGraph graph: A BEL graph
:rtype: Counter | [
"Count",
"how",
"many",
"of",
"each",
"type",
"of",
"variant",
"a",
"graph",
"has",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/node_summary.py#L202-L213 | train | 29,725 |
pybel/pybel | src/pybel/struct/summary/node_summary.py | get_top_hubs | def get_top_hubs(graph, *, n: Optional[int] = 15) -> List[Tuple[BaseEntity, int]]:
"""Get the top hubs in the graph by BEL.
:param pybel.BELGraph graph: A BEL graph
:param n: The number of top hubs to return. If None, returns all nodes
"""
return Counter(dict(graph.degree())).most_common(n=n) | python | def get_top_hubs(graph, *, n: Optional[int] = 15) -> List[Tuple[BaseEntity, int]]:
"""Get the top hubs in the graph by BEL.
:param pybel.BELGraph graph: A BEL graph
:param n: The number of top hubs to return. If None, returns all nodes
"""
return Counter(dict(graph.degree())).most_common(n=n) | [
"def",
"get_top_hubs",
"(",
"graph",
",",
"*",
",",
"n",
":",
"Optional",
"[",
"int",
"]",
"=",
"15",
")",
"->",
"List",
"[",
"Tuple",
"[",
"BaseEntity",
",",
"int",
"]",
"]",
":",
"return",
"Counter",
"(",
"dict",
"(",
"graph",
".",
"degree",
"(... | Get the top hubs in the graph by BEL.
:param pybel.BELGraph graph: A BEL graph
:param n: The number of top hubs to return. If None, returns all nodes | [
"Get",
"the",
"top",
"hubs",
"in",
"the",
"graph",
"by",
"BEL",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/node_summary.py#L216-L222 | train | 29,726 |
pybel/pybel | src/pybel/struct/summary/node_summary.py | _pathology_iterator | def _pathology_iterator(graph):
"""Iterate over edges in which either the source or target is a pathology node.
:param pybel.BELGraph graph: A BEL graph
:rtype: iter
"""
for node in itt.chain.from_iterable(graph.edges()):
if isinstance(node, Pathology):
yield node | python | def _pathology_iterator(graph):
"""Iterate over edges in which either the source or target is a pathology node.
:param pybel.BELGraph graph: A BEL graph
:rtype: iter
"""
for node in itt.chain.from_iterable(graph.edges()):
if isinstance(node, Pathology):
yield node | [
"def",
"_pathology_iterator",
"(",
"graph",
")",
":",
"for",
"node",
"in",
"itt",
".",
"chain",
".",
"from_iterable",
"(",
"graph",
".",
"edges",
"(",
")",
")",
":",
"if",
"isinstance",
"(",
"node",
",",
"Pathology",
")",
":",
"yield",
"node"
] | Iterate over edges in which either the source or target is a pathology node.
:param pybel.BELGraph graph: A BEL graph
:rtype: iter | [
"Iterate",
"over",
"edges",
"in",
"which",
"either",
"the",
"source",
"or",
"target",
"is",
"a",
"pathology",
"node",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/node_summary.py#L225-L233 | train | 29,727 |
pybel/pybel | src/pybel/struct/summary/node_summary.py | get_top_pathologies | def get_top_pathologies(graph, n: Optional[int] = 15) -> List[Tuple[BaseEntity, int]]:
"""Get the top highest relationship-having edges in the graph by BEL.
:param pybel.BELGraph graph: A BEL graph
:param n: The number of top connected pathologies to return. If None, returns all nodes
"""
return co... | python | def get_top_pathologies(graph, n: Optional[int] = 15) -> List[Tuple[BaseEntity, int]]:
"""Get the top highest relationship-having edges in the graph by BEL.
:param pybel.BELGraph graph: A BEL graph
:param n: The number of top connected pathologies to return. If None, returns all nodes
"""
return co... | [
"def",
"get_top_pathologies",
"(",
"graph",
",",
"n",
":",
"Optional",
"[",
"int",
"]",
"=",
"15",
")",
"->",
"List",
"[",
"Tuple",
"[",
"BaseEntity",
",",
"int",
"]",
"]",
":",
"return",
"count_pathologies",
"(",
"graph",
")",
".",
"most_common",
"(",... | Get the top highest relationship-having edges in the graph by BEL.
:param pybel.BELGraph graph: A BEL graph
:param n: The number of top connected pathologies to return. If None, returns all nodes | [
"Get",
"the",
"top",
"highest",
"relationship",
"-",
"having",
"edges",
"in",
"the",
"graph",
"by",
"BEL",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/node_summary.py#L245-L251 | train | 29,728 |
pybel/pybel | src/pybel/struct/mutation/inference/protein_rna_origins.py | enrich_proteins_with_rnas | def enrich_proteins_with_rnas(graph):
"""Add the corresponding RNA node for each protein node and connect them with a translation edge.
:param pybel.BELGraph graph: A BEL graph
"""
for protein_node in list(graph):
if not isinstance(protein_node, Protein):
continue
if protei... | python | def enrich_proteins_with_rnas(graph):
"""Add the corresponding RNA node for each protein node and connect them with a translation edge.
:param pybel.BELGraph graph: A BEL graph
"""
for protein_node in list(graph):
if not isinstance(protein_node, Protein):
continue
if protei... | [
"def",
"enrich_proteins_with_rnas",
"(",
"graph",
")",
":",
"for",
"protein_node",
"in",
"list",
"(",
"graph",
")",
":",
"if",
"not",
"isinstance",
"(",
"protein_node",
",",
"Protein",
")",
":",
"continue",
"if",
"protein_node",
".",
"variants",
":",
"contin... | Add the corresponding RNA node for each protein node and connect them with a translation edge.
:param pybel.BELGraph graph: A BEL graph | [
"Add",
"the",
"corresponding",
"RNA",
"node",
"for",
"each",
"protein",
"node",
"and",
"connect",
"them",
"with",
"a",
"translation",
"edge",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/inference/protein_rna_origins.py#L19-L32 | train | 29,729 |
pybel/pybel | src/pybel/struct/mutation/induction/upstream.py | get_upstream_causal_subgraph | def get_upstream_causal_subgraph(graph, nbunch: Union[BaseEntity, Iterable[BaseEntity]]):
"""Induce a sub-graph from all of the upstream causal entities of the nodes in the nbunch.
:type graph: pybel.BELGraph
:rtype: pybel.BELGraph
"""
return get_subgraph_by_edge_filter(graph, build_upstream_edge_p... | python | def get_upstream_causal_subgraph(graph, nbunch: Union[BaseEntity, Iterable[BaseEntity]]):
"""Induce a sub-graph from all of the upstream causal entities of the nodes in the nbunch.
:type graph: pybel.BELGraph
:rtype: pybel.BELGraph
"""
return get_subgraph_by_edge_filter(graph, build_upstream_edge_p... | [
"def",
"get_upstream_causal_subgraph",
"(",
"graph",
",",
"nbunch",
":",
"Union",
"[",
"BaseEntity",
",",
"Iterable",
"[",
"BaseEntity",
"]",
"]",
")",
":",
"return",
"get_subgraph_by_edge_filter",
"(",
"graph",
",",
"build_upstream_edge_predicate",
"(",
"nbunch",
... | Induce a sub-graph from all of the upstream causal entities of the nodes in the nbunch.
:type graph: pybel.BELGraph
:rtype: pybel.BELGraph | [
"Induce",
"a",
"sub",
"-",
"graph",
"from",
"all",
"of",
"the",
"upstream",
"causal",
"entities",
"of",
"the",
"nodes",
"in",
"the",
"nbunch",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/upstream.py#L22-L28 | train | 29,730 |
pybel/pybel | src/pybel/struct/mutation/induction/upstream.py | get_downstream_causal_subgraph | def get_downstream_causal_subgraph(graph, nbunch: Union[BaseEntity, Iterable[BaseEntity]]):
"""Induce a sub-graph from all of the downstream causal entities of the nodes in the nbunch.
:type graph: pybel.BELGraph
:rtype: pybel.BELGraph
"""
return get_subgraph_by_edge_filter(graph, build_downstream_... | python | def get_downstream_causal_subgraph(graph, nbunch: Union[BaseEntity, Iterable[BaseEntity]]):
"""Induce a sub-graph from all of the downstream causal entities of the nodes in the nbunch.
:type graph: pybel.BELGraph
:rtype: pybel.BELGraph
"""
return get_subgraph_by_edge_filter(graph, build_downstream_... | [
"def",
"get_downstream_causal_subgraph",
"(",
"graph",
",",
"nbunch",
":",
"Union",
"[",
"BaseEntity",
",",
"Iterable",
"[",
"BaseEntity",
"]",
"]",
")",
":",
"return",
"get_subgraph_by_edge_filter",
"(",
"graph",
",",
"build_downstream_edge_predicate",
"(",
"nbunch... | Induce a sub-graph from all of the downstream causal entities of the nodes in the nbunch.
:type graph: pybel.BELGraph
:rtype: pybel.BELGraph | [
"Induce",
"a",
"sub",
"-",
"graph",
"from",
"all",
"of",
"the",
"downstream",
"causal",
"entities",
"of",
"the",
"nodes",
"in",
"the",
"nbunch",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/upstream.py#L32-L38 | train | 29,731 |
pybel/pybel | src/pybel/struct/grouping/utils.py | cleanup | def cleanup(graph, subgraphs):
"""Clean up the metadata in the subgraphs.
:type graph: pybel.BELGraph
:type subgraphs: dict[Any,pybel.BELGraph]
"""
for subgraph in subgraphs.values():
update_node_helper(graph, subgraph)
update_metadata(graph, subgraph) | python | def cleanup(graph, subgraphs):
"""Clean up the metadata in the subgraphs.
:type graph: pybel.BELGraph
:type subgraphs: dict[Any,pybel.BELGraph]
"""
for subgraph in subgraphs.values():
update_node_helper(graph, subgraph)
update_metadata(graph, subgraph) | [
"def",
"cleanup",
"(",
"graph",
",",
"subgraphs",
")",
":",
"for",
"subgraph",
"in",
"subgraphs",
".",
"values",
"(",
")",
":",
"update_node_helper",
"(",
"graph",
",",
"subgraph",
")",
"update_metadata",
"(",
"graph",
",",
"subgraph",
")"
] | Clean up the metadata in the subgraphs.
:type graph: pybel.BELGraph
:type subgraphs: dict[Any,pybel.BELGraph] | [
"Clean",
"up",
"the",
"metadata",
"in",
"the",
"subgraphs",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/grouping/utils.py#L12-L20 | train | 29,732 |
pybel/pybel | src/pybel/parser/modifiers/fragment.py | get_fragment_language | def get_fragment_language() -> ParserElement:
"""Build a protein fragment parser."""
_fragment_value_inner = fragment_range | missing_fragment(FRAGMENT_MISSING)
_fragment_value = _fragment_value_inner | And([Suppress('"'), _fragment_value_inner, Suppress('"')])
parser_element = fragment_tag + nest(_frag... | python | def get_fragment_language() -> ParserElement:
"""Build a protein fragment parser."""
_fragment_value_inner = fragment_range | missing_fragment(FRAGMENT_MISSING)
_fragment_value = _fragment_value_inner | And([Suppress('"'), _fragment_value_inner, Suppress('"')])
parser_element = fragment_tag + nest(_frag... | [
"def",
"get_fragment_language",
"(",
")",
"->",
"ParserElement",
":",
"_fragment_value_inner",
"=",
"fragment_range",
"|",
"missing_fragment",
"(",
"FRAGMENT_MISSING",
")",
"_fragment_value",
"=",
"_fragment_value_inner",
"|",
"And",
"(",
"[",
"Suppress",
"(",
"'\"'",... | Build a protein fragment parser. | [
"Build",
"a",
"protein",
"fragment",
"parser",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/modifiers/fragment.py#L76-L81 | train | 29,733 |
pybel/pybel | src/pybel/parser/modifiers/protein_modification.py | get_protein_modification_language | def get_protein_modification_language(identifier_qualified: ParserElement) -> ParserElement:
"""Build a protein modification parser."""
pmod_identifier = MatchFirst([
identifier_qualified,
pmod_default_ns,
pmod_legacy_ns
])
return pmod_tag + nest(
Group(pmod_identifier)(... | python | def get_protein_modification_language(identifier_qualified: ParserElement) -> ParserElement:
"""Build a protein modification parser."""
pmod_identifier = MatchFirst([
identifier_qualified,
pmod_default_ns,
pmod_legacy_ns
])
return pmod_tag + nest(
Group(pmod_identifier)(... | [
"def",
"get_protein_modification_language",
"(",
"identifier_qualified",
":",
"ParserElement",
")",
"->",
"ParserElement",
":",
"pmod_identifier",
"=",
"MatchFirst",
"(",
"[",
"identifier_qualified",
",",
"pmod_default_ns",
",",
"pmod_legacy_ns",
"]",
")",
"return",
"pm... | Build a protein modification parser. | [
"Build",
"a",
"protein",
"modification",
"parser",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/modifiers/protein_modification.py#L112-L130 | train | 29,734 |
pybel/pybel | scripts/run_jgif.py | upload_cbn_dir | def upload_cbn_dir(dir_path, manager):
"""Uploads CBN data to edge store
:param str dir_path: Directory full of CBN JGIF files
:param pybel.Manager manager:
"""
t = time.time()
for jfg_path in os.listdir(dir_path):
if not jfg_path.endswith('.jgf'):
continue
path = ... | python | def upload_cbn_dir(dir_path, manager):
"""Uploads CBN data to edge store
:param str dir_path: Directory full of CBN JGIF files
:param pybel.Manager manager:
"""
t = time.time()
for jfg_path in os.listdir(dir_path):
if not jfg_path.endswith('.jgf'):
continue
path = ... | [
"def",
"upload_cbn_dir",
"(",
"dir_path",
",",
"manager",
")",
":",
"t",
"=",
"time",
".",
"time",
"(",
")",
"for",
"jfg_path",
"in",
"os",
".",
"listdir",
"(",
"dir_path",
")",
":",
"if",
"not",
"jfg_path",
".",
"endswith",
"(",
"'.jgf'",
")",
":",
... | Uploads CBN data to edge store
:param str dir_path: Directory full of CBN JGIF files
:param pybel.Manager manager: | [
"Uploads",
"CBN",
"data",
"to",
"edge",
"store"
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/scripts/run_jgif.py#L16-L47 | train | 29,735 |
pybel/pybel | src/pybel/dsl/edges.py | _activity_helper | def _activity_helper(modifier: str, location=None):
"""Make an activity dictionary.
:param str modifier:
:param Optional[dict] location: An entity from :func:`pybel.dsl.entity`
:rtype: dict
"""
rv = {MODIFIER: modifier}
if location:
rv[LOCATION] = location
return rv | python | def _activity_helper(modifier: str, location=None):
"""Make an activity dictionary.
:param str modifier:
:param Optional[dict] location: An entity from :func:`pybel.dsl.entity`
:rtype: dict
"""
rv = {MODIFIER: modifier}
if location:
rv[LOCATION] = location
return rv | [
"def",
"_activity_helper",
"(",
"modifier",
":",
"str",
",",
"location",
"=",
"None",
")",
":",
"rv",
"=",
"{",
"MODIFIER",
":",
"modifier",
"}",
"if",
"location",
":",
"rv",
"[",
"LOCATION",
"]",
"=",
"location",
"return",
"rv"
] | Make an activity dictionary.
:param str modifier:
:param Optional[dict] location: An entity from :func:`pybel.dsl.entity`
:rtype: dict | [
"Make",
"an",
"activity",
"dictionary",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/edges.py#L21-L33 | train | 29,736 |
pybel/pybel | src/pybel/dsl/edges.py | translocation | def translocation(from_loc, to_loc):
"""Make a translocation dictionary.
:param dict from_loc: An entity dictionary from :func:`pybel.dsl.entity`
:param dict to_loc: An entity dictionary from :func:`pybel.dsl.entity`
:rtype: dict
"""
rv = _activity_helper(TRANSLOCATION)
rv[EFFECT] = {
... | python | def translocation(from_loc, to_loc):
"""Make a translocation dictionary.
:param dict from_loc: An entity dictionary from :func:`pybel.dsl.entity`
:param dict to_loc: An entity dictionary from :func:`pybel.dsl.entity`
:rtype: dict
"""
rv = _activity_helper(TRANSLOCATION)
rv[EFFECT] = {
... | [
"def",
"translocation",
"(",
"from_loc",
",",
"to_loc",
")",
":",
"rv",
"=",
"_activity_helper",
"(",
"TRANSLOCATION",
")",
"rv",
"[",
"EFFECT",
"]",
"=",
"{",
"FROM_LOC",
":",
"Entity",
"(",
"namespace",
"=",
"BEL_DEFAULT_NAMESPACE",
",",
"name",
"=",
"fr... | Make a translocation dictionary.
:param dict from_loc: An entity dictionary from :func:`pybel.dsl.entity`
:param dict to_loc: An entity dictionary from :func:`pybel.dsl.entity`
:rtype: dict | [
"Make",
"a",
"translocation",
"dictionary",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/dsl/edges.py#L66-L78 | train | 29,737 |
pybel/pybel | src/pybel/struct/summary/provenance.py | iterate_pubmed_identifiers | def iterate_pubmed_identifiers(graph) -> Iterable[str]:
"""Iterate over all PubMed identifiers in a graph.
:param pybel.BELGraph graph: A BEL graph
:return: An iterator over the PubMed identifiers in the graph
"""
return (
data[CITATION][CITATION_REFERENCE].strip()
for _, _, data in... | python | def iterate_pubmed_identifiers(graph) -> Iterable[str]:
"""Iterate over all PubMed identifiers in a graph.
:param pybel.BELGraph graph: A BEL graph
:return: An iterator over the PubMed identifiers in the graph
"""
return (
data[CITATION][CITATION_REFERENCE].strip()
for _, _, data in... | [
"def",
"iterate_pubmed_identifiers",
"(",
"graph",
")",
"->",
"Iterable",
"[",
"str",
"]",
":",
"return",
"(",
"data",
"[",
"CITATION",
"]",
"[",
"CITATION_REFERENCE",
"]",
".",
"strip",
"(",
")",
"for",
"_",
",",
"_",
",",
"data",
"in",
"graph",
".",
... | Iterate over all PubMed identifiers in a graph.
:param pybel.BELGraph graph: A BEL graph
:return: An iterator over the PubMed identifiers in the graph | [
"Iterate",
"over",
"all",
"PubMed",
"identifiers",
"in",
"a",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/summary/provenance.py#L18-L28 | train | 29,738 |
pybel/pybel | src/pybel/struct/mutation/deletion/deletion.py | remove_filtered_edges | def remove_filtered_edges(graph, edge_predicates=None):
"""Remove edges passing the given edge predicates.
:param pybel.BELGraph graph: A BEL graph
:param edge_predicates: A predicate or list of predicates
:type edge_predicates: None or ((pybel.BELGraph, tuple, tuple, int) -> bool) or iter[(pybel.BELGr... | python | def remove_filtered_edges(graph, edge_predicates=None):
"""Remove edges passing the given edge predicates.
:param pybel.BELGraph graph: A BEL graph
:param edge_predicates: A predicate or list of predicates
:type edge_predicates: None or ((pybel.BELGraph, tuple, tuple, int) -> bool) or iter[(pybel.BELGr... | [
"def",
"remove_filtered_edges",
"(",
"graph",
",",
"edge_predicates",
"=",
"None",
")",
":",
"edges",
"=",
"list",
"(",
"filter_edges",
"(",
"graph",
",",
"edge_predicates",
"=",
"edge_predicates",
")",
")",
"graph",
".",
"remove_edges_from",
"(",
"edges",
")"... | Remove edges passing the given edge predicates.
:param pybel.BELGraph graph: A BEL graph
:param edge_predicates: A predicate or list of predicates
:type edge_predicates: None or ((pybel.BELGraph, tuple, tuple, int) -> bool) or iter[(pybel.BELGraph, tuple, tuple, int) -> bool]]
:return: | [
"Remove",
"edges",
"passing",
"the",
"given",
"edge",
"predicates",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/deletion/deletion.py#L24-L33 | train | 29,739 |
pybel/pybel | src/pybel/struct/mutation/deletion/deletion.py | remove_filtered_nodes | def remove_filtered_nodes(graph, node_predicates=None):
"""Remove nodes passing the given node predicates.
:param pybel.BELGraph graph: A BEL graph
:type node_predicates: None or ((pybel.BELGraph, tuple) -> bool) or iter[(pybel.BELGraph, tuple) -> bool)]
"""
nodes = list(filter_nodes(graph, node_pr... | python | def remove_filtered_nodes(graph, node_predicates=None):
"""Remove nodes passing the given node predicates.
:param pybel.BELGraph graph: A BEL graph
:type node_predicates: None or ((pybel.BELGraph, tuple) -> bool) or iter[(pybel.BELGraph, tuple) -> bool)]
"""
nodes = list(filter_nodes(graph, node_pr... | [
"def",
"remove_filtered_nodes",
"(",
"graph",
",",
"node_predicates",
"=",
"None",
")",
":",
"nodes",
"=",
"list",
"(",
"filter_nodes",
"(",
"graph",
",",
"node_predicates",
"=",
"node_predicates",
")",
")",
"graph",
".",
"remove_nodes_from",
"(",
"nodes",
")"... | Remove nodes passing the given node predicates.
:param pybel.BELGraph graph: A BEL graph
:type node_predicates: None or ((pybel.BELGraph, tuple) -> bool) or iter[(pybel.BELGraph, tuple) -> bool)] | [
"Remove",
"nodes",
"passing",
"the",
"given",
"node",
"predicates",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/deletion/deletion.py#L37-L44 | train | 29,740 |
pybel/pybel | src/pybel/struct/mutation/induction/neighborhood.py | get_subgraph_by_neighborhood | def get_subgraph_by_neighborhood(graph, nodes: Iterable[BaseEntity]):
"""Get a BEL graph around the neighborhoods of the given nodes.
Returns none if no nodes are in the graph.
:param pybel.BELGraph graph: A BEL graph
:param nodes: An iterable of BEL nodes
:return: A BEL graph induced around the n... | python | def get_subgraph_by_neighborhood(graph, nodes: Iterable[BaseEntity]):
"""Get a BEL graph around the neighborhoods of the given nodes.
Returns none if no nodes are in the graph.
:param pybel.BELGraph graph: A BEL graph
:param nodes: An iterable of BEL nodes
:return: A BEL graph induced around the n... | [
"def",
"get_subgraph_by_neighborhood",
"(",
"graph",
",",
"nodes",
":",
"Iterable",
"[",
"BaseEntity",
"]",
")",
":",
"node_set",
"=",
"set",
"(",
"nodes",
")",
"if",
"not",
"any",
"(",
"node",
"in",
"graph",
"for",
"node",
"in",
"node_set",
")",
":",
... | Get a BEL graph around the neighborhoods of the given nodes.
Returns none if no nodes are in the graph.
:param pybel.BELGraph graph: A BEL graph
:param nodes: An iterable of BEL nodes
:return: A BEL graph induced around the neighborhoods of the given nodes
:rtype: Optional[pybel.BELGraph] | [
"Get",
"a",
"BEL",
"graph",
"around",
"the",
"neighborhoods",
"of",
"the",
"given",
"nodes",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/neighborhood.py#L18-L42 | train | 29,741 |
pybel/pybel | src/pybel/parser/modifiers/gene_modification.py | get_gene_modification_language | def get_gene_modification_language(identifier_qualified: ParserElement) -> ParserElement:
"""Build a gene modification parser."""
gmod_identifier = MatchFirst([
identifier_qualified,
gmod_default_ns,
])
return gmod_tag + nest(
Group(gmod_identifier)(IDENTIFIER)
) | python | def get_gene_modification_language(identifier_qualified: ParserElement) -> ParserElement:
"""Build a gene modification parser."""
gmod_identifier = MatchFirst([
identifier_qualified,
gmod_default_ns,
])
return gmod_tag + nest(
Group(gmod_identifier)(IDENTIFIER)
) | [
"def",
"get_gene_modification_language",
"(",
"identifier_qualified",
":",
"ParserElement",
")",
"->",
"ParserElement",
":",
"gmod_identifier",
"=",
"MatchFirst",
"(",
"[",
"identifier_qualified",
",",
"gmod_default_ns",
",",
"]",
")",
"return",
"gmod_tag",
"+",
"nest... | Build a gene modification parser. | [
"Build",
"a",
"gene",
"modification",
"parser",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/modifiers/gene_modification.py#L66-L75 | train | 29,742 |
pybel/pybel | src/pybel/utils.py | expand_dict | def expand_dict(flat_dict, sep='_'):
"""Expand a flattened dictionary.
:param dict flat_dict: a nested dictionary that has been flattened so the keys are composite
:param str sep: the separator between concatenated keys
:rtype: dict
"""
res = {}
rdict = defaultdict(list)
for flat_key, ... | python | def expand_dict(flat_dict, sep='_'):
"""Expand a flattened dictionary.
:param dict flat_dict: a nested dictionary that has been flattened so the keys are composite
:param str sep: the separator between concatenated keys
:rtype: dict
"""
res = {}
rdict = defaultdict(list)
for flat_key, ... | [
"def",
"expand_dict",
"(",
"flat_dict",
",",
"sep",
"=",
"'_'",
")",
":",
"res",
"=",
"{",
"}",
"rdict",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"flat_key",
",",
"value",
"in",
"flat_dict",
".",
"items",
"(",
")",
":",
"key",
"=",
"flat_key",
... | Expand a flattened dictionary.
:param dict flat_dict: a nested dictionary that has been flattened so the keys are composite
:param str sep: the separator between concatenated keys
:rtype: dict | [
"Expand",
"a",
"flattened",
"dictionary",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/utils.py#L24-L44 | train | 29,743 |
pybel/pybel | src/pybel/utils.py | tokenize_version | def tokenize_version(version_string: str) -> Tuple[int, int, int]:
"""Tokenize a version string to a tuple.
Truncates qualifiers like ``-dev``.
:param version_string: A version string
:return: A tuple representing the version string
>>> tokenize_version('0.1.2-dev')
(0, 1, 2)
"""
befo... | python | def tokenize_version(version_string: str) -> Tuple[int, int, int]:
"""Tokenize a version string to a tuple.
Truncates qualifiers like ``-dev``.
:param version_string: A version string
:return: A tuple representing the version string
>>> tokenize_version('0.1.2-dev')
(0, 1, 2)
"""
befo... | [
"def",
"tokenize_version",
"(",
"version_string",
":",
"str",
")",
"->",
"Tuple",
"[",
"int",
",",
"int",
",",
"int",
"]",
":",
"before_dash",
"=",
"version_string",
".",
"split",
"(",
"'-'",
")",
"[",
"0",
"]",
"major",
",",
"minor",
",",
"patch",
"... | Tokenize a version string to a tuple.
Truncates qualifiers like ``-dev``.
:param version_string: A version string
:return: A tuple representing the version string
>>> tokenize_version('0.1.2-dev')
(0, 1, 2) | [
"Tokenize",
"a",
"version",
"string",
"to",
"a",
"tuple",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/utils.py#L79-L92 | train | 29,744 |
pybel/pybel | src/pybel/utils.py | parse_datetime | def parse_datetime(s: str) -> datetime.date:
"""Try to parse a datetime object from a standard datetime format or date format."""
for fmt in (CREATION_DATE_FMT, PUBLISHED_DATE_FMT, PUBLISHED_DATE_FMT_2):
try:
dt = datetime.strptime(s, fmt)
except ValueError:
pass
... | python | def parse_datetime(s: str) -> datetime.date:
"""Try to parse a datetime object from a standard datetime format or date format."""
for fmt in (CREATION_DATE_FMT, PUBLISHED_DATE_FMT, PUBLISHED_DATE_FMT_2):
try:
dt = datetime.strptime(s, fmt)
except ValueError:
pass
... | [
"def",
"parse_datetime",
"(",
"s",
":",
"str",
")",
"->",
"datetime",
".",
"date",
":",
"for",
"fmt",
"in",
"(",
"CREATION_DATE_FMT",
",",
"PUBLISHED_DATE_FMT",
",",
"PUBLISHED_DATE_FMT_2",
")",
":",
"try",
":",
"dt",
"=",
"datetime",
".",
"strptime",
"(",... | Try to parse a datetime object from a standard datetime format or date format. | [
"Try",
"to",
"parse",
"a",
"datetime",
"object",
"from",
"a",
"standard",
"datetime",
"format",
"or",
"date",
"format",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/utils.py#L124-L134 | train | 29,745 |
pybel/pybel | src/pybel/utils.py | _get_edge_tuple | def _get_edge_tuple(source,
target,
edge_data: EdgeData,
) -> Tuple[str, str, str, Optional[str], Tuple[str, Optional[Tuple], Optional[Tuple]]]:
"""Convert an edge to a consistent tuple.
:param BaseEntity source: The source BEL node
:param BaseEnt... | python | def _get_edge_tuple(source,
target,
edge_data: EdgeData,
) -> Tuple[str, str, str, Optional[str], Tuple[str, Optional[Tuple], Optional[Tuple]]]:
"""Convert an edge to a consistent tuple.
:param BaseEntity source: The source BEL node
:param BaseEnt... | [
"def",
"_get_edge_tuple",
"(",
"source",
",",
"target",
",",
"edge_data",
":",
"EdgeData",
",",
")",
"->",
"Tuple",
"[",
"str",
",",
"str",
",",
"str",
",",
"Optional",
"[",
"str",
"]",
",",
"Tuple",
"[",
"str",
",",
"Optional",
"[",
"Tuple",
"]",
... | Convert an edge to a consistent tuple.
:param BaseEntity source: The source BEL node
:param BaseEntity target: The target BEL node
:param edge_data: The edge's data dictionary
:return: A tuple that can be hashed representing this edge. Makes no promises to its structure. | [
"Convert",
"an",
"edge",
"to",
"a",
"consistent",
"tuple",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/utils.py#L150-L167 | train | 29,746 |
pybel/pybel | src/pybel/utils.py | hash_edge | def hash_edge(source, target, edge_data: EdgeData) -> str:
"""Convert an edge tuple to a SHA-512 hash.
:param BaseEntity source: The source BEL node
:param BaseEntity target: The target BEL node
:param edge_data: The edge's data dictionary
:return: A hashed version of the edge tuple using md5 hash ... | python | def hash_edge(source, target, edge_data: EdgeData) -> str:
"""Convert an edge tuple to a SHA-512 hash.
:param BaseEntity source: The source BEL node
:param BaseEntity target: The target BEL node
:param edge_data: The edge's data dictionary
:return: A hashed version of the edge tuple using md5 hash ... | [
"def",
"hash_edge",
"(",
"source",
",",
"target",
",",
"edge_data",
":",
"EdgeData",
")",
"->",
"str",
":",
"edge_tuple",
"=",
"_get_edge_tuple",
"(",
"source",
",",
"target",
",",
"edge_data",
")",
"return",
"_hash_tuple",
"(",
"edge_tuple",
")"
] | Convert an edge tuple to a SHA-512 hash.
:param BaseEntity source: The source BEL node
:param BaseEntity target: The target BEL node
:param edge_data: The edge's data dictionary
:return: A hashed version of the edge tuple using md5 hash of the binary pickle dump of u, v, and the json dump of d | [
"Convert",
"an",
"edge",
"tuple",
"to",
"a",
"SHA",
"-",
"512",
"hash",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/utils.py#L170-L179 | train | 29,747 |
pybel/pybel | src/pybel/utils.py | subdict_matches | def subdict_matches(target: Mapping, query: Mapping, partial_match: bool = True) -> bool:
"""Check if all the keys in the query dict are in the target dict, and that their values match.
1. Checks that all keys in the query dict are in the target dict
2. Matches the values of the keys in the query dict
... | python | def subdict_matches(target: Mapping, query: Mapping, partial_match: bool = True) -> bool:
"""Check if all the keys in the query dict are in the target dict, and that their values match.
1. Checks that all keys in the query dict are in the target dict
2. Matches the values of the keys in the query dict
... | [
"def",
"subdict_matches",
"(",
"target",
":",
"Mapping",
",",
"query",
":",
"Mapping",
",",
"partial_match",
":",
"bool",
"=",
"True",
")",
"->",
"bool",
":",
"for",
"k",
",",
"v",
"in",
"query",
".",
"items",
"(",
")",
":",
"if",
"k",
"not",
"in",... | Check if all the keys in the query dict are in the target dict, and that their values match.
1. Checks that all keys in the query dict are in the target dict
2. Matches the values of the keys in the query dict
a. If the value is a string, then must match exactly
b. If the value is a set/list/tu... | [
"Check",
"if",
"all",
"the",
"keys",
"in",
"the",
"query",
"dict",
"are",
"in",
"the",
"target",
"dict",
"and",
"that",
"their",
"values",
"match",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/utils.py#L182-L214 | train | 29,748 |
pybel/pybel | src/pybel/utils.py | hash_dump | def hash_dump(data) -> str:
"""Hash an arbitrary JSON dictionary by dumping it in sorted order, encoding it in UTF-8, then hashing the bytes.
:param data: An arbitrary JSON-serializable object
:type data: dict or list or tuple
"""
return hashlib.sha512(json.dumps(data, sort_keys=True).encode('utf-8... | python | def hash_dump(data) -> str:
"""Hash an arbitrary JSON dictionary by dumping it in sorted order, encoding it in UTF-8, then hashing the bytes.
:param data: An arbitrary JSON-serializable object
:type data: dict or list or tuple
"""
return hashlib.sha512(json.dumps(data, sort_keys=True).encode('utf-8... | [
"def",
"hash_dump",
"(",
"data",
")",
"->",
"str",
":",
"return",
"hashlib",
".",
"sha512",
"(",
"json",
".",
"dumps",
"(",
"data",
",",
"sort_keys",
"=",
"True",
")",
".",
"encode",
"(",
"'utf-8'",
")",
")",
".",
"hexdigest",
"(",
")"
] | Hash an arbitrary JSON dictionary by dumping it in sorted order, encoding it in UTF-8, then hashing the bytes.
:param data: An arbitrary JSON-serializable object
:type data: dict or list or tuple | [
"Hash",
"an",
"arbitrary",
"JSON",
"dictionary",
"by",
"dumping",
"it",
"in",
"sorted",
"order",
"encoding",
"it",
"in",
"UTF",
"-",
"8",
"then",
"hashing",
"the",
"bytes",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/utils.py#L217-L223 | train | 29,749 |
pybel/pybel | src/pybel/utils.py | hash_evidence | def hash_evidence(text: str, type: str, reference: str) -> str:
"""Create a hash for an evidence and its citation.
:param text: The evidence text
:param type: The corresponding citation type
:param reference: The citation reference
"""
s = u'{type}:{reference}:{text}'.format(type=type, referenc... | python | def hash_evidence(text: str, type: str, reference: str) -> str:
"""Create a hash for an evidence and its citation.
:param text: The evidence text
:param type: The corresponding citation type
:param reference: The citation reference
"""
s = u'{type}:{reference}:{text}'.format(type=type, referenc... | [
"def",
"hash_evidence",
"(",
"text",
":",
"str",
",",
"type",
":",
"str",
",",
"reference",
":",
"str",
")",
"->",
"str",
":",
"s",
"=",
"u'{type}:{reference}:{text}'",
".",
"format",
"(",
"type",
"=",
"type",
",",
"reference",
"=",
"reference",
",",
"... | Create a hash for an evidence and its citation.
:param text: The evidence text
:param type: The corresponding citation type
:param reference: The citation reference | [
"Create",
"a",
"hash",
"for",
"an",
"evidence",
"and",
"its",
"citation",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/utils.py#L236-L244 | train | 29,750 |
pybel/pybel | src/pybel/utils.py | canonicalize_edge | def canonicalize_edge(edge_data: EdgeData) -> Tuple[str, Optional[Tuple], Optional[Tuple]]:
"""Canonicalize the edge to a tuple based on the relation, subject modifications, and object modifications."""
return (
edge_data[RELATION],
_canonicalize_edge_modifications(edge_data.get(SUBJECT)),
... | python | def canonicalize_edge(edge_data: EdgeData) -> Tuple[str, Optional[Tuple], Optional[Tuple]]:
"""Canonicalize the edge to a tuple based on the relation, subject modifications, and object modifications."""
return (
edge_data[RELATION],
_canonicalize_edge_modifications(edge_data.get(SUBJECT)),
... | [
"def",
"canonicalize_edge",
"(",
"edge_data",
":",
"EdgeData",
")",
"->",
"Tuple",
"[",
"str",
",",
"Optional",
"[",
"Tuple",
"]",
",",
"Optional",
"[",
"Tuple",
"]",
"]",
":",
"return",
"(",
"edge_data",
"[",
"RELATION",
"]",
",",
"_canonicalize_edge_modi... | Canonicalize the edge to a tuple based on the relation, subject modifications, and object modifications. | [
"Canonicalize",
"the",
"edge",
"to",
"a",
"tuple",
"based",
"on",
"the",
"relation",
"subject",
"modifications",
"and",
"object",
"modifications",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/utils.py#L247-L253 | train | 29,751 |
pybel/pybel | src/pybel/utils.py | _canonicalize_edge_modifications | def _canonicalize_edge_modifications(edge_data: EdgeData) -> Optional[Tuple]:
"""Return the SUBJECT or OBJECT entry of a PyBEL edge data dictionary as a canonical tuple."""
if edge_data is None:
return
modifier = edge_data.get(MODIFIER)
location = edge_data.get(LOCATION)
effect = edge_data.... | python | def _canonicalize_edge_modifications(edge_data: EdgeData) -> Optional[Tuple]:
"""Return the SUBJECT or OBJECT entry of a PyBEL edge data dictionary as a canonical tuple."""
if edge_data is None:
return
modifier = edge_data.get(MODIFIER)
location = edge_data.get(LOCATION)
effect = edge_data.... | [
"def",
"_canonicalize_edge_modifications",
"(",
"edge_data",
":",
"EdgeData",
")",
"->",
"Optional",
"[",
"Tuple",
"]",
":",
"if",
"edge_data",
"is",
"None",
":",
"return",
"modifier",
"=",
"edge_data",
".",
"get",
"(",
"MODIFIER",
")",
"location",
"=",
"edg... | Return the SUBJECT or OBJECT entry of a PyBEL edge data dictionary as a canonical tuple. | [
"Return",
"the",
"SUBJECT",
"or",
"OBJECT",
"entry",
"of",
"a",
"PyBEL",
"edge",
"data",
"dictionary",
"as",
"a",
"canonical",
"tuple",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/utils.py#L256-L322 | train | 29,752 |
pybel/pybel | src/pybel/struct/grouping/provenance.py | get_subgraphs_by_citation | def get_subgraphs_by_citation(graph):
"""Stratify the graph based on citations.
:type graph: pybel.BELGraph
:rtype: dict[tuple[str,str],pybel.BELGraph]
"""
rv = defaultdict(graph.fresh_copy)
for u, v, key, data in graph.edges(keys=True, data=True):
if CITATION not in data:
... | python | def get_subgraphs_by_citation(graph):
"""Stratify the graph based on citations.
:type graph: pybel.BELGraph
:rtype: dict[tuple[str,str],pybel.BELGraph]
"""
rv = defaultdict(graph.fresh_copy)
for u, v, key, data in graph.edges(keys=True, data=True):
if CITATION not in data:
... | [
"def",
"get_subgraphs_by_citation",
"(",
"graph",
")",
":",
"rv",
"=",
"defaultdict",
"(",
"graph",
".",
"fresh_copy",
")",
"for",
"u",
",",
"v",
",",
"key",
",",
"data",
"in",
"graph",
".",
"edges",
"(",
"keys",
"=",
"True",
",",
"data",
"=",
"True"... | Stratify the graph based on citations.
:type graph: pybel.BELGraph
:rtype: dict[tuple[str,str],pybel.BELGraph] | [
"Stratify",
"the",
"graph",
"based",
"on",
"citations",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/grouping/provenance.py#L15-L32 | train | 29,753 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.raise_for_missing_citation | def raise_for_missing_citation(self, line: str, position: int) -> None:
"""Raise an exception if there is no citation present in the parser.
:raises: MissingCitationException
"""
if self.citation_clearing and not self.citation:
raise MissingCitationException(self.get_line_nu... | python | def raise_for_missing_citation(self, line: str, position: int) -> None:
"""Raise an exception if there is no citation present in the parser.
:raises: MissingCitationException
"""
if self.citation_clearing and not self.citation:
raise MissingCitationException(self.get_line_nu... | [
"def",
"raise_for_missing_citation",
"(",
"self",
",",
"line",
":",
"str",
",",
"position",
":",
"int",
")",
"->",
"None",
":",
"if",
"self",
".",
"citation_clearing",
"and",
"not",
"self",
".",
"citation",
":",
"raise",
"MissingCitationException",
"(",
"sel... | Raise an exception if there is no citation present in the parser.
:raises: MissingCitationException | [
"Raise",
"an",
"exception",
"if",
"there",
"is",
"no",
"citation",
"present",
"in",
"the",
"parser",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L185-L191 | train | 29,754 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.handle_annotation_key | def handle_annotation_key(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Handle an annotation key before parsing to validate that it's either enumerated or as a regex.
:raise: MissingCitationException or UndefinedAnnotationWarning
"""
key = tokens['key']
... | python | def handle_annotation_key(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Handle an annotation key before parsing to validate that it's either enumerated or as a regex.
:raise: MissingCitationException or UndefinedAnnotationWarning
"""
key = tokens['key']
... | [
"def",
"handle_annotation_key",
"(",
"self",
",",
"line",
":",
"str",
",",
"position",
":",
"int",
",",
"tokens",
":",
"ParseResults",
")",
"->",
"ParseResults",
":",
"key",
"=",
"tokens",
"[",
"'key'",
"]",
"self",
".",
"raise_for_missing_citation",
"(",
... | Handle an annotation key before parsing to validate that it's either enumerated or as a regex.
:raise: MissingCitationException or UndefinedAnnotationWarning | [
"Handle",
"an",
"annotation",
"key",
"before",
"parsing",
"to",
"validate",
"that",
"it",
"s",
"either",
"enumerated",
"or",
"as",
"a",
"regex",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L193-L201 | train | 29,755 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.handle_set_statement_group | def handle_set_statement_group(self, _, __, tokens: ParseResults) -> ParseResults:
"""Handle a ``SET STATEMENT_GROUP = "X"`` statement."""
self.statement_group = tokens['group']
return tokens | python | def handle_set_statement_group(self, _, __, tokens: ParseResults) -> ParseResults:
"""Handle a ``SET STATEMENT_GROUP = "X"`` statement."""
self.statement_group = tokens['group']
return tokens | [
"def",
"handle_set_statement_group",
"(",
"self",
",",
"_",
",",
"__",
",",
"tokens",
":",
"ParseResults",
")",
"->",
"ParseResults",
":",
"self",
".",
"statement_group",
"=",
"tokens",
"[",
"'group'",
"]",
"return",
"tokens"
] | Handle a ``SET STATEMENT_GROUP = "X"`` statement. | [
"Handle",
"a",
"SET",
"STATEMENT_GROUP",
"=",
"X",
"statement",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L203-L206 | train | 29,756 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.handle_set_evidence | def handle_set_evidence(self, _, __, tokens: ParseResults) -> ParseResults:
"""Handle a ``SET Evidence = ""`` statement."""
self.evidence = tokens['value']
return tokens | python | def handle_set_evidence(self, _, __, tokens: ParseResults) -> ParseResults:
"""Handle a ``SET Evidence = ""`` statement."""
self.evidence = tokens['value']
return tokens | [
"def",
"handle_set_evidence",
"(",
"self",
",",
"_",
",",
"__",
",",
"tokens",
":",
"ParseResults",
")",
"->",
"ParseResults",
":",
"self",
".",
"evidence",
"=",
"tokens",
"[",
"'value'",
"]",
"return",
"tokens"
] | Handle a ``SET Evidence = ""`` statement. | [
"Handle",
"a",
"SET",
"Evidence",
"=",
"statement",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L255-L258 | train | 29,757 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.handle_set_command | def handle_set_command(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Handle a ``SET X = "Y"`` statement."""
key, value = tokens['key'], tokens['value']
self.raise_for_invalid_annotation_value(line, position, key, value)
self.annotations[key] = value
re... | python | def handle_set_command(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Handle a ``SET X = "Y"`` statement."""
key, value = tokens['key'], tokens['value']
self.raise_for_invalid_annotation_value(line, position, key, value)
self.annotations[key] = value
re... | [
"def",
"handle_set_command",
"(",
"self",
",",
"line",
":",
"str",
",",
"position",
":",
"int",
",",
"tokens",
":",
"ParseResults",
")",
"->",
"ParseResults",
":",
"key",
",",
"value",
"=",
"tokens",
"[",
"'key'",
"]",
",",
"tokens",
"[",
"'value'",
"]... | Handle a ``SET X = "Y"`` statement. | [
"Handle",
"a",
"SET",
"X",
"=",
"Y",
"statement",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L260-L265 | train | 29,758 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.handle_unset_statement_group | def handle_unset_statement_group(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Unset the statement group, or raises an exception if it is not set.
:raises: MissingAnnotationKeyWarning
"""
if self.statement_group is None:
raise MissingAnnotationKey... | python | def handle_unset_statement_group(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Unset the statement group, or raises an exception if it is not set.
:raises: MissingAnnotationKeyWarning
"""
if self.statement_group is None:
raise MissingAnnotationKey... | [
"def",
"handle_unset_statement_group",
"(",
"self",
",",
"line",
":",
"str",
",",
"position",
":",
"int",
",",
"tokens",
":",
"ParseResults",
")",
"->",
"ParseResults",
":",
"if",
"self",
".",
"statement_group",
"is",
"None",
":",
"raise",
"MissingAnnotationKe... | Unset the statement group, or raises an exception if it is not set.
:raises: MissingAnnotationKeyWarning | [
"Unset",
"the",
"statement",
"group",
"or",
"raises",
"an",
"exception",
"if",
"it",
"is",
"not",
"set",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L275-L283 | train | 29,759 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.handle_unset_citation | def handle_unset_citation(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Unset the citation, or raise an exception if it is not set.
:raises: MissingAnnotationKeyWarning
"""
if not self.citation:
raise MissingAnnotationKeyWarning(self.get_line_numb... | python | def handle_unset_citation(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Unset the citation, or raise an exception if it is not set.
:raises: MissingAnnotationKeyWarning
"""
if not self.citation:
raise MissingAnnotationKeyWarning(self.get_line_numb... | [
"def",
"handle_unset_citation",
"(",
"self",
",",
"line",
":",
"str",
",",
"position",
":",
"int",
",",
"tokens",
":",
"ParseResults",
")",
"->",
"ParseResults",
":",
"if",
"not",
"self",
".",
"citation",
":",
"raise",
"MissingAnnotationKeyWarning",
"(",
"se... | Unset the citation, or raise an exception if it is not set.
:raises: MissingAnnotationKeyWarning | [
"Unset",
"the",
"citation",
"or",
"raise",
"an",
"exception",
"if",
"it",
"is",
"not",
"set",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L285-L294 | train | 29,760 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.handle_unset_evidence | def handle_unset_evidence(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Unset the evidence, or throws an exception if it is not already set.
The value for ``tokens[EVIDENCE]`` corresponds to which alternate of SupportingText or Evidence was used in
the BEL script.
... | python | def handle_unset_evidence(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Unset the evidence, or throws an exception if it is not already set.
The value for ``tokens[EVIDENCE]`` corresponds to which alternate of SupportingText or Evidence was used in
the BEL script.
... | [
"def",
"handle_unset_evidence",
"(",
"self",
",",
"line",
":",
"str",
",",
"position",
":",
"int",
",",
"tokens",
":",
"ParseResults",
")",
"->",
"ParseResults",
":",
"if",
"self",
".",
"evidence",
"is",
"None",
":",
"raise",
"MissingAnnotationKeyWarning",
"... | Unset the evidence, or throws an exception if it is not already set.
The value for ``tokens[EVIDENCE]`` corresponds to which alternate of SupportingText or Evidence was used in
the BEL script.
:raises: MissingAnnotationKeyWarning | [
"Unset",
"the",
"evidence",
"or",
"throws",
"an",
"exception",
"if",
"it",
"is",
"not",
"already",
"set",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L296-L307 | train | 29,761 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.validate_unset_command | def validate_unset_command(self, line: str, position: int, annotation: str) -> None:
"""Raise an exception when trying to ``UNSET X`` if ``X`` is not already set.
:raises: MissingAnnotationKeyWarning
"""
if annotation not in self.annotations:
raise MissingAnnotationKeyWarnin... | python | def validate_unset_command(self, line: str, position: int, annotation: str) -> None:
"""Raise an exception when trying to ``UNSET X`` if ``X`` is not already set.
:raises: MissingAnnotationKeyWarning
"""
if annotation not in self.annotations:
raise MissingAnnotationKeyWarnin... | [
"def",
"validate_unset_command",
"(",
"self",
",",
"line",
":",
"str",
",",
"position",
":",
"int",
",",
"annotation",
":",
"str",
")",
"->",
"None",
":",
"if",
"annotation",
"not",
"in",
"self",
".",
"annotations",
":",
"raise",
"MissingAnnotationKeyWarning... | Raise an exception when trying to ``UNSET X`` if ``X`` is not already set.
:raises: MissingAnnotationKeyWarning | [
"Raise",
"an",
"exception",
"when",
"trying",
"to",
"UNSET",
"X",
"if",
"X",
"is",
"not",
"already",
"set",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L309-L315 | train | 29,762 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.handle_unset_command | def handle_unset_command(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Handle an ``UNSET X`` statement or raises an exception if it is not already set.
:raises: MissingAnnotationKeyWarning
"""
key = tokens['key']
self.validate_unset_command(line, posi... | python | def handle_unset_command(self, line: str, position: int, tokens: ParseResults) -> ParseResults:
"""Handle an ``UNSET X`` statement or raises an exception if it is not already set.
:raises: MissingAnnotationKeyWarning
"""
key = tokens['key']
self.validate_unset_command(line, posi... | [
"def",
"handle_unset_command",
"(",
"self",
",",
"line",
":",
"str",
",",
"position",
":",
"int",
",",
"tokens",
":",
"ParseResults",
")",
"->",
"ParseResults",
":",
"key",
"=",
"tokens",
"[",
"'key'",
"]",
"self",
".",
"validate_unset_command",
"(",
"line... | Handle an ``UNSET X`` statement or raises an exception if it is not already set.
:raises: MissingAnnotationKeyWarning | [
"Handle",
"an",
"UNSET",
"X",
"statement",
"or",
"raises",
"an",
"exception",
"if",
"it",
"is",
"not",
"already",
"set",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L317-L325 | train | 29,763 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.get_annotations | def get_annotations(self) -> Dict:
"""Get the current annotations."""
return {
EVIDENCE: self.evidence,
CITATION: self.citation.copy(),
ANNOTATIONS: self.annotations.copy()
} | python | def get_annotations(self) -> Dict:
"""Get the current annotations."""
return {
EVIDENCE: self.evidence,
CITATION: self.citation.copy(),
ANNOTATIONS: self.annotations.copy()
} | [
"def",
"get_annotations",
"(",
"self",
")",
"->",
"Dict",
":",
"return",
"{",
"EVIDENCE",
":",
"self",
".",
"evidence",
",",
"CITATION",
":",
"self",
".",
"citation",
".",
"copy",
"(",
")",
",",
"ANNOTATIONS",
":",
"self",
".",
"annotations",
".",
"cop... | Get the current annotations. | [
"Get",
"the",
"current",
"annotations",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L348-L354 | train | 29,764 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.get_missing_required_annotations | def get_missing_required_annotations(self) -> List[str]:
"""Return missing required annotations."""
return [
required_annotation
for required_annotation in self.required_annotations
if required_annotation not in self.annotations
] | python | def get_missing_required_annotations(self) -> List[str]:
"""Return missing required annotations."""
return [
required_annotation
for required_annotation in self.required_annotations
if required_annotation not in self.annotations
] | [
"def",
"get_missing_required_annotations",
"(",
"self",
")",
"->",
"List",
"[",
"str",
"]",
":",
"return",
"[",
"required_annotation",
"for",
"required_annotation",
"in",
"self",
".",
"required_annotations",
"if",
"required_annotation",
"not",
"in",
"self",
".",
"... | Return missing required annotations. | [
"Return",
"missing",
"required",
"annotations",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L356-L362 | train | 29,765 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.clear_citation | def clear_citation(self):
"""Clear the citation and if citation clearing is enabled, clear the evidence and annotations."""
self.citation.clear()
if self.citation_clearing:
self.evidence = None
self.annotations.clear() | python | def clear_citation(self):
"""Clear the citation and if citation clearing is enabled, clear the evidence and annotations."""
self.citation.clear()
if self.citation_clearing:
self.evidence = None
self.annotations.clear() | [
"def",
"clear_citation",
"(",
"self",
")",
":",
"self",
".",
"citation",
".",
"clear",
"(",
")",
"if",
"self",
".",
"citation_clearing",
":",
"self",
".",
"evidence",
"=",
"None",
"self",
".",
"annotations",
".",
"clear",
"(",
")"
] | Clear the citation and if citation clearing is enabled, clear the evidence and annotations. | [
"Clear",
"the",
"citation",
"and",
"if",
"citation",
"clearing",
"is",
"enabled",
"clear",
"the",
"evidence",
"and",
"annotations",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L364-L370 | train | 29,766 |
pybel/pybel | src/pybel/parser/parse_control.py | ControlParser.clear | def clear(self):
"""Clear the statement_group, citation, evidence, and annotations."""
self.statement_group = None
self.citation.clear()
self.evidence = None
self.annotations.clear() | python | def clear(self):
"""Clear the statement_group, citation, evidence, and annotations."""
self.statement_group = None
self.citation.clear()
self.evidence = None
self.annotations.clear() | [
"def",
"clear",
"(",
"self",
")",
":",
"self",
".",
"statement_group",
"=",
"None",
"self",
".",
"citation",
".",
"clear",
"(",
")",
"self",
".",
"evidence",
"=",
"None",
"self",
".",
"annotations",
".",
"clear",
"(",
")"
] | Clear the statement_group, citation, evidence, and annotations. | [
"Clear",
"the",
"statement_group",
"citation",
"evidence",
"and",
"annotations",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_control.py#L372-L377 | train | 29,767 |
pybel/pybel | src/pybel/io/jgif.py | map_cbn | def map_cbn(d):
"""Pre-processes the JSON from the CBN.
- removes statements without evidence, or with placeholder evidence
:param dict d: Raw JGIF from the CBN
:return: Preprocessed JGIF
:rtype: dict
"""
for i, edge in enumerate(d['graph']['edges']):
if 'metadata' not in d['graph'... | python | def map_cbn(d):
"""Pre-processes the JSON from the CBN.
- removes statements without evidence, or with placeholder evidence
:param dict d: Raw JGIF from the CBN
:return: Preprocessed JGIF
:rtype: dict
"""
for i, edge in enumerate(d['graph']['edges']):
if 'metadata' not in d['graph'... | [
"def",
"map_cbn",
"(",
"d",
")",
":",
"for",
"i",
",",
"edge",
"in",
"enumerate",
"(",
"d",
"[",
"'graph'",
"]",
"[",
"'edges'",
"]",
")",
":",
"if",
"'metadata'",
"not",
"in",
"d",
"[",
"'graph'",
"]",
"[",
"'edges'",
"]",
"[",
"i",
"]",
":",
... | Pre-processes the JSON from the CBN.
- removes statements without evidence, or with placeholder evidence
:param dict d: Raw JGIF from the CBN
:return: Preprocessed JGIF
:rtype: dict | [
"Pre",
"-",
"processes",
"the",
"JSON",
"from",
"the",
"CBN",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/jgif.py#L62-L124 | train | 29,768 |
pybel/pybel | src/pybel/io/jgif.py | from_jgif | def from_jgif(graph_jgif_dict):
"""Build a BEL graph from a JGIF JSON object.
:param dict graph_jgif_dict: The JSON object representing the graph in JGIF format
:rtype: BELGraph
"""
graph = BELGraph()
root = graph_jgif_dict['graph']
if 'label' in root:
graph.name = root['label']
... | python | def from_jgif(graph_jgif_dict):
"""Build a BEL graph from a JGIF JSON object.
:param dict graph_jgif_dict: The JSON object representing the graph in JGIF format
:rtype: BELGraph
"""
graph = BELGraph()
root = graph_jgif_dict['graph']
if 'label' in root:
graph.name = root['label']
... | [
"def",
"from_jgif",
"(",
"graph_jgif_dict",
")",
":",
"graph",
"=",
"BELGraph",
"(",
")",
"root",
"=",
"graph_jgif_dict",
"[",
"'graph'",
"]",
"if",
"'label'",
"in",
"root",
":",
"graph",
".",
"name",
"=",
"root",
"[",
"'label'",
"]",
"if",
"'metadata'",... | Build a BEL graph from a JGIF JSON object.
:param dict graph_jgif_dict: The JSON object representing the graph in JGIF format
:rtype: BELGraph | [
"Build",
"a",
"BEL",
"graph",
"from",
"a",
"JGIF",
"JSON",
"object",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/jgif.py#L203-L291 | train | 29,769 |
pybel/pybel | src/pybel/io/jgif.py | to_jgif | def to_jgif(graph):
"""Build a JGIF dictionary from a BEL graph.
:param pybel.BELGraph graph: A BEL graph
:return: A JGIF dictionary
:rtype: dict
.. warning::
Untested! This format is not general purpose and is therefore time is not heavily invested. If you want to
use Cytoscape.j... | python | def to_jgif(graph):
"""Build a JGIF dictionary from a BEL graph.
:param pybel.BELGraph graph: A BEL graph
:return: A JGIF dictionary
:rtype: dict
.. warning::
Untested! This format is not general purpose and is therefore time is not heavily invested. If you want to
use Cytoscape.j... | [
"def",
"to_jgif",
"(",
"graph",
")",
":",
"node_bel",
"=",
"{",
"}",
"u_v_r_bel",
"=",
"{",
"}",
"nodes_entry",
"=",
"[",
"]",
"edges_entry",
"=",
"[",
"]",
"for",
"i",
",",
"node",
"in",
"enumerate",
"(",
"sorted",
"(",
"graph",
",",
"key",
"=",
... | Build a JGIF dictionary from a BEL graph.
:param pybel.BELGraph graph: A BEL graph
:return: A JGIF dictionary
:rtype: dict
.. warning::
Untested! This format is not general purpose and is therefore time is not heavily invested. If you want to
use Cytoscape.js, we suggest using :func:`... | [
"Build",
"a",
"JGIF",
"dictionary",
"from",
"a",
"BEL",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/jgif.py#L294-L374 | train | 29,770 |
pybel/pybel | src/pybel/struct/query/selection.py | get_subgraph | def get_subgraph(graph,
seed_method: Optional[str] = None,
seed_data: Optional[Any] = None,
expand_nodes: Optional[List[BaseEntity]] = None,
remove_nodes: Optional[List[BaseEntity]] = None,
):
"""Run a pipeline query on graph with ... | python | def get_subgraph(graph,
seed_method: Optional[str] = None,
seed_data: Optional[Any] = None,
expand_nodes: Optional[List[BaseEntity]] = None,
remove_nodes: Optional[List[BaseEntity]] = None,
):
"""Run a pipeline query on graph with ... | [
"def",
"get_subgraph",
"(",
"graph",
",",
"seed_method",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"seed_data",
":",
"Optional",
"[",
"Any",
"]",
"=",
"None",
",",
"expand_nodes",
":",
"Optional",
"[",
"List",
"[",
"BaseEntity",
"]",
"]",
"="... | Run a pipeline query on graph with multiple sub-graph filters and expanders.
Order of Operations:
1. Seeding by given function name and data
2. Add nodes
3. Remove nodes
:param pybel.BELGraph graph: A BEL graph
:param seed_method: The name of the get_subgraph_by_* function to use
:param s... | [
"Run",
"a",
"pipeline",
"query",
"on",
"graph",
"with",
"multiple",
"sub",
"-",
"graph",
"filters",
"and",
"expanders",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/query/selection.py#L26-L117 | train | 29,771 |
pybel/pybel | src/pybel/struct/mutation/induction/paths.py | _remove_pathologies_oop | def _remove_pathologies_oop(graph):
"""Remove pathology nodes from the graph."""
rv = graph.copy()
victims = [
node
for node in rv
if node[FUNCTION] == PATHOLOGY
]
rv.remove_nodes_from(victims)
return rv | python | def _remove_pathologies_oop(graph):
"""Remove pathology nodes from the graph."""
rv = graph.copy()
victims = [
node
for node in rv
if node[FUNCTION] == PATHOLOGY
]
rv.remove_nodes_from(victims)
return rv | [
"def",
"_remove_pathologies_oop",
"(",
"graph",
")",
":",
"rv",
"=",
"graph",
".",
"copy",
"(",
")",
"victims",
"=",
"[",
"node",
"for",
"node",
"in",
"rv",
"if",
"node",
"[",
"FUNCTION",
"]",
"==",
"PATHOLOGY",
"]",
"rv",
".",
"remove_nodes_from",
"("... | Remove pathology nodes from the graph. | [
"Remove",
"pathology",
"nodes",
"from",
"the",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/paths.py#L26-L35 | train | 29,772 |
pybel/pybel | src/pybel/struct/mutation/induction/paths.py | get_random_path | def get_random_path(graph) -> List[BaseEntity]:
"""Get a random path from the graph as a list of nodes.
:param pybel.BELGraph graph: A BEL graph
"""
wg = graph.to_undirected()
nodes = wg.nodes()
def pick_random_pair() -> Tuple[BaseEntity, BaseEntity]:
"""Get a pair of random nodes."""... | python | def get_random_path(graph) -> List[BaseEntity]:
"""Get a random path from the graph as a list of nodes.
:param pybel.BELGraph graph: A BEL graph
"""
wg = graph.to_undirected()
nodes = wg.nodes()
def pick_random_pair() -> Tuple[BaseEntity, BaseEntity]:
"""Get a pair of random nodes."""... | [
"def",
"get_random_path",
"(",
"graph",
")",
"->",
"List",
"[",
"BaseEntity",
"]",
":",
"wg",
"=",
"graph",
".",
"to_undirected",
"(",
")",
"nodes",
"=",
"wg",
".",
"nodes",
"(",
")",
"def",
"pick_random_pair",
"(",
")",
"->",
"Tuple",
"[",
"BaseEntity... | Get a random path from the graph as a list of nodes.
:param pybel.BELGraph graph: A BEL graph | [
"Get",
"a",
"random",
"path",
"from",
"the",
"graph",
"as",
"a",
"list",
"of",
"nodes",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/paths.py#L114-L139 | train | 29,773 |
pybel/pybel | src/pybel/io/gpickle.py | to_bytes | def to_bytes(graph: BELGraph, protocol: int = HIGHEST_PROTOCOL) -> bytes:
"""Convert a graph to bytes with pickle.
Note that the pickle module has some incompatibilities between Python 2 and 3. To export a universally importable
pickle, choose 0, 1, or 2.
:param graph: A BEL network
:param protoco... | python | def to_bytes(graph: BELGraph, protocol: int = HIGHEST_PROTOCOL) -> bytes:
"""Convert a graph to bytes with pickle.
Note that the pickle module has some incompatibilities between Python 2 and 3. To export a universally importable
pickle, choose 0, 1, or 2.
:param graph: A BEL network
:param protoco... | [
"def",
"to_bytes",
"(",
"graph",
":",
"BELGraph",
",",
"protocol",
":",
"int",
"=",
"HIGHEST_PROTOCOL",
")",
"->",
"bytes",
":",
"raise_for_not_bel",
"(",
"graph",
")",
"return",
"dumps",
"(",
"graph",
",",
"protocol",
"=",
"protocol",
")"
] | Convert a graph to bytes with pickle.
Note that the pickle module has some incompatibilities between Python 2 and 3. To export a universally importable
pickle, choose 0, 1, or 2.
:param graph: A BEL network
:param protocol: Pickling protocol to use. Defaults to ``HIGHEST_PROTOCOL``.
.. seealso:: ... | [
"Convert",
"a",
"graph",
"to",
"bytes",
"with",
"pickle",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/gpickle.py#L21-L33 | train | 29,774 |
pybel/pybel | src/pybel/io/gpickle.py | from_pickle | def from_pickle(path: Union[str, BinaryIO], check_version: bool = True) -> BELGraph:
"""Read a graph from a pickle file.
:param path: File or filename to read. Filenames ending in .gz or .bz2 will be uncompressed.
:param bool check_version: Checks if the graph was produced by this version of PyBEL
"""
... | python | def from_pickle(path: Union[str, BinaryIO], check_version: bool = True) -> BELGraph:
"""Read a graph from a pickle file.
:param path: File or filename to read. Filenames ending in .gz or .bz2 will be uncompressed.
:param bool check_version: Checks if the graph was produced by this version of PyBEL
"""
... | [
"def",
"from_pickle",
"(",
"path",
":",
"Union",
"[",
"str",
",",
"BinaryIO",
"]",
",",
"check_version",
":",
"bool",
"=",
"True",
")",
"->",
"BELGraph",
":",
"graph",
"=",
"nx",
".",
"read_gpickle",
"(",
"path",
")",
"raise_for_not_bel",
"(",
"graph",
... | Read a graph from a pickle file.
:param path: File or filename to read. Filenames ending in .gz or .bz2 will be uncompressed.
:param bool check_version: Checks if the graph was produced by this version of PyBEL | [
"Read",
"a",
"graph",
"from",
"a",
"pickle",
"file",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/gpickle.py#L67-L79 | train | 29,775 |
pybel/pybel | src/pybel/struct/filters/edge_predicate_builders.py | build_annotation_dict_all_filter | def build_annotation_dict_all_filter(annotations: Mapping[str, Iterable[str]]) -> EdgePredicate:
"""Build an edge predicate for edges whose annotations are super-dictionaries of the given dictionary.
If no annotations are given, will always evaluate to true.
:param annotations: The annotation query dict t... | python | def build_annotation_dict_all_filter(annotations: Mapping[str, Iterable[str]]) -> EdgePredicate:
"""Build an edge predicate for edges whose annotations are super-dictionaries of the given dictionary.
If no annotations are given, will always evaluate to true.
:param annotations: The annotation query dict t... | [
"def",
"build_annotation_dict_all_filter",
"(",
"annotations",
":",
"Mapping",
"[",
"str",
",",
"Iterable",
"[",
"str",
"]",
"]",
")",
"->",
"EdgePredicate",
":",
"if",
"not",
"annotations",
":",
"return",
"keep_edge_permissive",
"@",
"edge_predicate",
"def",
"a... | Build an edge predicate for edges whose annotations are super-dictionaries of the given dictionary.
If no annotations are given, will always evaluate to true.
:param annotations: The annotation query dict to match | [
"Build",
"an",
"edge",
"predicate",
"for",
"edges",
"whose",
"annotations",
"are",
"super",
"-",
"dictionaries",
"of",
"the",
"given",
"dictionary",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/edge_predicate_builders.py#L48-L63 | train | 29,776 |
pybel/pybel | src/pybel/struct/filters/edge_predicate_builders.py | build_annotation_dict_any_filter | def build_annotation_dict_any_filter(annotations: Mapping[str, Iterable[str]]) -> EdgePredicate:
"""Build an edge predicate that passes for edges whose data dictionaries match the given dictionary.
If the given dictionary is empty, will always evaluate to true.
:param annotations: The annotation query dic... | python | def build_annotation_dict_any_filter(annotations: Mapping[str, Iterable[str]]) -> EdgePredicate:
"""Build an edge predicate that passes for edges whose data dictionaries match the given dictionary.
If the given dictionary is empty, will always evaluate to true.
:param annotations: The annotation query dic... | [
"def",
"build_annotation_dict_any_filter",
"(",
"annotations",
":",
"Mapping",
"[",
"str",
",",
"Iterable",
"[",
"str",
"]",
"]",
")",
"->",
"EdgePredicate",
":",
"if",
"not",
"annotations",
":",
"return",
"keep_edge_permissive",
"@",
"edge_predicate",
"def",
"a... | Build an edge predicate that passes for edges whose data dictionaries match the given dictionary.
If the given dictionary is empty, will always evaluate to true.
:param annotations: The annotation query dict to match | [
"Build",
"an",
"edge",
"predicate",
"that",
"passes",
"for",
"edges",
"whose",
"data",
"dictionaries",
"match",
"the",
"given",
"dictionary",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/edge_predicate_builders.py#L83-L98 | train | 29,777 |
pybel/pybel | src/pybel/struct/filters/edge_predicate_builders.py | build_upstream_edge_predicate | def build_upstream_edge_predicate(nodes: Iterable[BaseEntity]) -> EdgePredicate:
"""Build an edge predicate that pass for relations for which one of the given nodes is the object."""
nodes = set(nodes)
def upstream_filter(graph: BELGraph, u: BaseEntity, v: BaseEntity, k: str) -> bool:
"""Pass for r... | python | def build_upstream_edge_predicate(nodes: Iterable[BaseEntity]) -> EdgePredicate:
"""Build an edge predicate that pass for relations for which one of the given nodes is the object."""
nodes = set(nodes)
def upstream_filter(graph: BELGraph, u: BaseEntity, v: BaseEntity, k: str) -> bool:
"""Pass for r... | [
"def",
"build_upstream_edge_predicate",
"(",
"nodes",
":",
"Iterable",
"[",
"BaseEntity",
"]",
")",
"->",
"EdgePredicate",
":",
"nodes",
"=",
"set",
"(",
"nodes",
")",
"def",
"upstream_filter",
"(",
"graph",
":",
"BELGraph",
",",
"u",
":",
"BaseEntity",
",",... | Build an edge predicate that pass for relations for which one of the given nodes is the object. | [
"Build",
"an",
"edge",
"predicate",
"that",
"pass",
"for",
"relations",
"for",
"which",
"one",
"of",
"the",
"given",
"nodes",
"is",
"the",
"object",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/edge_predicate_builders.py#L101-L109 | train | 29,778 |
pybel/pybel | src/pybel/struct/filters/edge_predicate_builders.py | build_downstream_edge_predicate | def build_downstream_edge_predicate(nodes: Iterable[BaseEntity]) -> EdgePredicate:
"""Build an edge predicate that passes for edges for which one of the given nodes is the subject."""
nodes = set(nodes)
def downstream_filter(graph: BELGraph, u: BaseEntity, v: BaseEntity, k: str) -> bool:
"""Pass fo... | python | def build_downstream_edge_predicate(nodes: Iterable[BaseEntity]) -> EdgePredicate:
"""Build an edge predicate that passes for edges for which one of the given nodes is the subject."""
nodes = set(nodes)
def downstream_filter(graph: BELGraph, u: BaseEntity, v: BaseEntity, k: str) -> bool:
"""Pass fo... | [
"def",
"build_downstream_edge_predicate",
"(",
"nodes",
":",
"Iterable",
"[",
"BaseEntity",
"]",
")",
"->",
"EdgePredicate",
":",
"nodes",
"=",
"set",
"(",
"nodes",
")",
"def",
"downstream_filter",
"(",
"graph",
":",
"BELGraph",
",",
"u",
":",
"BaseEntity",
... | Build an edge predicate that passes for edges for which one of the given nodes is the subject. | [
"Build",
"an",
"edge",
"predicate",
"that",
"passes",
"for",
"edges",
"for",
"which",
"one",
"of",
"the",
"given",
"nodes",
"is",
"the",
"subject",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/edge_predicate_builders.py#L112-L120 | train | 29,779 |
pybel/pybel | src/pybel/struct/filters/edge_predicate_builders.py | build_relation_predicate | def build_relation_predicate(relations: Strings) -> EdgePredicate:
"""Build an edge predicate that passes for edges with the given relation."""
if isinstance(relations, str):
@edge_predicate
def relation_predicate(edge_data: EdgeData) -> bool:
"""Pass for relations matching the enclo... | python | def build_relation_predicate(relations: Strings) -> EdgePredicate:
"""Build an edge predicate that passes for edges with the given relation."""
if isinstance(relations, str):
@edge_predicate
def relation_predicate(edge_data: EdgeData) -> bool:
"""Pass for relations matching the enclo... | [
"def",
"build_relation_predicate",
"(",
"relations",
":",
"Strings",
")",
"->",
"EdgePredicate",
":",
"if",
"isinstance",
"(",
"relations",
",",
"str",
")",
":",
"@",
"edge_predicate",
"def",
"relation_predicate",
"(",
"edge_data",
":",
"EdgeData",
")",
"->",
... | Build an edge predicate that passes for edges with the given relation. | [
"Build",
"an",
"edge",
"predicate",
"that",
"passes",
"for",
"edges",
"with",
"the",
"given",
"relation",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/filters/edge_predicate_builders.py#L123-L142 | train | 29,780 |
pybel/pybel | src/pybel/struct/pipeline/decorators.py | _register_function | def _register_function(name: str, func, universe: bool, in_place: bool):
"""Register a transformation function under the given name.
:param name: Name to register the function under
:param func: A function
:param universe:
:param in_place:
:return: The same function, with additional properties ... | python | def _register_function(name: str, func, universe: bool, in_place: bool):
"""Register a transformation function under the given name.
:param name: Name to register the function under
:param func: A function
:param universe:
:param in_place:
:return: The same function, with additional properties ... | [
"def",
"_register_function",
"(",
"name",
":",
"str",
",",
"func",
",",
"universe",
":",
"bool",
",",
"in_place",
":",
"bool",
")",
":",
"if",
"name",
"in",
"mapped",
":",
"mapped_func",
"=",
"mapped",
"[",
"name",
"]",
"raise",
"PipelineNameError",
"(",... | Register a transformation function under the given name.
:param name: Name to register the function under
:param func: A function
:param universe:
:param in_place:
:return: The same function, with additional properties added | [
"Register",
"a",
"transformation",
"function",
"under",
"the",
"given",
"name",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/decorators.py#L44-L74 | train | 29,781 |
pybel/pybel | src/pybel/struct/pipeline/decorators.py | _build_register_function | def _build_register_function(universe: bool, in_place: bool): # noqa: D202
"""Build a decorator function to tag transformation functions.
:param universe: Does the first positional argument of this function correspond to a universe graph?
:param in_place: Does this function return a new graph, or just mod... | python | def _build_register_function(universe: bool, in_place: bool): # noqa: D202
"""Build a decorator function to tag transformation functions.
:param universe: Does the first positional argument of this function correspond to a universe graph?
:param in_place: Does this function return a new graph, or just mod... | [
"def",
"_build_register_function",
"(",
"universe",
":",
"bool",
",",
"in_place",
":",
"bool",
")",
":",
"# noqa: D202",
"def",
"register",
"(",
"func",
")",
":",
"\"\"\"Tag a transformation function.\n\n :param func: A function\n :return: The same function, with ... | Build a decorator function to tag transformation functions.
:param universe: Does the first positional argument of this function correspond to a universe graph?
:param in_place: Does this function return a new graph, or just modify it in-place? | [
"Build",
"a",
"decorator",
"function",
"to",
"tag",
"transformation",
"functions",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/decorators.py#L77-L92 | train | 29,782 |
pybel/pybel | src/pybel/struct/pipeline/decorators.py | register_deprecated | def register_deprecated(deprecated_name: str):
"""Register a function as deprecated.
:param deprecated_name: The old name of the function
:return: A decorator
Usage:
This function must be applied last, since it introspects on the definitions from before
>>> @register_deprecated('my_function'... | python | def register_deprecated(deprecated_name: str):
"""Register a function as deprecated.
:param deprecated_name: The old name of the function
:return: A decorator
Usage:
This function must be applied last, since it introspects on the definitions from before
>>> @register_deprecated('my_function'... | [
"def",
"register_deprecated",
"(",
"deprecated_name",
":",
"str",
")",
":",
"if",
"deprecated_name",
"in",
"mapped",
":",
"raise",
"DeprecationMappingError",
"(",
"'function name already mapped. can not register as deprecated name.'",
")",
"def",
"register_deprecated_f",
"(",... | Register a function as deprecated.
:param deprecated_name: The old name of the function
:return: A decorator
Usage:
This function must be applied last, since it introspects on the definitions from before
>>> @register_deprecated('my_function')
>>> @transformation
>>> def my_old_function(... | [
"Register",
"a",
"function",
"as",
"deprecated",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/decorators.py#L105-L139 | train | 29,783 |
pybel/pybel | src/pybel/struct/pipeline/decorators.py | get_transformation | def get_transformation(name: str):
"""Get a transformation function and error if its name is not registered.
:param name: The name of a function to look up
:return: A transformation function
:raises MissingPipelineFunctionError: If the given function name is not registered
"""
func = mapped.get... | python | def get_transformation(name: str):
"""Get a transformation function and error if its name is not registered.
:param name: The name of a function to look up
:return: A transformation function
:raises MissingPipelineFunctionError: If the given function name is not registered
"""
func = mapped.get... | [
"def",
"get_transformation",
"(",
"name",
":",
"str",
")",
":",
"func",
"=",
"mapped",
".",
"get",
"(",
"name",
")",
"if",
"func",
"is",
"None",
":",
"raise",
"MissingPipelineFunctionError",
"(",
"'{} is not registered as a pipeline function'",
".",
"format",
"(... | Get a transformation function and error if its name is not registered.
:param name: The name of a function to look up
:return: A transformation function
:raises MissingPipelineFunctionError: If the given function name is not registered | [
"Get",
"a",
"transformation",
"function",
"and",
"error",
"if",
"its",
"name",
"is",
"not",
"registered",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/pipeline/decorators.py#L142-L154 | train | 29,784 |
pybel/pybel | src/pybel/struct/mutation/induction/random_subgraph.py | _random_edge_iterator | def _random_edge_iterator(graph, n_edges: int) -> Iterable[Tuple[BaseEntity, BaseEntity, int, Mapping]]:
"""Get a random set of edges from the graph and randomly samples a key from each.
:type graph: pybel.BELGraph
:param n_edges: Number of edges to randomly select from the given graph
"""
edges = ... | python | def _random_edge_iterator(graph, n_edges: int) -> Iterable[Tuple[BaseEntity, BaseEntity, int, Mapping]]:
"""Get a random set of edges from the graph and randomly samples a key from each.
:type graph: pybel.BELGraph
:param n_edges: Number of edges to randomly select from the given graph
"""
edges = ... | [
"def",
"_random_edge_iterator",
"(",
"graph",
",",
"n_edges",
":",
"int",
")",
"->",
"Iterable",
"[",
"Tuple",
"[",
"BaseEntity",
",",
"BaseEntity",
",",
"int",
",",
"Mapping",
"]",
"]",
":",
"edges",
"=",
"list",
"(",
"graph",
".",
"edges",
"(",
")",
... | Get a random set of edges from the graph and randomly samples a key from each.
:type graph: pybel.BELGraph
:param n_edges: Number of edges to randomly select from the given graph | [
"Get",
"a",
"random",
"set",
"of",
"edges",
"from",
"the",
"graph",
"and",
"randomly",
"samples",
"a",
"key",
"from",
"each",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/random_subgraph.py#L25-L36 | train | 29,785 |
pybel/pybel | src/pybel/struct/mutation/induction/random_subgraph.py | get_graph_with_random_edges | def get_graph_with_random_edges(graph, n_edges: int):
"""Build a new graph from a seeding of edges.
:type graph: pybel.BELGraph
:param n_edges: Number of edges to randomly select from the given graph
:rtype: pybel.BELGraph
"""
result = graph.fresh_copy()
result.add_edges_from(_random_edge_i... | python | def get_graph_with_random_edges(graph, n_edges: int):
"""Build a new graph from a seeding of edges.
:type graph: pybel.BELGraph
:param n_edges: Number of edges to randomly select from the given graph
:rtype: pybel.BELGraph
"""
result = graph.fresh_copy()
result.add_edges_from(_random_edge_i... | [
"def",
"get_graph_with_random_edges",
"(",
"graph",
",",
"n_edges",
":",
"int",
")",
":",
"result",
"=",
"graph",
".",
"fresh_copy",
"(",
")",
"result",
".",
"add_edges_from",
"(",
"_random_edge_iterator",
"(",
"graph",
",",
"n_edges",
")",
")",
"update_metada... | Build a new graph from a seeding of edges.
:type graph: pybel.BELGraph
:param n_edges: Number of edges to randomly select from the given graph
:rtype: pybel.BELGraph | [
"Build",
"a",
"new",
"graph",
"from",
"a",
"seeding",
"of",
"edges",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/random_subgraph.py#L40-L52 | train | 29,786 |
pybel/pybel | src/pybel/struct/mutation/induction/random_subgraph.py | get_random_node | def get_random_node(graph,
node_blacklist: Set[BaseEntity],
invert_degrees: Optional[bool] = None,
) -> Optional[BaseEntity]:
"""Choose a node from the graph with probabilities based on their degrees.
:type graph: networkx.Graph
:param node_blackl... | python | def get_random_node(graph,
node_blacklist: Set[BaseEntity],
invert_degrees: Optional[bool] = None,
) -> Optional[BaseEntity]:
"""Choose a node from the graph with probabilities based on their degrees.
:type graph: networkx.Graph
:param node_blackl... | [
"def",
"get_random_node",
"(",
"graph",
",",
"node_blacklist",
":",
"Set",
"[",
"BaseEntity",
"]",
",",
"invert_degrees",
":",
"Optional",
"[",
"bool",
"]",
"=",
"None",
",",
")",
"->",
"Optional",
"[",
"BaseEntity",
"]",
":",
"try",
":",
"nodes",
",",
... | Choose a node from the graph with probabilities based on their degrees.
:type graph: networkx.Graph
:param node_blacklist: Nodes to filter out
:param invert_degrees: Should the degrees be inverted? Defaults to true. | [
"Choose",
"a",
"node",
"from",
"the",
"graph",
"with",
"probabilities",
"based",
"on",
"their",
"degrees",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/random_subgraph.py#L95-L119 | train | 29,787 |
pybel/pybel | src/pybel/struct/mutation/induction/random_subgraph.py | _helper | def _helper(result,
graph,
number_edges_remaining: int,
node_blacklist: Set[BaseEntity],
invert_degrees: Optional[bool] = None,
):
"""Help build a random graph.
:type result: networkx.Graph
:type graph: networkx.Graph
"""
original_node_cou... | python | def _helper(result,
graph,
number_edges_remaining: int,
node_blacklist: Set[BaseEntity],
invert_degrees: Optional[bool] = None,
):
"""Help build a random graph.
:type result: networkx.Graph
:type graph: networkx.Graph
"""
original_node_cou... | [
"def",
"_helper",
"(",
"result",
",",
"graph",
",",
"number_edges_remaining",
":",
"int",
",",
"node_blacklist",
":",
"Set",
"[",
"BaseEntity",
"]",
",",
"invert_degrees",
":",
"Optional",
"[",
"bool",
"]",
"=",
"None",
",",
")",
":",
"original_node_count",
... | Help build a random graph.
:type result: networkx.Graph
:type graph: networkx.Graph | [
"Help",
"build",
"a",
"random",
"graph",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/random_subgraph.py#L122-L164 | train | 29,788 |
pybel/pybel | src/pybel/struct/mutation/induction/random_subgraph.py | get_random_subgraph | def get_random_subgraph(graph, number_edges=None, number_seed_edges=None, seed=None, invert_degrees=None):
"""Generate a random subgraph based on weighted random walks from random seed edges.
:type graph: pybel.BELGraph graph
:param Optional[int] number_edges: Maximum number of edges. Defaults to
:dat... | python | def get_random_subgraph(graph, number_edges=None, number_seed_edges=None, seed=None, invert_degrees=None):
"""Generate a random subgraph based on weighted random walks from random seed edges.
:type graph: pybel.BELGraph graph
:param Optional[int] number_edges: Maximum number of edges. Defaults to
:dat... | [
"def",
"get_random_subgraph",
"(",
"graph",
",",
"number_edges",
"=",
"None",
",",
"number_seed_edges",
"=",
"None",
",",
"seed",
"=",
"None",
",",
"invert_degrees",
"=",
"None",
")",
":",
"if",
"number_edges",
"is",
"None",
":",
"number_edges",
"=",
"SAMPLE... | Generate a random subgraph based on weighted random walks from random seed edges.
:type graph: pybel.BELGraph graph
:param Optional[int] number_edges: Maximum number of edges. Defaults to
:data:`pybel_tools.constants.SAMPLE_RANDOM_EDGE_COUNT` (250).
:param Optional[int] number_seed_edges: Number of no... | [
"Generate",
"a",
"random",
"subgraph",
"based",
"on",
"weighted",
"random",
"walks",
"from",
"random",
"seed",
"edges",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/random_subgraph.py#L168-L216 | train | 29,789 |
pybel/pybel | src/pybel/struct/mutation/induction/random_subgraph.py | WeightedRandomGenerator.next_index | def next_index(self) -> int:
"""Get a random index."""
return bisect.bisect_right(self.totals, random.random() * self.total) | python | def next_index(self) -> int:
"""Get a random index."""
return bisect.bisect_right(self.totals, random.random() * self.total) | [
"def",
"next_index",
"(",
"self",
")",
"->",
"int",
":",
"return",
"bisect",
".",
"bisect_right",
"(",
"self",
".",
"totals",
",",
"random",
".",
"random",
"(",
")",
"*",
"self",
".",
"total",
")"
] | Get a random index. | [
"Get",
"a",
"random",
"index",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/mutation/induction/random_subgraph.py#L86-L88 | train | 29,790 |
pybel/pybel | src/pybel/manager/models.py | Author.from_name | def from_name(cls, name):
"""Create an author by name, automatically populating the hash."""
return Author(name=name, sha512=cls.hash_name(name)) | python | def from_name(cls, name):
"""Create an author by name, automatically populating the hash."""
return Author(name=name, sha512=cls.hash_name(name)) | [
"def",
"from_name",
"(",
"cls",
",",
"name",
")",
":",
"return",
"Author",
"(",
"name",
"=",
"name",
",",
"sha512",
"=",
"cls",
".",
"hash_name",
"(",
"name",
")",
")"
] | Create an author by name, automatically populating the hash. | [
"Create",
"an",
"author",
"by",
"name",
"automatically",
"populating",
"the",
"hash",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/models.py#L503-L505 | train | 29,791 |
pybel/pybel | src/pybel/manager/models.py | Author.has_name_in | def has_name_in(cls, names):
"""Build a filter if the author has any of the given names."""
return cls.sha512.in_({
cls.hash_name(name)
for name in names
}) | python | def has_name_in(cls, names):
"""Build a filter if the author has any of the given names."""
return cls.sha512.in_({
cls.hash_name(name)
for name in names
}) | [
"def",
"has_name_in",
"(",
"cls",
",",
"names",
")",
":",
"return",
"cls",
".",
"sha512",
".",
"in_",
"(",
"{",
"cls",
".",
"hash_name",
"(",
"name",
")",
"for",
"name",
"in",
"names",
"}",
")"
] | Build a filter if the author has any of the given names. | [
"Build",
"a",
"filter",
"if",
"the",
"author",
"has",
"any",
"of",
"the",
"given",
"names",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/manager/models.py#L533-L538 | train | 29,792 |
pybel/pybel | src/pybel/io/utils.py | raise_for_old_graph | def raise_for_old_graph(graph):
"""Raise an ImportVersionWarning if the BEL graph was produced by a legacy version of PyBEL.
:raises ImportVersionWarning: If the BEL graph was produced by a legacy version of PyBEL
"""
graph_version = tokenize_version(graph.pybel_version)
if graph_version < PYBEL_MI... | python | def raise_for_old_graph(graph):
"""Raise an ImportVersionWarning if the BEL graph was produced by a legacy version of PyBEL.
:raises ImportVersionWarning: If the BEL graph was produced by a legacy version of PyBEL
"""
graph_version = tokenize_version(graph.pybel_version)
if graph_version < PYBEL_MI... | [
"def",
"raise_for_old_graph",
"(",
"graph",
")",
":",
"graph_version",
"=",
"tokenize_version",
"(",
"graph",
".",
"pybel_version",
")",
"if",
"graph_version",
"<",
"PYBEL_MINIMUM_IMPORT_VERSION",
":",
"raise",
"ImportVersionWarning",
"(",
"graph_version",
",",
"PYBEL... | Raise an ImportVersionWarning if the BEL graph was produced by a legacy version of PyBEL.
:raises ImportVersionWarning: If the BEL graph was produced by a legacy version of PyBEL | [
"Raise",
"an",
"ImportVersionWarning",
"if",
"the",
"BEL",
"graph",
"was",
"produced",
"by",
"a",
"legacy",
"version",
"of",
"PyBEL",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/io/utils.py#L11-L18 | train | 29,793 |
pybel/pybel | src/pybel/parser/utils.py | nest | def nest(*content):
"""Define a delimited list by enumerating each element of the list."""
if len(content) == 0:
raise ValueError('no arguments supplied')
return And([LPF, content[0]] + list(itt.chain.from_iterable(zip(itt.repeat(C), content[1:]))) + [RPF]) | python | def nest(*content):
"""Define a delimited list by enumerating each element of the list."""
if len(content) == 0:
raise ValueError('no arguments supplied')
return And([LPF, content[0]] + list(itt.chain.from_iterable(zip(itt.repeat(C), content[1:]))) + [RPF]) | [
"def",
"nest",
"(",
"*",
"content",
")",
":",
"if",
"len",
"(",
"content",
")",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"'no arguments supplied'",
")",
"return",
"And",
"(",
"[",
"LPF",
",",
"content",
"[",
"0",
"]",
"]",
"+",
"list",
"(",
"itt... | Define a delimited list by enumerating each element of the list. | [
"Define",
"a",
"delimited",
"list",
"by",
"enumerating",
"each",
"element",
"of",
"the",
"list",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/utils.py#L50-L54 | train | 29,794 |
pybel/pybel | src/pybel/parser/utils.py | triple | def triple(subject, relation, obj):
"""Build a simple triple in PyParsing that has a ``subject relation object`` format."""
return And([Group(subject)(SUBJECT), relation(RELATION), Group(obj)(OBJECT)]) | python | def triple(subject, relation, obj):
"""Build a simple triple in PyParsing that has a ``subject relation object`` format."""
return And([Group(subject)(SUBJECT), relation(RELATION), Group(obj)(OBJECT)]) | [
"def",
"triple",
"(",
"subject",
",",
"relation",
",",
"obj",
")",
":",
"return",
"And",
"(",
"[",
"Group",
"(",
"subject",
")",
"(",
"SUBJECT",
")",
",",
"relation",
"(",
"RELATION",
")",
",",
"Group",
"(",
"obj",
")",
"(",
"OBJECT",
")",
"]",
"... | Build a simple triple in PyParsing that has a ``subject relation object`` format. | [
"Build",
"a",
"simple",
"triple",
"in",
"PyParsing",
"that",
"has",
"a",
"subject",
"relation",
"object",
"format",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/utils.py#L78-L80 | train | 29,795 |
pybel/pybel | src/pybel/parser/modifiers/truncation.py | get_truncation_language | def get_truncation_language() -> ParserElement:
"""Build a parser for protein truncations."""
l1 = truncation_tag + nest(amino_acid(AMINO_ACID) + ppc.integer(TRUNCATION_POSITION))
l1.setParseAction(_handle_trunc)
l2 = truncation_tag + nest(ppc.integer(TRUNCATION_POSITION))
l2.setParseAction(_handle_... | python | def get_truncation_language() -> ParserElement:
"""Build a parser for protein truncations."""
l1 = truncation_tag + nest(amino_acid(AMINO_ACID) + ppc.integer(TRUNCATION_POSITION))
l1.setParseAction(_handle_trunc)
l2 = truncation_tag + nest(ppc.integer(TRUNCATION_POSITION))
l2.setParseAction(_handle_... | [
"def",
"get_truncation_language",
"(",
")",
"->",
"ParserElement",
":",
"l1",
"=",
"truncation_tag",
"+",
"nest",
"(",
"amino_acid",
"(",
"AMINO_ACID",
")",
"+",
"ppc",
".",
"integer",
"(",
"TRUNCATION_POSITION",
")",
")",
"l1",
".",
"setParseAction",
"(",
"... | Build a parser for protein truncations. | [
"Build",
"a",
"parser",
"for",
"protein",
"truncations",
"."
] | c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0 | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/modifiers/truncation.py#L57-L63 | train | 29,796 |
vhf/confusable_homoglyphs | confusable_homoglyphs/categories.py | aliases_categories | def aliases_categories(chr):
"""Retrieves the script block alias and unicode category for a unicode character.
>>> categories.aliases_categories('A')
('LATIN', 'L')
>>> categories.aliases_categories('τ')
('GREEK', 'L')
>>> categories.aliases_categories('-')
('COMMON', 'Pd')
:param chr:... | python | def aliases_categories(chr):
"""Retrieves the script block alias and unicode category for a unicode character.
>>> categories.aliases_categories('A')
('LATIN', 'L')
>>> categories.aliases_categories('τ')
('GREEK', 'L')
>>> categories.aliases_categories('-')
('COMMON', 'Pd')
:param chr:... | [
"def",
"aliases_categories",
"(",
"chr",
")",
":",
"l",
"=",
"0",
"r",
"=",
"len",
"(",
"categories_data",
"[",
"'code_points_ranges'",
"]",
")",
"-",
"1",
"c",
"=",
"ord",
"(",
"chr",
")",
"# binary search",
"while",
"r",
">=",
"l",
":",
"m",
"=",
... | Retrieves the script block alias and unicode category for a unicode character.
>>> categories.aliases_categories('A')
('LATIN', 'L')
>>> categories.aliases_categories('τ')
('GREEK', 'L')
>>> categories.aliases_categories('-')
('COMMON', 'Pd')
:param chr: A unicode character
:type chr: ... | [
"Retrieves",
"the",
"script",
"block",
"alias",
"and",
"unicode",
"category",
"for",
"a",
"unicode",
"character",
"."
] | 14f43ddd74099520ddcda29fac557c27a28190e6 | https://github.com/vhf/confusable_homoglyphs/blob/14f43ddd74099520ddcda29fac557c27a28190e6/confusable_homoglyphs/categories.py#L8-L38 | train | 29,797 |
vhf/confusable_homoglyphs | confusable_homoglyphs/confusables.py | is_mixed_script | def is_mixed_script(string, allowed_aliases=['COMMON']):
"""Checks if ``string`` contains mixed-scripts content, excluding script
blocks aliases in ``allowed_aliases``.
E.g. ``B. C`` is not considered mixed-scripts by default: it contains characters
from **Latin** and **Common**, but **Common** is excl... | python | def is_mixed_script(string, allowed_aliases=['COMMON']):
"""Checks if ``string`` contains mixed-scripts content, excluding script
blocks aliases in ``allowed_aliases``.
E.g. ``B. C`` is not considered mixed-scripts by default: it contains characters
from **Latin** and **Common**, but **Common** is excl... | [
"def",
"is_mixed_script",
"(",
"string",
",",
"allowed_aliases",
"=",
"[",
"'COMMON'",
"]",
")",
":",
"allowed_aliases",
"=",
"[",
"a",
".",
"upper",
"(",
")",
"for",
"a",
"in",
"allowed_aliases",
"]",
"cats",
"=",
"unique_aliases",
"(",
"string",
")",
"... | Checks if ``string`` contains mixed-scripts content, excluding script
blocks aliases in ``allowed_aliases``.
E.g. ``B. C`` is not considered mixed-scripts by default: it contains characters
from **Latin** and **Common**, but **Common** is excluded by default.
>>> confusables.is_mixed_script('Abç')
... | [
"Checks",
"if",
"string",
"contains",
"mixed",
"-",
"scripts",
"content",
"excluding",
"script",
"blocks",
"aliases",
"in",
"allowed_aliases",
"."
] | 14f43ddd74099520ddcda29fac557c27a28190e6 | https://github.com/vhf/confusable_homoglyphs/blob/14f43ddd74099520ddcda29fac557c27a28190e6/confusable_homoglyphs/confusables.py#L13-L38 | train | 29,798 |
vhf/confusable_homoglyphs | confusable_homoglyphs/confusables.py | is_confusable | def is_confusable(string, greedy=False, preferred_aliases=[]):
"""Checks if ``string`` contains characters which might be confusable with
characters from ``preferred_aliases``.
If ``greedy=False``, it will only return the first confusable character
found without looking at the rest of the string, ``gre... | python | def is_confusable(string, greedy=False, preferred_aliases=[]):
"""Checks if ``string`` contains characters which might be confusable with
characters from ``preferred_aliases``.
If ``greedy=False``, it will only return the first confusable character
found without looking at the rest of the string, ``gre... | [
"def",
"is_confusable",
"(",
"string",
",",
"greedy",
"=",
"False",
",",
"preferred_aliases",
"=",
"[",
"]",
")",
":",
"preferred_aliases",
"=",
"[",
"a",
".",
"upper",
"(",
")",
"for",
"a",
"in",
"preferred_aliases",
"]",
"outputs",
"=",
"[",
"]",
"ch... | Checks if ``string`` contains characters which might be confusable with
characters from ``preferred_aliases``.
If ``greedy=False``, it will only return the first confusable character
found without looking at the rest of the string, ``greedy=True`` returns
all of them.
``preferred_aliases=[]`` can ... | [
"Checks",
"if",
"string",
"contains",
"characters",
"which",
"might",
"be",
"confusable",
"with",
"characters",
"from",
"preferred_aliases",
"."
] | 14f43ddd74099520ddcda29fac557c27a28190e6 | https://github.com/vhf/confusable_homoglyphs/blob/14f43ddd74099520ddcda29fac557c27a28190e6/confusable_homoglyphs/confusables.py#L41-L133 | train | 29,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.