id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
46,100 | h2non/paco | paco/times.py | times | def times(coro, limit=1, raise_exception=False, return_value=None):
"""
Wraps a given coroutine function to be executed only a certain amount
of times.
If the execution limit is exceeded, the last execution return value will
be returned as result.
You can optionally define a custom return valu... | python | def times(coro, limit=1, raise_exception=False, return_value=None):
"""
Wraps a given coroutine function to be executed only a certain amount
of times.
If the execution limit is exceeded, the last execution return value will
be returned as result.
You can optionally define a custom return valu... | [
"def",
"times",
"(",
"coro",
",",
"limit",
"=",
"1",
",",
"raise_exception",
"=",
"False",
",",
"return_value",
"=",
"None",
")",
":",
"assert_corofunction",
"(",
"coro",
"=",
"coro",
")",
"# Store call times",
"limit",
"=",
"max",
"(",
"limit",
",",
"1"... | Wraps a given coroutine function to be executed only a certain amount
of times.
If the execution limit is exceeded, the last execution return value will
be returned as result.
You can optionally define a custom return value on exceeded via
`return_value` param.
This function can be used as de... | [
"Wraps",
"a",
"given",
"coroutine",
"function",
"to",
"be",
"executed",
"only",
"a",
"certain",
"amount",
"of",
"times",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/times.py#L10-L84 |
46,101 | camptocamp/anthem | anthem/output.py | log | def log(func=None, name=None, timing=True, timestamp=False):
""" Decorator to show a description of the running function
By default, it outputs the first line of the docstring.
If the docstring is empty, it displays the name of the function.
Alternatively, if a ``name`` is specified, it will display th... | python | def log(func=None, name=None, timing=True, timestamp=False):
""" Decorator to show a description of the running function
By default, it outputs the first line of the docstring.
If the docstring is empty, it displays the name of the function.
Alternatively, if a ``name`` is specified, it will display th... | [
"def",
"log",
"(",
"func",
"=",
"None",
",",
"name",
"=",
"None",
",",
"timing",
"=",
"True",
",",
"timestamp",
"=",
"False",
")",
":",
"# support to be called as @log or as @log(name='')",
"if",
"func",
"is",
"None",
":",
"return",
"functools",
".",
"partia... | Decorator to show a description of the running function
By default, it outputs the first line of the docstring.
If the docstring is empty, it displays the name of the function.
Alternatively, if a ``name`` is specified, it will display that only.
It can be called as ``@log`` or as
``@log(name='abc... | [
"Decorator",
"to",
"show",
"a",
"description",
"of",
"the",
"running",
"function"
] | 6800730764d31a2edced12049f823fefb367e9ad | https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/output.py#L57-L86 |
46,102 | h2non/paco | paco/constant.py | constant | def constant(value, delay=None):
"""
Returns a coroutine function that when called, always returns
the provided value.
This function has an alias: `paco.identity`.
Arguments:
value (mixed): value to constantly return when coroutine is called.
delay (int/float): optional return valu... | python | def constant(value, delay=None):
"""
Returns a coroutine function that when called, always returns
the provided value.
This function has an alias: `paco.identity`.
Arguments:
value (mixed): value to constantly return when coroutine is called.
delay (int/float): optional return valu... | [
"def",
"constant",
"(",
"value",
",",
"delay",
"=",
"None",
")",
":",
"@",
"asyncio",
".",
"coroutine",
"def",
"coro",
"(",
")",
":",
"if",
"delay",
":",
"yield",
"from",
"asyncio",
".",
"sleep",
"(",
"delay",
")",
"return",
"value",
"return",
"coro"... | Returns a coroutine function that when called, always returns
the provided value.
This function has an alias: `paco.identity`.
Arguments:
value (mixed): value to constantly return when coroutine is called.
delay (int/float): optional return value delay in seconds.
Returns:
cor... | [
"Returns",
"a",
"coroutine",
"function",
"that",
"when",
"called",
"always",
"returns",
"the",
"provided",
"value",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/constant.py#L5-L35 |
46,103 | h2non/paco | paco/dropwhile.py | dropwhile | def dropwhile(coro, iterable, loop=None):
"""
Make an iterator that drops elements from the iterable as long as the
predicate is true; afterwards, returns every element.
Note, the iterator does not produce any output until the predicate first
becomes false, so it may have a lengthy start-up time.
... | python | def dropwhile(coro, iterable, loop=None):
"""
Make an iterator that drops elements from the iterable as long as the
predicate is true; afterwards, returns every element.
Note, the iterator does not produce any output until the predicate first
becomes false, so it may have a lengthy start-up time.
... | [
"def",
"dropwhile",
"(",
"coro",
",",
"iterable",
",",
"loop",
"=",
"None",
")",
":",
"drop",
"=",
"False",
"@",
"asyncio",
".",
"coroutine",
"def",
"assert_fn",
"(",
"element",
")",
":",
"nonlocal",
"drop",
"if",
"element",
"and",
"not",
"drop",
":",
... | Make an iterator that drops elements from the iterable as long as the
predicate is true; afterwards, returns every element.
Note, the iterator does not produce any output until the predicate first
becomes false, so it may have a lengthy start-up time.
This function is pretty much equivalent to Python ... | [
"Make",
"an",
"iterator",
"that",
"drops",
"elements",
"from",
"the",
"iterable",
"as",
"long",
"as",
"the",
"predicate",
"is",
"true",
";",
"afterwards",
"returns",
"every",
"element",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/dropwhile.py#L9-L65 |
46,104 | camptocamp/anthem | anthem/lyrics/records.py | add_xmlid | def add_xmlid(ctx, record, xmlid, noupdate=False):
""" Add a XMLID on an existing record """
try:
ref_id, __, __ = ctx.env['ir.model.data'].xmlid_lookup(xmlid)
except ValueError:
pass # does not exist, we'll create a new one
else:
return ctx.env['ir.model.data'].browse(ref_id)
... | python | def add_xmlid(ctx, record, xmlid, noupdate=False):
""" Add a XMLID on an existing record """
try:
ref_id, __, __ = ctx.env['ir.model.data'].xmlid_lookup(xmlid)
except ValueError:
pass # does not exist, we'll create a new one
else:
return ctx.env['ir.model.data'].browse(ref_id)
... | [
"def",
"add_xmlid",
"(",
"ctx",
",",
"record",
",",
"xmlid",
",",
"noupdate",
"=",
"False",
")",
":",
"try",
":",
"ref_id",
",",
"__",
",",
"__",
"=",
"ctx",
".",
"env",
"[",
"'ir.model.data'",
"]",
".",
"xmlid_lookup",
"(",
"xmlid",
")",
"except",
... | Add a XMLID on an existing record | [
"Add",
"a",
"XMLID",
"on",
"an",
"existing",
"record"
] | 6800730764d31a2edced12049f823fefb367e9ad | https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/lyrics/records.py#L9-L28 |
46,105 | camptocamp/anthem | anthem/lyrics/records.py | create_or_update | def create_or_update(ctx, model, xmlid, values):
""" Create or update a record matching xmlid with values """
if isinstance(model, basestring):
model = ctx.env[model]
record = ctx.env.ref(xmlid, raise_if_not_found=False)
if record:
record.update(values)
else:
record = model.... | python | def create_or_update(ctx, model, xmlid, values):
""" Create or update a record matching xmlid with values """
if isinstance(model, basestring):
model = ctx.env[model]
record = ctx.env.ref(xmlid, raise_if_not_found=False)
if record:
record.update(values)
else:
record = model.... | [
"def",
"create_or_update",
"(",
"ctx",
",",
"model",
",",
"xmlid",
",",
"values",
")",
":",
"if",
"isinstance",
"(",
"model",
",",
"basestring",
")",
":",
"model",
"=",
"ctx",
".",
"env",
"[",
"model",
"]",
"record",
"=",
"ctx",
".",
"env",
".",
"r... | Create or update a record matching xmlid with values | [
"Create",
"or",
"update",
"a",
"record",
"matching",
"xmlid",
"with",
"values"
] | 6800730764d31a2edced12049f823fefb367e9ad | https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/lyrics/records.py#L31-L42 |
46,106 | camptocamp/anthem | anthem/lyrics/records.py | safe_record | def safe_record(ctx, item):
"""Make sure we get a record instance even if we pass an xmlid."""
if isinstance(item, basestring):
return ctx.env.ref(item)
return item | python | def safe_record(ctx, item):
"""Make sure we get a record instance even if we pass an xmlid."""
if isinstance(item, basestring):
return ctx.env.ref(item)
return item | [
"def",
"safe_record",
"(",
"ctx",
",",
"item",
")",
":",
"if",
"isinstance",
"(",
"item",
",",
"basestring",
")",
":",
"return",
"ctx",
".",
"env",
".",
"ref",
"(",
"item",
")",
"return",
"item"
] | Make sure we get a record instance even if we pass an xmlid. | [
"Make",
"sure",
"we",
"get",
"a",
"record",
"instance",
"even",
"if",
"we",
"pass",
"an",
"xmlid",
"."
] | 6800730764d31a2edced12049f823fefb367e9ad | https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/lyrics/records.py#L45-L49 |
46,107 | camptocamp/anthem | anthem/lyrics/records.py | switch_company | def switch_company(ctx, company):
"""Context manager to switch current company.
Accepts both company record and xmlid.
"""
current_company = ctx.env.user.company_id
ctx.env.user.company_id = safe_record(ctx, company)
yield ctx
ctx.env.user.company_id = current_company | python | def switch_company(ctx, company):
"""Context manager to switch current company.
Accepts both company record and xmlid.
"""
current_company = ctx.env.user.company_id
ctx.env.user.company_id = safe_record(ctx, company)
yield ctx
ctx.env.user.company_id = current_company | [
"def",
"switch_company",
"(",
"ctx",
",",
"company",
")",
":",
"current_company",
"=",
"ctx",
".",
"env",
".",
"user",
".",
"company_id",
"ctx",
".",
"env",
".",
"user",
".",
"company_id",
"=",
"safe_record",
"(",
"ctx",
",",
"company",
")",
"yield",
"... | Context manager to switch current company.
Accepts both company record and xmlid. | [
"Context",
"manager",
"to",
"switch",
"current",
"company",
"."
] | 6800730764d31a2edced12049f823fefb367e9ad | https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/lyrics/records.py#L53-L61 |
46,108 | h2non/paco | paco/apply.py | apply | def apply(coro, *args, **kw):
"""
Creates a continuation coroutine function with some arguments
already applied.
Useful as a shorthand when combined with other control flow functions.
Any arguments passed to the returned function are added to the arguments
originally passed to apply.
This ... | python | def apply(coro, *args, **kw):
"""
Creates a continuation coroutine function with some arguments
already applied.
Useful as a shorthand when combined with other control flow functions.
Any arguments passed to the returned function are added to the arguments
originally passed to apply.
This ... | [
"def",
"apply",
"(",
"coro",
",",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"assert_corofunction",
"(",
"coro",
"=",
"coro",
")",
"@",
"asyncio",
".",
"coroutine",
"def",
"wrapper",
"(",
"*",
"_args",
",",
"*",
"*",
"_kw",
")",
":",
"# Explicitel... | Creates a continuation coroutine function with some arguments
already applied.
Useful as a shorthand when combined with other control flow functions.
Any arguments passed to the returned function are added to the arguments
originally passed to apply.
This is similar to `paco.partial()`.
This ... | [
"Creates",
"a",
"continuation",
"coroutine",
"function",
"with",
"some",
"arguments",
"already",
"applied",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/apply.py#L8-L54 |
46,109 | h2non/paco | paco/run.py | run | def run(coro, loop=None):
"""
Convenient shortcut alias to ``loop.run_until_complete``.
Arguments:
coro (coroutine): coroutine object to schedule.
loop (asyncio.BaseEventLoop): optional event loop to use.
Defaults to: ``asyncio.get_event_loop()``.
Returns:
mixed: re... | python | def run(coro, loop=None):
"""
Convenient shortcut alias to ``loop.run_until_complete``.
Arguments:
coro (coroutine): coroutine object to schedule.
loop (asyncio.BaseEventLoop): optional event loop to use.
Defaults to: ``asyncio.get_event_loop()``.
Returns:
mixed: re... | [
"def",
"run",
"(",
"coro",
",",
"loop",
"=",
"None",
")",
":",
"loop",
"=",
"loop",
"or",
"asyncio",
".",
"get_event_loop",
"(",
")",
"return",
"loop",
".",
"run_until_complete",
"(",
"coro",
")"
] | Convenient shortcut alias to ``loop.run_until_complete``.
Arguments:
coro (coroutine): coroutine object to schedule.
loop (asyncio.BaseEventLoop): optional event loop to use.
Defaults to: ``asyncio.get_event_loop()``.
Returns:
mixed: returned value by coroutine.
Usage:... | [
"Convenient",
"shortcut",
"alias",
"to",
"loop",
".",
"run_until_complete",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/run.py#L4-L26 |
46,110 | h2non/paco | paco/wait.py | wait | def wait(*coros_or_futures, limit=0, timeout=None, loop=None,
return_exceptions=False, return_when='ALL_COMPLETED'):
"""
Wait for the Futures and coroutine objects given by the sequence
futures to complete, with optional concurrency limit.
Coroutines will be wrapped in Tasks.
``timeout`` c... | python | def wait(*coros_or_futures, limit=0, timeout=None, loop=None,
return_exceptions=False, return_when='ALL_COMPLETED'):
"""
Wait for the Futures and coroutine objects given by the sequence
futures to complete, with optional concurrency limit.
Coroutines will be wrapped in Tasks.
``timeout`` c... | [
"def",
"wait",
"(",
"*",
"coros_or_futures",
",",
"limit",
"=",
"0",
",",
"timeout",
"=",
"None",
",",
"loop",
"=",
"None",
",",
"return_exceptions",
"=",
"False",
",",
"return_when",
"=",
"'ALL_COMPLETED'",
")",
":",
"# Support iterable as first argument for be... | Wait for the Futures and coroutine objects given by the sequence
futures to complete, with optional concurrency limit.
Coroutines will be wrapped in Tasks.
``timeout`` can be used to control the maximum number of seconds to
wait before returning. timeout can be an int or float.
If timeout is not sp... | [
"Wait",
"for",
"the",
"Futures",
"and",
"coroutine",
"objects",
"given",
"by",
"the",
"sequence",
"futures",
"to",
"complete",
"with",
"optional",
"concurrency",
"limit",
".",
"Coroutines",
"will",
"be",
"wrapped",
"in",
"Tasks",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/wait.py#L8-L84 |
46,111 | h2non/paco | paco/series.py | series | def series(*coros_or_futures, timeout=None,
loop=None, return_exceptions=False):
"""
Run the given coroutine functions in series, each one
running once the previous execution has completed.
If any coroutines raises an exception, no more
coroutines are executed. Otherwise, the coroutines ... | python | def series(*coros_or_futures, timeout=None,
loop=None, return_exceptions=False):
"""
Run the given coroutine functions in series, each one
running once the previous execution has completed.
If any coroutines raises an exception, no more
coroutines are executed. Otherwise, the coroutines ... | [
"def",
"series",
"(",
"*",
"coros_or_futures",
",",
"timeout",
"=",
"None",
",",
"loop",
"=",
"None",
",",
"return_exceptions",
"=",
"False",
")",
":",
"return",
"(",
"yield",
"from",
"gather",
"(",
"*",
"coros_or_futures",
",",
"loop",
"=",
"loop",
",",... | Run the given coroutine functions in series, each one
running once the previous execution has completed.
If any coroutines raises an exception, no more
coroutines are executed. Otherwise, the coroutines returned values
will be returned as `list`.
``timeout`` can be used to control the maximum numb... | [
"Run",
"the",
"given",
"coroutine",
"functions",
"in",
"series",
"each",
"one",
"running",
"once",
"the",
"previous",
"execution",
"has",
"completed",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/series.py#L7-L68 |
46,112 | h2non/paco | paco/repeat.py | repeat | def repeat(coro, times=1, step=1, limit=1, loop=None):
"""
Executes the coroutine function ``x`` number of times,
and accumulates results in order as you would use with ``map``.
Execution concurrency is configurable using ``limit`` param.
This function is a coroutine.
Arguments:
coro... | python | def repeat(coro, times=1, step=1, limit=1, loop=None):
"""
Executes the coroutine function ``x`` number of times,
and accumulates results in order as you would use with ``map``.
Execution concurrency is configurable using ``limit`` param.
This function is a coroutine.
Arguments:
coro... | [
"def",
"repeat",
"(",
"coro",
",",
"times",
"=",
"1",
",",
"step",
"=",
"1",
",",
"limit",
"=",
"1",
",",
"loop",
"=",
"None",
")",
":",
"assert_corofunction",
"(",
"coro",
"=",
"coro",
")",
"# Iterate and attach coroutine for defer scheduling",
"times",
"... | Executes the coroutine function ``x`` number of times,
and accumulates results in order as you would use with ``map``.
Execution concurrency is configurable using ``limit`` param.
This function is a coroutine.
Arguments:
coro (coroutinefunction): coroutine function to schedule.
times... | [
"Executes",
"the",
"coroutine",
"function",
"x",
"number",
"of",
"times",
"and",
"accumulates",
"results",
"in",
"order",
"as",
"you",
"would",
"use",
"with",
"map",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/repeat.py#L8-L46 |
46,113 | h2non/paco | paco/once.py | once | def once(coro, raise_exception=False, return_value=None):
"""
Wrap a given coroutine function that is restricted to one execution.
Repeated calls to the coroutine function will return the value of the first
invocation.
This function can be used as decorator.
arguments:
coro (coroutine... | python | def once(coro, raise_exception=False, return_value=None):
"""
Wrap a given coroutine function that is restricted to one execution.
Repeated calls to the coroutine function will return the value of the first
invocation.
This function can be used as decorator.
arguments:
coro (coroutine... | [
"def",
"once",
"(",
"coro",
",",
"raise_exception",
"=",
"False",
",",
"return_value",
"=",
"None",
")",
":",
"return",
"times",
"(",
"coro",
",",
"limit",
"=",
"1",
",",
"return_value",
"=",
"return_value",
",",
"raise_exception",
"=",
"raise_exception",
... | Wrap a given coroutine function that is restricted to one execution.
Repeated calls to the coroutine function will return the value of the first
invocation.
This function can be used as decorator.
arguments:
coro (coroutinefunction): coroutine function to wrap.
raise_exception (bool):... | [
"Wrap",
"a",
"given",
"coroutine",
"function",
"that",
"is",
"restricted",
"to",
"one",
"execution",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/once.py#L7-L49 |
46,114 | h2non/paco | paco/defer.py | defer | def defer(coro, delay=1):
"""
Returns a coroutine function wrapper that will defer the given coroutine
execution for a certain amount of seconds in a non-blocking way.
This function can be used as decorator.
Arguments:
coro (coroutinefunction): coroutine function to defer.
delay (i... | python | def defer(coro, delay=1):
"""
Returns a coroutine function wrapper that will defer the given coroutine
execution for a certain amount of seconds in a non-blocking way.
This function can be used as decorator.
Arguments:
coro (coroutinefunction): coroutine function to defer.
delay (i... | [
"def",
"defer",
"(",
"coro",
",",
"delay",
"=",
"1",
")",
":",
"assert_corofunction",
"(",
"coro",
"=",
"coro",
")",
"@",
"asyncio",
".",
"coroutine",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"# Wait until we're done",
"yield"... | Returns a coroutine function wrapper that will defer the given coroutine
execution for a certain amount of seconds in a non-blocking way.
This function can be used as decorator.
Arguments:
coro (coroutinefunction): coroutine function to defer.
delay (int/float): number of seconds to defer ... | [
"Returns",
"a",
"coroutine",
"function",
"wrapper",
"that",
"will",
"defer",
"the",
"given",
"coroutine",
"execution",
"for",
"a",
"certain",
"amount",
"of",
"seconds",
"in",
"a",
"non",
"-",
"blocking",
"way",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/defer.py#L8-L48 |
46,115 | h2non/paco | paco/concurrent.py | safe_run | def safe_run(coro, return_exceptions=False):
"""
Executes a given coroutine and optionally catches exceptions, returning
them as value. This function is intended to be used internally.
"""
try:
result = yield from coro
except Exception as err:
if return_exceptions:
re... | python | def safe_run(coro, return_exceptions=False):
"""
Executes a given coroutine and optionally catches exceptions, returning
them as value. This function is intended to be used internally.
"""
try:
result = yield from coro
except Exception as err:
if return_exceptions:
re... | [
"def",
"safe_run",
"(",
"coro",
",",
"return_exceptions",
"=",
"False",
")",
":",
"try",
":",
"result",
"=",
"yield",
"from",
"coro",
"except",
"Exception",
"as",
"err",
":",
"if",
"return_exceptions",
":",
"result",
"=",
"err",
"else",
":",
"raise",
"er... | Executes a given coroutine and optionally catches exceptions, returning
them as value. This function is intended to be used internally. | [
"Executes",
"a",
"given",
"coroutine",
"and",
"optionally",
"catches",
"exceptions",
"returning",
"them",
"as",
"value",
".",
"This",
"function",
"is",
"intended",
"to",
"be",
"used",
"internally",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/concurrent.py#L27-L39 |
46,116 | h2non/paco | paco/concurrent.py | collect | def collect(coro, index, results,
preserve_order=False,
return_exceptions=False):
"""
Collect is used internally to execute coroutines and collect the returned
value. This function is intended to be used internally.
"""
result = yield from safe_run(coro, return_exceptions=ret... | python | def collect(coro, index, results,
preserve_order=False,
return_exceptions=False):
"""
Collect is used internally to execute coroutines and collect the returned
value. This function is intended to be used internally.
"""
result = yield from safe_run(coro, return_exceptions=ret... | [
"def",
"collect",
"(",
"coro",
",",
"index",
",",
"results",
",",
"preserve_order",
"=",
"False",
",",
"return_exceptions",
"=",
"False",
")",
":",
"result",
"=",
"yield",
"from",
"safe_run",
"(",
"coro",
",",
"return_exceptions",
"=",
"return_exceptions",
"... | Collect is used internally to execute coroutines and collect the returned
value. This function is intended to be used internally. | [
"Collect",
"is",
"used",
"internally",
"to",
"execute",
"coroutines",
"and",
"collect",
"the",
"returned",
"value",
".",
"This",
"function",
"is",
"intended",
"to",
"be",
"used",
"internally",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/concurrent.py#L43-L55 |
46,117 | h2non/paco | paco/concurrent.py | ConcurrentExecutor.reset | def reset(self):
"""
Resets the executer scheduler internal state.
Raises:
RuntimeError: is the executor is still running.
"""
if self.running:
raise RuntimeError('paco: executor is still running')
self.pool.clear()
self.observer.clear()
... | python | def reset(self):
"""
Resets the executer scheduler internal state.
Raises:
RuntimeError: is the executor is still running.
"""
if self.running:
raise RuntimeError('paco: executor is still running')
self.pool.clear()
self.observer.clear()
... | [
"def",
"reset",
"(",
"self",
")",
":",
"if",
"self",
".",
"running",
":",
"raise",
"RuntimeError",
"(",
"'paco: executor is still running'",
")",
"self",
".",
"pool",
".",
"clear",
"(",
")",
"self",
".",
"observer",
".",
"clear",
"(",
")",
"self",
".",
... | Resets the executer scheduler internal state.
Raises:
RuntimeError: is the executor is still running. | [
"Resets",
"the",
"executer",
"scheduler",
"internal",
"state",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/concurrent.py#L133-L145 |
46,118 | h2non/paco | paco/concurrent.py | ConcurrentExecutor.add | def add(self, coro, *args, **kw):
"""
Adds a new coroutine function with optional variadic argumetns.
Arguments:
coro (coroutine function): coroutine to execute.
*args (mixed): optional variadic arguments
Raises:
TypeError: if the coro object is not ... | python | def add(self, coro, *args, **kw):
"""
Adds a new coroutine function with optional variadic argumetns.
Arguments:
coro (coroutine function): coroutine to execute.
*args (mixed): optional variadic arguments
Raises:
TypeError: if the coro object is not ... | [
"def",
"add",
"(",
"self",
",",
"coro",
",",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"# Create coroutine object if a function is provided",
"if",
"asyncio",
".",
"iscoroutinefunction",
"(",
"coro",
")",
":",
"coro",
"=",
"coro",
"(",
"*",
"args",
",",
... | Adds a new coroutine function with optional variadic argumetns.
Arguments:
coro (coroutine function): coroutine to execute.
*args (mixed): optional variadic arguments
Raises:
TypeError: if the coro object is not a valid coroutine
Returns:
future... | [
"Adds",
"a",
"new",
"coroutine",
"function",
"with",
"optional",
"variadic",
"argumetns",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/concurrent.py#L184-L213 |
46,119 | h2non/paco | paco/concurrent.py | ConcurrentExecutor.run | def run(self,
timeout=None,
return_when=None,
return_exceptions=None,
ignore_empty=None):
"""
Executes the registered coroutines in the executor queue.
Arguments:
timeout (int/float): max execution timeout. No limit by default.
... | python | def run(self,
timeout=None,
return_when=None,
return_exceptions=None,
ignore_empty=None):
"""
Executes the registered coroutines in the executor queue.
Arguments:
timeout (int/float): max execution timeout. No limit by default.
... | [
"def",
"run",
"(",
"self",
",",
"timeout",
"=",
"None",
",",
"return_when",
"=",
"None",
",",
"return_exceptions",
"=",
"None",
",",
"ignore_empty",
"=",
"None",
")",
":",
"# Only allow 1 concurrent execution",
"if",
"self",
".",
"running",
":",
"raise",
"Ru... | Executes the registered coroutines in the executor queue.
Arguments:
timeout (int/float): max execution timeout. No limit by default.
return_exceptions (bool): in case of coroutine exception.
return_when (str): sets when coroutine should be resolved.
See `asy... | [
"Executes",
"the",
"registered",
"coroutines",
"in",
"the",
"executor",
"queue",
"."
] | 1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d | https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/concurrent.py#L306-L390 |
46,120 | gopalkoduri/pypeaks | pypeaks/intervals.py | Intervals.next_interval | def next_interval(self, interval):
"""
Given a value of an interval, this function returns the
next interval value
"""
index = np.where(self.intervals == interval)
if index[0][0] + 1 < len(self.intervals):
return self.intervals[index[0][0] + 1]
else:
... | python | def next_interval(self, interval):
"""
Given a value of an interval, this function returns the
next interval value
"""
index = np.where(self.intervals == interval)
if index[0][0] + 1 < len(self.intervals):
return self.intervals[index[0][0] + 1]
else:
... | [
"def",
"next_interval",
"(",
"self",
",",
"interval",
")",
":",
"index",
"=",
"np",
".",
"where",
"(",
"self",
".",
"intervals",
"==",
"interval",
")",
"if",
"index",
"[",
"0",
"]",
"[",
"0",
"]",
"+",
"1",
"<",
"len",
"(",
"self",
".",
"interval... | Given a value of an interval, this function returns the
next interval value | [
"Given",
"a",
"value",
"of",
"an",
"interval",
"this",
"function",
"returns",
"the",
"next",
"interval",
"value"
] | 59b1e4153e80c6a4c523dda241cc1713fd66161e | https://github.com/gopalkoduri/pypeaks/blob/59b1e4153e80c6a4c523dda241cc1713fd66161e/pypeaks/intervals.py#L23-L32 |
46,121 | gopalkoduri/pypeaks | pypeaks/intervals.py | Intervals.nearest_interval | def nearest_interval(self, interval):
"""
This function returns the nearest interval to any given interval.
"""
thresh_range = 25 # in cents
if interval < self.intervals[0] - thresh_range or interval > self.intervals[-1] + thresh_range:
raise IndexError("The interval... | python | def nearest_interval(self, interval):
"""
This function returns the nearest interval to any given interval.
"""
thresh_range = 25 # in cents
if interval < self.intervals[0] - thresh_range or interval > self.intervals[-1] + thresh_range:
raise IndexError("The interval... | [
"def",
"nearest_interval",
"(",
"self",
",",
"interval",
")",
":",
"thresh_range",
"=",
"25",
"# in cents",
"if",
"interval",
"<",
"self",
".",
"intervals",
"[",
"0",
"]",
"-",
"thresh_range",
"or",
"interval",
">",
"self",
".",
"intervals",
"[",
"-",
"1... | This function returns the nearest interval to any given interval. | [
"This",
"function",
"returns",
"the",
"nearest",
"interval",
"to",
"any",
"given",
"interval",
"."
] | 59b1e4153e80c6a4c523dda241cc1713fd66161e | https://github.com/gopalkoduri/pypeaks/blob/59b1e4153e80c6a4c523dda241cc1713fd66161e/pypeaks/intervals.py#L34-L44 |
46,122 | kgori/treeCl | treeCl/alignment.py | brent_optimise | def brent_optimise(node1, node2, min_brlen=0.001, max_brlen=10, verbose=False):
"""
Optimise ML distance between two partials. min and max set brackets
"""
from scipy.optimize import minimize_scalar
wrapper = BranchLengthOptimiser(node1, node2, (min_brlen + max_brlen) / 2.)
n = minimize_scalar(l... | python | def brent_optimise(node1, node2, min_brlen=0.001, max_brlen=10, verbose=False):
"""
Optimise ML distance between two partials. min and max set brackets
"""
from scipy.optimize import minimize_scalar
wrapper = BranchLengthOptimiser(node1, node2, (min_brlen + max_brlen) / 2.)
n = minimize_scalar(l... | [
"def",
"brent_optimise",
"(",
"node1",
",",
"node2",
",",
"min_brlen",
"=",
"0.001",
",",
"max_brlen",
"=",
"10",
",",
"verbose",
"=",
"False",
")",
":",
"from",
"scipy",
".",
"optimize",
"import",
"minimize_scalar",
"wrapper",
"=",
"BranchLengthOptimiser",
... | Optimise ML distance between two partials. min and max set brackets | [
"Optimise",
"ML",
"distance",
"between",
"two",
"partials",
".",
"min",
"and",
"max",
"set",
"brackets"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L297-L309 |
46,123 | kgori/treeCl | treeCl/alignment.py | pairdists | def pairdists(alignment, subs_model, alpha=None, ncat=4, tolerance=1e-6, verbose=False):
""" Load an alignment, calculate all pairwise distances and variances
model parameter must be a Substitution model type from phylo_utils """
# Check
if not isinstance(subs_model, phylo_utils.models.Model):
... | python | def pairdists(alignment, subs_model, alpha=None, ncat=4, tolerance=1e-6, verbose=False):
""" Load an alignment, calculate all pairwise distances and variances
model parameter must be a Substitution model type from phylo_utils """
# Check
if not isinstance(subs_model, phylo_utils.models.Model):
... | [
"def",
"pairdists",
"(",
"alignment",
",",
"subs_model",
",",
"alpha",
"=",
"None",
",",
"ncat",
"=",
"4",
",",
"tolerance",
"=",
"1e-6",
",",
"verbose",
"=",
"False",
")",
":",
"# Check",
"if",
"not",
"isinstance",
"(",
"subs_model",
",",
"phylo_utils",... | Load an alignment, calculate all pairwise distances and variances
model parameter must be a Substitution model type from phylo_utils | [
"Load",
"an",
"alignment",
"calculate",
"all",
"pairwise",
"distances",
"and",
"variances",
"model",
"parameter",
"must",
"be",
"a",
"Substitution",
"model",
"type",
"from",
"phylo_utils"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L311-L349 |
46,124 | kgori/treeCl | treeCl/alignment.py | Alignment.write_alignment | def write_alignment(self, filename, file_format, interleaved=None):
"""
Write the alignment to file using Bio.AlignIO
"""
if file_format == 'phylip':
file_format = 'phylip-relaxed'
AlignIO.write(self._msa, filename, file_format) | python | def write_alignment(self, filename, file_format, interleaved=None):
"""
Write the alignment to file using Bio.AlignIO
"""
if file_format == 'phylip':
file_format = 'phylip-relaxed'
AlignIO.write(self._msa, filename, file_format) | [
"def",
"write_alignment",
"(",
"self",
",",
"filename",
",",
"file_format",
",",
"interleaved",
"=",
"None",
")",
":",
"if",
"file_format",
"==",
"'phylip'",
":",
"file_format",
"=",
"'phylip-relaxed'",
"AlignIO",
".",
"write",
"(",
"self",
".",
"_msa",
",",... | Write the alignment to file using Bio.AlignIO | [
"Write",
"the",
"alignment",
"to",
"file",
"using",
"Bio",
".",
"AlignIO"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L166-L172 |
46,125 | kgori/treeCl | treeCl/alignment.py | Alignment.simulate | def simulate(self, nsites, transition_matrix, tree, ncat=1, alpha=1):
"""
Return sequences simulated under the transition matrix's model
"""
sim = SequenceSimulator(transition_matrix, tree, ncat, alpha)
return list(sim.simulate(nsites).items()) | python | def simulate(self, nsites, transition_matrix, tree, ncat=1, alpha=1):
"""
Return sequences simulated under the transition matrix's model
"""
sim = SequenceSimulator(transition_matrix, tree, ncat, alpha)
return list(sim.simulate(nsites).items()) | [
"def",
"simulate",
"(",
"self",
",",
"nsites",
",",
"transition_matrix",
",",
"tree",
",",
"ncat",
"=",
"1",
",",
"alpha",
"=",
"1",
")",
":",
"sim",
"=",
"SequenceSimulator",
"(",
"transition_matrix",
",",
"tree",
",",
"ncat",
",",
"alpha",
")",
"retu... | Return sequences simulated under the transition matrix's model | [
"Return",
"sequences",
"simulated",
"under",
"the",
"transition",
"matrix",
"s",
"model"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L230-L235 |
46,126 | kgori/treeCl | treeCl/alignment.py | Alignment.bootstrap | def bootstrap(self):
"""
Return a new Alignment that is a bootstrap replicate of self
"""
new_sites = sorted(sample_wr(self.get_sites()))
seqs = list(zip(self.get_names(), (''.join(seq) for seq in zip(*new_sites))))
return self.__class__(seqs) | python | def bootstrap(self):
"""
Return a new Alignment that is a bootstrap replicate of self
"""
new_sites = sorted(sample_wr(self.get_sites()))
seqs = list(zip(self.get_names(), (''.join(seq) for seq in zip(*new_sites))))
return self.__class__(seqs) | [
"def",
"bootstrap",
"(",
"self",
")",
":",
"new_sites",
"=",
"sorted",
"(",
"sample_wr",
"(",
"self",
".",
"get_sites",
"(",
")",
")",
")",
"seqs",
"=",
"list",
"(",
"zip",
"(",
"self",
".",
"get_names",
"(",
")",
",",
"(",
"''",
".",
"join",
"("... | Return a new Alignment that is a bootstrap replicate of self | [
"Return",
"a",
"new",
"Alignment",
"that",
"is",
"a",
"bootstrap",
"replicate",
"of",
"self"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L237-L243 |
46,127 | kgori/treeCl | treeCl/alignment.py | SequenceSimulator.simulate | def simulate(self, n):
"""
Evolve multiple sites during one tree traversal
"""
self.tree._tree.seed_node.states = self.ancestral_states(n)
categories = np.random.randint(self.ncat, size=n).astype(np.intc)
for node in self.tree.preorder(skip_seed=True):
node.s... | python | def simulate(self, n):
"""
Evolve multiple sites during one tree traversal
"""
self.tree._tree.seed_node.states = self.ancestral_states(n)
categories = np.random.randint(self.ncat, size=n).astype(np.intc)
for node in self.tree.preorder(skip_seed=True):
node.s... | [
"def",
"simulate",
"(",
"self",
",",
"n",
")",
":",
"self",
".",
"tree",
".",
"_tree",
".",
"seed_node",
".",
"states",
"=",
"self",
".",
"ancestral_states",
"(",
"n",
")",
"categories",
"=",
"np",
".",
"random",
".",
"randint",
"(",
"self",
".",
"... | Evolve multiple sites during one tree traversal | [
"Evolve",
"multiple",
"sites",
"during",
"one",
"tree",
"traversal"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L386-L397 |
46,128 | kgori/treeCl | treeCl/alignment.py | SequenceSimulator.ancestral_states | def ancestral_states(self, n):
"""
Generate ancestral sequence states from the equilibrium frequencies
"""
anc = np.empty(n, dtype=np.intc)
_weighted_choices(self.state_indices, self.freqs, anc)
return anc | python | def ancestral_states(self, n):
"""
Generate ancestral sequence states from the equilibrium frequencies
"""
anc = np.empty(n, dtype=np.intc)
_weighted_choices(self.state_indices, self.freqs, anc)
return anc | [
"def",
"ancestral_states",
"(",
"self",
",",
"n",
")",
":",
"anc",
"=",
"np",
".",
"empty",
"(",
"n",
",",
"dtype",
"=",
"np",
".",
"intc",
")",
"_weighted_choices",
"(",
"self",
".",
"state_indices",
",",
"self",
".",
"freqs",
",",
"anc",
")",
"re... | Generate ancestral sequence states from the equilibrium frequencies | [
"Generate",
"ancestral",
"sequence",
"states",
"from",
"the",
"equilibrium",
"frequencies"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L399-L405 |
46,129 | kgori/treeCl | treeCl/alignment.py | SequenceSimulator.sequences_to_string | def sequences_to_string(self):
"""
Convert state indices to a string of characters
"""
return {k: ''.join(self.states[v]) for (k, v) in self.sequences.items()} | python | def sequences_to_string(self):
"""
Convert state indices to a string of characters
"""
return {k: ''.join(self.states[v]) for (k, v) in self.sequences.items()} | [
"def",
"sequences_to_string",
"(",
"self",
")",
":",
"return",
"{",
"k",
":",
"''",
".",
"join",
"(",
"self",
".",
"states",
"[",
"v",
"]",
")",
"for",
"(",
"k",
",",
"v",
")",
"in",
"self",
".",
"sequences",
".",
"items",
"(",
")",
"}"
] | Convert state indices to a string of characters | [
"Convert",
"state",
"indices",
"to",
"a",
"string",
"of",
"characters"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L418-L422 |
46,130 | eerimoq/bincopy | bincopy.py | crc_srec | def crc_srec(hexstr):
"""Calculate the CRC for given Motorola S-Record hexstring.
"""
crc = sum(bytearray(binascii.unhexlify(hexstr)))
crc &= 0xff
crc ^= 0xff
return crc | python | def crc_srec(hexstr):
"""Calculate the CRC for given Motorola S-Record hexstring.
"""
crc = sum(bytearray(binascii.unhexlify(hexstr)))
crc &= 0xff
crc ^= 0xff
return crc | [
"def",
"crc_srec",
"(",
"hexstr",
")",
":",
"crc",
"=",
"sum",
"(",
"bytearray",
"(",
"binascii",
".",
"unhexlify",
"(",
"hexstr",
")",
")",
")",
"crc",
"&=",
"0xff",
"crc",
"^=",
"0xff",
"return",
"crc"
] | Calculate the CRC for given Motorola S-Record hexstring. | [
"Calculate",
"the",
"CRC",
"for",
"given",
"Motorola",
"S",
"-",
"Record",
"hexstring",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L57-L66 |
46,131 | eerimoq/bincopy | bincopy.py | crc_ihex | def crc_ihex(hexstr):
"""Calculate the CRC for given Intel HEX hexstring.
"""
crc = sum(bytearray(binascii.unhexlify(hexstr)))
crc &= 0xff
crc = ((~crc + 1) & 0xff)
return crc | python | def crc_ihex(hexstr):
"""Calculate the CRC for given Intel HEX hexstring.
"""
crc = sum(bytearray(binascii.unhexlify(hexstr)))
crc &= 0xff
crc = ((~crc + 1) & 0xff)
return crc | [
"def",
"crc_ihex",
"(",
"hexstr",
")",
":",
"crc",
"=",
"sum",
"(",
"bytearray",
"(",
"binascii",
".",
"unhexlify",
"(",
"hexstr",
")",
")",
")",
"crc",
"&=",
"0xff",
"crc",
"=",
"(",
"(",
"~",
"crc",
"+",
"1",
")",
"&",
"0xff",
")",
"return",
... | Calculate the CRC for given Intel HEX hexstring. | [
"Calculate",
"the",
"CRC",
"for",
"given",
"Intel",
"HEX",
"hexstring",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L69-L78 |
46,132 | eerimoq/bincopy | bincopy.py | pack_srec | def pack_srec(type_, address, size, data):
"""Create a Motorola S-Record record of given data.
"""
if type_ in '0159':
line = '{:02X}{:04X}'.format(size + 2 + 1, address)
elif type_ in '268':
line = '{:02X}{:06X}'.format(size + 3 + 1, address)
elif type_ in '37':
line = '{:... | python | def pack_srec(type_, address, size, data):
"""Create a Motorola S-Record record of given data.
"""
if type_ in '0159':
line = '{:02X}{:04X}'.format(size + 2 + 1, address)
elif type_ in '268':
line = '{:02X}{:06X}'.format(size + 3 + 1, address)
elif type_ in '37':
line = '{:... | [
"def",
"pack_srec",
"(",
"type_",
",",
"address",
",",
"size",
",",
"data",
")",
":",
"if",
"type_",
"in",
"'0159'",
":",
"line",
"=",
"'{:02X}{:04X}'",
".",
"format",
"(",
"size",
"+",
"2",
"+",
"1",
",",
"address",
")",
"elif",
"type_",
"in",
"'2... | Create a Motorola S-Record record of given data. | [
"Create",
"a",
"Motorola",
"S",
"-",
"Record",
"record",
"of",
"given",
"data",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L81-L99 |
46,133 | eerimoq/bincopy | bincopy.py | unpack_srec | def unpack_srec(record):
"""Unpack given Motorola S-Record record into variables.
"""
# Minimum STSSCC, where T is type, SS is size and CC is crc.
if len(record) < 6:
raise Error("record '{}' too short".format(record))
if record[0] != 'S':
raise Error(
"record '{}' not... | python | def unpack_srec(record):
"""Unpack given Motorola S-Record record into variables.
"""
# Minimum STSSCC, where T is type, SS is size and CC is crc.
if len(record) < 6:
raise Error("record '{}' too short".format(record))
if record[0] != 'S':
raise Error(
"record '{}' not... | [
"def",
"unpack_srec",
"(",
"record",
")",
":",
"# Minimum STSSCC, where T is type, SS is size and CC is crc.",
"if",
"len",
"(",
"record",
")",
"<",
"6",
":",
"raise",
"Error",
"(",
"\"record '{}' too short\"",
".",
"format",
"(",
"record",
")",
")",
"if",
"record... | Unpack given Motorola S-Record record into variables. | [
"Unpack",
"given",
"Motorola",
"S",
"-",
"Record",
"record",
"into",
"variables",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L102-L143 |
46,134 | eerimoq/bincopy | bincopy.py | pack_ihex | def pack_ihex(type_, address, size, data):
"""Create a Intel HEX record of given data.
"""
line = '{:02X}{:04X}{:02X}'.format(size, address, type_)
if data:
line += binascii.hexlify(data).decode('ascii').upper()
return ':{}{:02X}'.format(line, crc_ihex(line)) | python | def pack_ihex(type_, address, size, data):
"""Create a Intel HEX record of given data.
"""
line = '{:02X}{:04X}{:02X}'.format(size, address, type_)
if data:
line += binascii.hexlify(data).decode('ascii').upper()
return ':{}{:02X}'.format(line, crc_ihex(line)) | [
"def",
"pack_ihex",
"(",
"type_",
",",
"address",
",",
"size",
",",
"data",
")",
":",
"line",
"=",
"'{:02X}{:04X}{:02X}'",
".",
"format",
"(",
"size",
",",
"address",
",",
"type_",
")",
"if",
"data",
":",
"line",
"+=",
"binascii",
".",
"hexlify",
"(",
... | Create a Intel HEX record of given data. | [
"Create",
"a",
"Intel",
"HEX",
"record",
"of",
"given",
"data",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L146-L156 |
46,135 | eerimoq/bincopy | bincopy.py | unpack_ihex | def unpack_ihex(record):
"""Unpack given Intel HEX record into variables.
"""
# Minimum :SSAAAATTCC, where SS is size, AAAA is address, TT is
# type and CC is crc.
if len(record) < 11:
raise Error("record '{}' too short".format(record))
if record[0] != ':':
raise Error("record... | python | def unpack_ihex(record):
"""Unpack given Intel HEX record into variables.
"""
# Minimum :SSAAAATTCC, where SS is size, AAAA is address, TT is
# type and CC is crc.
if len(record) < 11:
raise Error("record '{}' too short".format(record))
if record[0] != ':':
raise Error("record... | [
"def",
"unpack_ihex",
"(",
"record",
")",
":",
"# Minimum :SSAAAATTCC, where SS is size, AAAA is address, TT is",
"# type and CC is crc.",
"if",
"len",
"(",
"record",
")",
"<",
"11",
":",
"raise",
"Error",
"(",
"\"record '{}' too short\"",
".",
"format",
"(",
"record",
... | Unpack given Intel HEX record into variables. | [
"Unpack",
"given",
"Intel",
"HEX",
"record",
"into",
"variables",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L159-L191 |
46,136 | eerimoq/bincopy | bincopy.py | _Segment.chunks | def chunks(self, size=32, alignment=1):
"""Return chunks of the data aligned as given by `alignment`. `size`
must be a multiple of `alignment`. Each chunk is returned as a
named two-tuple of its address and data.
"""
if (size % alignment) != 0:
raise Error(
... | python | def chunks(self, size=32, alignment=1):
"""Return chunks of the data aligned as given by `alignment`. `size`
must be a multiple of `alignment`. Each chunk is returned as a
named two-tuple of its address and data.
"""
if (size % alignment) != 0:
raise Error(
... | [
"def",
"chunks",
"(",
"self",
",",
"size",
"=",
"32",
",",
"alignment",
"=",
"1",
")",
":",
"if",
"(",
"size",
"%",
"alignment",
")",
"!=",
"0",
":",
"raise",
"Error",
"(",
"'size {} is not a multiple of alignment {}'",
".",
"format",
"(",
"size",
",",
... | Return chunks of the data aligned as given by `alignment`. `size`
must be a multiple of `alignment`. Each chunk is returned as a
named two-tuple of its address and data. | [
"Return",
"chunks",
"of",
"the",
"data",
"aligned",
"as",
"given",
"by",
"alignment",
".",
"size",
"must",
"be",
"a",
"multiple",
"of",
"alignment",
".",
"Each",
"chunk",
"is",
"returned",
"as",
"a",
"named",
"two",
"-",
"tuple",
"of",
"its",
"address",
... | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L236-L265 |
46,137 | eerimoq/bincopy | bincopy.py | _Segment.add_data | def add_data(self, minimum_address, maximum_address, data, overwrite):
"""Add given data to this segment. The added data must be adjacent to
the current segment data, otherwise an exception is thrown.
"""
if minimum_address == self.maximum_address:
self.maximum_address = ma... | python | def add_data(self, minimum_address, maximum_address, data, overwrite):
"""Add given data to this segment. The added data must be adjacent to
the current segment data, otherwise an exception is thrown.
"""
if minimum_address == self.maximum_address:
self.maximum_address = ma... | [
"def",
"add_data",
"(",
"self",
",",
"minimum_address",
",",
"maximum_address",
",",
"data",
",",
"overwrite",
")",
":",
"if",
"minimum_address",
"==",
"self",
".",
"maximum_address",
":",
"self",
".",
"maximum_address",
"=",
"maximum_address",
"self",
".",
"d... | Add given data to this segment. The added data must be adjacent to
the current segment data, otherwise an exception is thrown. | [
"Add",
"given",
"data",
"to",
"this",
"segment",
".",
"The",
"added",
"data",
"must",
"be",
"adjacent",
"to",
"the",
"current",
"segment",
"data",
"otherwise",
"an",
"exception",
"is",
"thrown",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L267-L308 |
46,138 | eerimoq/bincopy | bincopy.py | _Segment.remove_data | def remove_data(self, minimum_address, maximum_address):
"""Remove given data range from this segment. Returns the second
segment if the removed data splits this segment in two.
"""
if ((minimum_address >= self.maximum_address)
and (maximum_address <= self.minimum_address))... | python | def remove_data(self, minimum_address, maximum_address):
"""Remove given data range from this segment. Returns the second
segment if the removed data splits this segment in two.
"""
if ((minimum_address >= self.maximum_address)
and (maximum_address <= self.minimum_address))... | [
"def",
"remove_data",
"(",
"self",
",",
"minimum_address",
",",
"maximum_address",
")",
":",
"if",
"(",
"(",
"minimum_address",
">=",
"self",
".",
"maximum_address",
")",
"and",
"(",
"maximum_address",
"<=",
"self",
".",
"minimum_address",
")",
")",
":",
"ra... | Remove given data range from this segment. Returns the second
segment if the removed data splits this segment in two. | [
"Remove",
"given",
"data",
"range",
"from",
"this",
"segment",
".",
"Returns",
"the",
"second",
"segment",
"if",
"the",
"removed",
"data",
"splits",
"this",
"segment",
"in",
"two",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L310-L350 |
46,139 | eerimoq/bincopy | bincopy.py | _Segments.add | def add(self, segment, overwrite=False):
"""Add segments by ascending address.
"""
if self._list:
if segment.minimum_address == self._current_segment.maximum_address:
# Fast insertion for adjacent segments.
self._current_segment.add_data(segment.mini... | python | def add(self, segment, overwrite=False):
"""Add segments by ascending address.
"""
if self._list:
if segment.minimum_address == self._current_segment.maximum_address:
# Fast insertion for adjacent segments.
self._current_segment.add_data(segment.mini... | [
"def",
"add",
"(",
"self",
",",
"segment",
",",
"overwrite",
"=",
"False",
")",
":",
"if",
"self",
".",
"_list",
":",
"if",
"segment",
".",
"minimum_address",
"==",
"self",
".",
"_current_segment",
".",
"maximum_address",
":",
"# Fast insertion for adjacent se... | Add segments by ascending address. | [
"Add",
"segments",
"by",
"ascending",
"address",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L425-L482 |
46,140 | eerimoq/bincopy | bincopy.py | _Segments.chunks | def chunks(self, size=32, alignment=1):
"""Iterate over all segments and return chunks of the data aligned as
given by `alignment`. `size` must be a multiple of
`alignment`. Each chunk is returned as a named two-tuple of
its address and data.
"""
if (size % alignment) !... | python | def chunks(self, size=32, alignment=1):
"""Iterate over all segments and return chunks of the data aligned as
given by `alignment`. `size` must be a multiple of
`alignment`. Each chunk is returned as a named two-tuple of
its address and data.
"""
if (size % alignment) !... | [
"def",
"chunks",
"(",
"self",
",",
"size",
"=",
"32",
",",
"alignment",
"=",
"1",
")",
":",
"if",
"(",
"size",
"%",
"alignment",
")",
"!=",
"0",
":",
"raise",
"Error",
"(",
"'size {} is not a multiple of alignment {}'",
".",
"format",
"(",
"size",
",",
... | Iterate over all segments and return chunks of the data aligned as
given by `alignment`. `size` must be a multiple of
`alignment`. Each chunk is returned as a named two-tuple of
its address and data. | [
"Iterate",
"over",
"all",
"segments",
"and",
"return",
"chunks",
"of",
"the",
"data",
"aligned",
"as",
"given",
"by",
"alignment",
".",
"size",
"must",
"be",
"a",
"multiple",
"of",
"alignment",
".",
"Each",
"chunk",
"is",
"returned",
"as",
"a",
"named",
... | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L504-L520 |
46,141 | eerimoq/bincopy | bincopy.py | BinFile.minimum_address | def minimum_address(self):
"""The minimum address of the data, or ``None`` if the file is empty.
"""
minimum_address = self._segments.minimum_address
if minimum_address is not None:
minimum_address //= self.word_size_bytes
return minimum_address | python | def minimum_address(self):
"""The minimum address of the data, or ``None`` if the file is empty.
"""
minimum_address = self._segments.minimum_address
if minimum_address is not None:
minimum_address //= self.word_size_bytes
return minimum_address | [
"def",
"minimum_address",
"(",
"self",
")",
":",
"minimum_address",
"=",
"self",
".",
"_segments",
".",
"minimum_address",
"if",
"minimum_address",
"is",
"not",
"None",
":",
"minimum_address",
"//=",
"self",
".",
"word_size_bytes",
"return",
"minimum_address"
] | The minimum address of the data, or ``None`` if the file is empty. | [
"The",
"minimum",
"address",
"of",
"the",
"data",
"or",
"None",
"if",
"the",
"file",
"is",
"empty",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L645-L655 |
46,142 | eerimoq/bincopy | bincopy.py | BinFile.maximum_address | def maximum_address(self):
"""The maximum address of the data, or ``None`` if the file is empty.
"""
maximum_address = self._segments.maximum_address
if maximum_address is not None:
maximum_address //= self.word_size_bytes
return maximum_address | python | def maximum_address(self):
"""The maximum address of the data, or ``None`` if the file is empty.
"""
maximum_address = self._segments.maximum_address
if maximum_address is not None:
maximum_address //= self.word_size_bytes
return maximum_address | [
"def",
"maximum_address",
"(",
"self",
")",
":",
"maximum_address",
"=",
"self",
".",
"_segments",
".",
"maximum_address",
"if",
"maximum_address",
"is",
"not",
"None",
":",
"maximum_address",
"//=",
"self",
".",
"word_size_bytes",
"return",
"maximum_address"
] | The maximum address of the data, or ``None`` if the file is empty. | [
"The",
"maximum",
"address",
"of",
"the",
"data",
"or",
"None",
"if",
"the",
"file",
"is",
"empty",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L658-L668 |
46,143 | eerimoq/bincopy | bincopy.py | BinFile.add | def add(self, data, overwrite=False):
"""Add given data string by guessing its format. The format must be
Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to
``True`` to allow already added data to be overwritten.
"""
if is_srec(data):
self.add_srec(data, ov... | python | def add(self, data, overwrite=False):
"""Add given data string by guessing its format. The format must be
Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to
``True`` to allow already added data to be overwritten.
"""
if is_srec(data):
self.add_srec(data, ov... | [
"def",
"add",
"(",
"self",
",",
"data",
",",
"overwrite",
"=",
"False",
")",
":",
"if",
"is_srec",
"(",
"data",
")",
":",
"self",
".",
"add_srec",
"(",
"data",
",",
"overwrite",
")",
"elif",
"is_ihex",
"(",
"data",
")",
":",
"self",
".",
"add_ihex"... | Add given data string by guessing its format. The format must be
Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to
``True`` to allow already added data to be overwritten. | [
"Add",
"given",
"data",
"string",
"by",
"guessing",
"its",
"format",
".",
"The",
"format",
"must",
"be",
"Motorola",
"S",
"-",
"Records",
"Intel",
"HEX",
"or",
"TI",
"-",
"TXT",
".",
"Set",
"overwrite",
"to",
"True",
"to",
"allow",
"already",
"added",
... | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L738-L752 |
46,144 | eerimoq/bincopy | bincopy.py | BinFile.add_srec | def add_srec(self, records, overwrite=False):
"""Add given Motorola S-Records string. Set `overwrite` to ``True`` to
allow already added data to be overwritten.
"""
for record in StringIO(records):
type_, address, size, data = unpack_srec(record.strip())
if typ... | python | def add_srec(self, records, overwrite=False):
"""Add given Motorola S-Records string. Set `overwrite` to ``True`` to
allow already added data to be overwritten.
"""
for record in StringIO(records):
type_, address, size, data = unpack_srec(record.strip())
if typ... | [
"def",
"add_srec",
"(",
"self",
",",
"records",
",",
"overwrite",
"=",
"False",
")",
":",
"for",
"record",
"in",
"StringIO",
"(",
"records",
")",
":",
"type_",
",",
"address",
",",
"size",
",",
"data",
"=",
"unpack_srec",
"(",
"record",
".",
"strip",
... | Add given Motorola S-Records string. Set `overwrite` to ``True`` to
allow already added data to be overwritten. | [
"Add",
"given",
"Motorola",
"S",
"-",
"Records",
"string",
".",
"Set",
"overwrite",
"to",
"True",
"to",
"allow",
"already",
"added",
"data",
"to",
"be",
"overwritten",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L754-L773 |
46,145 | eerimoq/bincopy | bincopy.py | BinFile.add_ihex | def add_ihex(self, records, overwrite=False):
"""Add given Intel HEX records string. Set `overwrite` to ``True`` to
allow already added data to be overwritten.
"""
extended_segment_address = 0
extended_linear_address = 0
for record in StringIO(records):
typ... | python | def add_ihex(self, records, overwrite=False):
"""Add given Intel HEX records string. Set `overwrite` to ``True`` to
allow already added data to be overwritten.
"""
extended_segment_address = 0
extended_linear_address = 0
for record in StringIO(records):
typ... | [
"def",
"add_ihex",
"(",
"self",
",",
"records",
",",
"overwrite",
"=",
"False",
")",
":",
"extended_segment_address",
"=",
"0",
"extended_linear_address",
"=",
"0",
"for",
"record",
"in",
"StringIO",
"(",
"records",
")",
":",
"type_",
",",
"address",
",",
... | Add given Intel HEX records string. Set `overwrite` to ``True`` to
allow already added data to be overwritten. | [
"Add",
"given",
"Intel",
"HEX",
"records",
"string",
".",
"Set",
"overwrite",
"to",
"True",
"to",
"allow",
"already",
"added",
"data",
"to",
"be",
"overwritten",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L775-L810 |
46,146 | eerimoq/bincopy | bincopy.py | BinFile.add_ti_txt | def add_ti_txt(self, lines, overwrite=False):
"""Add given TI-TXT string `lines`. Set `overwrite` to ``True`` to
allow already added data to be overwritten.
"""
address = None
eof_found = False
for line in StringIO(lines):
# Abort if data is found after end... | python | def add_ti_txt(self, lines, overwrite=False):
"""Add given TI-TXT string `lines`. Set `overwrite` to ``True`` to
allow already added data to be overwritten.
"""
address = None
eof_found = False
for line in StringIO(lines):
# Abort if data is found after end... | [
"def",
"add_ti_txt",
"(",
"self",
",",
"lines",
",",
"overwrite",
"=",
"False",
")",
":",
"address",
"=",
"None",
"eof_found",
"=",
"False",
"for",
"line",
"in",
"StringIO",
"(",
"lines",
")",
":",
"# Abort if data is found after end of file.",
"if",
"eof_foun... | Add given TI-TXT string `lines`. Set `overwrite` to ``True`` to
allow already added data to be overwritten. | [
"Add",
"given",
"TI",
"-",
"TXT",
"string",
"lines",
".",
"Set",
"overwrite",
"to",
"True",
"to",
"allow",
"already",
"added",
"data",
"to",
"be",
"overwritten",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L812-L869 |
46,147 | eerimoq/bincopy | bincopy.py | BinFile.add_binary | def add_binary(self, data, address=0, overwrite=False):
"""Add given data at given address. Set `overwrite` to ``True`` to
allow already added data to be overwritten.
"""
address *= self.word_size_bytes
self._segments.add(_Segment(address,
ad... | python | def add_binary(self, data, address=0, overwrite=False):
"""Add given data at given address. Set `overwrite` to ``True`` to
allow already added data to be overwritten.
"""
address *= self.word_size_bytes
self._segments.add(_Segment(address,
ad... | [
"def",
"add_binary",
"(",
"self",
",",
"data",
",",
"address",
"=",
"0",
",",
"overwrite",
"=",
"False",
")",
":",
"address",
"*=",
"self",
".",
"word_size_bytes",
"self",
".",
"_segments",
".",
"add",
"(",
"_Segment",
"(",
"address",
",",
"address",
"... | Add given data at given address. Set `overwrite` to ``True`` to
allow already added data to be overwritten. | [
"Add",
"given",
"data",
"at",
"given",
"address",
".",
"Set",
"overwrite",
"to",
"True",
"to",
"allow",
"already",
"added",
"data",
"to",
"be",
"overwritten",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L871-L882 |
46,148 | eerimoq/bincopy | bincopy.py | BinFile.add_file | def add_file(self, filename, overwrite=False):
"""Open given file and add its data by guessing its format. The format
must be Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to
``True`` to allow already added data to be overwritten.
"""
with open(filename, 'r') as fin:... | python | def add_file(self, filename, overwrite=False):
"""Open given file and add its data by guessing its format. The format
must be Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to
``True`` to allow already added data to be overwritten.
"""
with open(filename, 'r') as fin:... | [
"def",
"add_file",
"(",
"self",
",",
"filename",
",",
"overwrite",
"=",
"False",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
")",
"as",
"fin",
":",
"self",
".",
"add",
"(",
"fin",
".",
"read",
"(",
")",
",",
"overwrite",
")"
] | Open given file and add its data by guessing its format. The format
must be Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to
``True`` to allow already added data to be overwritten. | [
"Open",
"given",
"file",
"and",
"add",
"its",
"data",
"by",
"guessing",
"its",
"format",
".",
"The",
"format",
"must",
"be",
"Motorola",
"S",
"-",
"Records",
"Intel",
"HEX",
"or",
"TI",
"-",
"TXT",
".",
"Set",
"overwrite",
"to",
"True",
"to",
"allow",
... | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L884-L892 |
46,149 | eerimoq/bincopy | bincopy.py | BinFile.add_srec_file | def add_srec_file(self, filename, overwrite=False):
"""Open given Motorola S-Records file and add its records. Set
`overwrite` to ``True`` to allow already added data to be
overwritten.
"""
with open(filename, 'r') as fin:
self.add_srec(fin.read(), overwrite) | python | def add_srec_file(self, filename, overwrite=False):
"""Open given Motorola S-Records file and add its records. Set
`overwrite` to ``True`` to allow already added data to be
overwritten.
"""
with open(filename, 'r') as fin:
self.add_srec(fin.read(), overwrite) | [
"def",
"add_srec_file",
"(",
"self",
",",
"filename",
",",
"overwrite",
"=",
"False",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
")",
"as",
"fin",
":",
"self",
".",
"add_srec",
"(",
"fin",
".",
"read",
"(",
")",
",",
"overwrite",
")"
] | Open given Motorola S-Records file and add its records. Set
`overwrite` to ``True`` to allow already added data to be
overwritten. | [
"Open",
"given",
"Motorola",
"S",
"-",
"Records",
"file",
"and",
"add",
"its",
"records",
".",
"Set",
"overwrite",
"to",
"True",
"to",
"allow",
"already",
"added",
"data",
"to",
"be",
"overwritten",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L894-L902 |
46,150 | eerimoq/bincopy | bincopy.py | BinFile.add_ihex_file | def add_ihex_file(self, filename, overwrite=False):
"""Open given Intel HEX file and add its records. Set `overwrite` to
``True`` to allow already added data to be overwritten.
"""
with open(filename, 'r') as fin:
self.add_ihex(fin.read(), overwrite) | python | def add_ihex_file(self, filename, overwrite=False):
"""Open given Intel HEX file and add its records. Set `overwrite` to
``True`` to allow already added data to be overwritten.
"""
with open(filename, 'r') as fin:
self.add_ihex(fin.read(), overwrite) | [
"def",
"add_ihex_file",
"(",
"self",
",",
"filename",
",",
"overwrite",
"=",
"False",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
")",
"as",
"fin",
":",
"self",
".",
"add_ihex",
"(",
"fin",
".",
"read",
"(",
")",
",",
"overwrite",
")"
] | Open given Intel HEX file and add its records. Set `overwrite` to
``True`` to allow already added data to be overwritten. | [
"Open",
"given",
"Intel",
"HEX",
"file",
"and",
"add",
"its",
"records",
".",
"Set",
"overwrite",
"to",
"True",
"to",
"allow",
"already",
"added",
"data",
"to",
"be",
"overwritten",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L904-L911 |
46,151 | eerimoq/bincopy | bincopy.py | BinFile.add_ti_txt_file | def add_ti_txt_file(self, filename, overwrite=False):
"""Open given TI-TXT file and add its contents. Set `overwrite` to
``True`` to allow already added data to be overwritten.
"""
with open(filename, 'r') as fin:
self.add_ti_txt(fin.read(), overwrite) | python | def add_ti_txt_file(self, filename, overwrite=False):
"""Open given TI-TXT file and add its contents. Set `overwrite` to
``True`` to allow already added data to be overwritten.
"""
with open(filename, 'r') as fin:
self.add_ti_txt(fin.read(), overwrite) | [
"def",
"add_ti_txt_file",
"(",
"self",
",",
"filename",
",",
"overwrite",
"=",
"False",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
")",
"as",
"fin",
":",
"self",
".",
"add_ti_txt",
"(",
"fin",
".",
"read",
"(",
")",
",",
"overwrite",
")"
... | Open given TI-TXT file and add its contents. Set `overwrite` to
``True`` to allow already added data to be overwritten. | [
"Open",
"given",
"TI",
"-",
"TXT",
"file",
"and",
"add",
"its",
"contents",
".",
"Set",
"overwrite",
"to",
"True",
"to",
"allow",
"already",
"added",
"data",
"to",
"be",
"overwritten",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L913-L920 |
46,152 | eerimoq/bincopy | bincopy.py | BinFile.add_binary_file | def add_binary_file(self, filename, address=0, overwrite=False):
"""Open given binary file and add its contents. Set `overwrite` to
``True`` to allow already added data to be overwritten.
"""
with open(filename, 'rb') as fin:
self.add_binary(fin.read(), address, overwrite) | python | def add_binary_file(self, filename, address=0, overwrite=False):
"""Open given binary file and add its contents. Set `overwrite` to
``True`` to allow already added data to be overwritten.
"""
with open(filename, 'rb') as fin:
self.add_binary(fin.read(), address, overwrite) | [
"def",
"add_binary_file",
"(",
"self",
",",
"filename",
",",
"address",
"=",
"0",
",",
"overwrite",
"=",
"False",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'rb'",
")",
"as",
"fin",
":",
"self",
".",
"add_binary",
"(",
"fin",
".",
"read",
"(",
... | Open given binary file and add its contents. Set `overwrite` to
``True`` to allow already added data to be overwritten. | [
"Open",
"given",
"binary",
"file",
"and",
"add",
"its",
"contents",
".",
"Set",
"overwrite",
"to",
"True",
"to",
"allow",
"already",
"added",
"data",
"to",
"be",
"overwritten",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L922-L929 |
46,153 | eerimoq/bincopy | bincopy.py | BinFile.as_srec | def as_srec(self, number_of_data_bytes=32, address_length_bits=32):
"""Format the binary file as Motorola S-Records records and return
them as a string.
`number_of_data_bytes` is the number of data bytes in each
record.
`address_length_bits` is the number of address bits in eac... | python | def as_srec(self, number_of_data_bytes=32, address_length_bits=32):
"""Format the binary file as Motorola S-Records records and return
them as a string.
`number_of_data_bytes` is the number of data bytes in each
record.
`address_length_bits` is the number of address bits in eac... | [
"def",
"as_srec",
"(",
"self",
",",
"number_of_data_bytes",
"=",
"32",
",",
"address_length_bits",
"=",
"32",
")",
":",
"header",
"=",
"[",
"]",
"if",
"self",
".",
"_header",
"is",
"not",
"None",
":",
"record",
"=",
"pack_srec",
"(",
"'0'",
",",
"0",
... | Format the binary file as Motorola S-Records records and return
them as a string.
`number_of_data_bytes` is the number of data bytes in each
record.
`address_length_bits` is the number of address bits in each
record.
>>> print(binfile.as_srec())
S32500000100214... | [
"Format",
"the",
"binary",
"file",
"as",
"Motorola",
"S",
"-",
"Records",
"records",
"and",
"return",
"them",
"as",
"a",
"string",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L931-L982 |
46,154 | eerimoq/bincopy | bincopy.py | BinFile.as_ihex | def as_ihex(self, number_of_data_bytes=32, address_length_bits=32):
"""Format the binary file as Intel HEX records and return them as a
string.
`number_of_data_bytes` is the number of data bytes in each
record.
`address_length_bits` is the number of address bits in each
... | python | def as_ihex(self, number_of_data_bytes=32, address_length_bits=32):
"""Format the binary file as Intel HEX records and return them as a
string.
`number_of_data_bytes` is the number of data bytes in each
record.
`address_length_bits` is the number of address bits in each
... | [
"def",
"as_ihex",
"(",
"self",
",",
"number_of_data_bytes",
"=",
"32",
",",
"address_length_bits",
"=",
"32",
")",
":",
"def",
"i32hex",
"(",
"address",
",",
"extended_linear_address",
",",
"data_address",
")",
":",
"if",
"address",
">",
"0xffffffff",
":",
"... | Format the binary file as Intel HEX records and return them as a
string.
`number_of_data_bytes` is the number of data bytes in each
record.
`address_length_bits` is the number of address bits in each
record.
>>> print(binfile.as_ihex())
:20010000214601360121470... | [
"Format",
"the",
"binary",
"file",
"as",
"Intel",
"HEX",
"records",
"and",
"return",
"them",
"as",
"a",
"string",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L984-L1100 |
46,155 | eerimoq/bincopy | bincopy.py | BinFile.as_ti_txt | def as_ti_txt(self):
"""Format the binary file as a TI-TXT file and return it as a string.
>>> print(binfile.as_ti_txt())
@0100
21 46 01 36 01 21 47 01 36 00 7E FE 09 D2 19 01
21 46 01 7E 17 C2 00 01 FF 5F 16 00 21 48 01 19
19 4E 79 23 46 23 96 57 78 23 9E DA 3F 01 B2 CA... | python | def as_ti_txt(self):
"""Format the binary file as a TI-TXT file and return it as a string.
>>> print(binfile.as_ti_txt())
@0100
21 46 01 36 01 21 47 01 36 00 7E FE 09 D2 19 01
21 46 01 7E 17 C2 00 01 FF 5F 16 00 21 48 01 19
19 4E 79 23 46 23 96 57 78 23 9E DA 3F 01 B2 CA... | [
"def",
"as_ti_txt",
"(",
"self",
")",
":",
"lines",
"=",
"[",
"]",
"for",
"segment",
"in",
"self",
".",
"_segments",
":",
"lines",
".",
"append",
"(",
"'@{:04X}'",
".",
"format",
"(",
"segment",
".",
"address",
")",
")",
"for",
"_",
",",
"data",
"i... | Format the binary file as a TI-TXT file and return it as a string.
>>> print(binfile.as_ti_txt())
@0100
21 46 01 36 01 21 47 01 36 00 7E FE 09 D2 19 01
21 46 01 7E 17 C2 00 01 FF 5F 16 00 21 48 01 19
19 4E 79 23 46 23 96 57 78 23 9E DA 3F 01 B2 CA
3F 01 56 70 2B 5E 71 2B... | [
"Format",
"the",
"binary",
"file",
"as",
"a",
"TI",
"-",
"TXT",
"file",
"and",
"return",
"it",
"as",
"a",
"string",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1102-L1125 |
46,156 | eerimoq/bincopy | bincopy.py | BinFile.as_binary | def as_binary(self,
minimum_address=None,
maximum_address=None,
padding=None):
"""Return a byte string of all data within given address range.
`minimum_address` is the absolute minimum address of the
resulting binary data.
`maximum_... | python | def as_binary(self,
minimum_address=None,
maximum_address=None,
padding=None):
"""Return a byte string of all data within given address range.
`minimum_address` is the absolute minimum address of the
resulting binary data.
`maximum_... | [
"def",
"as_binary",
"(",
"self",
",",
"minimum_address",
"=",
"None",
",",
"maximum_address",
"=",
"None",
",",
"padding",
"=",
"None",
")",
":",
"if",
"len",
"(",
"self",
".",
"_segments",
")",
"==",
"0",
":",
"return",
"b''",
"if",
"minimum_address",
... | Return a byte string of all data within given address range.
`minimum_address` is the absolute minimum address of the
resulting binary data.
`maximum_address` is the absolute maximum address of the
resulting binary data (non-inclusive).
`padding` is the word value of the paddi... | [
"Return",
"a",
"byte",
"string",
"of",
"all",
"data",
"within",
"given",
"address",
"range",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1127-L1197 |
46,157 | eerimoq/bincopy | bincopy.py | BinFile.as_array | def as_array(self, minimum_address=None, padding=None, separator=', '):
"""Format the binary file as a string values separated by given
separator `separator`. This function can be used to generate
array initialization code for C and other languages.
`minimum_address` is the start addres... | python | def as_array(self, minimum_address=None, padding=None, separator=', '):
"""Format the binary file as a string values separated by given
separator `separator`. This function can be used to generate
array initialization code for C and other languages.
`minimum_address` is the start addres... | [
"def",
"as_array",
"(",
"self",
",",
"minimum_address",
"=",
"None",
",",
"padding",
"=",
"None",
",",
"separator",
"=",
"', '",
")",
":",
"binary_data",
"=",
"self",
".",
"as_binary",
"(",
"minimum_address",
",",
"padding",
"=",
"padding",
")",
"words",
... | Format the binary file as a string values separated by given
separator `separator`. This function can be used to generate
array initialization code for C and other languages.
`minimum_address` is the start address of the resulting binary
data.
`padding` is the value of the padd... | [
"Format",
"the",
"binary",
"file",
"as",
"a",
"string",
"values",
"separated",
"by",
"given",
"separator",
"separator",
".",
"This",
"function",
"can",
"be",
"used",
"to",
"generate",
"array",
"initialization",
"code",
"for",
"C",
"and",
"other",
"languages",
... | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1199-L1233 |
46,158 | eerimoq/bincopy | bincopy.py | BinFile.as_hexdump | def as_hexdump(self):
"""Format the binary file as a hexdump and return it as a string.
>>> print(binfile.as_hexdump())
00000100 21 46 01 36 01 21 47 01 36 00 7e fe 09 d2 19 01 |!F.6.!G.6.~.....|
00000110 21 46 01 7e 17 c2 00 01 ff 5f 16 00 21 48 01 19 |!F.~....._..!H..|
0... | python | def as_hexdump(self):
"""Format the binary file as a hexdump and return it as a string.
>>> print(binfile.as_hexdump())
00000100 21 46 01 36 01 21 47 01 36 00 7e fe 09 d2 19 01 |!F.6.!G.6.~.....|
00000110 21 46 01 7e 17 c2 00 01 ff 5f 16 00 21 48 01 19 |!F.~....._..!H..|
0... | [
"def",
"as_hexdump",
"(",
"self",
")",
":",
"# Empty file?",
"if",
"len",
"(",
"self",
")",
"==",
"0",
":",
"return",
"'\\n'",
"non_dot_characters",
"=",
"set",
"(",
"string",
".",
"printable",
")",
"non_dot_characters",
"-=",
"set",
"(",
"string",
".",
... | Format the binary file as a hexdump and return it as a string.
>>> print(binfile.as_hexdump())
00000100 21 46 01 36 01 21 47 01 36 00 7e fe 09 d2 19 01 |!F.6.!G.6.~.....|
00000110 21 46 01 7e 17 c2 00 01 ff 5f 16 00 21 48 01 19 |!F.~....._..!H..|
00000120 19 4e 79 23 46 23 96 57 ... | [
"Format",
"the",
"binary",
"file",
"as",
"a",
"hexdump",
"and",
"return",
"it",
"as",
"a",
"string",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1235-L1313 |
46,159 | eerimoq/bincopy | bincopy.py | BinFile.fill | def fill(self, value=b'\xff'):
"""Fill all empty space between segments with given value `value`.
"""
previous_segment_maximum_address = None
fill_segments = []
for address, data in self._segments:
maximum_address = address + len(data)
if previous_segm... | python | def fill(self, value=b'\xff'):
"""Fill all empty space between segments with given value `value`.
"""
previous_segment_maximum_address = None
fill_segments = []
for address, data in self._segments:
maximum_address = address + len(data)
if previous_segm... | [
"def",
"fill",
"(",
"self",
",",
"value",
"=",
"b'\\xff'",
")",
":",
"previous_segment_maximum_address",
"=",
"None",
"fill_segments",
"=",
"[",
"]",
"for",
"address",
",",
"data",
"in",
"self",
".",
"_segments",
":",
"maximum_address",
"=",
"address",
"+",
... | Fill all empty space between segments with given value `value`. | [
"Fill",
"all",
"empty",
"space",
"between",
"segments",
"with",
"given",
"value",
"value",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1315-L1338 |
46,160 | eerimoq/bincopy | bincopy.py | BinFile.exclude | def exclude(self, minimum_address, maximum_address):
"""Exclude given range and keep the rest.
`minimum_address` is the first word address to exclude
(including).
`maximum_address` is the last word address to exclude
(excluding).
"""
if maximum_address < minim... | python | def exclude(self, minimum_address, maximum_address):
"""Exclude given range and keep the rest.
`minimum_address` is the first word address to exclude
(including).
`maximum_address` is the last word address to exclude
(excluding).
"""
if maximum_address < minim... | [
"def",
"exclude",
"(",
"self",
",",
"minimum_address",
",",
"maximum_address",
")",
":",
"if",
"maximum_address",
"<",
"minimum_address",
":",
"raise",
"Error",
"(",
"'bad address range'",
")",
"minimum_address",
"*=",
"self",
".",
"word_size_bytes",
"maximum_addres... | Exclude given range and keep the rest.
`minimum_address` is the first word address to exclude
(including).
`maximum_address` is the last word address to exclude
(excluding). | [
"Exclude",
"given",
"range",
"and",
"keep",
"the",
"rest",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1340-L1356 |
46,161 | eerimoq/bincopy | bincopy.py | BinFile.crop | def crop(self, minimum_address, maximum_address):
"""Keep given range and discard the rest.
`minimum_address` is the first word address to keep
(including).
`maximum_address` is the last word address to keep
(excluding).
"""
minimum_address *= self.word_size_b... | python | def crop(self, minimum_address, maximum_address):
"""Keep given range and discard the rest.
`minimum_address` is the first word address to keep
(including).
`maximum_address` is the last word address to keep
(excluding).
"""
minimum_address *= self.word_size_b... | [
"def",
"crop",
"(",
"self",
",",
"minimum_address",
",",
"maximum_address",
")",
":",
"minimum_address",
"*=",
"self",
".",
"word_size_bytes",
"maximum_address",
"*=",
"self",
".",
"word_size_bytes",
"maximum_address_address",
"=",
"self",
".",
"_segments",
".",
"... | Keep given range and discard the rest.
`minimum_address` is the first word address to keep
(including).
`maximum_address` is the last word address to keep
(excluding). | [
"Keep",
"given",
"range",
"and",
"discard",
"the",
"rest",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1358-L1373 |
46,162 | eerimoq/bincopy | bincopy.py | BinFile.info | def info(self):
"""Return a string of human readable information about the binary
file.
.. code-block:: python
>>> print(binfile.info())
Data ranges:
0x00000100 - 0x00000140 (64 bytes)
"""
info = ''
if self._header is not None:
... | python | def info(self):
"""Return a string of human readable information about the binary
file.
.. code-block:: python
>>> print(binfile.info())
Data ranges:
0x00000100 - 0x00000140 (64 bytes)
"""
info = ''
if self._header is not None:
... | [
"def",
"info",
"(",
"self",
")",
":",
"info",
"=",
"''",
"if",
"self",
".",
"_header",
"is",
"not",
"None",
":",
"if",
"self",
".",
"_header_encoding",
"is",
"None",
":",
"header",
"=",
"''",
"for",
"b",
"in",
"bytearray",
"(",
"self",
".",
"header... | Return a string of human readable information about the binary
file.
.. code-block:: python
>>> print(binfile.info())
Data ranges:
0x00000100 - 0x00000140 (64 bytes) | [
"Return",
"a",
"string",
"of",
"human",
"readable",
"information",
"about",
"the",
"binary",
"file",
"."
] | 5e02cd001c3e9b54729425db6bffad5f03e1beac | https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1375-L1420 |
46,163 | kgori/treeCl | treeCl/utils/kendallcolijn.py | KendallColijn._precompute | def _precompute(self, tree):
"""
Collect metric info in a single preorder traversal.
"""
d = {}
for n in tree.preorder_internal_node_iter():
d[n] = namedtuple('NodeDist', ['dist_from_root', 'edges_from_root'])
if n.parent_node:
d[n].dist_fr... | python | def _precompute(self, tree):
"""
Collect metric info in a single preorder traversal.
"""
d = {}
for n in tree.preorder_internal_node_iter():
d[n] = namedtuple('NodeDist', ['dist_from_root', 'edges_from_root'])
if n.parent_node:
d[n].dist_fr... | [
"def",
"_precompute",
"(",
"self",
",",
"tree",
")",
":",
"d",
"=",
"{",
"}",
"for",
"n",
"in",
"tree",
".",
"preorder_internal_node_iter",
"(",
")",
":",
"d",
"[",
"n",
"]",
"=",
"namedtuple",
"(",
"'NodeDist'",
",",
"[",
"'dist_from_root'",
",",
"'... | Collect metric info in a single preorder traversal. | [
"Collect",
"metric",
"info",
"in",
"a",
"single",
"preorder",
"traversal",
"."
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/utils/kendallcolijn.py#L37-L50 |
46,164 | kgori/treeCl | treeCl/utils/kendallcolijn.py | KendallColijn._get_vectors | def _get_vectors(self, tree, precomputed_info):
"""
Populate the vectors m and M.
"""
little_m = []
big_m = []
leaf_nodes = sorted(tree.leaf_nodes(), key=lambda x: x.taxon.label)
# inner nodes, sorted order
for leaf_a, leaf_b in combinations(leaf_nodes, 2... | python | def _get_vectors(self, tree, precomputed_info):
"""
Populate the vectors m and M.
"""
little_m = []
big_m = []
leaf_nodes = sorted(tree.leaf_nodes(), key=lambda x: x.taxon.label)
# inner nodes, sorted order
for leaf_a, leaf_b in combinations(leaf_nodes, 2... | [
"def",
"_get_vectors",
"(",
"self",
",",
"tree",
",",
"precomputed_info",
")",
":",
"little_m",
"=",
"[",
"]",
"big_m",
"=",
"[",
"]",
"leaf_nodes",
"=",
"sorted",
"(",
"tree",
".",
"leaf_nodes",
"(",
")",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
... | Populate the vectors m and M. | [
"Populate",
"the",
"vectors",
"m",
"and",
"M",
"."
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/utils/kendallcolijn.py#L52-L71 |
46,165 | kgori/treeCl | treeCl/utils/ambiguate.py | remove_empty | def remove_empty(rec):
""" Deletes sequences that were marked for deletion by convert_to_IUPAC """
for header, sequence in rec.mapping.items():
if all(char == 'X' for char in sequence):
rec.headers.remove(header)
rec.sequences.remove(sequence)
rec.update()
return rec | python | def remove_empty(rec):
""" Deletes sequences that were marked for deletion by convert_to_IUPAC """
for header, sequence in rec.mapping.items():
if all(char == 'X' for char in sequence):
rec.headers.remove(header)
rec.sequences.remove(sequence)
rec.update()
return rec | [
"def",
"remove_empty",
"(",
"rec",
")",
":",
"for",
"header",
",",
"sequence",
"in",
"rec",
".",
"mapping",
".",
"items",
"(",
")",
":",
"if",
"all",
"(",
"char",
"==",
"'X'",
"for",
"char",
"in",
"sequence",
")",
":",
"rec",
".",
"headers",
".",
... | Deletes sequences that were marked for deletion by convert_to_IUPAC | [
"Deletes",
"sequences",
"that",
"were",
"marked",
"for",
"deletion",
"by",
"convert_to_IUPAC"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/utils/ambiguate.py#L83-L90 |
46,166 | pudo/jsonmapping | jsonmapping/transforms.py | transliterate | def transliterate(text):
""" Utility to properly transliterate text. """
text = unidecode(six.text_type(text))
text = text.replace('@', 'a')
return text | python | def transliterate(text):
""" Utility to properly transliterate text. """
text = unidecode(six.text_type(text))
text = text.replace('@', 'a')
return text | [
"def",
"transliterate",
"(",
"text",
")",
":",
"text",
"=",
"unidecode",
"(",
"six",
".",
"text_type",
"(",
"text",
")",
")",
"text",
"=",
"text",
".",
"replace",
"(",
"'@'",
",",
"'a'",
")",
"return",
"text"
] | Utility to properly transliterate text. | [
"Utility",
"to",
"properly",
"transliterate",
"text",
"."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/transforms.py#L11-L15 |
46,167 | pudo/jsonmapping | jsonmapping/transforms.py | slugify | def slugify(mapping, bind, values):
""" Transform all values into URL-capable slugs. """
for value in values:
if isinstance(value, six.string_types):
value = transliterate(value)
value = normality.slugify(value)
yield value | python | def slugify(mapping, bind, values):
""" Transform all values into URL-capable slugs. """
for value in values:
if isinstance(value, six.string_types):
value = transliterate(value)
value = normality.slugify(value)
yield value | [
"def",
"slugify",
"(",
"mapping",
",",
"bind",
",",
"values",
")",
":",
"for",
"value",
"in",
"values",
":",
"if",
"isinstance",
"(",
"value",
",",
"six",
".",
"string_types",
")",
":",
"value",
"=",
"transliterate",
"(",
"value",
")",
"value",
"=",
... | Transform all values into URL-capable slugs. | [
"Transform",
"all",
"values",
"into",
"URL",
"-",
"capable",
"slugs",
"."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/transforms.py#L26-L32 |
46,168 | pudo/jsonmapping | jsonmapping/transforms.py | latinize | def latinize(mapping, bind, values):
""" Transliterate a given string into the latin alphabet. """
for v in values:
if isinstance(v, six.string_types):
v = transliterate(v)
yield v | python | def latinize(mapping, bind, values):
""" Transliterate a given string into the latin alphabet. """
for v in values:
if isinstance(v, six.string_types):
v = transliterate(v)
yield v | [
"def",
"latinize",
"(",
"mapping",
",",
"bind",
",",
"values",
")",
":",
"for",
"v",
"in",
"values",
":",
"if",
"isinstance",
"(",
"v",
",",
"six",
".",
"string_types",
")",
":",
"v",
"=",
"transliterate",
"(",
"v",
")",
"yield",
"v"
] | Transliterate a given string into the latin alphabet. | [
"Transliterate",
"a",
"given",
"string",
"into",
"the",
"latin",
"alphabet",
"."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/transforms.py#L35-L40 |
46,169 | pudo/jsonmapping | jsonmapping/transforms.py | join | def join(mapping, bind, values):
""" Merge all the strings. Put space between them. """
return [' '.join([six.text_type(v) for v in values if v is not None])] | python | def join(mapping, bind, values):
""" Merge all the strings. Put space between them. """
return [' '.join([six.text_type(v) for v in values if v is not None])] | [
"def",
"join",
"(",
"mapping",
",",
"bind",
",",
"values",
")",
":",
"return",
"[",
"' '",
".",
"join",
"(",
"[",
"six",
".",
"text_type",
"(",
"v",
")",
"for",
"v",
"in",
"values",
"if",
"v",
"is",
"not",
"None",
"]",
")",
"]"
] | Merge all the strings. Put space between them. | [
"Merge",
"all",
"the",
"strings",
".",
"Put",
"space",
"between",
"them",
"."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/transforms.py#L43-L45 |
46,170 | pudo/jsonmapping | jsonmapping/transforms.py | hash | def hash(mapping, bind, values):
""" Generate a sha1 for each of the given values. """
for v in values:
if v is None:
continue
if not isinstance(v, six.string_types):
v = six.text_type(v)
yield sha1(v.encode('utf-8')).hexdigest() | python | def hash(mapping, bind, values):
""" Generate a sha1 for each of the given values. """
for v in values:
if v is None:
continue
if not isinstance(v, six.string_types):
v = six.text_type(v)
yield sha1(v.encode('utf-8')).hexdigest() | [
"def",
"hash",
"(",
"mapping",
",",
"bind",
",",
"values",
")",
":",
"for",
"v",
"in",
"values",
":",
"if",
"v",
"is",
"None",
":",
"continue",
"if",
"not",
"isinstance",
"(",
"v",
",",
"six",
".",
"string_types",
")",
":",
"v",
"=",
"six",
".",
... | Generate a sha1 for each of the given values. | [
"Generate",
"a",
"sha1",
"for",
"each",
"of",
"the",
"given",
"values",
"."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/transforms.py#L58-L65 |
46,171 | pudo/jsonmapping | jsonmapping/transforms.py | clean | def clean(mapping, bind, values):
""" Perform several types of string cleaning for titles etc.. """
categories = {'C': ' '}
for value in values:
if isinstance(value, six.string_types):
value = normality.normalize(value, lowercase=False, collapse=True,
... | python | def clean(mapping, bind, values):
""" Perform several types of string cleaning for titles etc.. """
categories = {'C': ' '}
for value in values:
if isinstance(value, six.string_types):
value = normality.normalize(value, lowercase=False, collapse=True,
... | [
"def",
"clean",
"(",
"mapping",
",",
"bind",
",",
"values",
")",
":",
"categories",
"=",
"{",
"'C'",
":",
"' '",
"}",
"for",
"value",
"in",
"values",
":",
"if",
"isinstance",
"(",
"value",
",",
"six",
".",
"string_types",
")",
":",
"value",
"=",
"n... | Perform several types of string cleaning for titles etc.. | [
"Perform",
"several",
"types",
"of",
"string",
"cleaning",
"for",
"titles",
"etc",
".."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/transforms.py#L68-L76 |
46,172 | kgori/treeCl | treeCl/distance_matrix.py | isconnected | def isconnected(mask):
""" Checks that all nodes are reachable from the first node - i.e. that the
graph is fully connected. """
nodes_to_check = list((np.where(mask[0, :])[0])[1:])
seen = [True] + [False] * (len(mask) - 1)
while nodes_to_check and not all(seen):
node = nodes_to_check.pop()... | python | def isconnected(mask):
""" Checks that all nodes are reachable from the first node - i.e. that the
graph is fully connected. """
nodes_to_check = list((np.where(mask[0, :])[0])[1:])
seen = [True] + [False] * (len(mask) - 1)
while nodes_to_check and not all(seen):
node = nodes_to_check.pop()... | [
"def",
"isconnected",
"(",
"mask",
")",
":",
"nodes_to_check",
"=",
"list",
"(",
"(",
"np",
".",
"where",
"(",
"mask",
"[",
"0",
",",
":",
"]",
")",
"[",
"0",
"]",
")",
"[",
"1",
":",
"]",
")",
"seen",
"=",
"[",
"True",
"]",
"+",
"[",
"Fals... | Checks that all nodes are reachable from the first node - i.e. that the
graph is fully connected. | [
"Checks",
"that",
"all",
"nodes",
"are",
"reachable",
"from",
"the",
"first",
"node",
"-",
"i",
".",
"e",
".",
"that",
"the",
"graph",
"is",
"fully",
"connected",
"."
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/distance_matrix.py#L22-L35 |
46,173 | kgori/treeCl | treeCl/distance_matrix.py | normalise_rows | def normalise_rows(matrix):
""" Scales all rows to length 1. Fails when row is 0-length, so it
leaves these unchanged """
lengths = np.apply_along_axis(np.linalg.norm, 1, matrix)
if not (lengths > 0).all():
# raise ValueError('Cannot normalise 0 length vector to length 1')
# print(matri... | python | def normalise_rows(matrix):
""" Scales all rows to length 1. Fails when row is 0-length, so it
leaves these unchanged """
lengths = np.apply_along_axis(np.linalg.norm, 1, matrix)
if not (lengths > 0).all():
# raise ValueError('Cannot normalise 0 length vector to length 1')
# print(matri... | [
"def",
"normalise_rows",
"(",
"matrix",
")",
":",
"lengths",
"=",
"np",
".",
"apply_along_axis",
"(",
"np",
".",
"linalg",
".",
"norm",
",",
"1",
",",
"matrix",
")",
"if",
"not",
"(",
"lengths",
">",
"0",
")",
".",
"all",
"(",
")",
":",
"# raise Va... | Scales all rows to length 1. Fails when row is 0-length, so it
leaves these unchanged | [
"Scales",
"all",
"rows",
"to",
"length",
"1",
".",
"Fails",
"when",
"row",
"is",
"0",
"-",
"length",
"so",
"it",
"leaves",
"these",
"unchanged"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/distance_matrix.py#L147-L156 |
46,174 | kgori/treeCl | treeCl/distance_matrix.py | kdists | def kdists(matrix, k=7, ix=None):
""" Returns the k-th nearest distances, row-wise, as a column vector """
ix = ix or kindex(matrix, k)
return matrix[ix][np.newaxis].T | python | def kdists(matrix, k=7, ix=None):
""" Returns the k-th nearest distances, row-wise, as a column vector """
ix = ix or kindex(matrix, k)
return matrix[ix][np.newaxis].T | [
"def",
"kdists",
"(",
"matrix",
",",
"k",
"=",
"7",
",",
"ix",
"=",
"None",
")",
":",
"ix",
"=",
"ix",
"or",
"kindex",
"(",
"matrix",
",",
"k",
")",
"return",
"matrix",
"[",
"ix",
"]",
"[",
"np",
".",
"newaxis",
"]",
".",
"T"
] | Returns the k-th nearest distances, row-wise, as a column vector | [
"Returns",
"the",
"k",
"-",
"th",
"nearest",
"distances",
"row",
"-",
"wise",
"as",
"a",
"column",
"vector"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/distance_matrix.py#L159-L163 |
46,175 | kgori/treeCl | treeCl/distance_matrix.py | kindex | def kindex(matrix, k):
""" Returns indices to select the kth nearest neighbour"""
ix = (np.arange(len(matrix)), matrix.argsort(axis=0)[k])
return ix | python | def kindex(matrix, k):
""" Returns indices to select the kth nearest neighbour"""
ix = (np.arange(len(matrix)), matrix.argsort(axis=0)[k])
return ix | [
"def",
"kindex",
"(",
"matrix",
",",
"k",
")",
":",
"ix",
"=",
"(",
"np",
".",
"arange",
"(",
"len",
"(",
"matrix",
")",
")",
",",
"matrix",
".",
"argsort",
"(",
"axis",
"=",
"0",
")",
"[",
"k",
"]",
")",
"return",
"ix"
] | Returns indices to select the kth nearest neighbour | [
"Returns",
"indices",
"to",
"select",
"the",
"kth",
"nearest",
"neighbour"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/distance_matrix.py#L166-L170 |
46,176 | kgori/treeCl | treeCl/distance_matrix.py | kmask | def kmask(matrix, k=7, dists=None, logic='or'):
""" Creates a boolean mask to include points within k nearest
neighbours, and exclude the rest.
Logic can be OR or AND. OR gives the k-nearest-neighbour mask,
AND gives the mutual k-nearest-neighbour mask."""
dists = (kdists(matrix, k=k) if dists is N... | python | def kmask(matrix, k=7, dists=None, logic='or'):
""" Creates a boolean mask to include points within k nearest
neighbours, and exclude the rest.
Logic can be OR or AND. OR gives the k-nearest-neighbour mask,
AND gives the mutual k-nearest-neighbour mask."""
dists = (kdists(matrix, k=k) if dists is N... | [
"def",
"kmask",
"(",
"matrix",
",",
"k",
"=",
"7",
",",
"dists",
"=",
"None",
",",
"logic",
"=",
"'or'",
")",
":",
"dists",
"=",
"(",
"kdists",
"(",
"matrix",
",",
"k",
"=",
"k",
")",
"if",
"dists",
"is",
"None",
"else",
"dists",
")",
"mask",
... | Creates a boolean mask to include points within k nearest
neighbours, and exclude the rest.
Logic can be OR or AND. OR gives the k-nearest-neighbour mask,
AND gives the mutual k-nearest-neighbour mask. | [
"Creates",
"a",
"boolean",
"mask",
"to",
"include",
"points",
"within",
"k",
"nearest",
"neighbours",
"and",
"exclude",
"the",
"rest",
".",
"Logic",
"can",
"be",
"OR",
"or",
"AND",
".",
"OR",
"gives",
"the",
"k",
"-",
"nearest",
"-",
"neighbour",
"mask",... | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/distance_matrix.py#L173-L185 |
46,177 | kgori/treeCl | treeCl/distance_matrix.py | kscale | def kscale(matrix, k=7, dists=None):
""" Returns the local scale based on the k-th nearest neighbour """
dists = (kdists(matrix, k=k) if dists is None else dists)
scale = dists.dot(dists.T)
return scale | python | def kscale(matrix, k=7, dists=None):
""" Returns the local scale based on the k-th nearest neighbour """
dists = (kdists(matrix, k=k) if dists is None else dists)
scale = dists.dot(dists.T)
return scale | [
"def",
"kscale",
"(",
"matrix",
",",
"k",
"=",
"7",
",",
"dists",
"=",
"None",
")",
":",
"dists",
"=",
"(",
"kdists",
"(",
"matrix",
",",
"k",
"=",
"k",
")",
"if",
"dists",
"is",
"None",
"else",
"dists",
")",
"scale",
"=",
"dists",
".",
"dot",
... | Returns the local scale based on the k-th nearest neighbour | [
"Returns",
"the",
"local",
"scale",
"based",
"on",
"the",
"k",
"-",
"th",
"nearest",
"neighbour"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/distance_matrix.py#L188-L192 |
46,178 | kgori/treeCl | treeCl/distance_matrix.py | shift_and_scale | def shift_and_scale(matrix, shift, scale):
""" Shift and scale matrix so its minimum value is placed at `shift` and
its maximum value is scaled to `scale` """
zeroed = matrix - matrix.min()
scaled = (scale - shift) * (zeroed / zeroed.max())
return scaled + shift | python | def shift_and_scale(matrix, shift, scale):
""" Shift and scale matrix so its minimum value is placed at `shift` and
its maximum value is scaled to `scale` """
zeroed = matrix - matrix.min()
scaled = (scale - shift) * (zeroed / zeroed.max())
return scaled + shift | [
"def",
"shift_and_scale",
"(",
"matrix",
",",
"shift",
",",
"scale",
")",
":",
"zeroed",
"=",
"matrix",
"-",
"matrix",
".",
"min",
"(",
")",
"scaled",
"=",
"(",
"scale",
"-",
"shift",
")",
"*",
"(",
"zeroed",
"/",
"zeroed",
".",
"max",
"(",
")",
... | Shift and scale matrix so its minimum value is placed at `shift` and
its maximum value is scaled to `scale` | [
"Shift",
"and",
"scale",
"matrix",
"so",
"its",
"minimum",
"value",
"is",
"placed",
"at",
"shift",
"and",
"its",
"maximum",
"value",
"is",
"scaled",
"to",
"scale"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/distance_matrix.py#L222-L228 |
46,179 | kgori/treeCl | treeCl/distance_matrix.py | Decomp.coords_by_dimension | def coords_by_dimension(self, dimensions=3):
""" Returns fitted coordinates in specified number of dimensions, and
the amount of variance explained) """
coords_matrix = self.vecs[:, :dimensions]
varexp = self.cve[dimensions - 1]
return coords_matrix, varexp | python | def coords_by_dimension(self, dimensions=3):
""" Returns fitted coordinates in specified number of dimensions, and
the amount of variance explained) """
coords_matrix = self.vecs[:, :dimensions]
varexp = self.cve[dimensions - 1]
return coords_matrix, varexp | [
"def",
"coords_by_dimension",
"(",
"self",
",",
"dimensions",
"=",
"3",
")",
":",
"coords_matrix",
"=",
"self",
".",
"vecs",
"[",
":",
",",
":",
"dimensions",
"]",
"varexp",
"=",
"self",
".",
"cve",
"[",
"dimensions",
"-",
"1",
"]",
"return",
"coords_m... | Returns fitted coordinates in specified number of dimensions, and
the amount of variance explained) | [
"Returns",
"fitted",
"coordinates",
"in",
"specified",
"number",
"of",
"dimensions",
"and",
"the",
"amount",
"of",
"variance",
"explained",
")"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/distance_matrix.py#L423-L429 |
46,180 | pudo/jsonmapping | jsonmapping/value.py | extract_value | def extract_value(mapping, bind, data):
""" Given a mapping and JSON schema spec, extract a value from ``data``
and apply certain transformations to normalize the value. """
columns = mapping.get('columns', [mapping.get('column')])
values = [data.get(c) for c in columns]
for transform in mapping.ge... | python | def extract_value(mapping, bind, data):
""" Given a mapping and JSON schema spec, extract a value from ``data``
and apply certain transformations to normalize the value. """
columns = mapping.get('columns', [mapping.get('column')])
values = [data.get(c) for c in columns]
for transform in mapping.ge... | [
"def",
"extract_value",
"(",
"mapping",
",",
"bind",
",",
"data",
")",
":",
"columns",
"=",
"mapping",
".",
"get",
"(",
"'columns'",
",",
"[",
"mapping",
".",
"get",
"(",
"'column'",
")",
"]",
")",
"values",
"=",
"[",
"data",
".",
"get",
"(",
"c",
... | Given a mapping and JSON schema spec, extract a value from ``data``
and apply certain transformations to normalize the value. | [
"Given",
"a",
"mapping",
"and",
"JSON",
"schema",
"spec",
"extract",
"a",
"value",
"from",
"data",
"and",
"apply",
"certain",
"transformations",
"to",
"normalize",
"the",
"value",
"."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/value.py#L7-L25 |
46,181 | pudo/jsonmapping | jsonmapping/value.py | convert_value | def convert_value(bind, value):
""" Type casting. """
type_name = get_type(bind)
try:
return typecast.cast(type_name, value)
except typecast.ConverterError:
return value | python | def convert_value(bind, value):
""" Type casting. """
type_name = get_type(bind)
try:
return typecast.cast(type_name, value)
except typecast.ConverterError:
return value | [
"def",
"convert_value",
"(",
"bind",
",",
"value",
")",
":",
"type_name",
"=",
"get_type",
"(",
"bind",
")",
"try",
":",
"return",
"typecast",
".",
"cast",
"(",
"type_name",
",",
"value",
")",
"except",
"typecast",
".",
"ConverterError",
":",
"return",
"... | Type casting. | [
"Type",
"casting",
"."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/value.py#L39-L45 |
46,182 | gopalkoduri/pypeaks | pypeaks/slope.py | peaks | def peaks(x, y, lookahead=20, delta=0.00003):
"""
A wrapper around peakdetect to pack the return values in a nicer format
"""
_max, _min = peakdetect(y, x, lookahead, delta)
x_peaks = [p[0] for p in _max]
y_peaks = [p[1] for p in _max]
x_valleys = [p[0] for p in _min]
y_valleys = [p[1] f... | python | def peaks(x, y, lookahead=20, delta=0.00003):
"""
A wrapper around peakdetect to pack the return values in a nicer format
"""
_max, _min = peakdetect(y, x, lookahead, delta)
x_peaks = [p[0] for p in _max]
y_peaks = [p[1] for p in _max]
x_valleys = [p[0] for p in _min]
y_valleys = [p[1] f... | [
"def",
"peaks",
"(",
"x",
",",
"y",
",",
"lookahead",
"=",
"20",
",",
"delta",
"=",
"0.00003",
")",
":",
"_max",
",",
"_min",
"=",
"peakdetect",
"(",
"y",
",",
"x",
",",
"lookahead",
",",
"delta",
")",
"x_peaks",
"=",
"[",
"p",
"[",
"0",
"]",
... | A wrapper around peakdetect to pack the return values in a nicer format | [
"A",
"wrapper",
"around",
"peakdetect",
"to",
"pack",
"the",
"return",
"values",
"in",
"a",
"nicer",
"format"
] | 59b1e4153e80c6a4c523dda241cc1713fd66161e | https://github.com/gopalkoduri/pypeaks/blob/59b1e4153e80c6a4c523dda241cc1713fd66161e/pypeaks/slope.py#L142-L154 |
46,183 | kgori/treeCl | treeCl/partition.py | Partition._restricted_growth_notation | def _restricted_growth_notation(l):
""" The clustering returned by the hcluster module gives group
membership without regard for numerical order This function preserves
the group membership, but sorts the labelling into numerical order """
list_length = len(l)
d = defaultdict(l... | python | def _restricted_growth_notation(l):
""" The clustering returned by the hcluster module gives group
membership without regard for numerical order This function preserves
the group membership, but sorts the labelling into numerical order """
list_length = len(l)
d = defaultdict(l... | [
"def",
"_restricted_growth_notation",
"(",
"l",
")",
":",
"list_length",
"=",
"len",
"(",
"l",
")",
"d",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"(",
"i",
",",
"element",
")",
"in",
"enumerate",
"(",
"l",
")",
":",
"d",
"[",
"element",
"]",
".... | The clustering returned by the hcluster module gives group
membership without regard for numerical order This function preserves
the group membership, but sorts the labelling into numerical order | [
"The",
"clustering",
"returned",
"by",
"the",
"hcluster",
"module",
"gives",
"group",
"membership",
"without",
"regard",
"for",
"numerical",
"order",
"This",
"function",
"preserves",
"the",
"group",
"membership",
"but",
"sorts",
"the",
"labelling",
"into",
"numeri... | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/partition.py#L113-L130 |
46,184 | kgori/treeCl | treeCl/partition.py | Partition.get_membership | def get_membership(self):
"""
Alternative representation of group membership -
creates a list with one tuple per group; each tuple contains
the indices of its members
Example:
partition = (0,0,0,1,0,1,2,2)
membership = [(0,1,2,4), (3,5), (6,7)]
:return:... | python | def get_membership(self):
"""
Alternative representation of group membership -
creates a list with one tuple per group; each tuple contains
the indices of its members
Example:
partition = (0,0,0,1,0,1,2,2)
membership = [(0,1,2,4), (3,5), (6,7)]
:return:... | [
"def",
"get_membership",
"(",
"self",
")",
":",
"result",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"(",
"position",
",",
"value",
")",
"in",
"enumerate",
"(",
"self",
".",
"partition_vector",
")",
":",
"result",
"[",
"value",
"]",
".",
"append",
"(... | Alternative representation of group membership -
creates a list with one tuple per group; each tuple contains
the indices of its members
Example:
partition = (0,0,0,1,0,1,2,2)
membership = [(0,1,2,4), (3,5), (6,7)]
:return: list of tuples giving group memberships by in... | [
"Alternative",
"representation",
"of",
"group",
"membership",
"-",
"creates",
"a",
"list",
"with",
"one",
"tuple",
"per",
"group",
";",
"each",
"tuple",
"contains",
"the",
"indices",
"of",
"its",
"members"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/partition.py#L168-L183 |
46,185 | gopalkoduri/pypeaks | pypeaks/data.py | Data.extend_peaks | def extend_peaks(self, prop_thresh=50):
"""Each peak in the peaks of the object is checked for its presence in
other octaves. If it does not exist, it is created.
prop_thresh is the cent range within which the peak in the other octave
is expected to be present, i.e., only if ... | python | def extend_peaks(self, prop_thresh=50):
"""Each peak in the peaks of the object is checked for its presence in
other octaves. If it does not exist, it is created.
prop_thresh is the cent range within which the peak in the other octave
is expected to be present, i.e., only if ... | [
"def",
"extend_peaks",
"(",
"self",
",",
"prop_thresh",
"=",
"50",
")",
":",
"# octave propagation of the reference peaks",
"temp_peaks",
"=",
"[",
"i",
"+",
"1200",
"for",
"i",
"in",
"self",
".",
"peaks",
"[",
"\"peaks\"",
"]",
"[",
"0",
"]",
"]",
"temp_p... | Each peak in the peaks of the object is checked for its presence in
other octaves. If it does not exist, it is created.
prop_thresh is the cent range within which the peak in the other octave
is expected to be present, i.e., only if there is a peak within this
cent range in ... | [
"Each",
"peak",
"in",
"the",
"peaks",
"of",
"the",
"object",
"is",
"checked",
"for",
"its",
"presence",
"in",
"other",
"octaves",
".",
"If",
"it",
"does",
"not",
"exist",
"it",
"is",
"created",
".",
"prop_thresh",
"is",
"the",
"cent",
"range",
"within",
... | 59b1e4153e80c6a4c523dda241cc1713fd66161e | https://github.com/gopalkoduri/pypeaks/blob/59b1e4153e80c6a4c523dda241cc1713fd66161e/pypeaks/data.py#L255-L280 |
46,186 | gopalkoduri/pypeaks | pypeaks/data.py | Data.plot | def plot(self, intervals=None, new_fig=True):
"""This function plots histogram together with its smoothed
version and peak information if provided. Just intonation
intervals are plotted for a reference."""
import pylab as p
if new_fig:
p.figure()
#step 1: p... | python | def plot(self, intervals=None, new_fig=True):
"""This function plots histogram together with its smoothed
version and peak information if provided. Just intonation
intervals are plotted for a reference."""
import pylab as p
if new_fig:
p.figure()
#step 1: p... | [
"def",
"plot",
"(",
"self",
",",
"intervals",
"=",
"None",
",",
"new_fig",
"=",
"True",
")",
":",
"import",
"pylab",
"as",
"p",
"if",
"new_fig",
":",
"p",
".",
"figure",
"(",
")",
"#step 1: plot histogram",
"p",
".",
"plot",
"(",
"self",
".",
"x",
... | This function plots histogram together with its smoothed
version and peak information if provided. Just intonation
intervals are plotted for a reference. | [
"This",
"function",
"plots",
"histogram",
"together",
"with",
"its",
"smoothed",
"version",
"and",
"peak",
"information",
"if",
"provided",
".",
"Just",
"intonation",
"intervals",
"are",
"plotted",
"for",
"a",
"reference",
"."
] | 59b1e4153e80c6a4c523dda241cc1713fd66161e | https://github.com/gopalkoduri/pypeaks/blob/59b1e4153e80c6a4c523dda241cc1713fd66161e/pypeaks/data.py#L282-L323 |
46,187 | kgori/treeCl | treeCl/parutils.py | threadpool_map | def threadpool_map(task, args, message, concurrency, batchsize=1, nargs=None):
"""
Helper to map a function over a range of inputs, using a threadpool, with a progress meter
"""
import concurrent.futures
njobs = get_njobs(nargs, args)
show_progress = bool(message)
batches = grouper(batchsi... | python | def threadpool_map(task, args, message, concurrency, batchsize=1, nargs=None):
"""
Helper to map a function over a range of inputs, using a threadpool, with a progress meter
"""
import concurrent.futures
njobs = get_njobs(nargs, args)
show_progress = bool(message)
batches = grouper(batchsi... | [
"def",
"threadpool_map",
"(",
"task",
",",
"args",
",",
"message",
",",
"concurrency",
",",
"batchsize",
"=",
"1",
",",
"nargs",
"=",
"None",
")",
":",
"import",
"concurrent",
".",
"futures",
"njobs",
"=",
"get_njobs",
"(",
"nargs",
",",
"args",
")",
"... | Helper to map a function over a range of inputs, using a threadpool, with a progress meter | [
"Helper",
"to",
"map",
"a",
"function",
"over",
"a",
"range",
"of",
"inputs",
"using",
"a",
"threadpool",
"with",
"a",
"progress",
"meter"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/parutils.py#L143-L175 |
46,188 | kgori/treeCl | treeCl/utils/misc.py | insort_no_dup | def insort_no_dup(lst, item):
"""
If item is not in lst, add item to list at its sorted position
"""
import bisect
ix = bisect.bisect_left(lst, item)
if lst[ix] != item:
lst[ix:ix] = [item] | python | def insort_no_dup(lst, item):
"""
If item is not in lst, add item to list at its sorted position
"""
import bisect
ix = bisect.bisect_left(lst, item)
if lst[ix] != item:
lst[ix:ix] = [item] | [
"def",
"insort_no_dup",
"(",
"lst",
",",
"item",
")",
":",
"import",
"bisect",
"ix",
"=",
"bisect",
".",
"bisect_left",
"(",
"lst",
",",
"item",
")",
"if",
"lst",
"[",
"ix",
"]",
"!=",
"item",
":",
"lst",
"[",
"ix",
":",
"ix",
"]",
"=",
"[",
"i... | If item is not in lst, add item to list at its sorted position | [
"If",
"item",
"is",
"not",
"in",
"lst",
"add",
"item",
"to",
"list",
"at",
"its",
"sorted",
"position"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/utils/misc.py#L151-L158 |
46,189 | kgori/treeCl | treeCl/utils/misc.py | create_gamma_model | def create_gamma_model(alignment, missing_data=None, ncat=4):
""" Create a phylo_utils.likelihood.GammaMixture for calculating
likelihood on a tree, from a treeCl.Alignment and its matching
treeCl.Parameters """
model = alignment.parameters.partitions.model
freqs = alignment.parameters.partitions.f... | python | def create_gamma_model(alignment, missing_data=None, ncat=4):
""" Create a phylo_utils.likelihood.GammaMixture for calculating
likelihood on a tree, from a treeCl.Alignment and its matching
treeCl.Parameters """
model = alignment.parameters.partitions.model
freqs = alignment.parameters.partitions.f... | [
"def",
"create_gamma_model",
"(",
"alignment",
",",
"missing_data",
"=",
"None",
",",
"ncat",
"=",
"4",
")",
":",
"model",
"=",
"alignment",
".",
"parameters",
".",
"partitions",
".",
"model",
"freqs",
"=",
"alignment",
".",
"parameters",
".",
"partitions",
... | Create a phylo_utils.likelihood.GammaMixture for calculating
likelihood on a tree, from a treeCl.Alignment and its matching
treeCl.Parameters | [
"Create",
"a",
"phylo_utils",
".",
"likelihood",
".",
"GammaMixture",
"for",
"calculating",
"likelihood",
"on",
"a",
"tree",
"from",
"a",
"treeCl",
".",
"Alignment",
"and",
"its",
"matching",
"treeCl",
".",
"Parameters"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/utils/misc.py#L181-L200 |
46,190 | kgori/treeCl | treeCl/utils/misc.py | sample_wr | def sample_wr(lst):
"""
Sample from lst, with replacement
"""
arr = np.array(lst)
indices = np.random.randint(len(lst), size=len(lst))
sample = np.empty(arr.shape, dtype=arr.dtype)
for i, ix in enumerate(indices):
sample[i] = arr[ix]
return list(sample) | python | def sample_wr(lst):
"""
Sample from lst, with replacement
"""
arr = np.array(lst)
indices = np.random.randint(len(lst), size=len(lst))
sample = np.empty(arr.shape, dtype=arr.dtype)
for i, ix in enumerate(indices):
sample[i] = arr[ix]
return list(sample) | [
"def",
"sample_wr",
"(",
"lst",
")",
":",
"arr",
"=",
"np",
".",
"array",
"(",
"lst",
")",
"indices",
"=",
"np",
".",
"random",
".",
"randint",
"(",
"len",
"(",
"lst",
")",
",",
"size",
"=",
"len",
"(",
"lst",
")",
")",
"sample",
"=",
"np",
"... | Sample from lst, with replacement | [
"Sample",
"from",
"lst",
"with",
"replacement"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/utils/misc.py#L212-L221 |
46,191 | kgori/treeCl | treeCl/utils/math.py | _preprocess_inputs | def _preprocess_inputs(x, weights):
"""
Coerce inputs into compatible format
"""
if weights is None:
w_arr = np.ones(len(x))
else:
w_arr = np.array(weights)
x_arr = np.array(x)
if x_arr.ndim == 2:
if w_arr.ndim == 1:
w_arr = w_arr[:, np.newaxis]
return... | python | def _preprocess_inputs(x, weights):
"""
Coerce inputs into compatible format
"""
if weights is None:
w_arr = np.ones(len(x))
else:
w_arr = np.array(weights)
x_arr = np.array(x)
if x_arr.ndim == 2:
if w_arr.ndim == 1:
w_arr = w_arr[:, np.newaxis]
return... | [
"def",
"_preprocess_inputs",
"(",
"x",
",",
"weights",
")",
":",
"if",
"weights",
"is",
"None",
":",
"w_arr",
"=",
"np",
".",
"ones",
"(",
"len",
"(",
"x",
")",
")",
"else",
":",
"w_arr",
"=",
"np",
".",
"array",
"(",
"weights",
")",
"x_arr",
"="... | Coerce inputs into compatible format | [
"Coerce",
"inputs",
"into",
"compatible",
"format"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/utils/math.py#L5-L17 |
46,192 | kgori/treeCl | treeCl/utils/math.py | amean | def amean(x, weights=None):
"""
Return the weighted arithmetic mean of x
"""
w_arr, x_arr = _preprocess_inputs(x, weights)
return (w_arr*x_arr).sum(axis=0) / w_arr.sum(axis=0) | python | def amean(x, weights=None):
"""
Return the weighted arithmetic mean of x
"""
w_arr, x_arr = _preprocess_inputs(x, weights)
return (w_arr*x_arr).sum(axis=0) / w_arr.sum(axis=0) | [
"def",
"amean",
"(",
"x",
",",
"weights",
"=",
"None",
")",
":",
"w_arr",
",",
"x_arr",
"=",
"_preprocess_inputs",
"(",
"x",
",",
"weights",
")",
"return",
"(",
"w_arr",
"*",
"x_arr",
")",
".",
"sum",
"(",
"axis",
"=",
"0",
")",
"/",
"w_arr",
"."... | Return the weighted arithmetic mean of x | [
"Return",
"the",
"weighted",
"arithmetic",
"mean",
"of",
"x"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/utils/math.py#L19-L24 |
46,193 | kgori/treeCl | treeCl/utils/math.py | gmean | def gmean(x, weights=None):
"""
Return the weighted geometric mean of x
"""
w_arr, x_arr = _preprocess_inputs(x, weights)
return np.exp((w_arr*np.log(x_arr)).sum(axis=0) / w_arr.sum(axis=0)) | python | def gmean(x, weights=None):
"""
Return the weighted geometric mean of x
"""
w_arr, x_arr = _preprocess_inputs(x, weights)
return np.exp((w_arr*np.log(x_arr)).sum(axis=0) / w_arr.sum(axis=0)) | [
"def",
"gmean",
"(",
"x",
",",
"weights",
"=",
"None",
")",
":",
"w_arr",
",",
"x_arr",
"=",
"_preprocess_inputs",
"(",
"x",
",",
"weights",
")",
"return",
"np",
".",
"exp",
"(",
"(",
"w_arr",
"*",
"np",
".",
"log",
"(",
"x_arr",
")",
")",
".",
... | Return the weighted geometric mean of x | [
"Return",
"the",
"weighted",
"geometric",
"mean",
"of",
"x"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/utils/math.py#L26-L31 |
46,194 | kgori/treeCl | treeCl/utils/math.py | hmean | def hmean(x, weights=None):
"""
Return the weighted harmonic mean of x
"""
w_arr, x_arr = _preprocess_inputs(x, weights)
return w_arr.sum(axis=0) / (w_arr/x_arr).sum(axis=0) | python | def hmean(x, weights=None):
"""
Return the weighted harmonic mean of x
"""
w_arr, x_arr = _preprocess_inputs(x, weights)
return w_arr.sum(axis=0) / (w_arr/x_arr).sum(axis=0) | [
"def",
"hmean",
"(",
"x",
",",
"weights",
"=",
"None",
")",
":",
"w_arr",
",",
"x_arr",
"=",
"_preprocess_inputs",
"(",
"x",
",",
"weights",
")",
"return",
"w_arr",
".",
"sum",
"(",
"axis",
"=",
"0",
")",
"/",
"(",
"w_arr",
"/",
"x_arr",
")",
"."... | Return the weighted harmonic mean of x | [
"Return",
"the",
"weighted",
"harmonic",
"mean",
"of",
"x"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/utils/math.py#L33-L38 |
46,195 | kgori/treeCl | treeCl/collection.py | RecordsHandler.records | def records(self):
""" Returns a list of records in SORT_KEY order """
return [self._records[i] for i in range(len(self._records))] | python | def records(self):
""" Returns a list of records in SORT_KEY order """
return [self._records[i] for i in range(len(self._records))] | [
"def",
"records",
"(",
"self",
")",
":",
"return",
"[",
"self",
".",
"_records",
"[",
"i",
"]",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"_records",
")",
")",
"]"
] | Returns a list of records in SORT_KEY order | [
"Returns",
"a",
"list",
"of",
"records",
"in",
"SORT_KEY",
"order"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L137-L139 |
46,196 | kgori/treeCl | treeCl/collection.py | RecordsHandler.read_trees | def read_trees(self, input_dir):
""" Read a directory full of tree files, matching them up to the
already loaded alignments """
if self.show_progress:
pbar = setup_progressbar("Loading trees", len(self.records))
pbar.start()
for i, rec in enumerate(self.records)... | python | def read_trees(self, input_dir):
""" Read a directory full of tree files, matching them up to the
already loaded alignments """
if self.show_progress:
pbar = setup_progressbar("Loading trees", len(self.records))
pbar.start()
for i, rec in enumerate(self.records)... | [
"def",
"read_trees",
"(",
"self",
",",
"input_dir",
")",
":",
"if",
"self",
".",
"show_progress",
":",
"pbar",
"=",
"setup_progressbar",
"(",
"\"Loading trees\"",
",",
"len",
"(",
"self",
".",
"records",
")",
")",
"pbar",
".",
"start",
"(",
")",
"for",
... | Read a directory full of tree files, matching them up to the
already loaded alignments | [
"Read",
"a",
"directory",
"full",
"of",
"tree",
"files",
"matching",
"them",
"up",
"to",
"the",
"already",
"loaded",
"alignments"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L292-L319 |
46,197 | kgori/treeCl | treeCl/collection.py | RecordsHandler.read_parameters | def read_parameters(self, input_dir):
""" Read a directory full of json parameter files, matching them up to the
already loaded alignments """
if self.show_progress:
pbar = setup_progressbar("Loading parameters", len(self.records))
pbar.start()
for i, rec in enum... | python | def read_parameters(self, input_dir):
""" Read a directory full of json parameter files, matching them up to the
already loaded alignments """
if self.show_progress:
pbar = setup_progressbar("Loading parameters", len(self.records))
pbar.start()
for i, rec in enum... | [
"def",
"read_parameters",
"(",
"self",
",",
"input_dir",
")",
":",
"if",
"self",
".",
"show_progress",
":",
"pbar",
"=",
"setup_progressbar",
"(",
"\"Loading parameters\"",
",",
"len",
"(",
"self",
".",
"records",
")",
")",
"pbar",
".",
"start",
"(",
")",
... | Read a directory full of json parameter files, matching them up to the
already loaded alignments | [
"Read",
"a",
"directory",
"full",
"of",
"json",
"parameter",
"files",
"matching",
"them",
"up",
"to",
"the",
"already",
"loaded",
"alignments"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L321-L344 |
46,198 | kgori/treeCl | treeCl/collection.py | RecordsCalculatorMixin.calc_trees | def calc_trees(self, indices=None, task_interface=None, jobhandler=default_jobhandler, batchsize=1,
show_progress=True, **kwargs):
"""
Infer phylogenetic trees for the loaded Alignments
:param indices: Only run inference on the alignments at these given indices
:param... | python | def calc_trees(self, indices=None, task_interface=None, jobhandler=default_jobhandler, batchsize=1,
show_progress=True, **kwargs):
"""
Infer phylogenetic trees for the loaded Alignments
:param indices: Only run inference on the alignments at these given indices
:param... | [
"def",
"calc_trees",
"(",
"self",
",",
"indices",
"=",
"None",
",",
"task_interface",
"=",
"None",
",",
"jobhandler",
"=",
"default_jobhandler",
",",
"batchsize",
"=",
"1",
",",
"show_progress",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"indi... | Infer phylogenetic trees for the loaded Alignments
:param indices: Only run inference on the alignments at these given indices
:param task_interface: Inference tool specified via TaskInterface (default RaxmlTaskInterface)
:param jobhandler: Launch jobs via this JobHandler (default SequentialJob... | [
"Infer",
"phylogenetic",
"trees",
"for",
"the",
"loaded",
"Alignments"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L396-L428 |
46,199 | kgori/treeCl | treeCl/collection.py | Collection.num_species | def num_species(self):
""" Returns the number of species found over all records
"""
all_headers = reduce(lambda x, y: set(x) | set(y),
(rec.get_names() for rec in self.records))
return len(all_headers) | python | def num_species(self):
""" Returns the number of species found over all records
"""
all_headers = reduce(lambda x, y: set(x) | set(y),
(rec.get_names() for rec in self.records))
return len(all_headers) | [
"def",
"num_species",
"(",
"self",
")",
":",
"all_headers",
"=",
"reduce",
"(",
"lambda",
"x",
",",
"y",
":",
"set",
"(",
"x",
")",
"|",
"set",
"(",
"y",
")",
",",
"(",
"rec",
".",
"get_names",
"(",
")",
"for",
"rec",
"in",
"self",
".",
"record... | Returns the number of species found over all records | [
"Returns",
"the",
"number",
"of",
"species",
"found",
"over",
"all",
"records"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L482-L487 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.