repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.update_metadata | def update_metadata(self, key, value):
"""Set *key* in the metadata to *value*.
Returns the previous value of *key*, or None if the key was
not previously set.
"""
old_value = self.contents['metadata'].get(key)
self.contents['metadata'][key] = value
self._log('Up... | python | def update_metadata(self, key, value):
"""Set *key* in the metadata to *value*.
Returns the previous value of *key*, or None if the key was
not previously set.
"""
old_value = self.contents['metadata'].get(key)
self.contents['metadata'][key] = value
self._log('Up... | [
"def",
"update_metadata",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"old_value",
"=",
"self",
".",
"contents",
"[",
"'metadata'",
"]",
".",
"get",
"(",
"key",
")",
"self",
".",
"contents",
"[",
"'metadata'",
"]",
"[",
"key",
"]",
"=",
"value",... | Set *key* in the metadata to *value*.
Returns the previous value of *key*, or None if the key was
not previously set. | [
"Set",
"*",
"key",
"*",
"in",
"the",
"metadata",
"to",
"*",
"value",
"*",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L443-L452 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.update_file | def update_file(self, key, new_path):
"""Insert file *new_path* into the refpkg under *key*.
The filename of *new_path* will be preserved in the refpkg
unless it would conflict with a previously existing file, in
which case a suffix is appended which makes it unique. The
previo... | python | def update_file(self, key, new_path):
"""Insert file *new_path* into the refpkg under *key*.
The filename of *new_path* will be preserved in the refpkg
unless it would conflict with a previously existing file, in
which case a suffix is appended which makes it unique. The
previo... | [
"def",
"update_file",
"(",
"self",
",",
"key",
",",
"new_path",
")",
":",
"if",
"key",
"in",
"self",
".",
"contents",
"[",
"'files'",
"]",
":",
"old_path",
"=",
"self",
".",
"resource_path",
"(",
"key",
")",
"else",
":",
"old_path",
"=",
"None",
"sel... | Insert file *new_path* into the refpkg under *key*.
The filename of *new_path* will be preserved in the refpkg
unless it would conflict with a previously existing file, in
which case a suffix is appended which makes it unique. The
previous file, if there was one, is left in the refpkg.... | [
"Insert",
"file",
"*",
"new_path",
"*",
"into",
"the",
"refpkg",
"under",
"*",
"key",
"*",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L455-L480 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.reroot | def reroot(self, rppr=None, pretend=False):
"""Reroot the phylogenetic tree.
This operation calls ``rppr reroot`` to generate the rerooted
tree, so you must have ``pplacer`` and its auxiliary tools
``rppr`` and ``guppy`` installed for it to work. You can
specify the path to ``r... | python | def reroot(self, rppr=None, pretend=False):
"""Reroot the phylogenetic tree.
This operation calls ``rppr reroot`` to generate the rerooted
tree, so you must have ``pplacer`` and its auxiliary tools
``rppr`` and ``guppy`` installed for it to work. You can
specify the path to ``r... | [
"def",
"reroot",
"(",
"self",
",",
"rppr",
"=",
"None",
",",
"pretend",
"=",
"False",
")",
":",
"with",
"scratch_file",
"(",
"prefix",
"=",
"'tree'",
",",
"suffix",
"=",
"'.tre'",
")",
"as",
"name",
":",
"# Use a specific path to rppr, otherwise rely on $PATH"... | Reroot the phylogenetic tree.
This operation calls ``rppr reroot`` to generate the rerooted
tree, so you must have ``pplacer`` and its auxiliary tools
``rppr`` and ``guppy`` installed for it to work. You can
specify the path to ``rppr`` by giving it as the *rppr*
argument.
... | [
"Reroot",
"the",
"phylogenetic",
"tree",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L483-L501 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.update_phylo_model | def update_phylo_model(self, stats_type, stats_file, frequency_type=None):
"""Parse a stats log and use it to update ``phylo_model``.
``pplacer`` expects its input to include the deatils of the
phylogenetic model used for creating a tree in JSON format
under the key ``phylo_model``, but... | python | def update_phylo_model(self, stats_type, stats_file, frequency_type=None):
"""Parse a stats log and use it to update ``phylo_model``.
``pplacer`` expects its input to include the deatils of the
phylogenetic model used for creating a tree in JSON format
under the key ``phylo_model``, but... | [
"def",
"update_phylo_model",
"(",
"self",
",",
"stats_type",
",",
"stats_file",
",",
"frequency_type",
"=",
"None",
")",
":",
"if",
"frequency_type",
"not",
"in",
"(",
"None",
",",
"'model'",
",",
"'empirical'",
")",
":",
"raise",
"ValueError",
"(",
"'Unknow... | Parse a stats log and use it to update ``phylo_model``.
``pplacer`` expects its input to include the deatils of the
phylogenetic model used for creating a tree in JSON format
under the key ``phylo_model``, but no program actually outputs
that format.
This function takes a log g... | [
"Parse",
"a",
"stats",
"log",
"and",
"use",
"it",
"to",
"update",
"phylo_model",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L503-L562 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.rollback | def rollback(self):
"""Revert the previous modification to the refpkg.
"""
# This is slightly complicated because of Python's freakish
# assignment semantics and because we don't store multiple
# copies of the log.
if self.contents['rollback'] is None:
raise V... | python | def rollback(self):
"""Revert the previous modification to the refpkg.
"""
# This is slightly complicated because of Python's freakish
# assignment semantics and because we don't store multiple
# copies of the log.
if self.contents['rollback'] is None:
raise V... | [
"def",
"rollback",
"(",
"self",
")",
":",
"# This is slightly complicated because of Python's freakish",
"# assignment semantics and because we don't store multiple",
"# copies of the log.",
"if",
"self",
".",
"contents",
"[",
"'rollback'",
"]",
"is",
"None",
":",
"raise",
"V... | Revert the previous modification to the refpkg. | [
"Revert",
"the",
"previous",
"modification",
"to",
"the",
"refpkg",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L564-L579 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.rollforward | def rollforward(self):
"""Restore a reverted modification to the refpkg.
"""
if self.contents['rollforward'] is None:
raise ValueError("No operation to roll forward on refpkg")
new_log_message = self.contents['rollforward'][0]
new_contents = self.contents['rollforward... | python | def rollforward(self):
"""Restore a reverted modification to the refpkg.
"""
if self.contents['rollforward'] is None:
raise ValueError("No operation to roll forward on refpkg")
new_log_message = self.contents['rollforward'][0]
new_contents = self.contents['rollforward... | [
"def",
"rollforward",
"(",
"self",
")",
":",
"if",
"self",
".",
"contents",
"[",
"'rollforward'",
"]",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"No operation to roll forward on refpkg\"",
")",
"new_log_message",
"=",
"self",
".",
"contents",
"[",
"'rollf... | Restore a reverted modification to the refpkg. | [
"Restore",
"a",
"reverted",
"modification",
"to",
"the",
"refpkg",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L581-L593 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.strip | def strip(self):
"""Remove rollbacks, rollforwards, and all non-current files.
When distributing a refpkg, you probably want to distribute as
small a one as possible. strip removes everything from the
refpkg which is not relevant to its current state.
"""
self._sync_fro... | python | def strip(self):
"""Remove rollbacks, rollforwards, and all non-current files.
When distributing a refpkg, you probably want to distribute as
small a one as possible. strip removes everything from the
refpkg which is not relevant to its current state.
"""
self._sync_fro... | [
"def",
"strip",
"(",
"self",
")",
":",
"self",
".",
"_sync_from_disk",
"(",
")",
"current_filenames",
"=",
"set",
"(",
"self",
".",
"contents",
"[",
"'files'",
"]",
".",
"values",
"(",
")",
")",
"all_filenames",
"=",
"set",
"(",
"os",
".",
"listdir",
... | Remove rollbacks, rollforwards, and all non-current files.
When distributing a refpkg, you probably want to distribute as
small a one as possible. strip removes everything from the
refpkg which is not relevant to its current state. | [
"Remove",
"rollbacks",
"rollforwards",
"and",
"all",
"non",
"-",
"current",
"files",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L595-L613 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.start_transaction | def start_transaction(self):
"""Begin a transaction to group operations on the refpkg.
All the operations until the next call to
``commit_transaction`` will be recorded as a single operation
for rollback and rollforward, and recorded with a single line
in the log.
"""
... | python | def start_transaction(self):
"""Begin a transaction to group operations on the refpkg.
All the operations until the next call to
``commit_transaction`` will be recorded as a single operation
for rollback and rollforward, and recorded with a single line
in the log.
"""
... | [
"def",
"start_transaction",
"(",
"self",
")",
":",
"if",
"self",
".",
"current_transaction",
":",
"raise",
"ValueError",
"(",
"\"There is already a transaction going\"",
")",
"else",
":",
"initial_state",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"contents",... | Begin a transaction to group operations on the refpkg.
All the operations until the next call to
``commit_transaction`` will be recorded as a single operation
for rollback and rollforward, and recorded with a single line
in the log. | [
"Begin",
"a",
"transaction",
"to",
"group",
"operations",
"on",
"the",
"refpkg",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L615-L628 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.commit_transaction | def commit_transaction(self, log=None):
"""Commit a transaction, with *log* as the log entry."""
self.current_transaction['rollback'].pop('log')
self.current_transaction['rollback'].pop('rollforward')
self.contents['log'].insert(
0, log and log or self.current_transaction['lo... | python | def commit_transaction(self, log=None):
"""Commit a transaction, with *log* as the log entry."""
self.current_transaction['rollback'].pop('log')
self.current_transaction['rollback'].pop('rollforward')
self.contents['log'].insert(
0, log and log or self.current_transaction['lo... | [
"def",
"commit_transaction",
"(",
"self",
",",
"log",
"=",
"None",
")",
":",
"self",
".",
"current_transaction",
"[",
"'rollback'",
"]",
".",
"pop",
"(",
"'log'",
")",
"self",
".",
"current_transaction",
"[",
"'rollback'",
"]",
".",
"pop",
"(",
"'rollforwa... | Commit a transaction, with *log* as the log entry. | [
"Commit",
"a",
"transaction",
"with",
"*",
"log",
"*",
"as",
"the",
"log",
"entry",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L630-L639 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.is_ill_formed | def is_ill_formed(self):
"""Stronger set of checks than is_invalid for Refpkg.
Checks that FASTA, Stockholm, JSON, and CSV files under known
keys are all valid as well as calling is_invalid. Returns
either False or a string describing the error.
"""
m = self.is_invalid(... | python | def is_ill_formed(self):
"""Stronger set of checks than is_invalid for Refpkg.
Checks that FASTA, Stockholm, JSON, and CSV files under known
keys are all valid as well as calling is_invalid. Returns
either False or a string describing the error.
"""
m = self.is_invalid(... | [
"def",
"is_ill_formed",
"(",
"self",
")",
":",
"m",
"=",
"self",
".",
"is_invalid",
"(",
")",
"if",
"m",
":",
"return",
"m",
"required_keys",
"=",
"(",
"'aln_fasta'",
",",
"'aln_sto'",
",",
"'seq_info'",
",",
"'tree'",
",",
"'taxonomy'",
",",
"'phylo_mod... | Stronger set of checks than is_invalid for Refpkg.
Checks that FASTA, Stockholm, JSON, and CSV files under known
keys are all valid as well as calling is_invalid. Returns
either False or a string describing the error. | [
"Stronger",
"set",
"of",
"checks",
"than",
"is_invalid",
"for",
"Refpkg",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L641-L728 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.load_db | def load_db(self):
"""Load the taxonomy into a sqlite3 database.
This will set ``self.db`` to a sqlite3 database which contains all of
the taxonomic information in the reference package.
"""
db = taxdb.Taxdb()
db.create_tables()
reader = csv.DictReader(self.open... | python | def load_db(self):
"""Load the taxonomy into a sqlite3 database.
This will set ``self.db`` to a sqlite3 database which contains all of
the taxonomic information in the reference package.
"""
db = taxdb.Taxdb()
db.create_tables()
reader = csv.DictReader(self.open... | [
"def",
"load_db",
"(",
"self",
")",
":",
"db",
"=",
"taxdb",
".",
"Taxdb",
"(",
")",
"db",
".",
"create_tables",
"(",
")",
"reader",
"=",
"csv",
".",
"DictReader",
"(",
"self",
".",
"open_resource",
"(",
"'taxonomy'",
",",
"'rU'",
")",
")",
"db",
"... | Load the taxonomy into a sqlite3 database.
This will set ``self.db`` to a sqlite3 database which contains all of
the taxonomic information in the reference package. | [
"Load",
"the",
"taxonomy",
"into",
"a",
"sqlite3",
"database",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L730-L748 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.most_recent_common_ancestor | def most_recent_common_ancestor(self, *ts):
"""Find the MRCA of some tax_ids.
Returns the MRCA of the specified tax_ids, or raises ``NoAncestor`` if
no ancestor of the specified tax_ids could be found.
"""
if len(ts) > 200:
res = self._large_mrca(ts)
else:
... | python | def most_recent_common_ancestor(self, *ts):
"""Find the MRCA of some tax_ids.
Returns the MRCA of the specified tax_ids, or raises ``NoAncestor`` if
no ancestor of the specified tax_ids could be found.
"""
if len(ts) > 200:
res = self._large_mrca(ts)
else:
... | [
"def",
"most_recent_common_ancestor",
"(",
"self",
",",
"*",
"ts",
")",
":",
"if",
"len",
"(",
"ts",
")",
">",
"200",
":",
"res",
"=",
"self",
".",
"_large_mrca",
"(",
"ts",
")",
"else",
":",
"res",
"=",
"self",
".",
"_small_mrca",
"(",
"ts",
")",
... | Find the MRCA of some tax_ids.
Returns the MRCA of the specified tax_ids, or raises ``NoAncestor`` if
no ancestor of the specified tax_ids could be found. | [
"Find",
"the",
"MRCA",
"of",
"some",
"tax_ids",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L750-L765 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg._large_mrca | def _large_mrca(self, ts):
"""Find the MRCA using a temporary table."""
cursor = self.db.cursor()
cursor.execute("""
DROP TABLE IF EXISTS _mrca_temp
""")
cursor.execute("""
CREATE TEMPORARY TABLE _mrca_temp(
child TEXT PRIMARY KEY REFEREN... | python | def _large_mrca(self, ts):
"""Find the MRCA using a temporary table."""
cursor = self.db.cursor()
cursor.execute("""
DROP TABLE IF EXISTS _mrca_temp
""")
cursor.execute("""
CREATE TEMPORARY TABLE _mrca_temp(
child TEXT PRIMARY KEY REFEREN... | [
"def",
"_large_mrca",
"(",
"self",
",",
"ts",
")",
":",
"cursor",
"=",
"self",
".",
"db",
".",
"cursor",
"(",
")",
"cursor",
".",
"execute",
"(",
"\"\"\"\n DROP TABLE IF EXISTS _mrca_temp\n \"\"\"",
")",
"cursor",
".",
"execute",
"(",
"\"\"\"\n... | Find the MRCA using a temporary table. | [
"Find",
"the",
"MRCA",
"using",
"a",
"temporary",
"table",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L767-L798 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg._small_mrca | def _small_mrca(self, ts):
"""Find a MRCA using query parameters.
This only supports a limited number of tax_ids; ``_large_mrca`` will
support an arbitrary number.
"""
cursor = self.db.cursor()
qmarks = ', '.join('?' * len(ts))
cursor.execute("""
SELE... | python | def _small_mrca(self, ts):
"""Find a MRCA using query parameters.
This only supports a limited number of tax_ids; ``_large_mrca`` will
support an arbitrary number.
"""
cursor = self.db.cursor()
qmarks = ', '.join('?' * len(ts))
cursor.execute("""
SELE... | [
"def",
"_small_mrca",
"(",
"self",
",",
"ts",
")",
":",
"cursor",
"=",
"self",
".",
"db",
".",
"cursor",
"(",
")",
"qmarks",
"=",
"', '",
".",
"join",
"(",
"'?'",
"*",
"len",
"(",
"ts",
")",
")",
"cursor",
".",
"execute",
"(",
"\"\"\"\n ... | Find a MRCA using query parameters.
This only supports a limited number of tax_ids; ``_large_mrca`` will
support an arbitrary number. | [
"Find",
"a",
"MRCA",
"using",
"query",
"parameters",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L800-L821 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.file_abspath | def file_abspath(self, resource):
"""Deprecated alias for *resource_path*."""
warnings.warn(
"file_abspath is deprecated; use resource_path instead",
DeprecationWarning, stacklevel=2)
return self.resource_path(resource) | python | def file_abspath(self, resource):
"""Deprecated alias for *resource_path*."""
warnings.warn(
"file_abspath is deprecated; use resource_path instead",
DeprecationWarning, stacklevel=2)
return self.resource_path(resource) | [
"def",
"file_abspath",
"(",
"self",
",",
"resource",
")",
":",
"warnings",
".",
"warn",
"(",
"\"file_abspath is deprecated; use resource_path instead\"",
",",
"DeprecationWarning",
",",
"stacklevel",
"=",
"2",
")",
"return",
"self",
".",
"resource_path",
"(",
"resou... | Deprecated alias for *resource_path*. | [
"Deprecated",
"alias",
"for",
"*",
"resource_path",
"*",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L823-L828 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.file_name | def file_name(self, resource):
"""Deprecated alias for *resource_name*."""
warnings.warn(
"file_name is deprecated; use resource_name instead",
DeprecationWarning, stacklevel=2)
return self.resource_name(resource) | python | def file_name(self, resource):
"""Deprecated alias for *resource_name*."""
warnings.warn(
"file_name is deprecated; use resource_name instead",
DeprecationWarning, stacklevel=2)
return self.resource_name(resource) | [
"def",
"file_name",
"(",
"self",
",",
"resource",
")",
":",
"warnings",
".",
"warn",
"(",
"\"file_name is deprecated; use resource_name instead\"",
",",
"DeprecationWarning",
",",
"stacklevel",
"=",
"2",
")",
"return",
"self",
".",
"resource_name",
"(",
"resource",
... | Deprecated alias for *resource_name*. | [
"Deprecated",
"alias",
"for",
"*",
"resource_name",
"*",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L830-L835 |
fhcrc/taxtastic | taxtastic/refpkg.py | Refpkg.file_md5 | def file_md5(self, resource):
"""Deprecated alias for *resource_md5*."""
warnings.warn(
"file_md5 is deprecated; use resource_md5 instead",
DeprecationWarning, stacklevel=2)
return self.resource_md5(resource) | python | def file_md5(self, resource):
"""Deprecated alias for *resource_md5*."""
warnings.warn(
"file_md5 is deprecated; use resource_md5 instead",
DeprecationWarning, stacklevel=2)
return self.resource_md5(resource) | [
"def",
"file_md5",
"(",
"self",
",",
"resource",
")",
":",
"warnings",
".",
"warn",
"(",
"\"file_md5 is deprecated; use resource_md5 instead\"",
",",
"DeprecationWarning",
",",
"stacklevel",
"=",
"2",
")",
"return",
"self",
".",
"resource_md5",
"(",
"resource",
")... | Deprecated alias for *resource_md5*. | [
"Deprecated",
"alias",
"for",
"*",
"resource_md5",
"*",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/refpkg.py#L837-L842 |
seznam/shelter | shelter/main.py | get_app_settings | def get_app_settings(parser, known_args):
"""
Return **settings** module of the application according to
either command line argument or **SHELTER_SETTINGS_MODULE**
environment variable.
"""
args, dummy_remaining = parser.parse_known_args(known_args)
settings_module_path = (
args.set... | python | def get_app_settings(parser, known_args):
"""
Return **settings** module of the application according to
either command line argument or **SHELTER_SETTINGS_MODULE**
environment variable.
"""
args, dummy_remaining = parser.parse_known_args(known_args)
settings_module_path = (
args.set... | [
"def",
"get_app_settings",
"(",
"parser",
",",
"known_args",
")",
":",
"args",
",",
"dummy_remaining",
"=",
"parser",
".",
"parse_known_args",
"(",
"known_args",
")",
"settings_module_path",
"=",
"(",
"args",
".",
"settings",
"or",
"os",
".",
"environ",
".",
... | Return **settings** module of the application according to
either command line argument or **SHELTER_SETTINGS_MODULE**
environment variable. | [
"Return",
"**",
"settings",
"**",
"module",
"of",
"the",
"application",
"according",
"to",
"either",
"command",
"line",
"argument",
"or",
"**",
"SHELTER_SETTINGS_MODULE",
"**",
"environment",
"variable",
"."
] | train | https://github.com/seznam/shelter/blob/c652b0ff1cca70158f8fc97d9210c1fa5961ac1c/shelter/main.py#L28-L39 |
seznam/shelter | shelter/main.py | get_management_commands | def get_management_commands(settings):
"""
Find registered managemend commands and return their classes
as a :class:`dict`. Keys are names of the management command
and values are classes of the management command.
"""
app_commands = getattr(settings, 'MANAGEMENT_COMMANDS', ())
commands = {}... | python | def get_management_commands(settings):
"""
Find registered managemend commands and return their classes
as a :class:`dict`. Keys are names of the management command
and values are classes of the management command.
"""
app_commands = getattr(settings, 'MANAGEMENT_COMMANDS', ())
commands = {}... | [
"def",
"get_management_commands",
"(",
"settings",
")",
":",
"app_commands",
"=",
"getattr",
"(",
"settings",
",",
"'MANAGEMENT_COMMANDS'",
",",
"(",
")",
")",
"commands",
"=",
"{",
"}",
"for",
"name",
"in",
"itertools",
".",
"chain",
"(",
"SHELTER_MANAGEMENT_... | Find registered managemend commands and return their classes
as a :class:`dict`. Keys are names of the management command
and values are classes of the management command. | [
"Find",
"registered",
"managemend",
"commands",
"and",
"return",
"their",
"classes",
"as",
"a",
":",
"class",
":",
"dict",
".",
"Keys",
"are",
"names",
"of",
"the",
"management",
"command",
"and",
"values",
"are",
"classes",
"of",
"the",
"management",
"comma... | train | https://github.com/seznam/shelter/blob/c652b0ff1cca70158f8fc97d9210c1fa5961ac1c/shelter/main.py#L42-L55 |
seznam/shelter | shelter/main.py | get_config_class | def get_config_class(settings):
"""
According to **settings.CONFIG_CLASS** return either config class
defined by user or default :class:`shelter.core.config.Config`.
"""
config_cls_name = getattr(settings, 'CONFIG_CLASS', '')
if config_cls_name:
config_cls = import_object(config_cls_name... | python | def get_config_class(settings):
"""
According to **settings.CONFIG_CLASS** return either config class
defined by user or default :class:`shelter.core.config.Config`.
"""
config_cls_name = getattr(settings, 'CONFIG_CLASS', '')
if config_cls_name:
config_cls = import_object(config_cls_name... | [
"def",
"get_config_class",
"(",
"settings",
")",
":",
"config_cls_name",
"=",
"getattr",
"(",
"settings",
",",
"'CONFIG_CLASS'",
",",
"''",
")",
"if",
"config_cls_name",
":",
"config_cls",
"=",
"import_object",
"(",
"config_cls_name",
")",
"else",
":",
"config_c... | According to **settings.CONFIG_CLASS** return either config class
defined by user or default :class:`shelter.core.config.Config`. | [
"According",
"to",
"**",
"settings",
".",
"CONFIG_CLASS",
"**",
"return",
"either",
"config",
"class",
"defined",
"by",
"user",
"or",
"default",
":",
"class",
":",
"shelter",
".",
"core",
".",
"config",
".",
"Config",
"."
] | train | https://github.com/seznam/shelter/blob/c652b0ff1cca70158f8fc97d9210c1fa5961ac1c/shelter/main.py#L58-L68 |
seznam/shelter | shelter/main.py | main | def main(args=None):
"""
Run management command handled from command line.
"""
# Base command line parser. Help is not allowed because command
# line is parsed in two stages - in the first stage is found setting
# module of the application, in the second stage are found management
# command'... | python | def main(args=None):
"""
Run management command handled from command line.
"""
# Base command line parser. Help is not allowed because command
# line is parsed in two stages - in the first stage is found setting
# module of the application, in the second stage are found management
# command'... | [
"def",
"main",
"(",
"args",
"=",
"None",
")",
":",
"# Base command line parser. Help is not allowed because command",
"# line is parsed in two stages - in the first stage is found setting",
"# module of the application, in the second stage are found management",
"# command's arguments.",
"pa... | Run management command handled from command line. | [
"Run",
"management",
"command",
"handled",
"from",
"command",
"line",
"."
] | train | https://github.com/seznam/shelter/blob/c652b0ff1cca70158f8fc97d9210c1fa5961ac1c/shelter/main.py#L71-L149 |
seequent/vectormath | vectormath/vector.py | BaseVector.as_length | def as_length(self, value):
"""Return a new vector scaled to given length"""
new_vec = self.copy()
new_vec.length = value
return new_vec | python | def as_length(self, value):
"""Return a new vector scaled to given length"""
new_vec = self.copy()
new_vec.length = value
return new_vec | [
"def",
"as_length",
"(",
"self",
",",
"value",
")",
":",
"new_vec",
"=",
"self",
".",
"copy",
"(",
")",
"new_vec",
".",
"length",
"=",
"value",
"return",
"new_vec"
] | Return a new vector scaled to given length | [
"Return",
"a",
"new",
"vector",
"scaled",
"to",
"given",
"length"
] | train | https://github.com/seequent/vectormath/blob/a2259fb82cf5a665170f50d216b11a738400d878/vectormath/vector.py#L88-L92 |
seequent/vectormath | vectormath/vector.py | BaseVector.as_percent | def as_percent(self, value):
"""Return a new vector scaled by given decimal percent"""
new_vec = self.copy()
new_vec.length = value * self.length
return new_vec | python | def as_percent(self, value):
"""Return a new vector scaled by given decimal percent"""
new_vec = self.copy()
new_vec.length = value * self.length
return new_vec | [
"def",
"as_percent",
"(",
"self",
",",
"value",
")",
":",
"new_vec",
"=",
"self",
".",
"copy",
"(",
")",
"new_vec",
".",
"length",
"=",
"value",
"*",
"self",
".",
"length",
"return",
"new_vec"
] | Return a new vector scaled by given decimal percent | [
"Return",
"a",
"new",
"vector",
"scaled",
"by",
"given",
"decimal",
"percent"
] | train | https://github.com/seequent/vectormath/blob/a2259fb82cf5a665170f50d216b11a738400d878/vectormath/vector.py#L94-L98 |
seequent/vectormath | vectormath/vector.py | BaseVector.dot | def dot(self, vec):
"""Dot product with another vector"""
if not isinstance(vec, self.__class__):
raise TypeError('Dot product operand must be a vector')
return np.dot(self, vec) | python | def dot(self, vec):
"""Dot product with another vector"""
if not isinstance(vec, self.__class__):
raise TypeError('Dot product operand must be a vector')
return np.dot(self, vec) | [
"def",
"dot",
"(",
"self",
",",
"vec",
")",
":",
"if",
"not",
"isinstance",
"(",
"vec",
",",
"self",
".",
"__class__",
")",
":",
"raise",
"TypeError",
"(",
"'Dot product operand must be a vector'",
")",
"return",
"np",
".",
"dot",
"(",
"self",
",",
"vec"... | Dot product with another vector | [
"Dot",
"product",
"with",
"another",
"vector"
] | train | https://github.com/seequent/vectormath/blob/a2259fb82cf5a665170f50d216b11a738400d878/vectormath/vector.py#L111-L115 |
seequent/vectormath | vectormath/vector.py | BaseVector.cross | def cross(self, vec):
"""Cross product with another vector"""
if not isinstance(vec, self.__class__):
raise TypeError('Cross product operand must be a vector')
return self.__class__(np.cross(self, vec)) | python | def cross(self, vec):
"""Cross product with another vector"""
if not isinstance(vec, self.__class__):
raise TypeError('Cross product operand must be a vector')
return self.__class__(np.cross(self, vec)) | [
"def",
"cross",
"(",
"self",
",",
"vec",
")",
":",
"if",
"not",
"isinstance",
"(",
"vec",
",",
"self",
".",
"__class__",
")",
":",
"raise",
"TypeError",
"(",
"'Cross product operand must be a vector'",
")",
"return",
"self",
".",
"__class__",
"(",
"np",
".... | Cross product with another vector | [
"Cross",
"product",
"with",
"another",
"vector"
] | train | https://github.com/seequent/vectormath/blob/a2259fb82cf5a665170f50d216b11a738400d878/vectormath/vector.py#L117-L121 |
seequent/vectormath | vectormath/vector.py | BaseVector.angle | def angle(self, vec, unit='rad'):
"""Calculate the angle between two Vectors
unit: unit for returned angle, either 'rad' or 'deg'. Defaults to 'rad'
"""
if not isinstance(vec, self.__class__):
raise TypeError('Angle operand must be of class {}'
.f... | python | def angle(self, vec, unit='rad'):
"""Calculate the angle between two Vectors
unit: unit for returned angle, either 'rad' or 'deg'. Defaults to 'rad'
"""
if not isinstance(vec, self.__class__):
raise TypeError('Angle operand must be of class {}'
.f... | [
"def",
"angle",
"(",
"self",
",",
"vec",
",",
"unit",
"=",
"'rad'",
")",
":",
"if",
"not",
"isinstance",
"(",
"vec",
",",
"self",
".",
"__class__",
")",
":",
"raise",
"TypeError",
"(",
"'Angle operand must be of class {}'",
".",
"format",
"(",
"self",
".... | Calculate the angle between two Vectors
unit: unit for returned angle, either 'rad' or 'deg'. Defaults to 'rad' | [
"Calculate",
"the",
"angle",
"between",
"two",
"Vectors"
] | train | https://github.com/seequent/vectormath/blob/a2259fb82cf5a665170f50d216b11a738400d878/vectormath/vector.py#L123-L142 |
seequent/vectormath | vectormath/vector.py | Vector3.phi | def phi(self):
"""Polar angle / inclination of this vector in radians
Based on sperical coordinate space
returns angle between this vector and the positive z-azis
range: (0 <= phi <= pi)
"""
return np.arctan2(np.sqrt(self.x**2 + self.y**2), self.z) | python | def phi(self):
"""Polar angle / inclination of this vector in radians
Based on sperical coordinate space
returns angle between this vector and the positive z-azis
range: (0 <= phi <= pi)
"""
return np.arctan2(np.sqrt(self.x**2 + self.y**2), self.z) | [
"def",
"phi",
"(",
"self",
")",
":",
"return",
"np",
".",
"arctan2",
"(",
"np",
".",
"sqrt",
"(",
"self",
".",
"x",
"**",
"2",
"+",
"self",
".",
"y",
"**",
"2",
")",
",",
"self",
".",
"z",
")"
] | Polar angle / inclination of this vector in radians
Based on sperical coordinate space
returns angle between this vector and the positive z-azis
range: (0 <= phi <= pi) | [
"Polar",
"angle",
"/",
"inclination",
"of",
"this",
"vector",
"in",
"radians"
] | train | https://github.com/seequent/vectormath/blob/a2259fb82cf5a665170f50d216b11a738400d878/vectormath/vector.py#L220-L227 |
seequent/vectormath | vectormath/vector.py | Vector2.cross | def cross(self, vec):
"""Cross product with another vector"""
if not isinstance(vec, self.__class__):
raise TypeError('Cross product operand must be a vector')
return Vector3(0, 0, np.asscalar(np.cross(self, vec))) | python | def cross(self, vec):
"""Cross product with another vector"""
if not isinstance(vec, self.__class__):
raise TypeError('Cross product operand must be a vector')
return Vector3(0, 0, np.asscalar(np.cross(self, vec))) | [
"def",
"cross",
"(",
"self",
",",
"vec",
")",
":",
"if",
"not",
"isinstance",
"(",
"vec",
",",
"self",
".",
"__class__",
")",
":",
"raise",
"TypeError",
"(",
"'Cross product operand must be a vector'",
")",
"return",
"Vector3",
"(",
"0",
",",
"0",
",",
"... | Cross product with another vector | [
"Cross",
"product",
"with",
"another",
"vector"
] | train | https://github.com/seequent/vectormath/blob/a2259fb82cf5a665170f50d216b11a738400d878/vectormath/vector.py#L303-L307 |
seequent/vectormath | vectormath/vector.py | BaseVectorArray.length | def length(self):
"""Array of vector lengths"""
return np.sqrt(np.sum(self**2, axis=1)).view(np.ndarray) | python | def length(self):
"""Array of vector lengths"""
return np.sqrt(np.sum(self**2, axis=1)).view(np.ndarray) | [
"def",
"length",
"(",
"self",
")",
":",
"return",
"np",
".",
"sqrt",
"(",
"np",
".",
"sum",
"(",
"self",
"**",
"2",
",",
"axis",
"=",
"1",
")",
")",
".",
"view",
"(",
"np",
".",
"ndarray",
")"
] | Array of vector lengths | [
"Array",
"of",
"vector",
"lengths"
] | train | https://github.com/seequent/vectormath/blob/a2259fb82cf5a665170f50d216b11a738400d878/vectormath/vector.py#L347-L349 |
seequent/vectormath | vectormath/vector.py | BaseVectorArray.dot | def dot(self, vec):
"""Dot product with another vector"""
if not isinstance(vec, self.__class__):
raise TypeError('Dot product operand must be a VectorArray')
if self.nV != 1 and vec.nV != 1 and self.nV != vec.nV:
raise ValueError('Dot product operands must have the same ... | python | def dot(self, vec):
"""Dot product with another vector"""
if not isinstance(vec, self.__class__):
raise TypeError('Dot product operand must be a VectorArray')
if self.nV != 1 and vec.nV != 1 and self.nV != vec.nV:
raise ValueError('Dot product operands must have the same ... | [
"def",
"dot",
"(",
"self",
",",
"vec",
")",
":",
"if",
"not",
"isinstance",
"(",
"vec",
",",
"self",
".",
"__class__",
")",
":",
"raise",
"TypeError",
"(",
"'Dot product operand must be a VectorArray'",
")",
"if",
"self",
".",
"nV",
"!=",
"1",
"and",
"ve... | Dot product with another vector | [
"Dot",
"product",
"with",
"another",
"vector"
] | train | https://github.com/seequent/vectormath/blob/a2259fb82cf5a665170f50d216b11a738400d878/vectormath/vector.py#L381-L388 |
seequent/vectormath | vectormath/vector.py | Vector3Array.cross | def cross(self, vec):
"""Cross product with another Vector3Array"""
if not isinstance(vec, Vector3Array):
raise TypeError('Cross product operand must be a Vector3Array')
if self.nV != 1 and vec.nV != 1 and self.nV != vec.nV:
raise ValueError('Cross product operands must h... | python | def cross(self, vec):
"""Cross product with another Vector3Array"""
if not isinstance(vec, Vector3Array):
raise TypeError('Cross product operand must be a Vector3Array')
if self.nV != 1 and vec.nV != 1 and self.nV != vec.nV:
raise ValueError('Cross product operands must h... | [
"def",
"cross",
"(",
"self",
",",
"vec",
")",
":",
"if",
"not",
"isinstance",
"(",
"vec",
",",
"Vector3Array",
")",
":",
"raise",
"TypeError",
"(",
"'Cross product operand must be a Vector3Array'",
")",
"if",
"self",
".",
"nV",
"!=",
"1",
"and",
"vec",
"."... | Cross product with another Vector3Array | [
"Cross",
"product",
"with",
"another",
"Vector3Array"
] | train | https://github.com/seequent/vectormath/blob/a2259fb82cf5a665170f50d216b11a738400d878/vectormath/vector.py#L487-L494 |
amicks/Speculator | speculator/features/RSI.py | RSI.eval_rs | def eval_rs(gains, losses):
""" Evaluates the RS variable in RSI algorithm
Args:
gains: List of price gains.
losses: List of prices losses.
Returns:
Float of average gains over average losses.
"""
# Number of days that the data was collected ... | python | def eval_rs(gains, losses):
""" Evaluates the RS variable in RSI algorithm
Args:
gains: List of price gains.
losses: List of prices losses.
Returns:
Float of average gains over average losses.
"""
# Number of days that the data was collected ... | [
"def",
"eval_rs",
"(",
"gains",
",",
"losses",
")",
":",
"# Number of days that the data was collected through",
"count",
"=",
"len",
"(",
"gains",
")",
"+",
"len",
"(",
"losses",
")",
"avg_gains",
"=",
"stats",
".",
"avg",
"(",
"gains",
",",
"count",
"=",
... | Evaluates the RS variable in RSI algorithm
Args:
gains: List of price gains.
losses: List of prices losses.
Returns:
Float of average gains over average losses. | [
"Evaluates",
"the",
"RS",
"variable",
"in",
"RSI",
"algorithm"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/features/RSI.py#L26-L44 |
amicks/Speculator | speculator/features/RSI.py | RSI.eval_from_json | def eval_from_json(json):
""" Evaluates RSI from JSON (typically Poloniex API response)
Args:
json: List of dates where each entry is a dict of raw market data.
Returns:
Float between 0 and 100, momentum indicator
of a market measuring the speed and change o... | python | def eval_from_json(json):
""" Evaluates RSI from JSON (typically Poloniex API response)
Args:
json: List of dates where each entry is a dict of raw market data.
Returns:
Float between 0 and 100, momentum indicator
of a market measuring the speed and change o... | [
"def",
"eval_from_json",
"(",
"json",
")",
":",
"changes",
"=",
"poloniex",
".",
"get_gains_losses",
"(",
"poloniex",
".",
"parse_changes",
"(",
"json",
")",
")",
"return",
"RSI",
".",
"eval_algorithm",
"(",
"changes",
"[",
"'gains'",
"]",
",",
"changes",
... | Evaluates RSI from JSON (typically Poloniex API response)
Args:
json: List of dates where each entry is a dict of raw market data.
Returns:
Float between 0 and 100, momentum indicator
of a market measuring the speed and change of price movements. | [
"Evaluates",
"RSI",
"from",
"JSON",
"(",
"typically",
"Poloniex",
"API",
"response",
")"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/features/RSI.py#L46-L57 |
seznam/shelter | shelter/core/commands.py | BaseCommand.sigusr1_handler | def sigusr1_handler(self, unused_signum, unused_frame):
"""
Handle SIGUSR1 signal. Call function which is defined in the
**settings.SIGUSR1_HANDLER**.
"""
if self._sigusr1_handler_func is not None:
self._sigusr1_handler_func(self.context) | python | def sigusr1_handler(self, unused_signum, unused_frame):
"""
Handle SIGUSR1 signal. Call function which is defined in the
**settings.SIGUSR1_HANDLER**.
"""
if self._sigusr1_handler_func is not None:
self._sigusr1_handler_func(self.context) | [
"def",
"sigusr1_handler",
"(",
"self",
",",
"unused_signum",
",",
"unused_frame",
")",
":",
"if",
"self",
".",
"_sigusr1_handler_func",
"is",
"not",
"None",
":",
"self",
".",
"_sigusr1_handler_func",
"(",
"self",
".",
"context",
")"
] | Handle SIGUSR1 signal. Call function which is defined in the
**settings.SIGUSR1_HANDLER**. | [
"Handle",
"SIGUSR1",
"signal",
".",
"Call",
"function",
"which",
"is",
"defined",
"in",
"the",
"**",
"settings",
".",
"SIGUSR1_HANDLER",
"**",
"."
] | train | https://github.com/seznam/shelter/blob/c652b0ff1cca70158f8fc97d9210c1fa5961ac1c/shelter/core/commands.py#L129-L135 |
seznam/shelter | shelter/core/commands.py | BaseCommand.sigusr2_handler | def sigusr2_handler(self, unused_signum, unused_frame):
"""
Handle SIGUSR2 signal. Call function which is defined in the
**settings.SIGUSR2_HANDLER**.
"""
if self._sigusr1_handler_func is not None:
self._sigusr2_handler_func(self.context) | python | def sigusr2_handler(self, unused_signum, unused_frame):
"""
Handle SIGUSR2 signal. Call function which is defined in the
**settings.SIGUSR2_HANDLER**.
"""
if self._sigusr1_handler_func is not None:
self._sigusr2_handler_func(self.context) | [
"def",
"sigusr2_handler",
"(",
"self",
",",
"unused_signum",
",",
"unused_frame",
")",
":",
"if",
"self",
".",
"_sigusr1_handler_func",
"is",
"not",
"None",
":",
"self",
".",
"_sigusr2_handler_func",
"(",
"self",
".",
"context",
")"
] | Handle SIGUSR2 signal. Call function which is defined in the
**settings.SIGUSR2_HANDLER**. | [
"Handle",
"SIGUSR2",
"signal",
".",
"Call",
"function",
"which",
"is",
"defined",
"in",
"the",
"**",
"settings",
".",
"SIGUSR2_HANDLER",
"**",
"."
] | train | https://github.com/seznam/shelter/blob/c652b0ff1cca70158f8fc97d9210c1fa5961ac1c/shelter/core/commands.py#L137-L143 |
fhcrc/taxtastic | taxtastic/subcommands/info.py | action | def action(args):
"""
Show information about reference packages.
"""
log.info('loading reference package')
pkg = refpkg.Refpkg(args.refpkg, create=False)
with open(pkg.file_abspath('seq_info'), 'rU') as seq_info:
seqinfo = list(csv.DictReader(seq_info))
snames = [row['seqname']... | python | def action(args):
"""
Show information about reference packages.
"""
log.info('loading reference package')
pkg = refpkg.Refpkg(args.refpkg, create=False)
with open(pkg.file_abspath('seq_info'), 'rU') as seq_info:
seqinfo = list(csv.DictReader(seq_info))
snames = [row['seqname']... | [
"def",
"action",
"(",
"args",
")",
":",
"log",
".",
"info",
"(",
"'loading reference package'",
")",
"pkg",
"=",
"refpkg",
".",
"Refpkg",
"(",
"args",
".",
"refpkg",
",",
"create",
"=",
"False",
")",
"with",
"open",
"(",
"pkg",
".",
"file_abspath",
"("... | Show information about reference packages. | [
"Show",
"information",
"about",
"reference",
"packages",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/subcommands/info.py#L68-L88 |
amicks/Speculator | speculator/utils/poloniex.py | json_to_url | def json_to_url(json, symbol):
""" Converts a JSON to a URL by the Poloniex API
Args:
json: JSON data as a list of dict dates, where the keys are
the raw market statistics.
symbol: String of currency pair, like a ticker symbol.
Returns:
String URL to Poloniex API repre... | python | def json_to_url(json, symbol):
""" Converts a JSON to a URL by the Poloniex API
Args:
json: JSON data as a list of dict dates, where the keys are
the raw market statistics.
symbol: String of currency pair, like a ticker symbol.
Returns:
String URL to Poloniex API repre... | [
"def",
"json_to_url",
"(",
"json",
",",
"symbol",
")",
":",
"start",
"=",
"json",
"[",
"0",
"]",
"[",
"'date'",
"]",
"end",
"=",
"json",
"[",
"-",
"1",
"]",
"[",
"'date'",
"]",
"diff",
"=",
"end",
"-",
"start",
"# Get period by a ratio from calculated ... | Converts a JSON to a URL by the Poloniex API
Args:
json: JSON data as a list of dict dates, where the keys are
the raw market statistics.
symbol: String of currency pair, like a ticker symbol.
Returns:
String URL to Poloniex API representing the given JSON. | [
"Converts",
"a",
"JSON",
"to",
"a",
"URL",
"by",
"the",
"Poloniex",
"API"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/poloniex.py#L8-L37 |
amicks/Speculator | speculator/utils/poloniex.py | chart_json | def chart_json(start, end, period, symbol):
""" Requests chart data from Poloniex API
Args:
start: Int epoch date to START getting market stats from.
Note that this epoch is FURTHER from the current date.
end: Int epoch date to STOP getting market stats from.
Note th... | python | def chart_json(start, end, period, symbol):
""" Requests chart data from Poloniex API
Args:
start: Int epoch date to START getting market stats from.
Note that this epoch is FURTHER from the current date.
end: Int epoch date to STOP getting market stats from.
Note th... | [
"def",
"chart_json",
"(",
"start",
",",
"end",
",",
"period",
",",
"symbol",
")",
":",
"url",
"=",
"(",
"'https://poloniex.com/public?command'",
"'=returnChartData¤cyPair={0}&start={1}'",
"'&end={2}&period={3}'",
")",
".",
"format",
"(",
"symbol",
",",
"start",
... | Requests chart data from Poloniex API
Args:
start: Int epoch date to START getting market stats from.
Note that this epoch is FURTHER from the current date.
end: Int epoch date to STOP getting market stats from.
Note that this epoch is CLOSER to the current date.
... | [
"Requests",
"chart",
"data",
"from",
"Poloniex",
"API",
"Args",
":",
"start",
":",
"Int",
"epoch",
"date",
"to",
"START",
"getting",
"market",
"stats",
"from",
".",
"Note",
"that",
"this",
"epoch",
"is",
"FURTHER",
"from",
"the",
"current",
"date",
".",
... | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/poloniex.py#L39-L74 |
amicks/Speculator | speculator/utils/poloniex.py | parse_changes | def parse_changes(json):
""" Gets price changes from JSON
Args:
json: JSON data as a list of dict dates, where the keys are
the raw market statistics.
Returns:
List of floats of price changes between entries in JSON.
"""
changes = []
dates = len(json)
for date i... | python | def parse_changes(json):
""" Gets price changes from JSON
Args:
json: JSON data as a list of dict dates, where the keys are
the raw market statistics.
Returns:
List of floats of price changes between entries in JSON.
"""
changes = []
dates = len(json)
for date i... | [
"def",
"parse_changes",
"(",
"json",
")",
":",
"changes",
"=",
"[",
"]",
"dates",
"=",
"len",
"(",
"json",
")",
"for",
"date",
"in",
"range",
"(",
"1",
",",
"dates",
")",
":",
"last_close",
"=",
"json",
"[",
"date",
"-",
"1",
"]",
"[",
"'close'",... | Gets price changes from JSON
Args:
json: JSON data as a list of dict dates, where the keys are
the raw market statistics.
Returns:
List of floats of price changes between entries in JSON. | [
"Gets",
"price",
"changes",
"from",
"JSON"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/poloniex.py#L76-L93 |
amicks/Speculator | speculator/utils/poloniex.py | get_gains_losses | def get_gains_losses(changes):
""" Categorizes changes into gains and losses
Args:
changes: List of floats of price changes between entries in JSON.
Returns:
Dict of changes with keys 'gains' and 'losses'.
All values are positive.
"""
res = {'gains': [], 'losses': []}
f... | python | def get_gains_losses(changes):
""" Categorizes changes into gains and losses
Args:
changes: List of floats of price changes between entries in JSON.
Returns:
Dict of changes with keys 'gains' and 'losses'.
All values are positive.
"""
res = {'gains': [], 'losses': []}
f... | [
"def",
"get_gains_losses",
"(",
"changes",
")",
":",
"res",
"=",
"{",
"'gains'",
":",
"[",
"]",
",",
"'losses'",
":",
"[",
"]",
"}",
"for",
"change",
"in",
"changes",
":",
"if",
"change",
">",
"0",
":",
"res",
"[",
"'gains'",
"]",
".",
"append",
... | Categorizes changes into gains and losses
Args:
changes: List of floats of price changes between entries in JSON.
Returns:
Dict of changes with keys 'gains' and 'losses'.
All values are positive. | [
"Categorizes",
"changes",
"into",
"gains",
"and",
"losses"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/poloniex.py#L95-L113 |
amicks/Speculator | speculator/utils/poloniex.py | get_attribute | def get_attribute(json, attr):
""" Gets the values of an attribute from JSON
Args:
json: JSON data as a list of dict dates, where the keys are
the raw market statistics.
attr: String of attribute in JSON file to collect.
Returns:
List of values of specified attribute fr... | python | def get_attribute(json, attr):
""" Gets the values of an attribute from JSON
Args:
json: JSON data as a list of dict dates, where the keys are
the raw market statistics.
attr: String of attribute in JSON file to collect.
Returns:
List of values of specified attribute fr... | [
"def",
"get_attribute",
"(",
"json",
",",
"attr",
")",
":",
"res",
"=",
"[",
"json",
"[",
"entry",
"]",
"[",
"attr",
"]",
"for",
"entry",
",",
"_",
"in",
"enumerate",
"(",
"json",
")",
"]",
"logger",
".",
"debug",
"(",
"'{0}s (from JSON):\\n{1}'",
".... | Gets the values of an attribute from JSON
Args:
json: JSON data as a list of dict dates, where the keys are
the raw market statistics.
attr: String of attribute in JSON file to collect.
Returns:
List of values of specified attribute from JSON | [
"Gets",
"the",
"values",
"of",
"an",
"attribute",
"from",
"JSON"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/poloniex.py#L115-L128 |
amicks/Speculator | speculator/utils/poloniex.py | get_json_shift | def get_json_shift(year, month, day, unit, count, period, symbol):
""" Gets JSON from shifted date by the Poloniex API
Args:
year: Int between 1 and 9999.
month: Int between 1 and 12.
day: Int between 1 and 31.
unit: String of time period unit for count argument.
How... | python | def get_json_shift(year, month, day, unit, count, period, symbol):
""" Gets JSON from shifted date by the Poloniex API
Args:
year: Int between 1 and 9999.
month: Int between 1 and 12.
day: Int between 1 and 31.
unit: String of time period unit for count argument.
How... | [
"def",
"get_json_shift",
"(",
"year",
",",
"month",
",",
"day",
",",
"unit",
",",
"count",
",",
"period",
",",
"symbol",
")",
":",
"epochs",
"=",
"date",
".",
"get_end_start_epochs",
"(",
"year",
",",
"month",
",",
"day",
",",
"'last'",
",",
"unit",
... | Gets JSON from shifted date by the Poloniex API
Args:
year: Int between 1 and 9999.
month: Int between 1 and 12.
day: Int between 1 and 31.
unit: String of time period unit for count argument.
How far back to check historical market data.
Valid values: 'hour'... | [
"Gets",
"JSON",
"from",
"shifted",
"date",
"by",
"the",
"Poloniex",
"API"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/poloniex.py#L130-L149 |
fhcrc/taxtastic | taxtastic/subcommands/refpkg_intersection.py | filter_ranks | def filter_ranks(results):
"""
Find just the first rank for all the results for a given tax_id.
"""
for _, group in itertools.groupby(results, operator.itemgetter(0)):
yield next(group) | python | def filter_ranks(results):
"""
Find just the first rank for all the results for a given tax_id.
"""
for _, group in itertools.groupby(results, operator.itemgetter(0)):
yield next(group) | [
"def",
"filter_ranks",
"(",
"results",
")",
":",
"for",
"_",
",",
"group",
"in",
"itertools",
".",
"groupby",
"(",
"results",
",",
"operator",
".",
"itemgetter",
"(",
"0",
")",
")",
":",
"yield",
"next",
"(",
"group",
")"
] | Find just the first rank for all the results for a given tax_id. | [
"Find",
"just",
"the",
"first",
"rank",
"for",
"all",
"the",
"results",
"for",
"a",
"given",
"tax_id",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/subcommands/refpkg_intersection.py#L49-L54 |
amicks/Speculator | speculator/features/SO.py | SO.eval_algorithm | def eval_algorithm(closing, low, high):
""" Evaluates the SO algorithm
Args:
closing: Float of current closing price.
low: Float of lowest low closing price throughout some duration.
high: Float of highest high closing price throughout some duration.
Returns... | python | def eval_algorithm(closing, low, high):
""" Evaluates the SO algorithm
Args:
closing: Float of current closing price.
low: Float of lowest low closing price throughout some duration.
high: Float of highest high closing price throughout some duration.
Returns... | [
"def",
"eval_algorithm",
"(",
"closing",
",",
"low",
",",
"high",
")",
":",
"if",
"high",
"-",
"low",
"==",
"0",
":",
"# High and low are the same, zero division error",
"return",
"100",
"*",
"(",
"closing",
"-",
"low",
")",
"else",
":",
"return",
"100",
"... | Evaluates the SO algorithm
Args:
closing: Float of current closing price.
low: Float of lowest low closing price throughout some duration.
high: Float of highest high closing price throughout some duration.
Returns:
Float SO between 0 and 100. | [
"Evaluates",
"the",
"SO",
"algorithm"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/features/SO.py#L17-L31 |
amicks/Speculator | speculator/features/SO.py | SO.eval_from_json | def eval_from_json(json):
""" Evaluates SO from JSON (typically Poloniex API response)
Args:
json: List of dates where each entry is a dict of raw market data.
Returns:
Float SO between 0 and 100.
"""
close = json[-1]['close'] # Latest closing price
... | python | def eval_from_json(json):
""" Evaluates SO from JSON (typically Poloniex API response)
Args:
json: List of dates where each entry is a dict of raw market data.
Returns:
Float SO between 0 and 100.
"""
close = json[-1]['close'] # Latest closing price
... | [
"def",
"eval_from_json",
"(",
"json",
")",
":",
"close",
"=",
"json",
"[",
"-",
"1",
"]",
"[",
"'close'",
"]",
"# Latest closing price",
"low",
"=",
"min",
"(",
"poloniex",
".",
"get_attribute",
"(",
"json",
",",
"'low'",
")",
")",
"# Lowest low",
"high"... | Evaluates SO from JSON (typically Poloniex API response)
Args:
json: List of dates where each entry is a dict of raw market data.
Returns:
Float SO between 0 and 100. | [
"Evaluates",
"SO",
"from",
"JSON",
"(",
"typically",
"Poloniex",
"API",
"response",
")"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/features/SO.py#L33-L45 |
amicks/Speculator | speculator/utils/stats.py | avg | def avg(vals, count=None):
""" Returns the average value
Args:
vals: List of numbers to calculate average from.
count: Int of total count that vals was part of.
Returns:
Float average value throughout a count.
"""
sum = 0
for v in vals:
sum += v
if count is... | python | def avg(vals, count=None):
""" Returns the average value
Args:
vals: List of numbers to calculate average from.
count: Int of total count that vals was part of.
Returns:
Float average value throughout a count.
"""
sum = 0
for v in vals:
sum += v
if count is... | [
"def",
"avg",
"(",
"vals",
",",
"count",
"=",
"None",
")",
":",
"sum",
"=",
"0",
"for",
"v",
"in",
"vals",
":",
"sum",
"+=",
"v",
"if",
"count",
"is",
"None",
":",
"count",
"=",
"len",
"(",
"vals",
")",
"return",
"float",
"(",
"sum",
")",
"/"... | Returns the average value
Args:
vals: List of numbers to calculate average from.
count: Int of total count that vals was part of.
Returns:
Float average value throughout a count. | [
"Returns",
"the",
"average",
"value"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/stats.py#L5-L20 |
fhcrc/taxtastic | taxtastic/ncbi.py | db_connect | def db_connect(engine, schema=None, clobber=False):
"""Create a connection object to a database. Attempt to establish a
schema. If there are existing tables, delete them if clobber is
True and return otherwise. Returns a sqlalchemy engine object.
"""
if schema is None:
base = declarative_b... | python | def db_connect(engine, schema=None, clobber=False):
"""Create a connection object to a database. Attempt to establish a
schema. If there are existing tables, delete them if clobber is
True and return otherwise. Returns a sqlalchemy engine object.
"""
if schema is None:
base = declarative_b... | [
"def",
"db_connect",
"(",
"engine",
",",
"schema",
"=",
"None",
",",
"clobber",
"=",
"False",
")",
":",
"if",
"schema",
"is",
"None",
":",
"base",
"=",
"declarative_base",
"(",
")",
"else",
":",
"try",
":",
"engine",
".",
"execute",
"(",
"sqlalchemy",
... | Create a connection object to a database. Attempt to establish a
schema. If there are existing tables, delete them if clobber is
True and return otherwise. Returns a sqlalchemy engine object. | [
"Create",
"a",
"connection",
"object",
"to",
"a",
"database",
".",
"Attempt",
"to",
"establish",
"a",
"schema",
".",
"If",
"there",
"are",
"existing",
"tables",
"delete",
"them",
"if",
"clobber",
"is",
"True",
"and",
"return",
"otherwise",
".",
"Returns",
... | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/ncbi.py#L215-L240 |
fhcrc/taxtastic | taxtastic/ncbi.py | read_nodes | def read_nodes(rows, source_id=1):
"""
Return an iterator of rows ready to insert into table "nodes".
* rows - iterator of lists (eg, output from read_archive or read_dmp)
"""
ncbi_keys = ['tax_id', 'parent_id', 'rank', 'embl_code', 'division_id']
extra_keys = ['source_id', 'is_valid']
is_... | python | def read_nodes(rows, source_id=1):
"""
Return an iterator of rows ready to insert into table "nodes".
* rows - iterator of lists (eg, output from read_archive or read_dmp)
"""
ncbi_keys = ['tax_id', 'parent_id', 'rank', 'embl_code', 'division_id']
extra_keys = ['source_id', 'is_valid']
is_... | [
"def",
"read_nodes",
"(",
"rows",
",",
"source_id",
"=",
"1",
")",
":",
"ncbi_keys",
"=",
"[",
"'tax_id'",
",",
"'parent_id'",
",",
"'rank'",
",",
"'embl_code'",
",",
"'division_id'",
"]",
"extra_keys",
"=",
"[",
"'source_id'",
",",
"'is_valid'",
"]",
"is_... | Return an iterator of rows ready to insert into table "nodes".
* rows - iterator of lists (eg, output from read_archive or read_dmp) | [
"Return",
"an",
"iterator",
"of",
"rows",
"ready",
"to",
"insert",
"into",
"table",
"nodes",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/ncbi.py#L250-L280 |
fhcrc/taxtastic | taxtastic/ncbi.py | read_names | def read_names(rows, source_id=1):
"""Return an iterator of rows ready to insert into table
"names". Adds columns "is_primary" (identifying the primary name
for each tax_id with a vaule of 1) and "is_classified" (always None).
* rows - iterator of lists (eg, output from read_archive or read_dmp)
* ... | python | def read_names(rows, source_id=1):
"""Return an iterator of rows ready to insert into table
"names". Adds columns "is_primary" (identifying the primary name
for each tax_id with a vaule of 1) and "is_classified" (always None).
* rows - iterator of lists (eg, output from read_archive or read_dmp)
* ... | [
"def",
"read_names",
"(",
"rows",
",",
"source_id",
"=",
"1",
")",
":",
"ncbi_keys",
"=",
"[",
"'tax_id'",
",",
"'tax_name'",
",",
"'unique_name'",
",",
"'name_class'",
"]",
"extra_keys",
"=",
"[",
"'source_id'",
",",
"'is_primary'",
",",
"'is_classified'",
... | Return an iterator of rows ready to insert into table
"names". Adds columns "is_primary" (identifying the primary name
for each tax_id with a vaule of 1) and "is_classified" (always None).
* rows - iterator of lists (eg, output from read_archive or read_dmp)
* unclassified_regex - a compiled re matchin... | [
"Return",
"an",
"iterator",
"of",
"rows",
"ready",
"to",
"insert",
"into",
"table",
"names",
".",
"Adds",
"columns",
"is_primary",
"(",
"identifying",
"the",
"primary",
"name",
"for",
"each",
"tax_id",
"with",
"a",
"vaule",
"of",
"1",
")",
"and",
"is_class... | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/ncbi.py#L283-L326 |
fhcrc/taxtastic | taxtastic/ncbi.py | fetch_data | def fetch_data(dest_dir='.', clobber=False, url=DATA_URL):
"""
Download data from NCBI required to generate local taxonomy
database. Default url is ncbi.DATA_URL
* dest_dir - directory in which to save output files (created if necessary).
* clobber - don't download if False and target of url exists... | python | def fetch_data(dest_dir='.', clobber=False, url=DATA_URL):
"""
Download data from NCBI required to generate local taxonomy
database. Default url is ncbi.DATA_URL
* dest_dir - directory in which to save output files (created if necessary).
* clobber - don't download if False and target of url exists... | [
"def",
"fetch_data",
"(",
"dest_dir",
"=",
"'.'",
",",
"clobber",
"=",
"False",
",",
"url",
"=",
"DATA_URL",
")",
":",
"dest_dir",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"dest_dir",
")",
"try",
":",
"os",
".",
"mkdir",
"(",
"dest_dir",
")",
"... | Download data from NCBI required to generate local taxonomy
database. Default url is ncbi.DATA_URL
* dest_dir - directory in which to save output files (created if necessary).
* clobber - don't download if False and target of url exists in dest_dir
* url - url to archive; default is ncbi.DATA_URL
... | [
"Download",
"data",
"from",
"NCBI",
"required",
"to",
"generate",
"local",
"taxonomy",
"database",
".",
"Default",
"url",
"is",
"ncbi",
".",
"DATA_URL"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/ncbi.py#L495-L527 |
fhcrc/taxtastic | taxtastic/ncbi.py | read_archive | def read_archive(archive, fname):
"""Return an iterator of unique rows from a zip archive.
* archive - path to the zip archive.
* fname - name of the compressed file within the archive.
"""
# Note that deduplication here is equivalent to an upsert/ignore,
# but avoids requirement for a databa... | python | def read_archive(archive, fname):
"""Return an iterator of unique rows from a zip archive.
* archive - path to the zip archive.
* fname - name of the compressed file within the archive.
"""
# Note that deduplication here is equivalent to an upsert/ignore,
# but avoids requirement for a databa... | [
"def",
"read_archive",
"(",
"archive",
",",
"fname",
")",
":",
"# Note that deduplication here is equivalent to an upsert/ignore,",
"# but avoids requirement for a database-specific implementation.",
"zfile",
"=",
"zipfile",
".",
"ZipFile",
"(",
"archive",
")",
"contents",
"=",... | Return an iterator of unique rows from a zip archive.
* archive - path to the zip archive.
* fname - name of the compressed file within the archive. | [
"Return",
"an",
"iterator",
"of",
"unique",
"rows",
"from",
"a",
"zip",
"archive",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/ncbi.py#L530-L550 |
fhcrc/taxtastic | taxtastic/ncbi.py | NCBILoader.prepend_schema | def prepend_schema(self, name):
"""Prepend schema name to 'name' when a schema is specified
"""
return '.'.join([self.schema, name]) if self.schema else name | python | def prepend_schema(self, name):
"""Prepend schema name to 'name' when a schema is specified
"""
return '.'.join([self.schema, name]) if self.schema else name | [
"def",
"prepend_schema",
"(",
"self",
",",
"name",
")",
":",
"return",
"'.'",
".",
"join",
"(",
"[",
"self",
".",
"schema",
",",
"name",
"]",
")",
"if",
"self",
".",
"schema",
"else",
"name"
] | Prepend schema name to 'name' when a schema is specified | [
"Prepend",
"schema",
"name",
"to",
"name",
"when",
"a",
"schema",
"is",
"specified"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/ncbi.py#L338-L342 |
fhcrc/taxtastic | taxtastic/ncbi.py | NCBILoader.load_table | def load_table(self, table, rows, colnames=None, limit=None):
"""Load 'rows' into table 'table'. If 'colnames' is not provided, the
first element of 'rows' must provide column names.
"""
conn = self.engine.raw_connection()
cur = conn.cursor()
colnames = colnames or nex... | python | def load_table(self, table, rows, colnames=None, limit=None):
"""Load 'rows' into table 'table'. If 'colnames' is not provided, the
first element of 'rows' must provide column names.
"""
conn = self.engine.raw_connection()
cur = conn.cursor()
colnames = colnames or nex... | [
"def",
"load_table",
"(",
"self",
",",
"table",
",",
"rows",
",",
"colnames",
"=",
"None",
",",
"limit",
"=",
"None",
")",
":",
"conn",
"=",
"self",
".",
"engine",
".",
"raw_connection",
"(",
")",
"cur",
"=",
"conn",
".",
"cursor",
"(",
")",
"colna... | Load 'rows' into table 'table'. If 'colnames' is not provided, the
first element of 'rows' must provide column names. | [
"Load",
"rows",
"into",
"table",
"table",
".",
"If",
"colnames",
"is",
"not",
"provided",
"the",
"first",
"element",
"of",
"rows",
"must",
"provide",
"column",
"names",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/ncbi.py#L344-L361 |
fhcrc/taxtastic | taxtastic/ncbi.py | NCBILoader.load_archive | def load_archive(self, archive):
"""Load data from the zip archive of the NCBI taxonomy.
"""
# source
self.load_table(
'source',
rows=[('ncbi', DATA_URL)],
colnames=['name', 'description'],
)
conn = self.engine.raw_connection()
... | python | def load_archive(self, archive):
"""Load data from the zip archive of the NCBI taxonomy.
"""
# source
self.load_table(
'source',
rows=[('ncbi', DATA_URL)],
colnames=['name', 'description'],
)
conn = self.engine.raw_connection()
... | [
"def",
"load_archive",
"(",
"self",
",",
"archive",
")",
":",
"# source",
"self",
".",
"load_table",
"(",
"'source'",
",",
"rows",
"=",
"[",
"(",
"'ncbi'",
",",
"DATA_URL",
")",
"]",
",",
"colnames",
"=",
"[",
"'name'",
",",
"'description'",
"]",
",",
... | Load data from the zip archive of the NCBI taxonomy. | [
"Load",
"data",
"from",
"the",
"zip",
"archive",
"of",
"the",
"NCBI",
"taxonomy",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/ncbi.py#L363-L404 |
amicks/Speculator | speculator/utils/date.py | date_to_delorean | def date_to_delorean(year, month, day):
""" Converts date arguments to a Delorean instance in UTC
Args:
year: int between 1 and 9999.
month: int between 1 and 12.
day: int between 1 and 31.
Returns:
Delorean instance in UTC of date.
"""
return Delorean(datetime=... | python | def date_to_delorean(year, month, day):
""" Converts date arguments to a Delorean instance in UTC
Args:
year: int between 1 and 9999.
month: int between 1 and 12.
day: int between 1 and 31.
Returns:
Delorean instance in UTC of date.
"""
return Delorean(datetime=... | [
"def",
"date_to_delorean",
"(",
"year",
",",
"month",
",",
"day",
")",
":",
"return",
"Delorean",
"(",
"datetime",
"=",
"dt",
"(",
"year",
",",
"month",
",",
"day",
")",
",",
"timezone",
"=",
"'UTC'",
")"
] | Converts date arguments to a Delorean instance in UTC
Args:
year: int between 1 and 9999.
month: int between 1 and 12.
day: int between 1 and 31.
Returns:
Delorean instance in UTC of date. | [
"Converts",
"date",
"arguments",
"to",
"a",
"Delorean",
"instance",
"in",
"UTC",
"Args",
":",
"year",
":",
"int",
"between",
"1",
"and",
"9999",
".",
"month",
":",
"int",
"between",
"1",
"and",
"12",
".",
"day",
":",
"int",
"between",
"1",
"and",
"31... | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/date.py#L4-L15 |
amicks/Speculator | speculator/utils/date.py | date_to_epoch | def date_to_epoch(year, month, day):
""" Converts a date to epoch in UTC
Args:
year: int between 1 and 9999.
month: int between 1 and 12.
day: int between 1 and 31.
Returns:
Int epoch in UTC from date.
"""
return int(date_to_delorean(year, month, day).epoch) | python | def date_to_epoch(year, month, day):
""" Converts a date to epoch in UTC
Args:
year: int between 1 and 9999.
month: int between 1 and 12.
day: int between 1 and 31.
Returns:
Int epoch in UTC from date.
"""
return int(date_to_delorean(year, month, day).epoch) | [
"def",
"date_to_epoch",
"(",
"year",
",",
"month",
",",
"day",
")",
":",
"return",
"int",
"(",
"date_to_delorean",
"(",
"year",
",",
"month",
",",
"day",
")",
".",
"epoch",
")"
] | Converts a date to epoch in UTC
Args:
year: int between 1 and 9999.
month: int between 1 and 12.
day: int between 1 and 31.
Returns:
Int epoch in UTC from date. | [
"Converts",
"a",
"date",
"to",
"epoch",
"in",
"UTC"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/date.py#L17-L28 |
amicks/Speculator | speculator/utils/date.py | shift_epoch | def shift_epoch(delorean, direction, unit, count):
""" Gets the resulting epoch after a time shift of a Delorean
Args:
delorean: Delorean datetime instance to shift from.
direction: String to shift time forwards or backwards.
Valid values: 'last', 'next'.
unit: String of... | python | def shift_epoch(delorean, direction, unit, count):
""" Gets the resulting epoch after a time shift of a Delorean
Args:
delorean: Delorean datetime instance to shift from.
direction: String to shift time forwards or backwards.
Valid values: 'last', 'next'.
unit: String of... | [
"def",
"shift_epoch",
"(",
"delorean",
",",
"direction",
",",
"unit",
",",
"count",
")",
":",
"return",
"int",
"(",
"delorean",
".",
"_shift_date",
"(",
"direction",
",",
"unit",
",",
"count",
")",
".",
"epoch",
")"
] | Gets the resulting epoch after a time shift of a Delorean
Args:
delorean: Delorean datetime instance to shift from.
direction: String to shift time forwards or backwards.
Valid values: 'last', 'next'.
unit: String of time period unit for count argument.
What unit... | [
"Gets",
"the",
"resulting",
"epoch",
"after",
"a",
"time",
"shift",
"of",
"a",
"Delorean",
"Args",
":",
"delorean",
":",
"Delorean",
"datetime",
"instance",
"to",
"shift",
"from",
".",
"direction",
":",
"String",
"to",
"shift",
"time",
"forwards",
"or",
"b... | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/date.py#L34-L50 |
amicks/Speculator | speculator/utils/date.py | generate_epochs | def generate_epochs(delorean, direction, unit, count):
""" Generates epochs from a shifted Delorean instance
Args:
delorean: Delorean datetime instance to shift from.
direction: String to shift time forwards or backwards.
Valid values: 'last', 'next'.
unit: String of tim... | python | def generate_epochs(delorean, direction, unit, count):
""" Generates epochs from a shifted Delorean instance
Args:
delorean: Delorean datetime instance to shift from.
direction: String to shift time forwards or backwards.
Valid values: 'last', 'next'.
unit: String of tim... | [
"def",
"generate_epochs",
"(",
"delorean",
",",
"direction",
",",
"unit",
",",
"count",
")",
":",
"for",
"shift",
"in",
"range",
"(",
"count",
")",
":",
"yield",
"int",
"(",
"delorean",
".",
"_shift_date",
"(",
"direction",
",",
"unit",
",",
"shift",
"... | Generates epochs from a shifted Delorean instance
Args:
delorean: Delorean datetime instance to shift from.
direction: String to shift time forwards or backwards.
Valid values: 'last', 'next'.
unit: String of time period unit for count argument.
What unit in dire... | [
"Generates",
"epochs",
"from",
"a",
"shifted",
"Delorean",
"instance",
"Args",
":",
"delorean",
":",
"Delorean",
"datetime",
"instance",
"to",
"shift",
"from",
".",
"direction",
":",
"String",
"to",
"shift",
"time",
"forwards",
"or",
"backwards",
".",
"Valid",... | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/date.py#L52-L69 |
amicks/Speculator | speculator/utils/date.py | get_end_start_epochs | def get_end_start_epochs(year, month, day, direction, unit, count):
""" Gets epoch from a start date and epoch from a shifted date
Args:
year: Int between 1 and 9999.
month: Int between 1 and 12.
day: Int between 1 and 31.
direction: String to shift time forwards or backwards.
... | python | def get_end_start_epochs(year, month, day, direction, unit, count):
""" Gets epoch from a start date and epoch from a shifted date
Args:
year: Int between 1 and 9999.
month: Int between 1 and 12.
day: Int between 1 and 31.
direction: String to shift time forwards or backwards.
... | [
"def",
"get_end_start_epochs",
"(",
"year",
",",
"month",
",",
"day",
",",
"direction",
",",
"unit",
",",
"count",
")",
":",
"if",
"year",
"or",
"month",
"or",
"day",
":",
"# Date is specified",
"if",
"not",
"year",
":",
"year",
"=",
"2017",
"if",
"not... | Gets epoch from a start date and epoch from a shifted date
Args:
year: Int between 1 and 9999.
month: Int between 1 and 12.
day: Int between 1 and 31.
direction: String to shift time forwards or backwards.
Valid values: 'last', 'next'.
unit: String of time period... | [
"Gets",
"epoch",
"from",
"a",
"start",
"date",
"and",
"epoch",
"from",
"a",
"shifted",
"date"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/speculator/utils/date.py#L71-L103 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.add_child | def add_child(self, child):
"""
Add a child to this node.
"""
assert child != self
child.parent = self
child.ranks = self.ranks
child.index = self.index
assert child.tax_id not in self.index
self.index[child.tax_id] = child
self.children.ad... | python | def add_child(self, child):
"""
Add a child to this node.
"""
assert child != self
child.parent = self
child.ranks = self.ranks
child.index = self.index
assert child.tax_id not in self.index
self.index[child.tax_id] = child
self.children.ad... | [
"def",
"add_child",
"(",
"self",
",",
"child",
")",
":",
"assert",
"child",
"!=",
"self",
"child",
".",
"parent",
"=",
"self",
"child",
".",
"ranks",
"=",
"self",
".",
"ranks",
"child",
".",
"index",
"=",
"self",
".",
"index",
"assert",
"child",
".",... | Add a child to this node. | [
"Add",
"a",
"child",
"to",
"this",
"node",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L46-L56 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.remove_child | def remove_child(self, child):
"""
Remove a child from this node.
"""
assert child in self.children
self.children.remove(child)
self.index.pop(child.tax_id)
if child.parent is self:
child.parent = None
if child.index is self.index:
... | python | def remove_child(self, child):
"""
Remove a child from this node.
"""
assert child in self.children
self.children.remove(child)
self.index.pop(child.tax_id)
if child.parent is self:
child.parent = None
if child.index is self.index:
... | [
"def",
"remove_child",
"(",
"self",
",",
"child",
")",
":",
"assert",
"child",
"in",
"self",
".",
"children",
"self",
".",
"children",
".",
"remove",
"(",
"child",
")",
"self",
".",
"index",
".",
"pop",
"(",
"child",
".",
"tax_id",
")",
"if",
"child"... | Remove a child from this node. | [
"Remove",
"a",
"child",
"from",
"this",
"node",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L58-L76 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.drop | def drop(self):
"""
Remove this node from the taxonomy, maintaining child subtrees by
adding them to the node's parent, and moving sequences at this node
to the parent.
Not valid for root node.
"""
if self.is_root:
raise ValueError("Cannot drop root n... | python | def drop(self):
"""
Remove this node from the taxonomy, maintaining child subtrees by
adding them to the node's parent, and moving sequences at this node
to the parent.
Not valid for root node.
"""
if self.is_root:
raise ValueError("Cannot drop root n... | [
"def",
"drop",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_root",
":",
"raise",
"ValueError",
"(",
"\"Cannot drop root node!\"",
")",
"parent",
"=",
"self",
".",
"parent",
"for",
"child",
"in",
"self",
".",
"children",
":",
"child",
".",
"parent",
"=",... | Remove this node from the taxonomy, maintaining child subtrees by
adding them to the node's parent, and moving sequences at this node
to the parent.
Not valid for root node. | [
"Remove",
"this",
"node",
"from",
"the",
"taxonomy",
"maintaining",
"child",
"subtrees",
"by",
"adding",
"them",
"to",
"the",
"node",
"s",
"parent",
"and",
"moving",
"sequences",
"at",
"this",
"node",
"to",
"the",
"parent",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L78-L98 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.prune_unrepresented | def prune_unrepresented(self):
"""
Remove nodes without sequences or children below this node.
"""
for node in self.depth_first_iter(self_first=False):
if (not node.children and
not node.sequence_ids and
node is not self):
... | python | def prune_unrepresented(self):
"""
Remove nodes without sequences or children below this node.
"""
for node in self.depth_first_iter(self_first=False):
if (not node.children and
not node.sequence_ids and
node is not self):
... | [
"def",
"prune_unrepresented",
"(",
"self",
")",
":",
"for",
"node",
"in",
"self",
".",
"depth_first_iter",
"(",
"self_first",
"=",
"False",
")",
":",
"if",
"(",
"not",
"node",
".",
"children",
"and",
"not",
"node",
".",
"sequence_ids",
"and",
"node",
"is... | Remove nodes without sequences or children below this node. | [
"Remove",
"nodes",
"without",
"sequences",
"or",
"children",
"below",
"this",
"node",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L100-L108 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.at_rank | def at_rank(self, rank):
"""
Find the node above this node at rank ``rank``
"""
s = self
while s:
if s.rank == rank:
return s
s = s.parent
raise ValueError("No node at rank {0} for {1}".format(
rank, self.tax_id)) | python | def at_rank(self, rank):
"""
Find the node above this node at rank ``rank``
"""
s = self
while s:
if s.rank == rank:
return s
s = s.parent
raise ValueError("No node at rank {0} for {1}".format(
rank, self.tax_id)) | [
"def",
"at_rank",
"(",
"self",
",",
"rank",
")",
":",
"s",
"=",
"self",
"while",
"s",
":",
"if",
"s",
".",
"rank",
"==",
"rank",
":",
"return",
"s",
"s",
"=",
"s",
".",
"parent",
"raise",
"ValueError",
"(",
"\"No node at rank {0} for {1}\"",
".",
"fo... | Find the node above this node at rank ``rank`` | [
"Find",
"the",
"node",
"above",
"this",
"node",
"at",
"rank",
"rank"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L118-L128 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.depth_first_iter | def depth_first_iter(self, self_first=True):
"""
Iterate over nodes below this node, optionally yielding children before
self.
"""
if self_first:
yield self
for child in list(self.children):
for i in child.depth_first_iter(self_first):
... | python | def depth_first_iter(self, self_first=True):
"""
Iterate over nodes below this node, optionally yielding children before
self.
"""
if self_first:
yield self
for child in list(self.children):
for i in child.depth_first_iter(self_first):
... | [
"def",
"depth_first_iter",
"(",
"self",
",",
"self_first",
"=",
"True",
")",
":",
"if",
"self_first",
":",
"yield",
"self",
"for",
"child",
"in",
"list",
"(",
"self",
".",
"children",
")",
":",
"for",
"i",
"in",
"child",
".",
"depth_first_iter",
"(",
"... | Iterate over nodes below this node, optionally yielding children before
self. | [
"Iterate",
"over",
"nodes",
"below",
"this",
"node",
"optionally",
"yielding",
"children",
"before",
"self",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L130-L141 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.path | def path(self, tax_ids):
"""Get the node at the end of the path described by tax_ids."""
assert tax_ids[0] == self.tax_id
if len(tax_ids) == 1:
return self
n = tax_ids[1]
try:
child = next(i for i in self.children if i.tax_id == n)
except StopIter... | python | def path(self, tax_ids):
"""Get the node at the end of the path described by tax_ids."""
assert tax_ids[0] == self.tax_id
if len(tax_ids) == 1:
return self
n = tax_ids[1]
try:
child = next(i for i in self.children if i.tax_id == n)
except StopIter... | [
"def",
"path",
"(",
"self",
",",
"tax_ids",
")",
":",
"assert",
"tax_ids",
"[",
"0",
"]",
"==",
"self",
".",
"tax_id",
"if",
"len",
"(",
"tax_ids",
")",
"==",
"1",
":",
"return",
"self",
"n",
"=",
"tax_ids",
"[",
"1",
"]",
"try",
":",
"child",
... | Get the node at the end of the path described by tax_ids. | [
"Get",
"the",
"node",
"at",
"the",
"end",
"of",
"the",
"path",
"described",
"by",
"tax_ids",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L160-L172 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.lineage | def lineage(self):
"""
Return all nodes between this node and the root, including this one.
"""
if not self.parent:
return [self]
else:
L = self.parent.lineage()
L.append(self)
return L | python | def lineage(self):
"""
Return all nodes between this node and the root, including this one.
"""
if not self.parent:
return [self]
else:
L = self.parent.lineage()
L.append(self)
return L | [
"def",
"lineage",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"parent",
":",
"return",
"[",
"self",
"]",
"else",
":",
"L",
"=",
"self",
".",
"parent",
".",
"lineage",
"(",
")",
"L",
".",
"append",
"(",
"self",
")",
"return",
"L"
] | Return all nodes between this node and the root, including this one. | [
"Return",
"all",
"nodes",
"between",
"this",
"node",
"and",
"the",
"root",
"including",
"this",
"one",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L180-L189 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.write_taxtable | def write_taxtable(self, out_fp, **kwargs):
"""
Write a taxtable for this node and all descendants,
including the lineage leading to this node.
"""
ranks_represented = frozenset(i.rank for i in self) | \
frozenset(i.rank for i in self.lineage())
ranks = [i for... | python | def write_taxtable(self, out_fp, **kwargs):
"""
Write a taxtable for this node and all descendants,
including the lineage leading to this node.
"""
ranks_represented = frozenset(i.rank for i in self) | \
frozenset(i.rank for i in self.lineage())
ranks = [i for... | [
"def",
"write_taxtable",
"(",
"self",
",",
"out_fp",
",",
"*",
"*",
"kwargs",
")",
":",
"ranks_represented",
"=",
"frozenset",
"(",
"i",
".",
"rank",
"for",
"i",
"in",
"self",
")",
"|",
"frozenset",
"(",
"i",
".",
"rank",
"for",
"i",
"in",
"self",
... | Write a taxtable for this node and all descendants,
including the lineage leading to this node. | [
"Write",
"a",
"taxtable",
"for",
"this",
"node",
"and",
"all",
"descendants",
"including",
"the",
"lineage",
"leading",
"to",
"this",
"node",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L199-L226 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.populate_from_seqinfo | def populate_from_seqinfo(self, seqinfo):
"""Populate sequence_ids below this node from a seqinfo file object."""
for row in csv.DictReader(seqinfo):
node = self.index.get(row['tax_id'])
if node:
node.sequence_ids.add(row['seqname']) | python | def populate_from_seqinfo(self, seqinfo):
"""Populate sequence_ids below this node from a seqinfo file object."""
for row in csv.DictReader(seqinfo):
node = self.index.get(row['tax_id'])
if node:
node.sequence_ids.add(row['seqname']) | [
"def",
"populate_from_seqinfo",
"(",
"self",
",",
"seqinfo",
")",
":",
"for",
"row",
"in",
"csv",
".",
"DictReader",
"(",
"seqinfo",
")",
":",
"node",
"=",
"self",
".",
"index",
".",
"get",
"(",
"row",
"[",
"'tax_id'",
"]",
")",
"if",
"node",
":",
... | Populate sequence_ids below this node from a seqinfo file object. | [
"Populate",
"sequence_ids",
"below",
"this",
"node",
"from",
"a",
"seqinfo",
"file",
"object",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L228-L233 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.collapse | def collapse(self, remove=False):
"""
Move all ``sequence_ids`` in the subtree below this node to this node.
If ``remove`` is True, nodes below this one are deleted from the
taxonomy.
"""
descendants = iter(self)
# Skip this node
assert next(descendants) ... | python | def collapse(self, remove=False):
"""
Move all ``sequence_ids`` in the subtree below this node to this node.
If ``remove`` is True, nodes below this one are deleted from the
taxonomy.
"""
descendants = iter(self)
# Skip this node
assert next(descendants) ... | [
"def",
"collapse",
"(",
"self",
",",
"remove",
"=",
"False",
")",
":",
"descendants",
"=",
"iter",
"(",
"self",
")",
"# Skip this node",
"assert",
"next",
"(",
"descendants",
")",
"is",
"self",
"for",
"descendant",
"in",
"descendants",
":",
"self",
".",
... | Move all ``sequence_ids`` in the subtree below this node to this node.
If ``remove`` is True, nodes below this one are deleted from the
taxonomy. | [
"Move",
"all",
"sequence_ids",
"in",
"the",
"subtree",
"below",
"this",
"node",
"to",
"this",
"node",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L235-L251 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.write_seqinfo | def write_seqinfo(self, out_fp, include_name=True):
"""
Write a simple seq_info file, suitable for use in taxtastic.
Useful for printing out the results of collapsing tax nodes - super
bare bones, just tax_id and seqname.
If include_name is True, a column with the taxon name is ... | python | def write_seqinfo(self, out_fp, include_name=True):
"""
Write a simple seq_info file, suitable for use in taxtastic.
Useful for printing out the results of collapsing tax nodes - super
bare bones, just tax_id and seqname.
If include_name is True, a column with the taxon name is ... | [
"def",
"write_seqinfo",
"(",
"self",
",",
"out_fp",
",",
"include_name",
"=",
"True",
")",
":",
"header",
"=",
"[",
"'seqname'",
",",
"'tax_id'",
"]",
"if",
"include_name",
":",
"header",
".",
"append",
"(",
"'tax_name'",
")",
"w",
"=",
"csv",
".",
"Di... | Write a simple seq_info file, suitable for use in taxtastic.
Useful for printing out the results of collapsing tax nodes - super
bare bones, just tax_id and seqname.
If include_name is True, a column with the taxon name is included. | [
"Write",
"a",
"simple",
"seq_info",
"file",
"suitable",
"for",
"use",
"in",
"taxtastic",
".",
"Useful",
"for",
"printing",
"out",
"the",
"results",
"of",
"collapsing",
"tax",
"nodes",
"-",
"super",
"bare",
"bones",
"just",
"tax_id",
"and",
"seqname",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L253-L276 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.from_taxtable | def from_taxtable(cls, taxtable_fp):
"""
Generate a node from an open handle to a taxtable, as generated by
``taxit taxtable``
"""
r = csv.reader(taxtable_fp)
headers = next(r)
rows = (collections.OrderedDict(list(zip(headers, i))) for i in r)
row = next(... | python | def from_taxtable(cls, taxtable_fp):
"""
Generate a node from an open handle to a taxtable, as generated by
``taxit taxtable``
"""
r = csv.reader(taxtable_fp)
headers = next(r)
rows = (collections.OrderedDict(list(zip(headers, i))) for i in r)
row = next(... | [
"def",
"from_taxtable",
"(",
"cls",
",",
"taxtable_fp",
")",
":",
"r",
"=",
"csv",
".",
"reader",
"(",
"taxtable_fp",
")",
"headers",
"=",
"next",
"(",
"r",
")",
"rows",
"=",
"(",
"collections",
".",
"OrderedDict",
"(",
"list",
"(",
"zip",
"(",
"head... | Generate a node from an open handle to a taxtable, as generated by
``taxit taxtable`` | [
"Generate",
"a",
"node",
"from",
"an",
"open",
"handle",
"to",
"a",
"taxtable",
"as",
"generated",
"by",
"taxit",
"taxtable"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L279-L300 |
fhcrc/taxtastic | taxtastic/taxtable.py | TaxNode.from_taxdb | def from_taxdb(cls, con, root=None):
"""
Generate a TaxNode from a taxonomy database
"""
cursor = con.cursor()
if root is None:
cursor.execute(
"SELECT tax_id, rank FROM nodes WHERE tax_id = parent_id")
else:
cursor.execute(
... | python | def from_taxdb(cls, con, root=None):
"""
Generate a TaxNode from a taxonomy database
"""
cursor = con.cursor()
if root is None:
cursor.execute(
"SELECT tax_id, rank FROM nodes WHERE tax_id = parent_id")
else:
cursor.execute(
... | [
"def",
"from_taxdb",
"(",
"cls",
",",
"con",
",",
"root",
"=",
"None",
")",
":",
"cursor",
"=",
"con",
".",
"cursor",
"(",
")",
"if",
"root",
"is",
"None",
":",
"cursor",
".",
"execute",
"(",
"\"SELECT tax_id, rank FROM nodes WHERE tax_id = parent_id\"",
")"... | Generate a TaxNode from a taxonomy database | [
"Generate",
"a",
"TaxNode",
"from",
"a",
"taxonomy",
"database"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxtable.py#L303-L331 |
seznam/shelter | shelter/utils/net.py | parse_host | def parse_host(host):
"""
Parse *host* in format ``"[hostname:]port"`` and return :class:`tuple`
``(address, port)``.
>>> parse_host('localhost:4444')
('localhost', 4444)
>>> parse_host(':4444')
('', 4444)
>>> parse_host('4444')
('', 4444)
>>> parse_h... | python | def parse_host(host):
"""
Parse *host* in format ``"[hostname:]port"`` and return :class:`tuple`
``(address, port)``.
>>> parse_host('localhost:4444')
('localhost', 4444)
>>> parse_host(':4444')
('', 4444)
>>> parse_host('4444')
('', 4444)
>>> parse_h... | [
"def",
"parse_host",
"(",
"host",
")",
":",
"parts",
"=",
"host",
".",
"split",
"(",
"':'",
")",
"address",
"=",
"':'",
".",
"join",
"(",
"parts",
"[",
":",
"-",
"1",
"]",
")",
"try",
":",
"port",
"=",
"int",
"(",
"parts",
"[",
"-",
"1",
"]",... | Parse *host* in format ``"[hostname:]port"`` and return :class:`tuple`
``(address, port)``.
>>> parse_host('localhost:4444')
('localhost', 4444)
>>> parse_host(':4444')
('', 4444)
>>> parse_host('4444')
('', 4444)
>>> parse_host('2001:db8::1428:57ab:4444')
... | [
"Parse",
"*",
"host",
"*",
"in",
"format",
"[",
"hostname",
":",
"]",
"port",
"and",
"return",
":",
"class",
":",
"tuple",
"(",
"address",
"port",
")",
"."
] | train | https://github.com/seznam/shelter/blob/c652b0ff1cca70158f8fc97d9210c1fa5961ac1c/shelter/utils/net.py#L8-L32 |
fhcrc/taxtastic | taxtastic/subcommands/taxids.py | get_children | def get_children(engine, parent_ids, rank='species', schema=None):
"""
Recursively fetch children of tax_ids in `parent_ids` until the
rank of `rank`
"""
if not parent_ids:
return []
nodes = schema + '.nodes' if schema else 'nodes'
names = schema + '.names' if schema else 'names'
... | python | def get_children(engine, parent_ids, rank='species', schema=None):
"""
Recursively fetch children of tax_ids in `parent_ids` until the
rank of `rank`
"""
if not parent_ids:
return []
nodes = schema + '.nodes' if schema else 'nodes'
names = schema + '.names' if schema else 'names'
... | [
"def",
"get_children",
"(",
"engine",
",",
"parent_ids",
",",
"rank",
"=",
"'species'",
",",
"schema",
"=",
"None",
")",
":",
"if",
"not",
"parent_ids",
":",
"return",
"[",
"]",
"nodes",
"=",
"schema",
"+",
"'.nodes'",
"if",
"schema",
"else",
"'nodes'",
... | Recursively fetch children of tax_ids in `parent_ids` until the
rank of `rank` | [
"Recursively",
"fetch",
"children",
"of",
"tax_ids",
"in",
"parent_ids",
"until",
"the",
"rank",
"of",
"rank"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/subcommands/taxids.py#L33-L62 |
seznam/shelter | shelter/core/config.py | Config.get_config_items | def get_config_items(self):
"""
Return current configuration as a :class:`tuple` with
option-value pairs.
::
(('option1', value1), ('option2', value2))
"""
return (
('settings', self.settings),
('context_class', self.context_class),
... | python | def get_config_items(self):
"""
Return current configuration as a :class:`tuple` with
option-value pairs.
::
(('option1', value1), ('option2', value2))
"""
return (
('settings', self.settings),
('context_class', self.context_class),
... | [
"def",
"get_config_items",
"(",
"self",
")",
":",
"return",
"(",
"(",
"'settings'",
",",
"self",
".",
"settings",
")",
",",
"(",
"'context_class'",
",",
"self",
".",
"context_class",
")",
",",
"(",
"'interfaces'",
",",
"self",
".",
"interfaces",
")",
","... | Return current configuration as a :class:`tuple` with
option-value pairs.
::
(('option1', value1), ('option2', value2)) | [
"Return",
"current",
"configuration",
"as",
"a",
":",
"class",
":",
"tuple",
"with",
"option",
"-",
"value",
"pairs",
"."
] | train | https://github.com/seznam/shelter/blob/c652b0ff1cca70158f8fc97d9210c1fa5961ac1c/shelter/core/config.py#L88-L105 |
seznam/shelter | shelter/core/config.py | Config.context_class | def context_class(self):
"""
Context as a :class:`shelter.core.context.Context` class or subclass.
"""
if 'context_class' not in self._cached_values:
context_cls_name = getattr(self.settings, 'CONTEXT_CLASS', '')
if context_cls_name:
context_class ... | python | def context_class(self):
"""
Context as a :class:`shelter.core.context.Context` class or subclass.
"""
if 'context_class' not in self._cached_values:
context_cls_name = getattr(self.settings, 'CONTEXT_CLASS', '')
if context_cls_name:
context_class ... | [
"def",
"context_class",
"(",
"self",
")",
":",
"if",
"'context_class'",
"not",
"in",
"self",
".",
"_cached_values",
":",
"context_cls_name",
"=",
"getattr",
"(",
"self",
".",
"settings",
",",
"'CONTEXT_CLASS'",
",",
"''",
")",
"if",
"context_cls_name",
":",
... | Context as a :class:`shelter.core.context.Context` class or subclass. | [
"Context",
"as",
"a",
":",
"class",
":",
"shelter",
".",
"core",
".",
"context",
".",
"Context",
"class",
"or",
"subclass",
"."
] | train | https://github.com/seznam/shelter/blob/c652b0ff1cca70158f8fc97d9210c1fa5961ac1c/shelter/core/config.py#L122-L133 |
seznam/shelter | shelter/core/config.py | Config.interfaces | def interfaces(self):
"""
Interfaces as a :class:`list`of the
:class:`shelter.core.config.Config.Interface` instances.
"""
if 'interfaces' not in self._cached_values:
self._cached_values['interfaces'] = []
for name, interface in six.iteritems(self.settings... | python | def interfaces(self):
"""
Interfaces as a :class:`list`of the
:class:`shelter.core.config.Config.Interface` instances.
"""
if 'interfaces' not in self._cached_values:
self._cached_values['interfaces'] = []
for name, interface in six.iteritems(self.settings... | [
"def",
"interfaces",
"(",
"self",
")",
":",
"if",
"'interfaces'",
"not",
"in",
"self",
".",
"_cached_values",
":",
"self",
".",
"_cached_values",
"[",
"'interfaces'",
"]",
"=",
"[",
"]",
"for",
"name",
",",
"interface",
"in",
"six",
".",
"iteritems",
"("... | Interfaces as a :class:`list`of the
:class:`shelter.core.config.Config.Interface` instances. | [
"Interfaces",
"as",
"a",
":",
"class",
":",
"list",
"of",
"the",
":",
"class",
":",
"shelter",
".",
"core",
".",
"config",
".",
"Config",
".",
"Interface",
"instances",
"."
] | train | https://github.com/seznam/shelter/blob/c652b0ff1cca70158f8fc97d9210c1fa5961ac1c/shelter/core/config.py#L136-L161 |
fhcrc/taxtastic | taxtastic/subcommands/update.py | action | def action(args):
"""Updates a Refpkg with new files.
*args* should be an argparse object with fields refpkg (giving the
path to the refpkg to operate on) and changes (a series of strings
of the form 'key=file' giving the key to update in the refpkg and
the file to store under that key)."
"""
... | python | def action(args):
"""Updates a Refpkg with new files.
*args* should be an argparse object with fields refpkg (giving the
path to the refpkg to operate on) and changes (a series of strings
of the form 'key=file' giving the key to update in the refpkg and
the file to store under that key)."
"""
... | [
"def",
"action",
"(",
"args",
")",
":",
"log",
".",
"info",
"(",
"'loading reference package'",
")",
"pairs",
"=",
"[",
"p",
".",
"split",
"(",
"'='",
",",
"1",
")",
"for",
"p",
"in",
"args",
".",
"changes",
"]",
"if",
"args",
".",
"metadata",
":",... | Updates a Refpkg with new files.
*args* should be an argparse object with fields refpkg (giving the
path to the refpkg to operate on) and changes (a series of strings
of the form 'key=file' giving the key to update in the refpkg and
the file to store under that key)." | [
"Updates",
"a",
"Refpkg",
"with",
"new",
"files",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/subcommands/update.py#L82-L125 |
seznam/shelter | shelter/utils/imports.py | import_object | def import_object(name):
"""
Import module and return object from it. *name* is :class:`str` in
format ``module.path.ObjectClass``.
::
>>> import_command('module.path.ObjectClass')
<class 'module.path.ObjectClass'>
"""
parts = name.split('.')
if len(parts) < 2:
raise... | python | def import_object(name):
"""
Import module and return object from it. *name* is :class:`str` in
format ``module.path.ObjectClass``.
::
>>> import_command('module.path.ObjectClass')
<class 'module.path.ObjectClass'>
"""
parts = name.split('.')
if len(parts) < 2:
raise... | [
"def",
"import_object",
"(",
"name",
")",
":",
"parts",
"=",
"name",
".",
"split",
"(",
"'.'",
")",
"if",
"len",
"(",
"parts",
")",
"<",
"2",
":",
"raise",
"ValueError",
"(",
"\"Invalid name '%s'\"",
"%",
"name",
")",
"module_name",
"=",
"\".\"",
".",
... | Import module and return object from it. *name* is :class:`str` in
format ``module.path.ObjectClass``.
::
>>> import_command('module.path.ObjectClass')
<class 'module.path.ObjectClass'> | [
"Import",
"module",
"and",
"return",
"object",
"from",
"it",
".",
"*",
"name",
"*",
"is",
":",
"class",
":",
"str",
"in",
"format",
"module",
".",
"path",
".",
"ObjectClass",
"."
] | train | https://github.com/seznam/shelter/blob/c652b0ff1cca70158f8fc97d9210c1fa5961ac1c/shelter/utils/imports.py#L10-L25 |
fhcrc/taxtastic | taxtastic/scripts/taxit.py | parse_arguments | def parse_arguments(argv):
"""Create the argument parser
"""
parser = argparse.ArgumentParser(description=DESCRIPTION)
base_parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-V', '--version', action='version',
version='taxit v' + version,
... | python | def parse_arguments(argv):
"""Create the argument parser
"""
parser = argparse.ArgumentParser(description=DESCRIPTION)
base_parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-V', '--version', action='version',
version='taxit v' + version,
... | [
"def",
"parse_arguments",
"(",
"argv",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"DESCRIPTION",
")",
"base_parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"add_help",
"=",
"False",
")",
"parser",
".",
"add_argum... | Create the argument parser | [
"Create",
"the",
"argument",
"parser"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/scripts/taxit.py#L56-L120 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.execute | def execute(self, statements, exc=IntegrityError, rasie_as=ValueError):
"""Execute ``statements`` in a session, and perform a rollback on
error. ``exc`` is a single exception object or a tuple of
objects to be used in the except clause. The error message is
re-raised as the exception spe... | python | def execute(self, statements, exc=IntegrityError, rasie_as=ValueError):
"""Execute ``statements`` in a session, and perform a rollback on
error. ``exc`` is a single exception object or a tuple of
objects to be used in the except clause. The error message is
re-raised as the exception spe... | [
"def",
"execute",
"(",
"self",
",",
"statements",
",",
"exc",
"=",
"IntegrityError",
",",
"rasie_as",
"=",
"ValueError",
")",
":",
"Session",
"=",
"sessionmaker",
"(",
"bind",
"=",
"self",
".",
"engine",
")",
"session",
"=",
"Session",
"(",
")",
"try",
... | Execute ``statements`` in a session, and perform a rollback on
error. ``exc`` is a single exception object or a tuple of
objects to be used in the except clause. The error message is
re-raised as the exception specified by ``raise_as``. | [
"Execute",
"statements",
"in",
"a",
"session",
"and",
"perform",
"a",
"rollback",
"on",
"error",
".",
"exc",
"is",
"a",
"single",
"exception",
"object",
"or",
"a",
"tuple",
"of",
"objects",
"to",
"be",
"used",
"in",
"the",
"except",
"clause",
".",
"The",... | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L114-L134 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy._node | def _node(self, tax_id):
"""
Returns parent_id, rank
FIXME: expand return rank to include custom 'below' ranks built when
get_lineage is caled
"""
s = select([self.nodes.c.parent_id, self.nodes.c.rank],
self.nodes.c.tax_id == tax_id)
res... | python | def _node(self, tax_id):
"""
Returns parent_id, rank
FIXME: expand return rank to include custom 'below' ranks built when
get_lineage is caled
"""
s = select([self.nodes.c.parent_id, self.nodes.c.rank],
self.nodes.c.tax_id == tax_id)
res... | [
"def",
"_node",
"(",
"self",
",",
"tax_id",
")",
":",
"s",
"=",
"select",
"(",
"[",
"self",
".",
"nodes",
".",
"c",
".",
"parent_id",
",",
"self",
".",
"nodes",
".",
"c",
".",
"rank",
"]",
",",
"self",
".",
"nodes",
".",
"c",
".",
"tax_id",
"... | Returns parent_id, rank
FIXME: expand return rank to include custom 'below' ranks built when
get_lineage is caled | [
"Returns",
"parent_id",
"rank"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L136-L151 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.primary_from_id | def primary_from_id(self, tax_id):
"""
Returns primary taxonomic name associated with tax_id
"""
s = select([self.names.c.tax_name],
and_(self.names.c.tax_id == tax_id,
self.names.c.is_primary))
res = s.execute()
output = res.fet... | python | def primary_from_id(self, tax_id):
"""
Returns primary taxonomic name associated with tax_id
"""
s = select([self.names.c.tax_name],
and_(self.names.c.tax_id == tax_id,
self.names.c.is_primary))
res = s.execute()
output = res.fet... | [
"def",
"primary_from_id",
"(",
"self",
",",
"tax_id",
")",
":",
"s",
"=",
"select",
"(",
"[",
"self",
".",
"names",
".",
"c",
".",
"tax_name",
"]",
",",
"and_",
"(",
"self",
".",
"names",
".",
"c",
".",
"tax_id",
"==",
"tax_id",
",",
"self",
".",... | Returns primary taxonomic name associated with tax_id | [
"Returns",
"primary",
"taxonomic",
"name",
"associated",
"with",
"tax_id"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L153-L167 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.primary_from_name | def primary_from_name(self, tax_name):
"""
Return tax_id and primary tax_name corresponding to tax_name.
"""
names = self.names
s1 = select([names.c.tax_id, names.c.is_primary],
names.c.tax_name == tax_name)
log.debug(str(s1))
res = s1.execu... | python | def primary_from_name(self, tax_name):
"""
Return tax_id and primary tax_name corresponding to tax_name.
"""
names = self.names
s1 = select([names.c.tax_id, names.c.is_primary],
names.c.tax_name == tax_name)
log.debug(str(s1))
res = s1.execu... | [
"def",
"primary_from_name",
"(",
"self",
",",
"tax_name",
")",
":",
"names",
"=",
"self",
".",
"names",
"s1",
"=",
"select",
"(",
"[",
"names",
".",
"c",
".",
"tax_id",
",",
"names",
".",
"c",
".",
"is_primary",
"]",
",",
"names",
".",
"c",
".",
... | Return tax_id and primary tax_name corresponding to tax_name. | [
"Return",
"tax_id",
"and",
"primary",
"tax_name",
"corresponding",
"to",
"tax_name",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L169-L193 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy._get_merged | def _get_merged(self, tax_id):
"""Returns tax_id into which `tax_id` has been merged or `tax_id` of
not obsolete.
"""
cmd = """
SELECT COALESCE(
(SELECT new_tax_id FROM {merged}
WHERE old_tax_id = {x}), {x})
""".format(x=self.placeholder, merged=self.me... | python | def _get_merged(self, tax_id):
"""Returns tax_id into which `tax_id` has been merged or `tax_id` of
not obsolete.
"""
cmd = """
SELECT COALESCE(
(SELECT new_tax_id FROM {merged}
WHERE old_tax_id = {x}), {x})
""".format(x=self.placeholder, merged=self.me... | [
"def",
"_get_merged",
"(",
"self",
",",
"tax_id",
")",
":",
"cmd",
"=",
"\"\"\"\n SELECT COALESCE(\n (SELECT new_tax_id FROM {merged}\n WHERE old_tax_id = {x}), {x})\n \"\"\"",
".",
"format",
"(",
"x",
"=",
"self",
".",
"placeholder",
",",
"merged... | Returns tax_id into which `tax_id` has been merged or `tax_id` of
not obsolete. | [
"Returns",
"tax_id",
"into",
"which",
"tax_id",
"has",
"been",
"merged",
"or",
"tax_id",
"of",
"not",
"obsolete",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L195-L209 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy._get_lineage | def _get_lineage(self, tax_id, merge_obsolete=True):
"""Return a list of [(rank, tax_id)] describing the lineage of
tax_id. If ``merge_obsolete`` is True and ``tax_id`` has been
replaced, use the corresponding value in table merged.
"""
# Be sure we aren't working with an obsol... | python | def _get_lineage(self, tax_id, merge_obsolete=True):
"""Return a list of [(rank, tax_id)] describing the lineage of
tax_id. If ``merge_obsolete`` is True and ``tax_id`` has been
replaced, use the corresponding value in table merged.
"""
# Be sure we aren't working with an obsol... | [
"def",
"_get_lineage",
"(",
"self",
",",
"tax_id",
",",
"merge_obsolete",
"=",
"True",
")",
":",
"# Be sure we aren't working with an obsolete tax_id",
"if",
"merge_obsolete",
":",
"tax_id",
"=",
"self",
".",
"_get_merged",
"(",
"tax_id",
")",
"# Note: joining with ra... | Return a list of [(rank, tax_id)] describing the lineage of
tax_id. If ``merge_obsolete`` is True and ``tax_id`` has been
replaced, use the corresponding value in table merged. | [
"Return",
"a",
"list",
"of",
"[",
"(",
"rank",
"tax_id",
")",
"]",
"describing",
"the",
"lineage",
"of",
"tax_id",
".",
"If",
"merge_obsolete",
"is",
"True",
"and",
"tax_id",
"has",
"been",
"replaced",
"use",
"the",
"corresponding",
"value",
"in",
"table",... | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L211-L254 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy._get_lineage_table | def _get_lineage_table(self, tax_ids, merge_obsolete=True):
"""Return a list of [(rank, tax_id, tax_name)] describing the lineage
of tax_id. If ``merge_obsolete`` is True and ``tax_id`` has
been replaced, use the corresponding value in table merged.
"""
try:
with se... | python | def _get_lineage_table(self, tax_ids, merge_obsolete=True):
"""Return a list of [(rank, tax_id, tax_name)] describing the lineage
of tax_id. If ``merge_obsolete`` is True and ``tax_id`` has
been replaced, use the corresponding value in table merged.
"""
try:
with se... | [
"def",
"_get_lineage_table",
"(",
"self",
",",
"tax_ids",
",",
"merge_obsolete",
"=",
"True",
")",
":",
"try",
":",
"with",
"self",
".",
"engine",
".",
"connect",
"(",
")",
"as",
"con",
":",
"# insert tax_ids into a temporary table",
"temptab",
"=",
"self",
... | Return a list of [(rank, tax_id, tax_name)] describing the lineage
of tax_id. If ``merge_obsolete`` is True and ``tax_id`` has
been replaced, use the corresponding value in table merged. | [
"Return",
"a",
"list",
"of",
"[",
"(",
"rank",
"tax_id",
"tax_name",
")",
"]",
"describing",
"the",
"lineage",
"of",
"tax_id",
".",
"If",
"merge_obsolete",
"is",
"True",
"and",
"tax_id",
"has",
"been",
"replaced",
"use",
"the",
"corresponding",
"value",
"i... | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L262-L336 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.lineage | def lineage(self, tax_id=None, tax_name=None):
"""Public method for returning a lineage; includes tax_name and rank
"""
if not bool(tax_id) ^ bool(tax_name):
msg = 'Exactly one of tax_id and tax_name may be provided.'
raise ValueError(msg)
if tax_name:
... | python | def lineage(self, tax_id=None, tax_name=None):
"""Public method for returning a lineage; includes tax_name and rank
"""
if not bool(tax_id) ^ bool(tax_name):
msg = 'Exactly one of tax_id and tax_name may be provided.'
raise ValueError(msg)
if tax_name:
... | [
"def",
"lineage",
"(",
"self",
",",
"tax_id",
"=",
"None",
",",
"tax_name",
"=",
"None",
")",
":",
"if",
"not",
"bool",
"(",
"tax_id",
")",
"^",
"bool",
"(",
"tax_name",
")",
":",
"msg",
"=",
"'Exactly one of tax_id and tax_name may be provided.'",
"raise",
... | Public method for returning a lineage; includes tax_name and rank | [
"Public",
"method",
"for",
"returning",
"a",
"lineage",
";",
"includes",
"tax_name",
"and",
"rank"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L375-L403 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.add_source | def add_source(self, source_name, description=None):
"""Adds a row to table "source" if "name" does not
exist. Returns (source_id, True) if a new row is created,
(source_id, False) otherwise.
"""
# TODO: shoud be able to do this inside a transaction
if not source_name:... | python | def add_source(self, source_name, description=None):
"""Adds a row to table "source" if "name" does not
exist. Returns (source_id, True) if a new row is created,
(source_id, False) otherwise.
"""
# TODO: shoud be able to do this inside a transaction
if not source_name:... | [
"def",
"add_source",
"(",
"self",
",",
"source_name",
",",
"description",
"=",
"None",
")",
":",
"# TODO: shoud be able to do this inside a transaction",
"if",
"not",
"source_name",
":",
"raise",
"ValueError",
"(",
"'\"source_name\" may not be None or an empty string'",
")"... | Adds a row to table "source" if "name" does not
exist. Returns (source_id, True) if a new row is created,
(source_id, False) otherwise. | [
"Adds",
"a",
"row",
"to",
"table",
"source",
"if",
"name",
"does",
"not",
"exist",
".",
"Returns",
"(",
"source_id",
"True",
")",
"if",
"a",
"new",
"row",
"is",
"created",
"(",
"source_id",
"False",
")",
"otherwise",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L405-L424 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.get_source | def get_source(self, source_id=None, source_name=None):
"""Returns a dict with keys ['id', 'name', 'description'] or None if
no match. The ``id`` field is guaranteed to be an int that
exists in table source. Requires exactly one of ``source_id``
or ``source_name``. A new source correspon... | python | def get_source(self, source_id=None, source_name=None):
"""Returns a dict with keys ['id', 'name', 'description'] or None if
no match. The ``id`` field is guaranteed to be an int that
exists in table source. Requires exactly one of ``source_id``
or ``source_name``. A new source correspon... | [
"def",
"get_source",
"(",
"self",
",",
"source_id",
"=",
"None",
",",
"source_name",
"=",
"None",
")",
":",
"if",
"not",
"(",
"bool",
"(",
"source_id",
")",
"^",
"bool",
"(",
"source_name",
")",
")",
":",
"raise",
"ValueError",
"(",
"'exactly one of sour... | Returns a dict with keys ['id', 'name', 'description'] or None if
no match. The ``id`` field is guaranteed to be an int that
exists in table source. Requires exactly one of ``source_id``
or ``source_name``. A new source corresponding to
``source_name`` is created if necessary. | [
"Returns",
"a",
"dict",
"with",
"keys",
"[",
"id",
"name",
"description",
"]",
"or",
"None",
"if",
"no",
"match",
".",
"The",
"id",
"field",
"is",
"guaranteed",
"to",
"be",
"an",
"int",
"that",
"exists",
"in",
"table",
"source",
".",
"Requires",
"exact... | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L426-L455 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.verify_rank_integrity | def verify_rank_integrity(self, tax_id, rank, parent_id, children):
"""Confirm that for each node the parent ranks and children ranks are
coherent
"""
def _lower(n1, n2):
return self.ranks.index(n1) < self.ranks.index(n2)
if rank not in self.ranks:
raise... | python | def verify_rank_integrity(self, tax_id, rank, parent_id, children):
"""Confirm that for each node the parent ranks and children ranks are
coherent
"""
def _lower(n1, n2):
return self.ranks.index(n1) < self.ranks.index(n2)
if rank not in self.ranks:
raise... | [
"def",
"verify_rank_integrity",
"(",
"self",
",",
"tax_id",
",",
"rank",
",",
"parent_id",
",",
"children",
")",
":",
"def",
"_lower",
"(",
"n1",
",",
"n2",
")",
":",
"return",
"self",
".",
"ranks",
".",
"index",
"(",
"n1",
")",
"<",
"self",
".",
"... | Confirm that for each node the parent ranks and children ranks are
coherent | [
"Confirm",
"that",
"for",
"each",
"node",
"the",
"parent",
"ranks",
"and",
"children",
"ranks",
"are",
"coherent"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L457-L481 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.add_node | def add_node(self, tax_id, parent_id, rank, names, source_name, children=None,
is_valid=True, execute=True, **ignored):
"""Add a node to the taxonomy.
``source_name`` is added to table "source" if necessary.
"""
if ignored:
log.info('some arguments were ig... | python | def add_node(self, tax_id, parent_id, rank, names, source_name, children=None,
is_valid=True, execute=True, **ignored):
"""Add a node to the taxonomy.
``source_name`` is added to table "source" if necessary.
"""
if ignored:
log.info('some arguments were ig... | [
"def",
"add_node",
"(",
"self",
",",
"tax_id",
",",
"parent_id",
",",
"rank",
",",
"names",
",",
"source_name",
",",
"children",
"=",
"None",
",",
"is_valid",
"=",
"True",
",",
"execute",
"=",
"True",
",",
"*",
"*",
"ignored",
")",
":",
"if",
"ignore... | Add a node to the taxonomy.
``source_name`` is added to table "source" if necessary. | [
"Add",
"a",
"node",
"to",
"the",
"taxonomy",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L487-L541 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.add_name | def add_name(self, tax_id, tax_name, source_name=None, source_id=None,
name_class='synonym', is_primary=False, is_classified=None,
execute=True, **ignored):
"""Add a record to the names table corresponding to
``tax_id``. Arguments are as follows:
- tax_id (str... | python | def add_name(self, tax_id, tax_name, source_name=None, source_id=None,
name_class='synonym', is_primary=False, is_classified=None,
execute=True, **ignored):
"""Add a record to the names table corresponding to
``tax_id``. Arguments are as follows:
- tax_id (str... | [
"def",
"add_name",
"(",
"self",
",",
"tax_id",
",",
"tax_name",
",",
"source_name",
"=",
"None",
",",
"source_id",
"=",
"None",
",",
"name_class",
"=",
"'synonym'",
",",
"is_primary",
"=",
"False",
",",
"is_classified",
"=",
"None",
",",
"execute",
"=",
... | Add a record to the names table corresponding to
``tax_id``. Arguments are as follows:
- tax_id (string, required)
- tax_name (string, required)
*one* of the following are required:
- source_id (int or string coercable to int)
- source_name (string)
``source_i... | [
"Add",
"a",
"record",
"to",
"the",
"names",
"table",
"corresponding",
"to",
"tax_id",
".",
"Arguments",
"are",
"as",
"follows",
":"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L593-L648 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.add_names | def add_names(self, tax_id, names, execute=True):
"""Associate one or more names with ``tax_id``.
``names`` is a list of one or more dicts, with keys
corresponding to the signature of ``self.add_name()``
(excluding ``execute``).
"""
primary_names = [n['tax_name'] for n... | python | def add_names(self, tax_id, names, execute=True):
"""Associate one or more names with ``tax_id``.
``names`` is a list of one or more dicts, with keys
corresponding to the signature of ``self.add_name()``
(excluding ``execute``).
"""
primary_names = [n['tax_name'] for n... | [
"def",
"add_names",
"(",
"self",
",",
"tax_id",
",",
"names",
",",
"execute",
"=",
"True",
")",
":",
"primary_names",
"=",
"[",
"n",
"[",
"'tax_name'",
"]",
"for",
"n",
"in",
"names",
"if",
"n",
".",
"get",
"(",
"'is_primary'",
")",
"]",
"if",
"len... | Associate one or more names with ``tax_id``.
``names`` is a list of one or more dicts, with keys
corresponding to the signature of ``self.add_name()``
(excluding ``execute``). | [
"Associate",
"one",
"or",
"more",
"names",
"with",
"tax_id",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L650-L675 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.sibling_of | def sibling_of(self, tax_id):
"""Return None or a tax_id of a sibling of *tax_id*.
If ``tax_id`` is None, then always returns None. Otherwise,
returns None if there is no sibling.
"""
if tax_id is None:
return None
parent_id, rank = self._node(tax_id)
... | python | def sibling_of(self, tax_id):
"""Return None or a tax_id of a sibling of *tax_id*.
If ``tax_id`` is None, then always returns None. Otherwise,
returns None if there is no sibling.
"""
if tax_id is None:
return None
parent_id, rank = self._node(tax_id)
... | [
"def",
"sibling_of",
"(",
"self",
",",
"tax_id",
")",
":",
"if",
"tax_id",
"is",
"None",
":",
"return",
"None",
"parent_id",
",",
"rank",
"=",
"self",
".",
"_node",
"(",
"tax_id",
")",
"s",
"=",
"select",
"(",
"[",
"self",
".",
"nodes",
".",
"c",
... | Return None or a tax_id of a sibling of *tax_id*.
If ``tax_id`` is None, then always returns None. Otherwise,
returns None if there is no sibling. | [
"Return",
"None",
"or",
"a",
"tax_id",
"of",
"a",
"sibling",
"of",
"*",
"tax_id",
"*",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L677-L698 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.tax_ids | def tax_ids(self):
'''
Return all tax_ids in node table
'''
fetch = select([self.nodes.c.tax_id]).execute().fetchall()
ids = [t[0] for t in fetch]
return ids | python | def tax_ids(self):
'''
Return all tax_ids in node table
'''
fetch = select([self.nodes.c.tax_id]).execute().fetchall()
ids = [t[0] for t in fetch]
return ids | [
"def",
"tax_ids",
"(",
"self",
")",
":",
"fetch",
"=",
"select",
"(",
"[",
"self",
".",
"nodes",
".",
"c",
".",
"tax_id",
"]",
")",
".",
"execute",
"(",
")",
".",
"fetchall",
"(",
")",
"ids",
"=",
"[",
"t",
"[",
"0",
"]",
"for",
"t",
"in",
... | Return all tax_ids in node table | [
"Return",
"all",
"tax_ids",
"in",
"node",
"table"
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L716-L722 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.child_of | def child_of(self, tax_id):
"""Return None or a tax id of a child of *tax_id*.
If *tax_id* is None, then always returns None. Otherwise
returns a child if one exists, else None. The child must have
a proper rank below that of tax_id (i.e., genus, species, but
not no_rank or belo... | python | def child_of(self, tax_id):
"""Return None or a tax id of a child of *tax_id*.
If *tax_id* is None, then always returns None. Otherwise
returns a child if one exists, else None. The child must have
a proper rank below that of tax_id (i.e., genus, species, but
not no_rank or belo... | [
"def",
"child_of",
"(",
"self",
",",
"tax_id",
")",
":",
"if",
"tax_id",
"is",
"None",
":",
"return",
"None",
"parent_id",
",",
"rank",
"=",
"self",
".",
"_node",
"(",
"tax_id",
")",
"s",
"=",
"select",
"(",
"[",
"self",
".",
"nodes",
".",
"c",
"... | Return None or a tax id of a child of *tax_id*.
If *tax_id* is None, then always returns None. Otherwise
returns a child if one exists, else None. The child must have
a proper rank below that of tax_id (i.e., genus, species, but
not no_rank or below_below_kingdom). | [
"Return",
"None",
"or",
"a",
"tax",
"id",
"of",
"a",
"child",
"of",
"*",
"tax_id",
"*",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L724-L750 |
fhcrc/taxtastic | taxtastic/taxonomy.py | Taxonomy.nary_subtree | def nary_subtree(self, tax_id, n=2):
"""Return a list of species tax_ids under *tax_id* such that
node under *tax_id* and above the species has two children.
"""
if tax_id is None:
return None
parent_id, rank = self._node(tax_id)
if rank == 'species':
... | python | def nary_subtree(self, tax_id, n=2):
"""Return a list of species tax_ids under *tax_id* such that
node under *tax_id* and above the species has two children.
"""
if tax_id is None:
return None
parent_id, rank = self._node(tax_id)
if rank == 'species':
... | [
"def",
"nary_subtree",
"(",
"self",
",",
"tax_id",
",",
"n",
"=",
"2",
")",
":",
"if",
"tax_id",
"is",
"None",
":",
"return",
"None",
"parent_id",
",",
"rank",
"=",
"self",
".",
"_node",
"(",
"tax_id",
")",
"if",
"rank",
"==",
"'species'",
":",
"re... | Return a list of species tax_ids under *tax_id* such that
node under *tax_id* and above the species has two children. | [
"Return",
"a",
"list",
"of",
"species",
"tax_ids",
"under",
"*",
"tax_id",
"*",
"such",
"that",
"node",
"under",
"*",
"tax_id",
"*",
"and",
"above",
"the",
"species",
"has",
"two",
"children",
"."
] | train | https://github.com/fhcrc/taxtastic/blob/4e874b7f2cc146178828bfba386314f8c342722b/taxtastic/taxonomy.py#L784-L798 |
amicks/Speculator | api/helpers.py | validate_db | def validate_db(sqlalchemy_bind, is_enabled=ENABLE_DB):
""" Checks if a DB is authorized and responding before executing the function """
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
def is_db_responsive():
try:
sqlalchemy_bind.s... | python | def validate_db(sqlalchemy_bind, is_enabled=ENABLE_DB):
""" Checks if a DB is authorized and responding before executing the function """
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
def is_db_responsive():
try:
sqlalchemy_bind.s... | [
"def",
"validate_db",
"(",
"sqlalchemy_bind",
",",
"is_enabled",
"=",
"ENABLE_DB",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"is_... | Checks if a DB is authorized and responding before executing the function | [
"Checks",
"if",
"a",
"DB",
"is",
"authorized",
"and",
"responding",
"before",
"executing",
"the",
"function"
] | train | https://github.com/amicks/Speculator/blob/f7d6590aded20b1e1b5df16a4b27228ee821c4ab/api/helpers.py#L17-L34 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.