repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | train | 63,100 |
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 | train | 63,101 |
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 | train | 63,102 |
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 | train | 63,103 |
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 | train | 63,104 |
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 | train | 63,105 |
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 | train | 63,106 |
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 | train | 63,107 |
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 | train | 63,108 |
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 | train | 63,109 |
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 | train | 63,110 |
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 | train | 63,111 |
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 | train | 63,112 |
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 | train | 63,113 |
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 | train | 63,114 |
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 | train | 63,115 |
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 | train | 63,116 |
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 | train | 63,117 |
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 | train | 63,118 |
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 | train | 63,119 |
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 | train | 63,120 |
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 | train | 63,121 |
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 | train | 63,122 |
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 | train | 63,123 |
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 | train | 63,124 |
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 | train | 63,125 |
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 | train | 63,126 |
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 | train | 63,127 |
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 | train | 63,128 |
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 | train | 63,129 |
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 | train | 63,130 |
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 | train | 63,131 |
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 | train | 63,132 |
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 | train | 63,133 |
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 | train | 63,134 |
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 | train | 63,135 |
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 | train | 63,136 |
kgori/treeCl | treeCl/collection.py | Collection.permuted_copy | def permuted_copy(self, partition=None):
""" Return a copy of the collection with all alignment columns permuted
"""
def take(n, iterable):
return [next(iterable) for _ in range(n)]
if partition is None:
partition = Partition([1] * len(self))
index_tuple... | python | def permuted_copy(self, partition=None):
""" Return a copy of the collection with all alignment columns permuted
"""
def take(n, iterable):
return [next(iterable) for _ in range(n)]
if partition is None:
partition = Partition([1] * len(self))
index_tuple... | [
"def",
"permuted_copy",
"(",
"self",
",",
"partition",
"=",
"None",
")",
":",
"def",
"take",
"(",
"n",
",",
"iterable",
")",
":",
"return",
"[",
"next",
"(",
"iterable",
")",
"for",
"_",
"in",
"range",
"(",
"n",
")",
"]",
"if",
"partition",
"is",
... | Return a copy of the collection with all alignment columns permuted | [
"Return",
"a",
"copy",
"of",
"the",
"collection",
"with",
"all",
"alignment",
"columns",
"permuted"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L489-L513 | train | 63,137 |
kgori/treeCl | treeCl/collection.py | Scorer.get_id | def get_id(self, grp):
"""
Return a hash of the tuple of indices that specify the group
"""
thehash = hex(hash(grp))
if ISPY3: # use default encoding to get bytes
thehash = thehash.encode()
return self.cache.get(grp, hashlib.sha1(thehash).hexdigest()) | python | def get_id(self, grp):
"""
Return a hash of the tuple of indices that specify the group
"""
thehash = hex(hash(grp))
if ISPY3: # use default encoding to get bytes
thehash = thehash.encode()
return self.cache.get(grp, hashlib.sha1(thehash).hexdigest()) | [
"def",
"get_id",
"(",
"self",
",",
"grp",
")",
":",
"thehash",
"=",
"hex",
"(",
"hash",
"(",
"grp",
")",
")",
"if",
"ISPY3",
":",
"# use default encoding to get bytes",
"thehash",
"=",
"thehash",
".",
"encode",
"(",
")",
"return",
"self",
".",
"cache",
... | Return a hash of the tuple of indices that specify the group | [
"Return",
"a",
"hash",
"of",
"the",
"tuple",
"of",
"indices",
"that",
"specify",
"the",
"group"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L534-L541 | train | 63,138 |
kgori/treeCl | treeCl/collection.py | Scorer.check_work_done | def check_work_done(self, grp):
"""
Check for the existence of alignment and result files.
"""
id_ = self.get_id(grp)
concat_file = os.path.join(self.cache_dir, '{}.phy'.format(id_))
result_file = os.path.join(self.cache_dir, '{}.{}.json'.format(id_, self.task_interface.n... | python | def check_work_done(self, grp):
"""
Check for the existence of alignment and result files.
"""
id_ = self.get_id(grp)
concat_file = os.path.join(self.cache_dir, '{}.phy'.format(id_))
result_file = os.path.join(self.cache_dir, '{}.{}.json'.format(id_, self.task_interface.n... | [
"def",
"check_work_done",
"(",
"self",
",",
"grp",
")",
":",
"id_",
"=",
"self",
".",
"get_id",
"(",
"grp",
")",
"concat_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"cache_dir",
",",
"'{}.phy'",
".",
"format",
"(",
"id_",
")",
")"... | Check for the existence of alignment and result files. | [
"Check",
"for",
"the",
"existence",
"of",
"alignment",
"and",
"result",
"files",
"."
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L543-L550 | train | 63,139 |
kgori/treeCl | treeCl/collection.py | Scorer.write_group | def write_group(self, grp, overwrite=False, **kwargs):
"""
Write the concatenated alignment to disk in the location specified by
self.cache_dir
"""
id_ = self.get_id(grp)
alignment_done, result_done = self.check_work_done(grp)
self.cache[grp] = id_
al_file... | python | def write_group(self, grp, overwrite=False, **kwargs):
"""
Write the concatenated alignment to disk in the location specified by
self.cache_dir
"""
id_ = self.get_id(grp)
alignment_done, result_done = self.check_work_done(grp)
self.cache[grp] = id_
al_file... | [
"def",
"write_group",
"(",
"self",
",",
"grp",
",",
"overwrite",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"id_",
"=",
"self",
".",
"get_id",
"(",
"grp",
")",
"alignment_done",
",",
"result_done",
"=",
"self",
".",
"check_work_done",
"(",
"grp",... | Write the concatenated alignment to disk in the location specified by
self.cache_dir | [
"Write",
"the",
"concatenated",
"alignment",
"to",
"disk",
"in",
"the",
"location",
"specified",
"by",
"self",
".",
"cache_dir"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L552-L568 | train | 63,140 |
kgori/treeCl | treeCl/collection.py | Scorer.get_group_result | def get_group_result(self, grp, **kwargs):
"""
Retrieve the results for a group. Needs this to already be calculated -
errors out if result not available.
"""
id_ = self.get_id(grp)
self.cache[grp] = id_
# Check if this file is already processed
alignment... | python | def get_group_result(self, grp, **kwargs):
"""
Retrieve the results for a group. Needs this to already be calculated -
errors out if result not available.
"""
id_ = self.get_id(grp)
self.cache[grp] = id_
# Check if this file is already processed
alignment... | [
"def",
"get_group_result",
"(",
"self",
",",
"grp",
",",
"*",
"*",
"kwargs",
")",
":",
"id_",
"=",
"self",
".",
"get_id",
"(",
"grp",
")",
"self",
".",
"cache",
"[",
"grp",
"]",
"=",
"id_",
"# Check if this file is already processed",
"alignment_written",
... | Retrieve the results for a group. Needs this to already be calculated -
errors out if result not available. | [
"Retrieve",
"the",
"results",
"for",
"a",
"group",
".",
"Needs",
"this",
"to",
"already",
"be",
"calculated",
"-",
"errors",
"out",
"if",
"result",
"not",
"available",
"."
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L570-L588 | train | 63,141 |
kgori/treeCl | treeCl/collection.py | Scorer.get_partition_score | def get_partition_score(self, p):
"""
Assumes analysis is done and written to id.json!
"""
scores = []
for grp in p.get_membership():
try:
result = self.get_group_result(grp)
scores.append(result['likelihood'])
except ValueE... | python | def get_partition_score(self, p):
"""
Assumes analysis is done and written to id.json!
"""
scores = []
for grp in p.get_membership():
try:
result = self.get_group_result(grp)
scores.append(result['likelihood'])
except ValueE... | [
"def",
"get_partition_score",
"(",
"self",
",",
"p",
")",
":",
"scores",
"=",
"[",
"]",
"for",
"grp",
"in",
"p",
".",
"get_membership",
"(",
")",
":",
"try",
":",
"result",
"=",
"self",
".",
"get_group_result",
"(",
"grp",
")",
"scores",
".",
"append... | Assumes analysis is done and written to id.json! | [
"Assumes",
"analysis",
"is",
"done",
"and",
"written",
"to",
"id",
".",
"json!"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L640-L651 | train | 63,142 |
kgori/treeCl | treeCl/collection.py | Scorer.get_partition_trees | def get_partition_trees(self, p):
"""
Return the trees associated with a partition, p
"""
trees = []
for grp in p.get_membership():
try:
result = self.get_group_result(grp)
trees.append(result['ml_tree'])
except ValueError:
... | python | def get_partition_trees(self, p):
"""
Return the trees associated with a partition, p
"""
trees = []
for grp in p.get_membership():
try:
result = self.get_group_result(grp)
trees.append(result['ml_tree'])
except ValueError:
... | [
"def",
"get_partition_trees",
"(",
"self",
",",
"p",
")",
":",
"trees",
"=",
"[",
"]",
"for",
"grp",
"in",
"p",
".",
"get_membership",
"(",
")",
":",
"try",
":",
"result",
"=",
"self",
".",
"get_group_result",
"(",
"grp",
")",
"trees",
".",
"append",... | Return the trees associated with a partition, p | [
"Return",
"the",
"trees",
"associated",
"with",
"a",
"partition",
"p"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L653-L665 | train | 63,143 |
kgori/treeCl | treeCl/collection.py | Optimiser.expect | def expect(self, use_proportions=True):
""" The Expectation step of the CEM algorithm """
changed = self.get_changed(self.partition, self.prev_partition)
lk_table = self.generate_lktable(self.partition, changed, use_proportions)
self.table = self.likelihood_table_to_probs(lk_table) | python | def expect(self, use_proportions=True):
""" The Expectation step of the CEM algorithm """
changed = self.get_changed(self.partition, self.prev_partition)
lk_table = self.generate_lktable(self.partition, changed, use_proportions)
self.table = self.likelihood_table_to_probs(lk_table) | [
"def",
"expect",
"(",
"self",
",",
"use_proportions",
"=",
"True",
")",
":",
"changed",
"=",
"self",
".",
"get_changed",
"(",
"self",
".",
"partition",
",",
"self",
".",
"prev_partition",
")",
"lk_table",
"=",
"self",
".",
"generate_lktable",
"(",
"self",
... | The Expectation step of the CEM algorithm | [
"The",
"Expectation",
"step",
"of",
"the",
"CEM",
"algorithm"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L791-L795 | train | 63,144 |
kgori/treeCl | treeCl/collection.py | Optimiser.classify | def classify(self, table, weighted_choice=False, transform=None):
""" The Classification step of the CEM algorithm """
assert table.shape[1] == self.numgrp
if weighted_choice:
if transform is not None:
probs = transform_fn(table.copy(), transform) #
else:... | python | def classify(self, table, weighted_choice=False, transform=None):
""" The Classification step of the CEM algorithm """
assert table.shape[1] == self.numgrp
if weighted_choice:
if transform is not None:
probs = transform_fn(table.copy(), transform) #
else:... | [
"def",
"classify",
"(",
"self",
",",
"table",
",",
"weighted_choice",
"=",
"False",
",",
"transform",
"=",
"None",
")",
":",
"assert",
"table",
".",
"shape",
"[",
"1",
"]",
"==",
"self",
".",
"numgrp",
"if",
"weighted_choice",
":",
"if",
"transform",
"... | The Classification step of the CEM algorithm | [
"The",
"Classification",
"step",
"of",
"the",
"CEM",
"algorithm"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L797-L816 | train | 63,145 |
kgori/treeCl | treeCl/collection.py | Optimiser.maximise | def maximise(self, **kwargs):
""" The Maximisation step of the CEM algorithm """
self.scorer.write_partition(self.partition)
self.scorer.analyse_cache_dir(**kwargs)
self.likelihood = self.scorer.get_partition_score(self.partition)
self.scorer.clean_cache()
changed = self.... | python | def maximise(self, **kwargs):
""" The Maximisation step of the CEM algorithm """
self.scorer.write_partition(self.partition)
self.scorer.analyse_cache_dir(**kwargs)
self.likelihood = self.scorer.get_partition_score(self.partition)
self.scorer.clean_cache()
changed = self.... | [
"def",
"maximise",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"scorer",
".",
"write_partition",
"(",
"self",
".",
"partition",
")",
"self",
".",
"scorer",
".",
"analyse_cache_dir",
"(",
"*",
"*",
"kwargs",
")",
"self",
".",
"likelihoo... | The Maximisation step of the CEM algorithm | [
"The",
"Maximisation",
"step",
"of",
"the",
"CEM",
"algorithm"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L818-L826 | train | 63,146 |
kgori/treeCl | treeCl/collection.py | Optimiser.set_partition | def set_partition(self, partition):
"""
Store the partition in self.partition, and
move the old self.partition into self.prev_partition
"""
assert len(partition) == self.numgrp
self.partition, self.prev_partition = partition, self.partition | python | def set_partition(self, partition):
"""
Store the partition in self.partition, and
move the old self.partition into self.prev_partition
"""
assert len(partition) == self.numgrp
self.partition, self.prev_partition = partition, self.partition | [
"def",
"set_partition",
"(",
"self",
",",
"partition",
")",
":",
"assert",
"len",
"(",
"partition",
")",
"==",
"self",
".",
"numgrp",
"self",
".",
"partition",
",",
"self",
".",
"prev_partition",
"=",
"partition",
",",
"self",
".",
"partition"
] | Store the partition in self.partition, and
move the old self.partition into self.prev_partition | [
"Store",
"the",
"partition",
"in",
"self",
".",
"partition",
"and",
"move",
"the",
"old",
"self",
".",
"partition",
"into",
"self",
".",
"prev_partition"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L844-L850 | train | 63,147 |
kgori/treeCl | treeCl/collection.py | Optimiser.get_changed | def get_changed(self, p1, p2):
"""
Return the loci that are in clusters that have changed between
partitions p1 and p2
"""
if p1 is None or p2 is None:
return list(range(len(self.insts)))
return set(flatten_list(set(p1) - set(p2))) | python | def get_changed(self, p1, p2):
"""
Return the loci that are in clusters that have changed between
partitions p1 and p2
"""
if p1 is None or p2 is None:
return list(range(len(self.insts)))
return set(flatten_list(set(p1) - set(p2))) | [
"def",
"get_changed",
"(",
"self",
",",
"p1",
",",
"p2",
")",
":",
"if",
"p1",
"is",
"None",
"or",
"p2",
"is",
"None",
":",
"return",
"list",
"(",
"range",
"(",
"len",
"(",
"self",
".",
"insts",
")",
")",
")",
"return",
"set",
"(",
"flatten_list"... | Return the loci that are in clusters that have changed between
partitions p1 and p2 | [
"Return",
"the",
"loci",
"that",
"are",
"in",
"clusters",
"that",
"have",
"changed",
"between",
"partitions",
"p1",
"and",
"p2"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L868-L875 | train | 63,148 |
kgori/treeCl | treeCl/collection.py | Optimiser._update_likelihood_model | def _update_likelihood_model(self, inst, partition_parameters, tree):
"""
Set parameters of likelihood model - inst -
using values in dictionary - partition_parameters -,
and - tree -
"""
# Build transition matrix from dict
model = partition_parameters['model']
... | python | def _update_likelihood_model(self, inst, partition_parameters, tree):
"""
Set parameters of likelihood model - inst -
using values in dictionary - partition_parameters -,
and - tree -
"""
# Build transition matrix from dict
model = partition_parameters['model']
... | [
"def",
"_update_likelihood_model",
"(",
"self",
",",
"inst",
",",
"partition_parameters",
",",
"tree",
")",
":",
"# Build transition matrix from dict",
"model",
"=",
"partition_parameters",
"[",
"'model'",
"]",
"freqs",
"=",
"partition_parameters",
".",
"get",
"(",
... | Set parameters of likelihood model - inst -
using values in dictionary - partition_parameters -,
and - tree - | [
"Set",
"parameters",
"of",
"likelihood",
"model",
"-",
"inst",
"-",
"using",
"values",
"in",
"dictionary",
"-",
"partition_parameters",
"-",
"and",
"-",
"tree",
"-"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L911-L935 | train | 63,149 |
kgori/treeCl | treeCl/collection.py | Optimiser._fill_empty_groups_old | def _fill_empty_groups_old(self, probs, assignment):
""" Does the simple thing - if any group is empty, but needs to have at
least one member, assign the data point with highest probability of
membership """
new_assignment = np.array(assignment.tolist())
for k in range(self.numgr... | python | def _fill_empty_groups_old(self, probs, assignment):
""" Does the simple thing - if any group is empty, but needs to have at
least one member, assign the data point with highest probability of
membership """
new_assignment = np.array(assignment.tolist())
for k in range(self.numgr... | [
"def",
"_fill_empty_groups_old",
"(",
"self",
",",
"probs",
",",
"assignment",
")",
":",
"new_assignment",
"=",
"np",
".",
"array",
"(",
"assignment",
".",
"tolist",
"(",
")",
")",
"for",
"k",
"in",
"range",
"(",
"self",
".",
"numgrp",
")",
":",
"if",
... | Does the simple thing - if any group is empty, but needs to have at
least one member, assign the data point with highest probability of
membership | [
"Does",
"the",
"simple",
"thing",
"-",
"if",
"any",
"group",
"is",
"empty",
"but",
"needs",
"to",
"have",
"at",
"least",
"one",
"member",
"assign",
"the",
"data",
"point",
"with",
"highest",
"probability",
"of",
"membership"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/collection.py#L1005-L1016 | train | 63,150 |
kgori/treeCl | treeCl/bootstrap.py | jac | def jac(x,a):
""" Jacobian matrix given Christophe's suggestion of f """
return (x-a) / np.sqrt(((x-a)**2).sum(1))[:,np.newaxis] | python | def jac(x,a):
""" Jacobian matrix given Christophe's suggestion of f """
return (x-a) / np.sqrt(((x-a)**2).sum(1))[:,np.newaxis] | [
"def",
"jac",
"(",
"x",
",",
"a",
")",
":",
"return",
"(",
"x",
"-",
"a",
")",
"/",
"np",
".",
"sqrt",
"(",
"(",
"(",
"x",
"-",
"a",
")",
"**",
"2",
")",
".",
"sum",
"(",
"1",
")",
")",
"[",
":",
",",
"np",
".",
"newaxis",
"]"
] | Jacobian matrix given Christophe's suggestion of f | [
"Jacobian",
"matrix",
"given",
"Christophe",
"s",
"suggestion",
"of",
"f"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/bootstrap.py#L70-L72 | train | 63,151 |
kgori/treeCl | treeCl/bootstrap.py | gradient | def gradient(x, a, c):
""" J'.G """
return jac(x, a).T.dot(g(x, a, c)) | python | def gradient(x, a, c):
""" J'.G """
return jac(x, a).T.dot(g(x, a, c)) | [
"def",
"gradient",
"(",
"x",
",",
"a",
",",
"c",
")",
":",
"return",
"jac",
"(",
"x",
",",
"a",
")",
".",
"T",
".",
"dot",
"(",
"g",
"(",
"x",
",",
"a",
",",
"c",
")",
")"
] | J'.G | [
"J",
".",
"G"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/bootstrap.py#L74-L76 | train | 63,152 |
kgori/treeCl | treeCl/bootstrap.py | hessian | def hessian(x, a):
""" J'.J """
j = jac(x, a)
return j.T.dot(j) | python | def hessian(x, a):
""" J'.J """
j = jac(x, a)
return j.T.dot(j) | [
"def",
"hessian",
"(",
"x",
",",
"a",
")",
":",
"j",
"=",
"jac",
"(",
"x",
",",
"a",
")",
"return",
"j",
".",
"T",
".",
"dot",
"(",
"j",
")"
] | J'.J | [
"J",
".",
"J"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/bootstrap.py#L78-L81 | train | 63,153 |
kgori/treeCl | treeCl/bootstrap.py | grad_desc_update | def grad_desc_update(x, a, c, step=0.01):
"""
Given a value of x, return a better x
using gradient descent
"""
return x - step * gradient(x,a,c) | python | def grad_desc_update(x, a, c, step=0.01):
"""
Given a value of x, return a better x
using gradient descent
"""
return x - step * gradient(x,a,c) | [
"def",
"grad_desc_update",
"(",
"x",
",",
"a",
",",
"c",
",",
"step",
"=",
"0.01",
")",
":",
"return",
"x",
"-",
"step",
"*",
"gradient",
"(",
"x",
",",
"a",
",",
"c",
")"
] | Given a value of x, return a better x
using gradient descent | [
"Given",
"a",
"value",
"of",
"x",
"return",
"a",
"better",
"x",
"using",
"gradient",
"descent"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/bootstrap.py#L83-L88 | train | 63,154 |
kgori/treeCl | treeCl/bootstrap.py | optimise_levenberg_marquardt | def optimise_levenberg_marquardt(x, a, c, damping=0.001, tolerance=0.001):
"""
Optimise value of x using levenberg-marquardt
"""
x_new = x
x_old = x-1 # dummy value
f_old = f(x_new, a, c)
while np.abs(x_new - x_old).sum() > tolerance:
x_old = x_new
x_tmp = levenberg_marquardt... | python | def optimise_levenberg_marquardt(x, a, c, damping=0.001, tolerance=0.001):
"""
Optimise value of x using levenberg-marquardt
"""
x_new = x
x_old = x-1 # dummy value
f_old = f(x_new, a, c)
while np.abs(x_new - x_old).sum() > tolerance:
x_old = x_new
x_tmp = levenberg_marquardt... | [
"def",
"optimise_levenberg_marquardt",
"(",
"x",
",",
"a",
",",
"c",
",",
"damping",
"=",
"0.001",
",",
"tolerance",
"=",
"0.001",
")",
":",
"x_new",
"=",
"x",
"x_old",
"=",
"x",
"-",
"1",
"# dummy value",
"f_old",
"=",
"f",
"(",
"x_new",
",",
"a",
... | Optimise value of x using levenberg-marquardt | [
"Optimise",
"value",
"of",
"x",
"using",
"levenberg",
"-",
"marquardt"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/bootstrap.py#L143-L160 | train | 63,155 |
kgori/treeCl | treeCl/bootstrap.py | run_out_of_sample_mds | def run_out_of_sample_mds(boot_collection, ref_collection, ref_distance_matrix, index, dimensions, task=_fast_geo, rooted=False, **kwargs):
"""
index = index of the locus the bootstrap sample corresponds to - only important if
using recalc=True in kwargs
"""
fit = np.empty((len(boot_collecti... | python | def run_out_of_sample_mds(boot_collection, ref_collection, ref_distance_matrix, index, dimensions, task=_fast_geo, rooted=False, **kwargs):
"""
index = index of the locus the bootstrap sample corresponds to - only important if
using recalc=True in kwargs
"""
fit = np.empty((len(boot_collecti... | [
"def",
"run_out_of_sample_mds",
"(",
"boot_collection",
",",
"ref_collection",
",",
"ref_distance_matrix",
",",
"index",
",",
"dimensions",
",",
"task",
"=",
"_fast_geo",
",",
"rooted",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"fit",
"=",
"np",
".",
... | index = index of the locus the bootstrap sample corresponds to - only important if
using recalc=True in kwargs | [
"index",
"=",
"index",
"of",
"the",
"locus",
"the",
"bootstrap",
"sample",
"corresponds",
"to",
"-",
"only",
"important",
"if",
"using",
"recalc",
"=",
"True",
"in",
"kwargs"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/bootstrap.py#L190-L206 | train | 63,156 |
kgori/treeCl | treeCl/bootstrap.py | stress | def stress(ref_cds, est_cds):
"""
Kruskal's stress
"""
ref_dists = pdist(ref_cds)
est_dists = pdist(est_cds)
return np.sqrt(((ref_dists - est_dists)**2).sum() / (ref_dists**2).sum()) | python | def stress(ref_cds, est_cds):
"""
Kruskal's stress
"""
ref_dists = pdist(ref_cds)
est_dists = pdist(est_cds)
return np.sqrt(((ref_dists - est_dists)**2).sum() / (ref_dists**2).sum()) | [
"def",
"stress",
"(",
"ref_cds",
",",
"est_cds",
")",
":",
"ref_dists",
"=",
"pdist",
"(",
"ref_cds",
")",
"est_dists",
"=",
"pdist",
"(",
"est_cds",
")",
"return",
"np",
".",
"sqrt",
"(",
"(",
"(",
"ref_dists",
"-",
"est_dists",
")",
"**",
"2",
")",... | Kruskal's stress | [
"Kruskal",
"s",
"stress"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/bootstrap.py#L224-L230 | train | 63,157 |
kgori/treeCl | treeCl/bootstrap.py | rmsd | def rmsd(ref_cds, est_cds):
"""
Root-mean-squared-difference
"""
ref_dists = pdist(ref_cds)
est_dists = pdist(est_cds)
return np.sqrt(((ref_dists - est_dists)**2).mean()) | python | def rmsd(ref_cds, est_cds):
"""
Root-mean-squared-difference
"""
ref_dists = pdist(ref_cds)
est_dists = pdist(est_cds)
return np.sqrt(((ref_dists - est_dists)**2).mean()) | [
"def",
"rmsd",
"(",
"ref_cds",
",",
"est_cds",
")",
":",
"ref_dists",
"=",
"pdist",
"(",
"ref_cds",
")",
"est_dists",
"=",
"pdist",
"(",
"est_cds",
")",
"return",
"np",
".",
"sqrt",
"(",
"(",
"(",
"ref_dists",
"-",
"est_dists",
")",
"**",
"2",
")",
... | Root-mean-squared-difference | [
"Root",
"-",
"mean",
"-",
"squared",
"-",
"difference"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/bootstrap.py#L237-L243 | train | 63,158 |
kgori/treeCl | treeCl/bootstrap.py | OptimiseDistanceFit.levenberg_marquardt | def levenberg_marquardt(self, start_x=None, damping=1.0e-3, tolerance=1.0e-6):
"""
Optimise value of x using levenberg marquardt
"""
if start_x is None:
start_x = self._analytical_fitter.fit(self._c)
return optimise_levenberg_marquardt(start_x, self._a, self._c, toler... | python | def levenberg_marquardt(self, start_x=None, damping=1.0e-3, tolerance=1.0e-6):
"""
Optimise value of x using levenberg marquardt
"""
if start_x is None:
start_x = self._analytical_fitter.fit(self._c)
return optimise_levenberg_marquardt(start_x, self._a, self._c, toler... | [
"def",
"levenberg_marquardt",
"(",
"self",
",",
"start_x",
"=",
"None",
",",
"damping",
"=",
"1.0e-3",
",",
"tolerance",
"=",
"1.0e-6",
")",
":",
"if",
"start_x",
"is",
"None",
":",
"start_x",
"=",
"self",
".",
"_analytical_fitter",
".",
"fit",
"(",
"sel... | Optimise value of x using levenberg marquardt | [
"Optimise",
"value",
"of",
"x",
"using",
"levenberg",
"marquardt"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/bootstrap.py#L316-L322 | train | 63,159 |
kgori/treeCl | treeCl/bootstrap.py | AnalyticalFit._make_A_and_part_of_b_adjacent | def _make_A_and_part_of_b_adjacent(self, ref_crds):
"""
Make A and part of b. See docstring of this class
for answer to "What are A and b?"
"""
rot = self._rotate_rows(ref_crds)
A = 2*(rot - ref_crds)
partial_b = (rot**2 - ref_crds**2).sum(1)
return A, par... | python | def _make_A_and_part_of_b_adjacent(self, ref_crds):
"""
Make A and part of b. See docstring of this class
for answer to "What are A and b?"
"""
rot = self._rotate_rows(ref_crds)
A = 2*(rot - ref_crds)
partial_b = (rot**2 - ref_crds**2).sum(1)
return A, par... | [
"def",
"_make_A_and_part_of_b_adjacent",
"(",
"self",
",",
"ref_crds",
")",
":",
"rot",
"=",
"self",
".",
"_rotate_rows",
"(",
"ref_crds",
")",
"A",
"=",
"2",
"*",
"(",
"rot",
"-",
"ref_crds",
")",
"partial_b",
"=",
"(",
"rot",
"**",
"2",
"-",
"ref_crd... | Make A and part of b. See docstring of this class
for answer to "What are A and b?" | [
"Make",
"A",
"and",
"part",
"of",
"b",
".",
"See",
"docstring",
"of",
"this",
"class",
"for",
"answer",
"to",
"What",
"are",
"A",
"and",
"b?"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/bootstrap.py#L442-L450 | train | 63,160 |
pudo/jsonmapping | jsonmapping/elastic.py | generate_schema_mapping | def generate_schema_mapping(resolver, schema_uri, depth=1):
""" Try and recursively iterate a JSON schema and to generate an ES mapping
that encasulates it. """
visitor = SchemaVisitor({'$ref': schema_uri}, resolver)
return _generate_schema_mapping(visitor, set(), depth) | python | def generate_schema_mapping(resolver, schema_uri, depth=1):
""" Try and recursively iterate a JSON schema and to generate an ES mapping
that encasulates it. """
visitor = SchemaVisitor({'$ref': schema_uri}, resolver)
return _generate_schema_mapping(visitor, set(), depth) | [
"def",
"generate_schema_mapping",
"(",
"resolver",
",",
"schema_uri",
",",
"depth",
"=",
"1",
")",
":",
"visitor",
"=",
"SchemaVisitor",
"(",
"{",
"'$ref'",
":",
"schema_uri",
"}",
",",
"resolver",
")",
"return",
"_generate_schema_mapping",
"(",
"visitor",
","... | Try and recursively iterate a JSON schema and to generate an ES mapping
that encasulates it. | [
"Try",
"and",
"recursively",
"iterate",
"a",
"JSON",
"schema",
"and",
"to",
"generate",
"an",
"ES",
"mapping",
"that",
"encasulates",
"it",
"."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/elastic.py#L6-L10 | train | 63,161 |
kgori/treeCl | treeCl/tasks.py | phyml_task | def phyml_task(alignment_file, model, **kwargs):
"""
Kwargs are passed to the Phyml process command line
"""
import re
fl = os.path.abspath(alignment_file)
ph = Phyml(verbose=False)
if model in ['JC69', 'K80', 'F81', 'F84', 'HKY85', 'TN93', 'GTR']:
datatype = 'nt'
elif re.search(... | python | def phyml_task(alignment_file, model, **kwargs):
"""
Kwargs are passed to the Phyml process command line
"""
import re
fl = os.path.abspath(alignment_file)
ph = Phyml(verbose=False)
if model in ['JC69', 'K80', 'F81', 'F84', 'HKY85', 'TN93', 'GTR']:
datatype = 'nt'
elif re.search(... | [
"def",
"phyml_task",
"(",
"alignment_file",
",",
"model",
",",
"*",
"*",
"kwargs",
")",
":",
"import",
"re",
"fl",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"alignment_file",
")",
"ph",
"=",
"Phyml",
"(",
"verbose",
"=",
"False",
")",
"if",
"model... | Kwargs are passed to the Phyml process command line | [
"Kwargs",
"are",
"passed",
"to",
"the",
"Phyml",
"process",
"command",
"line"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/tasks.py#L111-L145 | train | 63,162 |
pudo/jsonmapping | jsonmapping/util.py | validate_mapping | def validate_mapping(mapping):
""" Validate a mapping configuration file against the relevant schema. """
file_path = os.path.join(os.path.dirname(__file__),
'schemas', 'mapping.json')
with open(file_path, 'r') as fh:
validator = Draft4Validator(json.load(fh))
va... | python | def validate_mapping(mapping):
""" Validate a mapping configuration file against the relevant schema. """
file_path = os.path.join(os.path.dirname(__file__),
'schemas', 'mapping.json')
with open(file_path, 'r') as fh:
validator = Draft4Validator(json.load(fh))
va... | [
"def",
"validate_mapping",
"(",
"mapping",
")",
":",
"file_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
",",
"'schemas'",
",",
"'mapping.json'",
")",
"with",
"open",
"(",
"file_path",
",",
"'... | Validate a mapping configuration file against the relevant schema. | [
"Validate",
"a",
"mapping",
"configuration",
"file",
"against",
"the",
"relevant",
"schema",
"."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/util.py#L7-L14 | train | 63,163 |
kgori/treeCl | treeCl/plotter.py | Plotter.heatmap | def heatmap(self, partition=None, cmap=CM.Blues):
""" Plots a visual representation of a distance matrix """
if isinstance(self.dm, DistanceMatrix):
length = self.dm.values.shape[0]
else:
length = self.dm.shape[0]
datamax = float(np.abs(self.dm).max())
fi... | python | def heatmap(self, partition=None, cmap=CM.Blues):
""" Plots a visual representation of a distance matrix """
if isinstance(self.dm, DistanceMatrix):
length = self.dm.values.shape[0]
else:
length = self.dm.shape[0]
datamax = float(np.abs(self.dm).max())
fi... | [
"def",
"heatmap",
"(",
"self",
",",
"partition",
"=",
"None",
",",
"cmap",
"=",
"CM",
".",
"Blues",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"dm",
",",
"DistanceMatrix",
")",
":",
"length",
"=",
"self",
".",
"dm",
".",
"values",
".",
"shape"... | Plots a visual representation of a distance matrix | [
"Plots",
"a",
"visual",
"representation",
"of",
"a",
"distance",
"matrix"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/plotter.py#L249-L274 | train | 63,164 |
kgori/treeCl | treeCl/concatenation.py | Concatenation.get_tree_collection_strings | def get_tree_collection_strings(self, scale=1, guide_tree=None):
""" Function to get input strings for tree_collection
tree_collection needs distvar, genome_map and labels -
these are returned in the order above
"""
records = [self.collection[i] for i in self.indices]
ret... | python | def get_tree_collection_strings(self, scale=1, guide_tree=None):
""" Function to get input strings for tree_collection
tree_collection needs distvar, genome_map and labels -
these are returned in the order above
"""
records = [self.collection[i] for i in self.indices]
ret... | [
"def",
"get_tree_collection_strings",
"(",
"self",
",",
"scale",
"=",
"1",
",",
"guide_tree",
"=",
"None",
")",
":",
"records",
"=",
"[",
"self",
".",
"collection",
"[",
"i",
"]",
"for",
"i",
"in",
"self",
".",
"indices",
"]",
"return",
"TreeCollectionTa... | Function to get input strings for tree_collection
tree_collection needs distvar, genome_map and labels -
these are returned in the order above | [
"Function",
"to",
"get",
"input",
"strings",
"for",
"tree_collection",
"tree_collection",
"needs",
"distvar",
"genome_map",
"and",
"labels",
"-",
"these",
"are",
"returned",
"in",
"the",
"order",
"above"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/concatenation.py#L90-L96 | train | 63,165 |
getsentry/libsourcemap | libsourcemap/highlevel.py | from_json | def from_json(buffer, auto_flatten=True, raise_for_index=True):
"""Parses a JSON string into either a view or an index. If auto flatten
is enabled a sourcemap index that does not contain external references is
automatically flattened into a view. By default if an index would be
returned an `IndexedSou... | python | def from_json(buffer, auto_flatten=True, raise_for_index=True):
"""Parses a JSON string into either a view or an index. If auto flatten
is enabled a sourcemap index that does not contain external references is
automatically flattened into a view. By default if an index would be
returned an `IndexedSou... | [
"def",
"from_json",
"(",
"buffer",
",",
"auto_flatten",
"=",
"True",
",",
"raise_for_index",
"=",
"True",
")",
":",
"buffer",
"=",
"to_bytes",
"(",
"buffer",
")",
"view_out",
"=",
"_ffi",
".",
"new",
"(",
"'lsm_view_t **'",
")",
"index_out",
"=",
"_ffi",
... | Parses a JSON string into either a view or an index. If auto flatten
is enabled a sourcemap index that does not contain external references is
automatically flattened into a view. By default if an index would be
returned an `IndexedSourceMap` error is raised instead which holds the
index. | [
"Parses",
"a",
"JSON",
"string",
"into",
"either",
"a",
"view",
"or",
"an",
"index",
".",
"If",
"auto",
"flatten",
"is",
"enabled",
"a",
"sourcemap",
"index",
"that",
"does",
"not",
"contain",
"external",
"references",
"is",
"automatically",
"flattened",
"in... | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L62-L89 | train | 63,166 |
getsentry/libsourcemap | libsourcemap/highlevel.py | View.from_memdb | def from_memdb(buffer):
"""Creates a sourcemap view from MemDB bytes."""
buffer = to_bytes(buffer)
return View._from_ptr(rustcall(
_lib.lsm_view_from_memdb,
buffer, len(buffer))) | python | def from_memdb(buffer):
"""Creates a sourcemap view from MemDB bytes."""
buffer = to_bytes(buffer)
return View._from_ptr(rustcall(
_lib.lsm_view_from_memdb,
buffer, len(buffer))) | [
"def",
"from_memdb",
"(",
"buffer",
")",
":",
"buffer",
"=",
"to_bytes",
"(",
"buffer",
")",
"return",
"View",
".",
"_from_ptr",
"(",
"rustcall",
"(",
"_lib",
".",
"lsm_view_from_memdb",
",",
"buffer",
",",
"len",
"(",
"buffer",
")",
")",
")"
] | Creates a sourcemap view from MemDB bytes. | [
"Creates",
"a",
"sourcemap",
"view",
"from",
"MemDB",
"bytes",
"."
] | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L114-L119 | train | 63,167 |
getsentry/libsourcemap | libsourcemap/highlevel.py | View.from_memdb_file | def from_memdb_file(path):
"""Creates a sourcemap view from MemDB at a given file."""
path = to_bytes(path)
return View._from_ptr(rustcall(_lib.lsm_view_from_memdb_file, path)) | python | def from_memdb_file(path):
"""Creates a sourcemap view from MemDB at a given file."""
path = to_bytes(path)
return View._from_ptr(rustcall(_lib.lsm_view_from_memdb_file, path)) | [
"def",
"from_memdb_file",
"(",
"path",
")",
":",
"path",
"=",
"to_bytes",
"(",
"path",
")",
"return",
"View",
".",
"_from_ptr",
"(",
"rustcall",
"(",
"_lib",
".",
"lsm_view_from_memdb_file",
",",
"path",
")",
")"
] | Creates a sourcemap view from MemDB at a given file. | [
"Creates",
"a",
"sourcemap",
"view",
"from",
"MemDB",
"at",
"a",
"given",
"file",
"."
] | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L122-L125 | train | 63,168 |
getsentry/libsourcemap | libsourcemap/highlevel.py | View.dump_memdb | def dump_memdb(self, with_source_contents=True, with_names=True):
"""Dumps a sourcemap in MemDB format into bytes."""
len_out = _ffi.new('unsigned int *')
buf = rustcall(
_lib.lsm_view_dump_memdb,
self._get_ptr(), len_out,
with_source_contents, with_names)
... | python | def dump_memdb(self, with_source_contents=True, with_names=True):
"""Dumps a sourcemap in MemDB format into bytes."""
len_out = _ffi.new('unsigned int *')
buf = rustcall(
_lib.lsm_view_dump_memdb,
self._get_ptr(), len_out,
with_source_contents, with_names)
... | [
"def",
"dump_memdb",
"(",
"self",
",",
"with_source_contents",
"=",
"True",
",",
"with_names",
"=",
"True",
")",
":",
"len_out",
"=",
"_ffi",
".",
"new",
"(",
"'unsigned int *'",
")",
"buf",
"=",
"rustcall",
"(",
"_lib",
".",
"lsm_view_dump_memdb",
",",
"s... | Dumps a sourcemap in MemDB format into bytes. | [
"Dumps",
"a",
"sourcemap",
"in",
"MemDB",
"format",
"into",
"bytes",
"."
] | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L138-L149 | train | 63,169 |
getsentry/libsourcemap | libsourcemap/highlevel.py | View.lookup_token | def lookup_token(self, line, col):
"""Given a minified location, this tries to locate the closest
token that is a match. Returns `None` if no match can be found.
"""
# Silently ignore underflows
if line < 0 or col < 0:
return None
tok_out = _ffi.new('lsm_toke... | python | def lookup_token(self, line, col):
"""Given a minified location, this tries to locate the closest
token that is a match. Returns `None` if no match can be found.
"""
# Silently ignore underflows
if line < 0 or col < 0:
return None
tok_out = _ffi.new('lsm_toke... | [
"def",
"lookup_token",
"(",
"self",
",",
"line",
",",
"col",
")",
":",
"# Silently ignore underflows",
"if",
"line",
"<",
"0",
"or",
"col",
"<",
"0",
":",
"return",
"None",
"tok_out",
"=",
"_ffi",
".",
"new",
"(",
"'lsm_token_t *'",
")",
"if",
"rustcall"... | Given a minified location, this tries to locate the closest
token that is a match. Returns `None` if no match can be found. | [
"Given",
"a",
"minified",
"location",
"this",
"tries",
"to",
"locate",
"the",
"closest",
"token",
"that",
"is",
"a",
"match",
".",
"Returns",
"None",
"if",
"no",
"match",
"can",
"be",
"found",
"."
] | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L151-L161 | train | 63,170 |
getsentry/libsourcemap | libsourcemap/highlevel.py | View.get_original_function_name | def get_original_function_name(self, line, col, minified_name,
minified_source):
"""Given a token location and a minified function name and the
minified source file this returns the original function name if it
can be found of the minified function in scope.
... | python | def get_original_function_name(self, line, col, minified_name,
minified_source):
"""Given a token location and a minified function name and the
minified source file this returns the original function name if it
can be found of the minified function in scope.
... | [
"def",
"get_original_function_name",
"(",
"self",
",",
"line",
",",
"col",
",",
"minified_name",
",",
"minified_source",
")",
":",
"# Silently ignore underflows",
"if",
"line",
"<",
"0",
"or",
"col",
"<",
"0",
":",
"return",
"None",
"minified_name",
"=",
"mini... | Given a token location and a minified function name and the
minified source file this returns the original function name if it
can be found of the minified function in scope. | [
"Given",
"a",
"token",
"location",
"and",
"a",
"minified",
"function",
"name",
"and",
"the",
"minified",
"source",
"file",
"this",
"returns",
"the",
"original",
"function",
"name",
"if",
"it",
"can",
"be",
"found",
"of",
"the",
"minified",
"function",
"in",
... | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L163-L185 | train | 63,171 |
getsentry/libsourcemap | libsourcemap/highlevel.py | View.get_source_contents | def get_source_contents(self, src_id):
"""Given a source ID this returns the embedded sourcecode if there
is. The sourcecode is returned as UTF-8 bytes for more efficient
processing.
"""
len_out = _ffi.new('unsigned int *')
must_free = _ffi.new('int *')
rv = rust... | python | def get_source_contents(self, src_id):
"""Given a source ID this returns the embedded sourcecode if there
is. The sourcecode is returned as UTF-8 bytes for more efficient
processing.
"""
len_out = _ffi.new('unsigned int *')
must_free = _ffi.new('int *')
rv = rust... | [
"def",
"get_source_contents",
"(",
"self",
",",
"src_id",
")",
":",
"len_out",
"=",
"_ffi",
".",
"new",
"(",
"'unsigned int *'",
")",
"must_free",
"=",
"_ffi",
".",
"new",
"(",
"'int *'",
")",
"rv",
"=",
"rustcall",
"(",
"_lib",
".",
"lsm_view_get_source_c... | Given a source ID this returns the embedded sourcecode if there
is. The sourcecode is returned as UTF-8 bytes for more efficient
processing. | [
"Given",
"a",
"source",
"ID",
"this",
"returns",
"the",
"embedded",
"sourcecode",
"if",
"there",
"is",
".",
"The",
"sourcecode",
"is",
"returned",
"as",
"UTF",
"-",
"8",
"bytes",
"for",
"more",
"efficient",
"processing",
"."
] | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L187-L201 | train | 63,172 |
getsentry/libsourcemap | libsourcemap/highlevel.py | View.has_source_contents | def has_source_contents(self, src_id):
"""Checks if some sources exist."""
return bool(rustcall(_lib.lsm_view_has_source_contents,
self._get_ptr(), src_id)) | python | def has_source_contents(self, src_id):
"""Checks if some sources exist."""
return bool(rustcall(_lib.lsm_view_has_source_contents,
self._get_ptr(), src_id)) | [
"def",
"has_source_contents",
"(",
"self",
",",
"src_id",
")",
":",
"return",
"bool",
"(",
"rustcall",
"(",
"_lib",
".",
"lsm_view_has_source_contents",
",",
"self",
".",
"_get_ptr",
"(",
")",
",",
"src_id",
")",
")"
] | Checks if some sources exist. | [
"Checks",
"if",
"some",
"sources",
"exist",
"."
] | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L203-L206 | train | 63,173 |
getsentry/libsourcemap | libsourcemap/highlevel.py | View.get_source_name | def get_source_name(self, src_id):
"""Returns the name of the given source."""
len_out = _ffi.new('unsigned int *')
rv = rustcall(_lib.lsm_view_get_source_name,
self._get_ptr(), src_id, len_out)
if rv:
return decode_rust_str(rv, len_out[0]) | python | def get_source_name(self, src_id):
"""Returns the name of the given source."""
len_out = _ffi.new('unsigned int *')
rv = rustcall(_lib.lsm_view_get_source_name,
self._get_ptr(), src_id, len_out)
if rv:
return decode_rust_str(rv, len_out[0]) | [
"def",
"get_source_name",
"(",
"self",
",",
"src_id",
")",
":",
"len_out",
"=",
"_ffi",
".",
"new",
"(",
"'unsigned int *'",
")",
"rv",
"=",
"rustcall",
"(",
"_lib",
".",
"lsm_view_get_source_name",
",",
"self",
".",
"_get_ptr",
"(",
")",
",",
"src_id",
... | Returns the name of the given source. | [
"Returns",
"the",
"name",
"of",
"the",
"given",
"source",
"."
] | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L208-L214 | train | 63,174 |
getsentry/libsourcemap | libsourcemap/highlevel.py | View.iter_sources | def iter_sources(self):
"""Iterates over all source names and IDs."""
for src_id in xrange(self.get_source_count()):
yield src_id, self.get_source_name(src_id) | python | def iter_sources(self):
"""Iterates over all source names and IDs."""
for src_id in xrange(self.get_source_count()):
yield src_id, self.get_source_name(src_id) | [
"def",
"iter_sources",
"(",
"self",
")",
":",
"for",
"src_id",
"in",
"xrange",
"(",
"self",
".",
"get_source_count",
"(",
")",
")",
":",
"yield",
"src_id",
",",
"self",
".",
"get_source_name",
"(",
"src_id",
")"
] | Iterates over all source names and IDs. | [
"Iterates",
"over",
"all",
"source",
"names",
"and",
"IDs",
"."
] | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L221-L224 | train | 63,175 |
getsentry/libsourcemap | libsourcemap/highlevel.py | Index.from_json | def from_json(buffer):
"""Creates an index from a JSON string."""
buffer = to_bytes(buffer)
return Index._from_ptr(rustcall(
_lib.lsm_index_from_json,
buffer, len(buffer))) | python | def from_json(buffer):
"""Creates an index from a JSON string."""
buffer = to_bytes(buffer)
return Index._from_ptr(rustcall(
_lib.lsm_index_from_json,
buffer, len(buffer))) | [
"def",
"from_json",
"(",
"buffer",
")",
":",
"buffer",
"=",
"to_bytes",
"(",
"buffer",
")",
"return",
"Index",
".",
"_from_ptr",
"(",
"rustcall",
"(",
"_lib",
".",
"lsm_index_from_json",
",",
"buffer",
",",
"len",
"(",
"buffer",
")",
")",
")"
] | Creates an index from a JSON string. | [
"Creates",
"an",
"index",
"from",
"a",
"JSON",
"string",
"."
] | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L253-L258 | train | 63,176 |
getsentry/libsourcemap | libsourcemap/highlevel.py | Index.into_view | def into_view(self):
"""Converts the index into a view"""
try:
return View._from_ptr(rustcall(
_lib.lsm_index_into_view,
self._get_ptr()))
finally:
self._ptr = None | python | def into_view(self):
"""Converts the index into a view"""
try:
return View._from_ptr(rustcall(
_lib.lsm_index_into_view,
self._get_ptr()))
finally:
self._ptr = None | [
"def",
"into_view",
"(",
"self",
")",
":",
"try",
":",
"return",
"View",
".",
"_from_ptr",
"(",
"rustcall",
"(",
"_lib",
".",
"lsm_index_into_view",
",",
"self",
".",
"_get_ptr",
"(",
")",
")",
")",
"finally",
":",
"self",
".",
"_ptr",
"=",
"None"
] | Converts the index into a view | [
"Converts",
"the",
"index",
"into",
"a",
"view"
] | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L276-L283 | train | 63,177 |
getsentry/libsourcemap | libsourcemap/highlevel.py | ProguardView.from_path | def from_path(filename):
"""Creates a sourcemap view from a file path."""
filename = to_bytes(filename)
if NULL_BYTE in filename:
raise ValueError('null byte in path')
return ProguardView._from_ptr(rustcall(
_lib.lsm_proguard_mapping_from_path,
filenam... | python | def from_path(filename):
"""Creates a sourcemap view from a file path."""
filename = to_bytes(filename)
if NULL_BYTE in filename:
raise ValueError('null byte in path')
return ProguardView._from_ptr(rustcall(
_lib.lsm_proguard_mapping_from_path,
filenam... | [
"def",
"from_path",
"(",
"filename",
")",
":",
"filename",
"=",
"to_bytes",
"(",
"filename",
")",
"if",
"NULL_BYTE",
"in",
"filename",
":",
"raise",
"ValueError",
"(",
"'null byte in path'",
")",
"return",
"ProguardView",
".",
"_from_ptr",
"(",
"rustcall",
"("... | Creates a sourcemap view from a file path. | [
"Creates",
"a",
"sourcemap",
"view",
"from",
"a",
"file",
"path",
"."
] | 94b5a34814fafee9dc23da8ec0ccca77f30e3370 | https://github.com/getsentry/libsourcemap/blob/94b5a34814fafee9dc23da8ec0ccca77f30e3370/libsourcemap/highlevel.py#L311-L318 | train | 63,178 |
pudo/jsonmapping | jsonmapping/mapper.py | Mapper.apply | def apply(self, data):
""" Apply the given mapping to ``data``, recursively. The return type
is a tuple of a boolean and the resulting data element. The boolean
indicates whether any values were mapped in the child nodes of the
mapping. It is used to skip optional branches of the object ... | python | def apply(self, data):
""" Apply the given mapping to ``data``, recursively. The return type
is a tuple of a boolean and the resulting data element. The boolean
indicates whether any values were mapped in the child nodes of the
mapping. It is used to skip optional branches of the object ... | [
"def",
"apply",
"(",
"self",
",",
"data",
")",
":",
"if",
"self",
".",
"visitor",
".",
"is_object",
":",
"obj",
"=",
"{",
"}",
"if",
"self",
".",
"visitor",
".",
"parent",
"is",
"None",
":",
"obj",
"[",
"'$schema'",
"]",
"=",
"self",
".",
"visito... | Apply the given mapping to ``data``, recursively. The return type
is a tuple of a boolean and the resulting data element. The boolean
indicates whether any values were mapped in the child nodes of the
mapping. It is used to skip optional branches of the object graph. | [
"Apply",
"the",
"given",
"mapping",
"to",
"data",
"recursively",
".",
"The",
"return",
"type",
"is",
"a",
"tuple",
"of",
"a",
"boolean",
"and",
"the",
"resulting",
"data",
"element",
".",
"The",
"boolean",
"indicates",
"whether",
"any",
"values",
"were",
"... | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/mapper.py#L52-L79 | train | 63,179 |
kgori/treeCl | treeCl/utils/translator.py | Translator.translate | def translate(self, text):
""" Translate text, returns the modified text. """
# Reset substitution counter
self.count = 0
# Process text
return self._make_regex().sub(self, text) | python | def translate(self, text):
""" Translate text, returns the modified text. """
# Reset substitution counter
self.count = 0
# Process text
return self._make_regex().sub(self, text) | [
"def",
"translate",
"(",
"self",
",",
"text",
")",
":",
"# Reset substitution counter",
"self",
".",
"count",
"=",
"0",
"# Process text",
"return",
"self",
".",
"_make_regex",
"(",
")",
".",
"sub",
"(",
"self",
",",
"text",
")"
] | Translate text, returns the modified text. | [
"Translate",
"text",
"returns",
"the",
"modified",
"text",
"."
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/utils/translator.py#L25-L32 | train | 63,180 |
kgori/treeCl | treeCl/clustering.py | Spectral.cluster | def cluster(self, n, embed_dim=None, algo=spectral.SPECTRAL, method=methods.KMEANS):
"""
Cluster the embedded coordinates using spectral clustering
Parameters
----------
n: int
The number of clusters to return
embed_dim: ... | python | def cluster(self, n, embed_dim=None, algo=spectral.SPECTRAL, method=methods.KMEANS):
"""
Cluster the embedded coordinates using spectral clustering
Parameters
----------
n: int
The number of clusters to return
embed_dim: ... | [
"def",
"cluster",
"(",
"self",
",",
"n",
",",
"embed_dim",
"=",
"None",
",",
"algo",
"=",
"spectral",
".",
"SPECTRAL",
",",
"method",
"=",
"methods",
".",
"KMEANS",
")",
":",
"if",
"n",
"==",
"1",
":",
"return",
"Partition",
"(",
"[",
"1",
"]",
"... | Cluster the embedded coordinates using spectral clustering
Parameters
----------
n: int
The number of clusters to return
embed_dim: int
The dimensionality of the underlying coordinates
... | [
"Cluster",
"the",
"embedded",
"coordinates",
"using",
"spectral",
"clustering"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/clustering.py#L234-L279 | train | 63,181 |
kgori/treeCl | treeCl/clustering.py | Spectral.spectral_embedding | def spectral_embedding(self, n):
"""
Embed the points using spectral decomposition of the laplacian of
the affinity matrix
Parameters
----------
n: int
The number of dimensions
"""
coords = spectral_embedding(self._affinity, n)
... | python | def spectral_embedding(self, n):
"""
Embed the points using spectral decomposition of the laplacian of
the affinity matrix
Parameters
----------
n: int
The number of dimensions
"""
coords = spectral_embedding(self._affinity, n)
... | [
"def",
"spectral_embedding",
"(",
"self",
",",
"n",
")",
":",
"coords",
"=",
"spectral_embedding",
"(",
"self",
".",
"_affinity",
",",
"n",
")",
"return",
"CoordinateMatrix",
"(",
"normalise_rows",
"(",
"coords",
")",
")"
] | Embed the points using spectral decomposition of the laplacian of
the affinity matrix
Parameters
----------
n: int
The number of dimensions | [
"Embed",
"the",
"points",
"using",
"spectral",
"decomposition",
"of",
"the",
"laplacian",
"of",
"the",
"affinity",
"matrix"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/clustering.py#L281-L292 | train | 63,182 |
kgori/treeCl | treeCl/clustering.py | Spectral.kpca_embedding | def kpca_embedding(self, n):
"""
Embed the points using kernel PCA of the affinity matrix
Parameters
----------
n: int
The number of dimensions
"""
return self.dm.embedding(n, 'kpca', affinity_matrix=self._affinity) | python | def kpca_embedding(self, n):
"""
Embed the points using kernel PCA of the affinity matrix
Parameters
----------
n: int
The number of dimensions
"""
return self.dm.embedding(n, 'kpca', affinity_matrix=self._affinity) | [
"def",
"kpca_embedding",
"(",
"self",
",",
"n",
")",
":",
"return",
"self",
".",
"dm",
".",
"embedding",
"(",
"n",
",",
"'kpca'",
",",
"affinity_matrix",
"=",
"self",
".",
"_affinity",
")"
] | Embed the points using kernel PCA of the affinity matrix
Parameters
----------
n: int
The number of dimensions | [
"Embed",
"the",
"points",
"using",
"kernel",
"PCA",
"of",
"the",
"affinity",
"matrix"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/clustering.py#L309-L318 | train | 63,183 |
kgori/treeCl | treeCl/clustering.py | MultidimensionalScaling.cluster | def cluster(self, n, embed_dim=None, algo=mds.CLASSICAL, method=methods.KMEANS):
"""
Cluster the embedded coordinates using multidimensional scaling
Parameters
----------
n: int
The number of clusters to return
embed_dim ... | python | def cluster(self, n, embed_dim=None, algo=mds.CLASSICAL, method=methods.KMEANS):
"""
Cluster the embedded coordinates using multidimensional scaling
Parameters
----------
n: int
The number of clusters to return
embed_dim ... | [
"def",
"cluster",
"(",
"self",
",",
"n",
",",
"embed_dim",
"=",
"None",
",",
"algo",
"=",
"mds",
".",
"CLASSICAL",
",",
"method",
"=",
"methods",
".",
"KMEANS",
")",
":",
"if",
"n",
"==",
"1",
":",
"return",
"Partition",
"(",
"[",
"1",
"]",
"*",
... | Cluster the embedded coordinates using multidimensional scaling
Parameters
----------
n: int
The number of clusters to return
embed_dim int
The dimensionality of the underlying coordinates
... | [
"Cluster",
"the",
"embedded",
"coordinates",
"using",
"multidimensional",
"scaling"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/clustering.py#L329-L371 | train | 63,184 |
kgori/treeCl | treeCl/wrappers/abstract_wrapper.py | AbstractWrapper._log_thread | def _log_thread(self, pipe, queue):
"""
Start a thread logging output from pipe
"""
# thread function to log subprocess output (LOG is a queue)
def enqueue_output(out, q):
for line in iter(out.readline, b''):
q.put(line.rstrip())
out.close... | python | def _log_thread(self, pipe, queue):
"""
Start a thread logging output from pipe
"""
# thread function to log subprocess output (LOG is a queue)
def enqueue_output(out, q):
for line in iter(out.readline, b''):
q.put(line.rstrip())
out.close... | [
"def",
"_log_thread",
"(",
"self",
",",
"pipe",
",",
"queue",
")",
":",
"# thread function to log subprocess output (LOG is a queue)",
"def",
"enqueue_output",
"(",
"out",
",",
"q",
")",
":",
"for",
"line",
"in",
"iter",
"(",
"out",
".",
"readline",
",",
"b''"... | Start a thread logging output from pipe | [
"Start",
"a",
"thread",
"logging",
"output",
"from",
"pipe"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/wrappers/abstract_wrapper.py#L143-L159 | train | 63,185 |
kgori/treeCl | treeCl/wrappers/abstract_wrapper.py | AbstractWrapper._search_for_executable | def _search_for_executable(self, executable):
"""
Search for file give in "executable". If it is not found, we try the environment PATH.
Returns either the absolute path to the found executable, or None if the executable
couldn't be found.
"""
if os.path.isfile(executable... | python | def _search_for_executable(self, executable):
"""
Search for file give in "executable". If it is not found, we try the environment PATH.
Returns either the absolute path to the found executable, or None if the executable
couldn't be found.
"""
if os.path.isfile(executable... | [
"def",
"_search_for_executable",
"(",
"self",
",",
"executable",
")",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"executable",
")",
":",
"return",
"os",
".",
"path",
".",
"abspath",
"(",
"executable",
")",
"else",
":",
"envpath",
"=",
"os",
".",... | Search for file give in "executable". If it is not found, we try the environment PATH.
Returns either the absolute path to the found executable, or None if the executable
couldn't be found. | [
"Search",
"for",
"file",
"give",
"in",
"executable",
".",
"If",
"it",
"is",
"not",
"found",
"we",
"try",
"the",
"environment",
"PATH",
".",
"Returns",
"either",
"the",
"absolute",
"path",
"to",
"the",
"found",
"executable",
"or",
"None",
"if",
"the",
"ex... | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/wrappers/abstract_wrapper.py#L161-L176 | train | 63,186 |
fedelemantuano/tika-app-python | tikapp/tikapp.py | TikaApp._command_template | def _command_template(self, switches, objectInput=None):
"""Template for Tika app commands
Args:
switches (list): list of switches to Tika app Jar
objectInput (object): file object/standard input to analyze
Return:
Standard output data (unicode Python 2, str... | python | def _command_template(self, switches, objectInput=None):
"""Template for Tika app commands
Args:
switches (list): list of switches to Tika app Jar
objectInput (object): file object/standard input to analyze
Return:
Standard output data (unicode Python 2, str... | [
"def",
"_command_template",
"(",
"self",
",",
"switches",
",",
"objectInput",
"=",
"None",
")",
":",
"command",
"=",
"[",
"\"java\"",
",",
"\"-jar\"",
",",
"self",
".",
"file_jar",
",",
"\"-eUTF-8\"",
"]",
"if",
"self",
".",
"memory_allocation",
":",
"comm... | Template for Tika app commands
Args:
switches (list): list of switches to Tika app Jar
objectInput (object): file object/standard input to analyze
Return:
Standard output data (unicode Python 2, str Python 3) | [
"Template",
"for",
"Tika",
"app",
"commands"
] | 9a462aa611af2032306c78a9c996c8545288c212 | https://github.com/fedelemantuano/tika-app-python/blob/9a462aa611af2032306c78a9c996c8545288c212/tikapp/tikapp.py#L76-L112 | train | 63,187 |
fedelemantuano/tika-app-python | tikapp/tikapp.py | TikaApp.detect_content_type | def detect_content_type(self, path=None, payload=None, objectInput=None):
"""
Return the content type of passed file or payload.
Args:
path (string): Path of file to analyze
payload (string): Payload base64 to analyze
objectInput (object): file object/standar... | python | def detect_content_type(self, path=None, payload=None, objectInput=None):
"""
Return the content type of passed file or payload.
Args:
path (string): Path of file to analyze
payload (string): Payload base64 to analyze
objectInput (object): file object/standar... | [
"def",
"detect_content_type",
"(",
"self",
",",
"path",
"=",
"None",
",",
"payload",
"=",
"None",
",",
"objectInput",
"=",
"None",
")",
":",
"# From Python detection content type from stdin doesn't work TO FIX",
"if",
"objectInput",
":",
"message",
"=",
"\"Detection c... | Return the content type of passed file or payload.
Args:
path (string): Path of file to analyze
payload (string): Payload base64 to analyze
objectInput (object): file object/standard input to analyze
Returns:
content type of file (string) | [
"Return",
"the",
"content",
"type",
"of",
"passed",
"file",
"or",
"payload",
"."
] | 9a462aa611af2032306c78a9c996c8545288c212 | https://github.com/fedelemantuano/tika-app-python/blob/9a462aa611af2032306c78a9c996c8545288c212/tikapp/tikapp.py#L119-L140 | train | 63,188 |
fedelemantuano/tika-app-python | tikapp/tikapp.py | TikaApp.extract_only_content | def extract_only_content(self, path=None, payload=None, objectInput=None):
"""
Return only the text content of passed file.
These parameters are in OR. Only one of them can be analyzed.
Args:
path (string): Path of file to analyze
payload (string): Payload base64... | python | def extract_only_content(self, path=None, payload=None, objectInput=None):
"""
Return only the text content of passed file.
These parameters are in OR. Only one of them can be analyzed.
Args:
path (string): Path of file to analyze
payload (string): Payload base64... | [
"def",
"extract_only_content",
"(",
"self",
",",
"path",
"=",
"None",
",",
"payload",
"=",
"None",
",",
"objectInput",
"=",
"None",
")",
":",
"if",
"objectInput",
":",
"switches",
"=",
"[",
"\"-t\"",
"]",
"result",
"=",
"self",
".",
"_command_template",
... | Return only the text content of passed file.
These parameters are in OR. Only one of them can be analyzed.
Args:
path (string): Path of file to analyze
payload (string): Payload base64 to analyze
objectInput (object): file object/standard input to analyze
Re... | [
"Return",
"only",
"the",
"text",
"content",
"of",
"passed",
"file",
".",
"These",
"parameters",
"are",
"in",
"OR",
".",
"Only",
"one",
"of",
"them",
"can",
"be",
"analyzed",
"."
] | 9a462aa611af2032306c78a9c996c8545288c212 | https://github.com/fedelemantuano/tika-app-python/blob/9a462aa611af2032306c78a9c996c8545288c212/tikapp/tikapp.py#L143-L164 | train | 63,189 |
fedelemantuano/tika-app-python | tikapp/tikapp.py | TikaApp.extract_all_content | def extract_all_content(
self,
path=None,
payload=None,
objectInput=None,
pretty_print=False,
convert_to_obj=False,
):
"""
This function returns a JSON of all contents and
metadata of passed file
Args:
path (string): Path o... | python | def extract_all_content(
self,
path=None,
payload=None,
objectInput=None,
pretty_print=False,
convert_to_obj=False,
):
"""
This function returns a JSON of all contents and
metadata of passed file
Args:
path (string): Path o... | [
"def",
"extract_all_content",
"(",
"self",
",",
"path",
"=",
"None",
",",
"payload",
"=",
"None",
",",
"objectInput",
"=",
"None",
",",
"pretty_print",
"=",
"False",
",",
"convert_to_obj",
"=",
"False",
",",
")",
":",
"f",
"=",
"file_path",
"(",
"path",
... | This function returns a JSON of all contents and
metadata of passed file
Args:
path (string): Path of file to analyze
payload (string): Payload base64 to analyze
objectInput (object): file object/standard input to analyze
pretty_print (boolean): If True a... | [
"This",
"function",
"returns",
"a",
"JSON",
"of",
"all",
"contents",
"and",
"metadata",
"of",
"passed",
"file"
] | 9a462aa611af2032306c78a9c996c8545288c212 | https://github.com/fedelemantuano/tika-app-python/blob/9a462aa611af2032306c78a9c996c8545288c212/tikapp/tikapp.py#L190-L219 | train | 63,190 |
fedelemantuano/tika-app-python | tikapp/utils.py | clean | def clean(func):
"""
This decorator removes the temp file from disk. This is the case where
you want to analyze from a payload.
"""
def wrapper(*args, **kwargs):
# tuple: output command, path given from command line,
# path of templ file when you give the payload
out, given_p... | python | def clean(func):
"""
This decorator removes the temp file from disk. This is the case where
you want to analyze from a payload.
"""
def wrapper(*args, **kwargs):
# tuple: output command, path given from command line,
# path of templ file when you give the payload
out, given_p... | [
"def",
"clean",
"(",
"func",
")",
":",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# tuple: output command, path given from command line,",
"# path of templ file when you give the payload",
"out",
",",
"given_path",
",",
"path",
"=",
"fun... | This decorator removes the temp file from disk. This is the case where
you want to analyze from a payload. | [
"This",
"decorator",
"removes",
"the",
"temp",
"file",
"from",
"disk",
".",
"This",
"is",
"the",
"case",
"where",
"you",
"want",
"to",
"analyze",
"from",
"a",
"payload",
"."
] | 9a462aa611af2032306c78a9c996c8545288c212 | https://github.com/fedelemantuano/tika-app-python/blob/9a462aa611af2032306c78a9c996c8545288c212/tikapp/utils.py#L43-L61 | train | 63,191 |
fedelemantuano/tika-app-python | tikapp/utils.py | file_path | def file_path(path=None, payload=None, objectInput=None):
"""
Given a file path, payload or file object, it writes file on disk and
returns the temp path.
Args:
path (string): path of real file
payload(string): payload in base64 of file
objectInput (object): file object/standard... | python | def file_path(path=None, payload=None, objectInput=None):
"""
Given a file path, payload or file object, it writes file on disk and
returns the temp path.
Args:
path (string): path of real file
payload(string): payload in base64 of file
objectInput (object): file object/standard... | [
"def",
"file_path",
"(",
"path",
"=",
"None",
",",
"payload",
"=",
"None",
",",
"objectInput",
"=",
"None",
")",
":",
"f",
"=",
"path",
"if",
"path",
"else",
"write_payload",
"(",
"payload",
",",
"objectInput",
")",
"if",
"not",
"os",
".",
"path",
".... | Given a file path, payload or file object, it writes file on disk and
returns the temp path.
Args:
path (string): path of real file
payload(string): payload in base64 of file
objectInput (object): file object/standard input to analyze
Returns:
Path of file | [
"Given",
"a",
"file",
"path",
"payload",
"or",
"file",
"object",
"it",
"writes",
"file",
"on",
"disk",
"and",
"returns",
"the",
"temp",
"path",
"."
] | 9a462aa611af2032306c78a9c996c8545288c212 | https://github.com/fedelemantuano/tika-app-python/blob/9a462aa611af2032306c78a9c996c8545288c212/tikapp/utils.py#L64-L84 | train | 63,192 |
fedelemantuano/tika-app-python | tikapp/utils.py | write_payload | def write_payload(payload=None, objectInput=None):
"""
This function writes a base64 payload or file object on disk.
Args:
payload (string): payload in base64
objectInput (object): file object/standard input to analyze
Returns:
Path of file
"""
temp = tempfile.mkstemp(... | python | def write_payload(payload=None, objectInput=None):
"""
This function writes a base64 payload or file object on disk.
Args:
payload (string): payload in base64
objectInput (object): file object/standard input to analyze
Returns:
Path of file
"""
temp = tempfile.mkstemp(... | [
"def",
"write_payload",
"(",
"payload",
"=",
"None",
",",
"objectInput",
"=",
"None",
")",
":",
"temp",
"=",
"tempfile",
".",
"mkstemp",
"(",
")",
"[",
"1",
"]",
"log",
".",
"debug",
"(",
"\"Write payload in temp file {!r}\"",
".",
"format",
"(",
"temp",
... | This function writes a base64 payload or file object on disk.
Args:
payload (string): payload in base64
objectInput (object): file object/standard input to analyze
Returns:
Path of file | [
"This",
"function",
"writes",
"a",
"base64",
"payload",
"or",
"file",
"object",
"on",
"disk",
"."
] | 9a462aa611af2032306c78a9c996c8545288c212 | https://github.com/fedelemantuano/tika-app-python/blob/9a462aa611af2032306c78a9c996c8545288c212/tikapp/utils.py#L87-L113 | train | 63,193 |
pudo/jsonmapping | jsonmapping/statements.py | StatementsVisitor.get_subject | def get_subject(self, data):
""" Try to get a unique ID from the object. By default, this will be
the 'id' field of any given object, or a field specified by the
'rdfSubject' property. If no other option is available, a UUID will be
generated. """
if not isinstance(data, Mapping)... | python | def get_subject(self, data):
""" Try to get a unique ID from the object. By default, this will be
the 'id' field of any given object, or a field specified by the
'rdfSubject' property. If no other option is available, a UUID will be
generated. """
if not isinstance(data, Mapping)... | [
"def",
"get_subject",
"(",
"self",
",",
"data",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"Mapping",
")",
":",
"return",
"None",
"if",
"data",
".",
"get",
"(",
"self",
".",
"subject",
")",
":",
"return",
"data",
".",
"get",
"(",
"self"... | Try to get a unique ID from the object. By default, this will be
the 'id' field of any given object, or a field specified by the
'rdfSubject' property. If no other option is available, a UUID will be
generated. | [
"Try",
"to",
"get",
"a",
"unique",
"ID",
"from",
"the",
"object",
".",
"By",
"default",
"this",
"will",
"be",
"the",
"id",
"field",
"of",
"any",
"given",
"object",
"or",
"a",
"field",
"specified",
"by",
"the",
"rdfSubject",
"property",
".",
"If",
"no",... | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/statements.py#L22-L31 | train | 63,194 |
pudo/jsonmapping | jsonmapping/statements.py | StatementsVisitor.triplify | def triplify(self, data, parent=None):
""" Recursively generate statements from the data supplied. """
if data is None:
return
if self.is_object:
for res in self._triplify_object(data, parent):
yield res
elif self.is_array:
for item in... | python | def triplify(self, data, parent=None):
""" Recursively generate statements from the data supplied. """
if data is None:
return
if self.is_object:
for res in self._triplify_object(data, parent):
yield res
elif self.is_array:
for item in... | [
"def",
"triplify",
"(",
"self",
",",
"data",
",",
"parent",
"=",
"None",
")",
":",
"if",
"data",
"is",
"None",
":",
"return",
"if",
"self",
".",
"is_object",
":",
"for",
"res",
"in",
"self",
".",
"_triplify_object",
"(",
"data",
",",
"parent",
")",
... | Recursively generate statements from the data supplied. | [
"Recursively",
"generate",
"statements",
"from",
"the",
"data",
"supplied",
"."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/statements.py#L53-L71 | train | 63,195 |
pudo/jsonmapping | jsonmapping/statements.py | StatementsVisitor._triplify_object | def _triplify_object(self, data, parent):
""" Create bi-directional statements for object relationships. """
subject = self.get_subject(data)
if self.path:
yield (subject, TYPE_SCHEMA, self.path, TYPE_SCHEMA)
if parent is not None:
yield (parent, self.predicate, ... | python | def _triplify_object(self, data, parent):
""" Create bi-directional statements for object relationships. """
subject = self.get_subject(data)
if self.path:
yield (subject, TYPE_SCHEMA, self.path, TYPE_SCHEMA)
if parent is not None:
yield (parent, self.predicate, ... | [
"def",
"_triplify_object",
"(",
"self",
",",
"data",
",",
"parent",
")",
":",
"subject",
"=",
"self",
".",
"get_subject",
"(",
"data",
")",
"if",
"self",
".",
"path",
":",
"yield",
"(",
"subject",
",",
"TYPE_SCHEMA",
",",
"self",
".",
"path",
",",
"T... | Create bi-directional statements for object relationships. | [
"Create",
"bi",
"-",
"directional",
"statements",
"for",
"object",
"relationships",
"."
] | 4cf0a20a393ba82e00651c6fd39522a67a0155de | https://github.com/pudo/jsonmapping/blob/4cf0a20a393ba82e00651c6fd39522a67a0155de/jsonmapping/statements.py#L73-L86 | train | 63,196 |
praekelt/django-simple-autocomplete | simple_autocomplete/views.py | get_json | def get_json(request, token):
"""Return matching results as JSON"""
result = []
searchtext = request.GET['q']
if len(searchtext) >= 3:
pickled = _simple_autocomplete_queryset_cache.get(token, None)
if pickled is not None:
app_label, model_name, query = pickle.loads(pickled)
... | python | def get_json(request, token):
"""Return matching results as JSON"""
result = []
searchtext = request.GET['q']
if len(searchtext) >= 3:
pickled = _simple_autocomplete_queryset_cache.get(token, None)
if pickled is not None:
app_label, model_name, query = pickle.loads(pickled)
... | [
"def",
"get_json",
"(",
"request",
",",
"token",
")",
":",
"result",
"=",
"[",
"]",
"searchtext",
"=",
"request",
".",
"GET",
"[",
"'q'",
"]",
"if",
"len",
"(",
"searchtext",
")",
">=",
"3",
":",
"pickled",
"=",
"_simple_autocomplete_queryset_cache",
"."... | Return matching results as JSON | [
"Return",
"matching",
"results",
"as",
"JSON"
] | 925b639a6a7fac2350dda9656845d8bd9aa2e748 | https://github.com/praekelt/django-simple-autocomplete/blob/925b639a6a7fac2350dda9656845d8bd9aa2e748/simple_autocomplete/views.py#L14-L62 | train | 63,197 |
kgori/treeCl | treeCl/parsers.py | RaxmlParser._dash_f_e_to_dict | def _dash_f_e_to_dict(self, info_filename, tree_filename):
"""
Raxml provides an option to fit model params to a tree,
selected with -f e.
The output is different and needs a different parser.
"""
with open(info_filename) as fl:
models, likelihood, partition_p... | python | def _dash_f_e_to_dict(self, info_filename, tree_filename):
"""
Raxml provides an option to fit model params to a tree,
selected with -f e.
The output is different and needs a different parser.
"""
with open(info_filename) as fl:
models, likelihood, partition_p... | [
"def",
"_dash_f_e_to_dict",
"(",
"self",
",",
"info_filename",
",",
"tree_filename",
")",
":",
"with",
"open",
"(",
"info_filename",
")",
"as",
"fl",
":",
"models",
",",
"likelihood",
",",
"partition_params",
"=",
"self",
".",
"_dash_f_e_parser",
".",
"parseFi... | Raxml provides an option to fit model params to a tree,
selected with -f e.
The output is different and needs a different parser. | [
"Raxml",
"provides",
"an",
"option",
"to",
"fit",
"model",
"params",
"to",
"a",
"tree",
"selected",
"with",
"-",
"f",
"e",
".",
"The",
"output",
"is",
"different",
"and",
"needs",
"a",
"different",
"parser",
"."
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/parsers.py#L222-L246 | train | 63,198 |
kgori/treeCl | treeCl/parsers.py | RaxmlParser.to_dict | def to_dict(self, info_filename, tree_filename, dash_f_e=False):
"""
Parse raxml output and return a dict
Option dash_f_e=True will parse the output of a raxml -f e run,
which has different output
"""
logger.debug('info_filename: {} {}'
.format(info_f... | python | def to_dict(self, info_filename, tree_filename, dash_f_e=False):
"""
Parse raxml output and return a dict
Option dash_f_e=True will parse the output of a raxml -f e run,
which has different output
"""
logger.debug('info_filename: {} {}'
.format(info_f... | [
"def",
"to_dict",
"(",
"self",
",",
"info_filename",
",",
"tree_filename",
",",
"dash_f_e",
"=",
"False",
")",
":",
"logger",
".",
"debug",
"(",
"'info_filename: {} {}'",
".",
"format",
"(",
"info_filename",
",",
"'(FOUND)'",
"if",
"os",
".",
"path",
".",
... | Parse raxml output and return a dict
Option dash_f_e=True will parse the output of a raxml -f e run,
which has different output | [
"Parse",
"raxml",
"output",
"and",
"return",
"a",
"dict",
"Option",
"dash_f_e",
"=",
"True",
"will",
"parse",
"the",
"output",
"of",
"a",
"raxml",
"-",
"f",
"e",
"run",
"which",
"has",
"different",
"output"
] | fed624b3db1c19cc07175ca04e3eda6905a8d305 | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/parsers.py#L248-L261 | train | 63,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.