repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
cggh/scikit-allel | allel/model/ndarray.py | SortedIndex.is_unique | def is_unique(self):
"""True if no duplicate entries."""
if self._is_unique is None:
t = self.values[:-1] == self.values[1:] # type: np.ndarray
self._is_unique = ~np.any(t)
return self._is_unique | python | def is_unique(self):
"""True if no duplicate entries."""
if self._is_unique is None:
t = self.values[:-1] == self.values[1:] # type: np.ndarray
self._is_unique = ~np.any(t)
return self._is_unique | [
"def",
"is_unique",
"(",
"self",
")",
":",
"if",
"self",
".",
"_is_unique",
"is",
"None",
":",
"t",
"=",
"self",
".",
"values",
"[",
":",
"-",
"1",
"]",
"==",
"self",
".",
"values",
"[",
"1",
":",
"]",
"# type: np.ndarray",
"self",
".",
"_is_unique... | True if no duplicate entries. | [
"True",
"if",
"no",
"duplicate",
"entries",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3404-L3409 |
cggh/scikit-allel | allel/model/ndarray.py | SortedIndex.locate_key | def locate_key(self, key):
"""Get index location for the requested key.
Parameters
----------
key : object
Value to locate.
Returns
-------
loc : int or slice
Location of `key` (will be slice if there are duplicate entries).
Exam... | python | def locate_key(self, key):
"""Get index location for the requested key.
Parameters
----------
key : object
Value to locate.
Returns
-------
loc : int or slice
Location of `key` (will be slice if there are duplicate entries).
Exam... | [
"def",
"locate_key",
"(",
"self",
",",
"key",
")",
":",
"left",
"=",
"bisect",
".",
"bisect_left",
"(",
"self",
",",
"key",
")",
"right",
"=",
"bisect",
".",
"bisect_right",
"(",
"self",
",",
"key",
")",
"diff",
"=",
"right",
"-",
"left",
"if",
"di... | Get index location for the requested key.
Parameters
----------
key : object
Value to locate.
Returns
-------
loc : int or slice
Location of `key` (will be slice if there are duplicate entries).
Examples
--------
>>> imp... | [
"Get",
"index",
"location",
"for",
"the",
"requested",
"key",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3429-L3470 |
cggh/scikit-allel | allel/model/ndarray.py | SortedIndex.locate_intersection | def locate_intersection(self, other):
"""Locate the intersection with another array.
Parameters
----------
other : array_like, int
Array of values to intersect.
Returns
-------
loc : ndarray, bool
Boolean array with location of intersecti... | python | def locate_intersection(self, other):
"""Locate the intersection with another array.
Parameters
----------
other : array_like, int
Array of values to intersect.
Returns
-------
loc : ndarray, bool
Boolean array with location of intersecti... | [
"def",
"locate_intersection",
"(",
"self",
",",
"other",
")",
":",
"# check inputs",
"other",
"=",
"SortedIndex",
"(",
"other",
",",
"copy",
"=",
"False",
")",
"# find intersection",
"assume_unique",
"=",
"self",
".",
"is_unique",
"and",
"other",
".",
"is_uniq... | Locate the intersection with another array.
Parameters
----------
other : array_like, int
Array of values to intersect.
Returns
-------
loc : ndarray, bool
Boolean array with location of intersection.
loc_other : ndarray, bool
... | [
"Locate",
"the",
"intersection",
"with",
"another",
"array",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3472-L3515 |
cggh/scikit-allel | allel/model/ndarray.py | SortedIndex.locate_keys | def locate_keys(self, keys, strict=True):
"""Get index locations for the requested keys.
Parameters
----------
keys : array_like
Array of keys to locate.
strict : bool, optional
If True, raise KeyError if any keys are not found in the index.
Retu... | python | def locate_keys(self, keys, strict=True):
"""Get index locations for the requested keys.
Parameters
----------
keys : array_like
Array of keys to locate.
strict : bool, optional
If True, raise KeyError if any keys are not found in the index.
Retu... | [
"def",
"locate_keys",
"(",
"self",
",",
"keys",
",",
"strict",
"=",
"True",
")",
":",
"# check inputs",
"keys",
"=",
"SortedIndex",
"(",
"keys",
",",
"copy",
"=",
"False",
")",
"# find intersection",
"loc",
",",
"found",
"=",
"self",
".",
"locate_intersect... | Get index locations for the requested keys.
Parameters
----------
keys : array_like
Array of keys to locate.
strict : bool, optional
If True, raise KeyError if any keys are not found in the index.
Returns
-------
loc : ndarray, bool
... | [
"Get",
"index",
"locations",
"for",
"the",
"requested",
"keys",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3517-L3556 |
cggh/scikit-allel | allel/model/ndarray.py | SortedIndex.intersect | def intersect(self, other):
"""Intersect with `other` sorted index.
Parameters
----------
other : array_like, int
Array of values to intersect with.
Returns
-------
out : SortedIndex
Values in common.
Examples
--------
... | python | def intersect(self, other):
"""Intersect with `other` sorted index.
Parameters
----------
other : array_like, int
Array of values to intersect with.
Returns
-------
out : SortedIndex
Values in common.
Examples
--------
... | [
"def",
"intersect",
"(",
"self",
",",
"other",
")",
":",
"loc",
"=",
"self",
".",
"locate_keys",
"(",
"other",
",",
"strict",
"=",
"False",
")",
"return",
"self",
".",
"compress",
"(",
"loc",
",",
"axis",
"=",
"0",
")"
] | Intersect with `other` sorted index.
Parameters
----------
other : array_like, int
Array of values to intersect with.
Returns
-------
out : SortedIndex
Values in common.
Examples
--------
>>> import allel
>>> idx... | [
"Intersect",
"with",
"other",
"sorted",
"index",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3558-L3584 |
cggh/scikit-allel | allel/model/ndarray.py | SortedIndex.locate_range | def locate_range(self, start=None, stop=None):
"""Locate slice of index containing all entries within `start` and
`stop` values **inclusive**.
Parameters
----------
start : int, optional
Start value.
stop : int, optional
Stop value.
Retur... | python | def locate_range(self, start=None, stop=None):
"""Locate slice of index containing all entries within `start` and
`stop` values **inclusive**.
Parameters
----------
start : int, optional
Start value.
stop : int, optional
Stop value.
Retur... | [
"def",
"locate_range",
"(",
"self",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
")",
":",
"# locate start and stop indices",
"if",
"start",
"is",
"None",
":",
"start_index",
"=",
"0",
"else",
":",
"start_index",
"=",
"bisect",
".",
"bisect_left",
... | Locate slice of index containing all entries within `start` and
`stop` values **inclusive**.
Parameters
----------
start : int, optional
Start value.
stop : int, optional
Stop value.
Returns
-------
loc : slice
Slice o... | [
"Locate",
"slice",
"of",
"index",
"containing",
"all",
"entries",
"within",
"start",
"and",
"stop",
"values",
"**",
"inclusive",
"**",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3586-L3630 |
cggh/scikit-allel | allel/model/ndarray.py | SortedIndex.intersect_range | def intersect_range(self, start=None, stop=None):
"""Intersect with range defined by `start` and `stop` values
**inclusive**.
Parameters
----------
start : int, optional
Start value.
stop : int, optional
Stop value.
Returns
------... | python | def intersect_range(self, start=None, stop=None):
"""Intersect with range defined by `start` and `stop` values
**inclusive**.
Parameters
----------
start : int, optional
Start value.
stop : int, optional
Stop value.
Returns
------... | [
"def",
"intersect_range",
"(",
"self",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
")",
":",
"try",
":",
"loc",
"=",
"self",
".",
"locate_range",
"(",
"start",
"=",
"start",
",",
"stop",
"=",
"stop",
")",
"except",
"KeyError",
":",
"return",... | Intersect with range defined by `start` and `stop` values
**inclusive**.
Parameters
----------
start : int, optional
Start value.
stop : int, optional
Stop value.
Returns
-------
idx : SortedIndex
Examples
-------... | [
"Intersect",
"with",
"range",
"defined",
"by",
"start",
"and",
"stop",
"values",
"**",
"inclusive",
"**",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3632-L3663 |
cggh/scikit-allel | allel/model/ndarray.py | SortedIndex.locate_intersection_ranges | def locate_intersection_ranges(self, starts, stops):
"""Locate the intersection with a set of ranges.
Parameters
----------
starts : array_like, int
Range start values.
stops : array_like, int
Range stop values.
Returns
-------
lo... | python | def locate_intersection_ranges(self, starts, stops):
"""Locate the intersection with a set of ranges.
Parameters
----------
starts : array_like, int
Range start values.
stops : array_like, int
Range stop values.
Returns
-------
lo... | [
"def",
"locate_intersection_ranges",
"(",
"self",
",",
"starts",
",",
"stops",
")",
":",
"# check inputs",
"starts",
"=",
"asarray_ndim",
"(",
"starts",
",",
"1",
")",
"stops",
"=",
"asarray_ndim",
"(",
"stops",
",",
"1",
")",
"check_dim0_aligned",
"(",
"sta... | Locate the intersection with a set of ranges.
Parameters
----------
starts : array_like, int
Range start values.
stops : array_like, int
Range stop values.
Returns
-------
loc : ndarray, bool
Boolean array with location of ent... | [
"Locate",
"the",
"intersection",
"with",
"a",
"set",
"of",
"ranges",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3665-L3724 |
cggh/scikit-allel | allel/model/ndarray.py | SortedIndex.locate_ranges | def locate_ranges(self, starts, stops, strict=True):
"""Locate items within the given ranges.
Parameters
----------
starts : array_like, int
Range start values.
stops : array_like, int
Range stop values.
strict : bool, optional
If True... | python | def locate_ranges(self, starts, stops, strict=True):
"""Locate items within the given ranges.
Parameters
----------
starts : array_like, int
Range start values.
stops : array_like, int
Range stop values.
strict : bool, optional
If True... | [
"def",
"locate_ranges",
"(",
"self",
",",
"starts",
",",
"stops",
",",
"strict",
"=",
"True",
")",
":",
"loc",
",",
"found",
"=",
"self",
".",
"locate_intersection_ranges",
"(",
"starts",
",",
"stops",
")",
"if",
"strict",
"and",
"np",
".",
"any",
"(",... | Locate items within the given ranges.
Parameters
----------
starts : array_like, int
Range start values.
stops : array_like, int
Range stop values.
strict : bool, optional
If True, raise KeyError if any ranges contain no entries.
Retu... | [
"Locate",
"items",
"within",
"the",
"given",
"ranges",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3726-L3767 |
cggh/scikit-allel | allel/model/ndarray.py | SortedIndex.intersect_ranges | def intersect_ranges(self, starts, stops):
"""Intersect with a set of ranges.
Parameters
----------
starts : array_like, int
Range start values.
stops : array_like, int
Range stop values.
Returns
-------
idx : SortedIndex
... | python | def intersect_ranges(self, starts, stops):
"""Intersect with a set of ranges.
Parameters
----------
starts : array_like, int
Range start values.
stops : array_like, int
Range stop values.
Returns
-------
idx : SortedIndex
... | [
"def",
"intersect_ranges",
"(",
"self",
",",
"starts",
",",
"stops",
")",
":",
"loc",
"=",
"self",
".",
"locate_ranges",
"(",
"starts",
",",
"stops",
",",
"strict",
"=",
"False",
")",
"return",
"self",
".",
"compress",
"(",
"loc",
",",
"axis",
"=",
"... | Intersect with a set of ranges.
Parameters
----------
starts : array_like, int
Range start values.
stops : array_like, int
Range stop values.
Returns
-------
idx : SortedIndex
Examples
--------
>>> import allel
... | [
"Intersect",
"with",
"a",
"set",
"of",
"ranges",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3769-L3800 |
cggh/scikit-allel | allel/model/ndarray.py | UniqueIndex.locate_intersection | def locate_intersection(self, other):
"""Locate the intersection with another array.
Parameters
----------
other : array_like
Array to intersect.
Returns
-------
loc : ndarray, bool
Boolean array with location of intersection.
loc... | python | def locate_intersection(self, other):
"""Locate the intersection with another array.
Parameters
----------
other : array_like
Array to intersect.
Returns
-------
loc : ndarray, bool
Boolean array with location of intersection.
loc... | [
"def",
"locate_intersection",
"(",
"self",
",",
"other",
")",
":",
"# check inputs",
"other",
"=",
"UniqueIndex",
"(",
"other",
")",
"# find intersection",
"assume_unique",
"=",
"True",
"loc",
"=",
"np",
".",
"in1d",
"(",
"self",
",",
"other",
",",
"assume_u... | Locate the intersection with another array.
Parameters
----------
other : array_like
Array to intersect.
Returns
-------
loc : ndarray, bool
Boolean array with location of intersection.
loc_other : ndarray, bool
Boolean array ... | [
"Locate",
"the",
"intersection",
"with",
"another",
"array",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3904-L3947 |
cggh/scikit-allel | allel/model/ndarray.py | UniqueIndex.locate_keys | def locate_keys(self, keys, strict=True):
"""Get index locations for the requested keys.
Parameters
----------
keys : array_like
Array of keys to locate.
strict : bool, optional
If True, raise KeyError if any keys are not found in the index.
Retu... | python | def locate_keys(self, keys, strict=True):
"""Get index locations for the requested keys.
Parameters
----------
keys : array_like
Array of keys to locate.
strict : bool, optional
If True, raise KeyError if any keys are not found in the index.
Retu... | [
"def",
"locate_keys",
"(",
"self",
",",
"keys",
",",
"strict",
"=",
"True",
")",
":",
"# check inputs",
"keys",
"=",
"UniqueIndex",
"(",
"keys",
")",
"# find intersection",
"loc",
",",
"found",
"=",
"self",
".",
"locate_intersection",
"(",
"keys",
")",
"if... | Get index locations for the requested keys.
Parameters
----------
keys : array_like
Array of keys to locate.
strict : bool, optional
If True, raise KeyError if any keys are not found in the index.
Returns
-------
loc : ndarray, bool
... | [
"Get",
"index",
"locations",
"for",
"the",
"requested",
"keys",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L3949-L3985 |
cggh/scikit-allel | allel/model/ndarray.py | SortedMultiIndex.locate_key | def locate_key(self, k1, k2=None):
"""
Get index location for the requested key.
Parameters
----------
k1 : object
Level 1 key.
k2 : object, optional
Level 2 key.
Returns
-------
loc : int or slice
Location of ... | python | def locate_key(self, k1, k2=None):
"""
Get index location for the requested key.
Parameters
----------
k1 : object
Level 1 key.
k2 : object, optional
Level 2 key.
Returns
-------
loc : int or slice
Location of ... | [
"def",
"locate_key",
"(",
"self",
",",
"k1",
",",
"k2",
"=",
"None",
")",
":",
"loc1",
"=",
"self",
".",
"l1",
".",
"locate_key",
"(",
"k1",
")",
"if",
"k2",
"is",
"None",
":",
"return",
"loc1",
"if",
"isinstance",
"(",
"loc1",
",",
"slice",
")",... | Get index location for the requested key.
Parameters
----------
k1 : object
Level 1 key.
k2 : object, optional
Level 2 key.
Returns
-------
loc : int or slice
Location of requested key (will be slice if there are duplicate
... | [
"Get",
"index",
"location",
"for",
"the",
"requested",
"key",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L4102-L4164 |
cggh/scikit-allel | allel/model/ndarray.py | SortedMultiIndex.locate_range | def locate_range(self, key, start=None, stop=None):
"""Locate slice of index containing all entries within the range
`key`:`start`-`stop` **inclusive**.
Parameters
----------
key : object
Level 1 key value.
start : object, optional
Level 2 start v... | python | def locate_range(self, key, start=None, stop=None):
"""Locate slice of index containing all entries within the range
`key`:`start`-`stop` **inclusive**.
Parameters
----------
key : object
Level 1 key value.
start : object, optional
Level 2 start v... | [
"def",
"locate_range",
"(",
"self",
",",
"key",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
")",
":",
"loc1",
"=",
"self",
".",
"l1",
".",
"locate_key",
"(",
"key",
")",
"if",
"start",
"is",
"None",
"and",
"stop",
"is",
"None",
":",
"loc... | Locate slice of index containing all entries within the range
`key`:`start`-`stop` **inclusive**.
Parameters
----------
key : object
Level 1 key value.
start : object, optional
Level 2 start value.
stop : object, optional
Level 2 stop ... | [
"Locate",
"slice",
"of",
"index",
"containing",
"all",
"entries",
"within",
"the",
"range",
"key",
":",
"start",
"-",
"stop",
"**",
"inclusive",
"**",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L4166-L4227 |
cggh/scikit-allel | allel/model/ndarray.py | ChromPosIndex.locate_key | def locate_key(self, chrom, pos=None):
"""
Get index location for the requested key.
Parameters
----------
chrom : object
Chromosome or contig.
pos : int, optional
Position within chromosome or contig.
Returns
-------
loc ... | python | def locate_key(self, chrom, pos=None):
"""
Get index location for the requested key.
Parameters
----------
chrom : object
Chromosome or contig.
pos : int, optional
Position within chromosome or contig.
Returns
-------
loc ... | [
"def",
"locate_key",
"(",
"self",
",",
"chrom",
",",
"pos",
"=",
"None",
")",
":",
"if",
"pos",
"is",
"None",
":",
"# we just want the region for a chromosome",
"if",
"chrom",
"in",
"self",
".",
"chrom_ranges",
":",
"# return previously cached result",
"return",
... | Get index location for the requested key.
Parameters
----------
chrom : object
Chromosome or contig.
pos : int, optional
Position within chromosome or contig.
Returns
-------
loc : int or slice
Location of requested key (will ... | [
"Get",
"index",
"location",
"for",
"the",
"requested",
"key",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L4322-L4386 |
cggh/scikit-allel | allel/model/ndarray.py | ChromPosIndex.locate_range | def locate_range(self, chrom, start=None, stop=None):
"""Locate slice of index containing all entries within the range
`key`:`start`-`stop` **inclusive**.
Parameters
----------
chrom : object
Chromosome or contig.
start : int, optional
Position st... | python | def locate_range(self, chrom, start=None, stop=None):
"""Locate slice of index containing all entries within the range
`key`:`start`-`stop` **inclusive**.
Parameters
----------
chrom : object
Chromosome or contig.
start : int, optional
Position st... | [
"def",
"locate_range",
"(",
"self",
",",
"chrom",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
")",
":",
"slice_chrom",
"=",
"self",
".",
"locate_key",
"(",
"chrom",
")",
"if",
"start",
"is",
"None",
"and",
"stop",
"is",
"None",
":",
"return"... | Locate slice of index containing all entries within the range
`key`:`start`-`stop` **inclusive**.
Parameters
----------
chrom : object
Chromosome or contig.
start : int, optional
Position start value.
stop : int, optional
Position stop... | [
"Locate",
"slice",
"of",
"index",
"containing",
"all",
"entries",
"within",
"the",
"range",
"key",
":",
"start",
"-",
"stop",
"**",
"inclusive",
"**",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L4388-L4441 |
cggh/scikit-allel | allel/model/ndarray.py | VariantTable.set_index | def set_index(self, index):
"""Set or reset the index.
Parameters
----------
index : string or pair of strings, optional
Names of columns to use for positional index, e.g., 'POS' if table
contains a 'POS' column and records from a single
chromosome/co... | python | def set_index(self, index):
"""Set or reset the index.
Parameters
----------
index : string or pair of strings, optional
Names of columns to use for positional index, e.g., 'POS' if table
contains a 'POS' column and records from a single
chromosome/co... | [
"def",
"set_index",
"(",
"self",
",",
"index",
")",
":",
"if",
"index",
"is",
"None",
":",
"pass",
"elif",
"isinstance",
"(",
"index",
",",
"str",
")",
":",
"index",
"=",
"SortedIndex",
"(",
"self",
"[",
"index",
"]",
",",
"copy",
"=",
"False",
")"... | Set or reset the index.
Parameters
----------
index : string or pair of strings, optional
Names of columns to use for positional index, e.g., 'POS' if table
contains a 'POS' column and records from a single
chromosome/contig, or ('CHROM', 'POS') if table cont... | [
"Set",
"or",
"reset",
"the",
"index",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L4541-L4563 |
cggh/scikit-allel | allel/model/ndarray.py | VariantTable.query_position | def query_position(self, chrom=None, position=None):
"""Query the table, returning row or rows matching the given genomic
position.
Parameters
----------
chrom : string, optional
Chromosome/contig.
position : int, optional
Position (1-based).
... | python | def query_position(self, chrom=None, position=None):
"""Query the table, returning row or rows matching the given genomic
position.
Parameters
----------
chrom : string, optional
Chromosome/contig.
position : int, optional
Position (1-based).
... | [
"def",
"query_position",
"(",
"self",
",",
"chrom",
"=",
"None",
",",
"position",
"=",
"None",
")",
":",
"if",
"self",
".",
"index",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'no index has been set'",
")",
"if",
"isinstance",
"(",
"self",
".",
"ind... | Query the table, returning row or rows matching the given genomic
position.
Parameters
----------
chrom : string, optional
Chromosome/contig.
position : int, optional
Position (1-based).
Returns
-------
result : row or VariantTabl... | [
"Query",
"the",
"table",
"returning",
"row",
"or",
"rows",
"matching",
"the",
"given",
"genomic",
"position",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L4565-L4589 |
cggh/scikit-allel | allel/model/ndarray.py | VariantTable.query_region | def query_region(self, chrom=None, start=None, stop=None):
"""Query the table, returning row or rows within the given genomic
region.
Parameters
----------
chrom : string, optional
Chromosome/contig.
start : int, optional
Region start position (1-... | python | def query_region(self, chrom=None, start=None, stop=None):
"""Query the table, returning row or rows within the given genomic
region.
Parameters
----------
chrom : string, optional
Chromosome/contig.
start : int, optional
Region start position (1-... | [
"def",
"query_region",
"(",
"self",
",",
"chrom",
"=",
"None",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
")",
":",
"if",
"self",
".",
"index",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'no index has been set'",
")",
"if",
"isinstance",
... | Query the table, returning row or rows within the given genomic
region.
Parameters
----------
chrom : string, optional
Chromosome/contig.
start : int, optional
Region start position (1-based).
stop : int, optional
Region stop position ... | [
"Query",
"the",
"table",
"returning",
"row",
"or",
"rows",
"within",
"the",
"given",
"genomic",
"region",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L4591-L4616 |
cggh/scikit-allel | allel/model/ndarray.py | VariantTable.to_vcf | def to_vcf(self, path, rename=None, number=None, description=None,
fill=None, write_header=True):
r"""Write to a variant call format (VCF) file.
Parameters
----------
path : string
File path.
rename : dict, optional
Rename these columns in ... | python | def to_vcf(self, path, rename=None, number=None, description=None,
fill=None, write_header=True):
r"""Write to a variant call format (VCF) file.
Parameters
----------
path : string
File path.
rename : dict, optional
Rename these columns in ... | [
"def",
"to_vcf",
"(",
"self",
",",
"path",
",",
"rename",
"=",
"None",
",",
"number",
"=",
"None",
",",
"description",
"=",
"None",
",",
"fill",
"=",
"None",
",",
"write_header",
"=",
"True",
")",
":",
"write_vcf",
"(",
"path",
",",
"callset",
"=",
... | r"""Write to a variant call format (VCF) file.
Parameters
----------
path : string
File path.
rename : dict, optional
Rename these columns in the VCF.
number : dict, optional
Override the number specified in INFO headers.
description :... | [
"r",
"Write",
"to",
"a",
"variant",
"call",
"format",
"(",
"VCF",
")",
"file",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L4618-L4708 |
cggh/scikit-allel | allel/model/ndarray.py | FeatureTable.to_mask | def to_mask(self, size, start_name='start', stop_name='end'):
"""Construct a mask array where elements are True if the fall within
features in the table.
Parameters
----------
size : int
Size of chromosome/contig.
start_name : string, optional
Na... | python | def to_mask(self, size, start_name='start', stop_name='end'):
"""Construct a mask array where elements are True if the fall within
features in the table.
Parameters
----------
size : int
Size of chromosome/contig.
start_name : string, optional
Na... | [
"def",
"to_mask",
"(",
"self",
",",
"size",
",",
"start_name",
"=",
"'start'",
",",
"stop_name",
"=",
"'end'",
")",
":",
"m",
"=",
"np",
".",
"zeros",
"(",
"size",
",",
"dtype",
"=",
"bool",
")",
"for",
"start",
",",
"stop",
"in",
"self",
"[",
"[... | Construct a mask array where elements are True if the fall within
features in the table.
Parameters
----------
size : int
Size of chromosome/contig.
start_name : string, optional
Name of column with start coordinates.
stop_name : string, optional... | [
"Construct",
"a",
"mask",
"array",
"where",
"elements",
"are",
"True",
"if",
"the",
"fall",
"within",
"features",
"in",
"the",
"table",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L4734-L4757 |
cggh/scikit-allel | allel/model/ndarray.py | FeatureTable.from_gff3 | def from_gff3(path, attributes=None, region=None, score_fill=-1, phase_fill=-1,
attributes_fill='.', dtype=None):
"""Read a feature table from a GFF3 format file.
Parameters
----------
path : string
File path.
attributes : list of strings, optional
... | python | def from_gff3(path, attributes=None, region=None, score_fill=-1, phase_fill=-1,
attributes_fill='.', dtype=None):
"""Read a feature table from a GFF3 format file.
Parameters
----------
path : string
File path.
attributes : list of strings, optional
... | [
"def",
"from_gff3",
"(",
"path",
",",
"attributes",
"=",
"None",
",",
"region",
"=",
"None",
",",
"score_fill",
"=",
"-",
"1",
",",
"phase_fill",
"=",
"-",
"1",
",",
"attributes_fill",
"=",
"'.'",
",",
"dtype",
"=",
"None",
")",
":",
"a",
"=",
"gff... | Read a feature table from a GFF3 format file.
Parameters
----------
path : string
File path.
attributes : list of strings, optional
List of columns to extract from the "attributes" field.
region : string, optional
Genome region to extract. If ... | [
"Read",
"a",
"feature",
"table",
"from",
"a",
"GFF3",
"format",
"file",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/ndarray.py#L4760-L4795 |
cggh/scikit-allel | allel/stats/distance.py | pairwise_distance | def pairwise_distance(x, metric, chunked=False, blen=None):
"""Compute pairwise distance between individuals (e.g., samples or
haplotypes).
Parameters
----------
x : array_like, shape (n, m, ...)
Array of m observations (e.g., samples or haplotypes) in a space
with n dimensions (e.g... | python | def pairwise_distance(x, metric, chunked=False, blen=None):
"""Compute pairwise distance between individuals (e.g., samples or
haplotypes).
Parameters
----------
x : array_like, shape (n, m, ...)
Array of m observations (e.g., samples or haplotypes) in a space
with n dimensions (e.g... | [
"def",
"pairwise_distance",
"(",
"x",
",",
"metric",
",",
"chunked",
"=",
"False",
",",
"blen",
"=",
"None",
")",
":",
"import",
"scipy",
".",
"spatial",
"# check inputs",
"if",
"not",
"hasattr",
"(",
"x",
",",
"'ndim'",
")",
":",
"x",
"=",
"np",
"."... | Compute pairwise distance between individuals (e.g., samples or
haplotypes).
Parameters
----------
x : array_like, shape (n, m, ...)
Array of m observations (e.g., samples or haplotypes) in a space
with n dimensions (e.g., variants). Note that the order of the first
two dimensio... | [
"Compute",
"pairwise",
"distance",
"between",
"individuals",
"(",
"e",
".",
"g",
".",
"samples",
"or",
"haplotypes",
")",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/distance.py#L17-L106 |
cggh/scikit-allel | allel/stats/distance.py | pdist | def pdist(x, metric):
"""Alternative implementation of :func:`scipy.spatial.distance.pdist`
which is slower but more flexible in that arrays with >2 dimensions can be
passed, allowing for multidimensional observations, e.g., diploid
genotype calls or allele counts.
Parameters
----------
x :... | python | def pdist(x, metric):
"""Alternative implementation of :func:`scipy.spatial.distance.pdist`
which is slower but more flexible in that arrays with >2 dimensions can be
passed, allowing for multidimensional observations, e.g., diploid
genotype calls or allele counts.
Parameters
----------
x :... | [
"def",
"pdist",
"(",
"x",
",",
"metric",
")",
":",
"if",
"isinstance",
"(",
"metric",
",",
"str",
")",
":",
"import",
"scipy",
".",
"spatial",
"if",
"hasattr",
"(",
"scipy",
".",
"spatial",
".",
"distance",
",",
"metric",
")",
":",
"metric",
"=",
"... | Alternative implementation of :func:`scipy.spatial.distance.pdist`
which is slower but more flexible in that arrays with >2 dimensions can be
passed, allowing for multidimensional observations, e.g., diploid
genotype calls or allele counts.
Parameters
----------
x : array_like, shape (n, m, ...... | [
"Alternative",
"implementation",
"of",
":",
"func",
":",
"scipy",
".",
"spatial",
".",
"distance",
".",
"pdist",
"which",
"is",
"slower",
"but",
"more",
"flexible",
"in",
"that",
"arrays",
"with",
">",
"2",
"dimensions",
"can",
"be",
"passed",
"allowing",
... | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/distance.py#L109-L148 |
cggh/scikit-allel | allel/stats/distance.py | pairwise_dxy | def pairwise_dxy(pos, gac, start=None, stop=None, is_accessible=None):
"""Convenience function to calculate a pairwise distance matrix using
nucleotide divergence (a.k.a. Dxy) as the distance metric.
Parameters
----------
pos : array_like, int, shape (n_variants,)
Variant positions.
gac... | python | def pairwise_dxy(pos, gac, start=None, stop=None, is_accessible=None):
"""Convenience function to calculate a pairwise distance matrix using
nucleotide divergence (a.k.a. Dxy) as the distance metric.
Parameters
----------
pos : array_like, int, shape (n_variants,)
Variant positions.
gac... | [
"def",
"pairwise_dxy",
"(",
"pos",
",",
"gac",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
",",
"is_accessible",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"pos",
",",
"SortedIndex",
")",
":",
"pos",
"=",
"SortedIndex",
"(",
"pos... | Convenience function to calculate a pairwise distance matrix using
nucleotide divergence (a.k.a. Dxy) as the distance metric.
Parameters
----------
pos : array_like, int, shape (n_variants,)
Variant positions.
gac : array_like, int, shape (n_variants, n_samples, n_alleles)
Per-genot... | [
"Convenience",
"function",
"to",
"calculate",
"a",
"pairwise",
"distance",
"matrix",
"using",
"nucleotide",
"divergence",
"(",
"a",
".",
"k",
".",
"a",
".",
"Dxy",
")",
"as",
"the",
"distance",
"metric",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/distance.py#L151-L196 |
cggh/scikit-allel | allel/stats/distance.py | pcoa | def pcoa(dist):
"""Perform principal coordinate analysis of a distance matrix, a.k.a.
classical multi-dimensional scaling.
Parameters
----------
dist : array_like
Distance matrix in condensed form.
Returns
-------
coords : ndarray, shape (n_samples, n_dimensions)
Transf... | python | def pcoa(dist):
"""Perform principal coordinate analysis of a distance matrix, a.k.a.
classical multi-dimensional scaling.
Parameters
----------
dist : array_like
Distance matrix in condensed form.
Returns
-------
coords : ndarray, shape (n_samples, n_dimensions)
Transf... | [
"def",
"pcoa",
"(",
"dist",
")",
":",
"import",
"scipy",
".",
"linalg",
"# This implementation is based on the skbio.math.stats.ordination.PCoA",
"# implementation, with some minor adjustments.",
"# check inputs",
"dist",
"=",
"ensure_square",
"(",
"dist",
")",
"# perform scali... | Perform principal coordinate analysis of a distance matrix, a.k.a.
classical multi-dimensional scaling.
Parameters
----------
dist : array_like
Distance matrix in condensed form.
Returns
-------
coords : ndarray, shape (n_samples, n_dimensions)
Transformed coordinates for t... | [
"Perform",
"principal",
"coordinate",
"analysis",
"of",
"a",
"distance",
"matrix",
"a",
".",
"k",
".",
"a",
".",
"classical",
"multi",
"-",
"dimensional",
"scaling",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/distance.py#L199-L252 |
cggh/scikit-allel | allel/stats/distance.py | condensed_coords | def condensed_coords(i, j, n):
"""Transform square distance matrix coordinates to the corresponding
index into a condensed, 1D form of the matrix.
Parameters
----------
i : int
Row index.
j : int
Column index.
n : int
Size of the square matrix (length of first or sec... | python | def condensed_coords(i, j, n):
"""Transform square distance matrix coordinates to the corresponding
index into a condensed, 1D form of the matrix.
Parameters
----------
i : int
Row index.
j : int
Column index.
n : int
Size of the square matrix (length of first or sec... | [
"def",
"condensed_coords",
"(",
"i",
",",
"j",
",",
"n",
")",
":",
"# guard conditions",
"if",
"i",
"==",
"j",
"or",
"i",
">=",
"n",
"or",
"j",
">=",
"n",
"or",
"i",
"<",
"0",
"or",
"j",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"'invalid coordi... | Transform square distance matrix coordinates to the corresponding
index into a condensed, 1D form of the matrix.
Parameters
----------
i : int
Row index.
j : int
Column index.
n : int
Size of the square matrix (length of first or second dimension).
Returns
-----... | [
"Transform",
"square",
"distance",
"matrix",
"coordinates",
"to",
"the",
"corresponding",
"index",
"into",
"a",
"condensed",
"1D",
"form",
"of",
"the",
"matrix",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/distance.py#L255-L288 |
cggh/scikit-allel | allel/stats/distance.py | condensed_coords_within | def condensed_coords_within(pop, n):
"""Return indices into a condensed distance matrix for all
pairwise comparisons within the given population.
Parameters
----------
pop : array_like, int
Indices of samples or haplotypes within the population.
n : int
Size of the square matrix... | python | def condensed_coords_within(pop, n):
"""Return indices into a condensed distance matrix for all
pairwise comparisons within the given population.
Parameters
----------
pop : array_like, int
Indices of samples or haplotypes within the population.
n : int
Size of the square matrix... | [
"def",
"condensed_coords_within",
"(",
"pop",
",",
"n",
")",
":",
"return",
"[",
"condensed_coords",
"(",
"i",
",",
"j",
",",
"n",
")",
"for",
"i",
",",
"j",
"in",
"itertools",
".",
"combinations",
"(",
"sorted",
"(",
"pop",
")",
",",
"2",
")",
"]"... | Return indices into a condensed distance matrix for all
pairwise comparisons within the given population.
Parameters
----------
pop : array_like, int
Indices of samples or haplotypes within the population.
n : int
Size of the square matrix (length of first or second dimension).
... | [
"Return",
"indices",
"into",
"a",
"condensed",
"distance",
"matrix",
"for",
"all",
"pairwise",
"comparisons",
"within",
"the",
"given",
"population",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/distance.py#L291-L309 |
cggh/scikit-allel | allel/stats/distance.py | condensed_coords_between | def condensed_coords_between(pop1, pop2, n):
"""Return indices into a condensed distance matrix for all pairwise
comparisons between two populations.
Parameters
----------
pop1 : array_like, int
Indices of samples or haplotypes within the first population.
pop2 : array_like, int
... | python | def condensed_coords_between(pop1, pop2, n):
"""Return indices into a condensed distance matrix for all pairwise
comparisons between two populations.
Parameters
----------
pop1 : array_like, int
Indices of samples or haplotypes within the first population.
pop2 : array_like, int
... | [
"def",
"condensed_coords_between",
"(",
"pop1",
",",
"pop2",
",",
"n",
")",
":",
"return",
"[",
"condensed_coords",
"(",
"i",
",",
"j",
",",
"n",
")",
"for",
"i",
",",
"j",
"in",
"itertools",
".",
"product",
"(",
"sorted",
"(",
"pop1",
")",
",",
"s... | Return indices into a condensed distance matrix for all pairwise
comparisons between two populations.
Parameters
----------
pop1 : array_like, int
Indices of samples or haplotypes within the first population.
pop2 : array_like, int
Indices of samples or haplotypes within the second ... | [
"Return",
"indices",
"into",
"a",
"condensed",
"distance",
"matrix",
"for",
"all",
"pairwise",
"comparisons",
"between",
"two",
"populations",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/distance.py#L312-L332 |
cggh/scikit-allel | allel/stats/distance.py | plot_pairwise_distance | def plot_pairwise_distance(dist, labels=None, colorbar=True, ax=None,
imshow_kwargs=None):
"""Plot a pairwise distance matrix.
Parameters
----------
dist : array_like
The distance matrix in condensed form.
labels : sequence of strings, optional
Sample labe... | python | def plot_pairwise_distance(dist, labels=None, colorbar=True, ax=None,
imshow_kwargs=None):
"""Plot a pairwise distance matrix.
Parameters
----------
dist : array_like
The distance matrix in condensed form.
labels : sequence of strings, optional
Sample labe... | [
"def",
"plot_pairwise_distance",
"(",
"dist",
",",
"labels",
"=",
"None",
",",
"colorbar",
"=",
"True",
",",
"ax",
"=",
"None",
",",
"imshow_kwargs",
"=",
"None",
")",
":",
"import",
"matplotlib",
".",
"pyplot",
"as",
"plt",
"# check inputs",
"dist_square",
... | Plot a pairwise distance matrix.
Parameters
----------
dist : array_like
The distance matrix in condensed form.
labels : sequence of strings, optional
Sample labels for the axes.
colorbar : bool, optional
If True, add a colorbar to the current figure.
ax : axes, optional... | [
"Plot",
"a",
"pairwise",
"distance",
"matrix",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/distance.py#L335-L396 |
cggh/scikit-allel | allel/stats/misc.py | jackknife | def jackknife(values, statistic):
"""Estimate standard error for `statistic` computed over `values` using
the jackknife.
Parameters
----------
values : array_like or tuple of array_like
Input array, or tuple of input arrays.
statistic : function
The statistic to compute.
Re... | python | def jackknife(values, statistic):
"""Estimate standard error for `statistic` computed over `values` using
the jackknife.
Parameters
----------
values : array_like or tuple of array_like
Input array, or tuple of input arrays.
statistic : function
The statistic to compute.
Re... | [
"def",
"jackknife",
"(",
"values",
",",
"statistic",
")",
":",
"if",
"isinstance",
"(",
"values",
",",
"tuple",
")",
":",
"# multiple input arrays",
"n",
"=",
"len",
"(",
"values",
"[",
"0",
"]",
")",
"masked_values",
"=",
"[",
"np",
".",
"ma",
".",
... | Estimate standard error for `statistic` computed over `values` using
the jackknife.
Parameters
----------
values : array_like or tuple of array_like
Input array, or tuple of input arrays.
statistic : function
The statistic to compute.
Returns
-------
m : float
M... | [
"Estimate",
"standard",
"error",
"for",
"statistic",
"computed",
"over",
"values",
"using",
"the",
"jackknife",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/misc.py#L15-L82 |
cggh/scikit-allel | allel/stats/misc.py | plot_variant_locator | def plot_variant_locator(pos, step=None, ax=None, start=None,
stop=None, flip=False,
line_kwargs=None):
"""
Plot lines indicating the physical genome location of variants from a
single chromosome/contig. By default the top x axis is in variant index
spac... | python | def plot_variant_locator(pos, step=None, ax=None, start=None,
stop=None, flip=False,
line_kwargs=None):
"""
Plot lines indicating the physical genome location of variants from a
single chromosome/contig. By default the top x axis is in variant index
spac... | [
"def",
"plot_variant_locator",
"(",
"pos",
",",
"step",
"=",
"None",
",",
"ax",
"=",
"None",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
",",
"flip",
"=",
"False",
",",
"line_kwargs",
"=",
"None",
")",
":",
"import",
"matplotlib",
".",
"pypl... | Plot lines indicating the physical genome location of variants from a
single chromosome/contig. By default the top x axis is in variant index
space, and the bottom x axis is in genome position space.
Parameters
----------
pos : array_like
A sorted 1-dimensional array of genomic positions f... | [
"Plot",
"lines",
"indicating",
"the",
"physical",
"genome",
"location",
"of",
"variants",
"from",
"a",
"single",
"chromosome",
"/",
"contig",
".",
"By",
"default",
"the",
"top",
"x",
"axis",
"is",
"in",
"variant",
"index",
"space",
"and",
"the",
"bottom",
... | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/misc.py#L85-L171 |
cggh/scikit-allel | allel/stats/misc.py | tabulate_state_transitions | def tabulate_state_transitions(x, states, pos=None):
"""Construct a dataframe where each row provides information about a state transition.
Parameters
----------
x : array_like, int
1-dimensional array of state values.
states : set
Set of states of interest. Any state value not in t... | python | def tabulate_state_transitions(x, states, pos=None):
"""Construct a dataframe where each row provides information about a state transition.
Parameters
----------
x : array_like, int
1-dimensional array of state values.
states : set
Set of states of interest. Any state value not in t... | [
"def",
"tabulate_state_transitions",
"(",
"x",
",",
"states",
",",
"pos",
"=",
"None",
")",
":",
"# check inputs",
"x",
"=",
"asarray_ndim",
"(",
"x",
",",
"1",
")",
"check_integer_dtype",
"(",
"x",
")",
"x",
"=",
"memoryview_safe",
"(",
"x",
")",
"# fin... | Construct a dataframe where each row provides information about a state transition.
Parameters
----------
x : array_like, int
1-dimensional array of state values.
states : set
Set of states of interest. Any state value not in this set will be ignored.
pos : array_like, int, optional... | [
"Construct",
"a",
"dataframe",
"where",
"each",
"row",
"provides",
"information",
"about",
"a",
"state",
"transition",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/misc.py#L174-L248 |
cggh/scikit-allel | allel/stats/misc.py | tabulate_state_blocks | def tabulate_state_blocks(x, states, pos=None):
"""Construct a dataframe where each row provides information about continuous state blocks.
Parameters
----------
x : array_like, int
1-dimensional array of state values.
states : set
Set of states of interest. Any state value not in t... | python | def tabulate_state_blocks(x, states, pos=None):
"""Construct a dataframe where each row provides information about continuous state blocks.
Parameters
----------
x : array_like, int
1-dimensional array of state values.
states : set
Set of states of interest. Any state value not in t... | [
"def",
"tabulate_state_blocks",
"(",
"x",
",",
"states",
",",
"pos",
"=",
"None",
")",
":",
"# check inputs",
"x",
"=",
"asarray_ndim",
"(",
"x",
",",
"1",
")",
"check_integer_dtype",
"(",
"x",
")",
"x",
"=",
"memoryview_safe",
"(",
"x",
")",
"# find sta... | Construct a dataframe where each row provides information about continuous state blocks.
Parameters
----------
x : array_like, int
1-dimensional array of state values.
states : set
Set of states of interest. Any state value not in this set will be ignored.
pos : array_like, int, opt... | [
"Construct",
"a",
"dataframe",
"where",
"each",
"row",
"provides",
"information",
"about",
"continuous",
"state",
"blocks",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/misc.py#L251-L349 |
cggh/scikit-allel | allel/io/vcf_write.py | write_vcf | def write_vcf(path, callset, rename=None, number=None, description=None,
fill=None, write_header=True):
"""Preliminary support for writing a VCF file. Currently does not support sample data.
Needs further work."""
names, callset = normalize_callset(callset)
with open(path, 'w') as vcf_fi... | python | def write_vcf(path, callset, rename=None, number=None, description=None,
fill=None, write_header=True):
"""Preliminary support for writing a VCF file. Currently does not support sample data.
Needs further work."""
names, callset = normalize_callset(callset)
with open(path, 'w') as vcf_fi... | [
"def",
"write_vcf",
"(",
"path",
",",
"callset",
",",
"rename",
"=",
"None",
",",
"number",
"=",
"None",
",",
"description",
"=",
"None",
",",
"fill",
"=",
"None",
",",
"write_header",
"=",
"True",
")",
":",
"names",
",",
"callset",
"=",
"normalize_cal... | Preliminary support for writing a VCF file. Currently does not support sample data.
Needs further work. | [
"Preliminary",
"support",
"for",
"writing",
"a",
"VCF",
"file",
".",
"Currently",
"does",
"not",
"support",
"sample",
"data",
".",
"Needs",
"further",
"work",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/io/vcf_write.py#L50-L61 |
cggh/scikit-allel | allel/util.py | asarray_ndim | def asarray_ndim(a, *ndims, **kwargs):
"""Ensure numpy array.
Parameters
----------
a : array_like
*ndims : int, optional
Allowed values for number of dimensions.
**kwargs
Passed through to :func:`numpy.array`.
Returns
-------
a : numpy.ndarray
"""
allow_no... | python | def asarray_ndim(a, *ndims, **kwargs):
"""Ensure numpy array.
Parameters
----------
a : array_like
*ndims : int, optional
Allowed values for number of dimensions.
**kwargs
Passed through to :func:`numpy.array`.
Returns
-------
a : numpy.ndarray
"""
allow_no... | [
"def",
"asarray_ndim",
"(",
"a",
",",
"*",
"ndims",
",",
"*",
"*",
"kwargs",
")",
":",
"allow_none",
"=",
"kwargs",
".",
"pop",
"(",
"'allow_none'",
",",
"False",
")",
"kwargs",
".",
"setdefault",
"(",
"'copy'",
",",
"False",
")",
"if",
"a",
"is",
... | Ensure numpy array.
Parameters
----------
a : array_like
*ndims : int, optional
Allowed values for number of dimensions.
**kwargs
Passed through to :func:`numpy.array`.
Returns
-------
a : numpy.ndarray | [
"Ensure",
"numpy",
"array",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/util.py#L32-L61 |
cggh/scikit-allel | allel/util.py | hdf5_cache | def hdf5_cache(filepath=None, parent=None, group=None, names=None, typed=False,
hashed_key=False, **h5dcreate_kwargs):
"""HDF5 cache decorator.
Parameters
----------
filepath : string, optional
Path to HDF5 file. If None a temporary file name will be used.
parent : string, op... | python | def hdf5_cache(filepath=None, parent=None, group=None, names=None, typed=False,
hashed_key=False, **h5dcreate_kwargs):
"""HDF5 cache decorator.
Parameters
----------
filepath : string, optional
Path to HDF5 file. If None a temporary file name will be used.
parent : string, op... | [
"def",
"hdf5_cache",
"(",
"filepath",
"=",
"None",
",",
"parent",
"=",
"None",
",",
"group",
"=",
"None",
",",
"names",
"=",
"None",
",",
"typed",
"=",
"False",
",",
"hashed_key",
"=",
"False",
",",
"*",
"*",
"h5dcreate_kwargs",
")",
":",
"# initialise... | HDF5 cache decorator.
Parameters
----------
filepath : string, optional
Path to HDF5 file. If None a temporary file name will be used.
parent : string, optional
Path to group within HDF5 file to use as parent. If None the root
group will be used.
group : string, optional
... | [
"HDF5",
"cache",
"decorator",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/util.py#L283-L401 |
cggh/scikit-allel | allel/stats/decomposition.py | pca | def pca(gn, n_components=10, copy=True, scaler='patterson', ploidy=2):
"""Perform principal components analysis of genotype data, via singular
value decomposition.
Parameters
----------
gn : array_like, float, shape (n_variants, n_samples)
Genotypes at biallelic variants, coded as the numb... | python | def pca(gn, n_components=10, copy=True, scaler='patterson', ploidy=2):
"""Perform principal components analysis of genotype data, via singular
value decomposition.
Parameters
----------
gn : array_like, float, shape (n_variants, n_samples)
Genotypes at biallelic variants, coded as the numb... | [
"def",
"pca",
"(",
"gn",
",",
"n_components",
"=",
"10",
",",
"copy",
"=",
"True",
",",
"scaler",
"=",
"'patterson'",
",",
"ploidy",
"=",
"2",
")",
":",
"# set up the model",
"model",
"=",
"GenotypePCA",
"(",
"n_components",
",",
"copy",
"=",
"copy",
"... | Perform principal components analysis of genotype data, via singular
value decomposition.
Parameters
----------
gn : array_like, float, shape (n_variants, n_samples)
Genotypes at biallelic variants, coded as the number of alternate
alleles per call (i.e., 0 = hom ref, 1 = het, 2 = hom ... | [
"Perform",
"principal",
"components",
"analysis",
"of",
"genotype",
"data",
"via",
"singular",
"value",
"decomposition",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/decomposition.py#L11-L60 |
cggh/scikit-allel | allel/stats/decomposition.py | randomized_pca | def randomized_pca(gn, n_components=10, copy=True, iterated_power=3,
random_state=None, scaler='patterson', ploidy=2):
"""Perform principal components analysis of genotype data, via an
approximate truncated singular value decomposition using randomization
to speed up the computation.
... | python | def randomized_pca(gn, n_components=10, copy=True, iterated_power=3,
random_state=None, scaler='patterson', ploidy=2):
"""Perform principal components analysis of genotype data, via an
approximate truncated singular value decomposition using randomization
to speed up the computation.
... | [
"def",
"randomized_pca",
"(",
"gn",
",",
"n_components",
"=",
"10",
",",
"copy",
"=",
"True",
",",
"iterated_power",
"=",
"3",
",",
"random_state",
"=",
"None",
",",
"scaler",
"=",
"'patterson'",
",",
"ploidy",
"=",
"2",
")",
":",
"# set up the model",
"... | Perform principal components analysis of genotype data, via an
approximate truncated singular value decomposition using randomization
to speed up the computation.
Parameters
----------
gn : array_like, float, shape (n_variants, n_samples)
Genotypes at biallelic variants, coded as the numbe... | [
"Perform",
"principal",
"components",
"analysis",
"of",
"genotype",
"data",
"via",
"an",
"approximate",
"truncated",
"singular",
"value",
"decomposition",
"using",
"randomization",
"to",
"speed",
"up",
"the",
"computation",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/decomposition.py#L126-L187 |
cggh/scikit-allel | allel/stats/admixture.py | h_hat | def h_hat(ac):
"""Unbiased estimator for h, where 2*h is the heterozygosity
of the population.
Parameters
----------
ac : array_like, int, shape (n_variants, 2)
Allele counts array for a single population.
Returns
-------
h_hat : ndarray, float, shape (n_variants,)
Notes
... | python | def h_hat(ac):
"""Unbiased estimator for h, where 2*h is the heterozygosity
of the population.
Parameters
----------
ac : array_like, int, shape (n_variants, 2)
Allele counts array for a single population.
Returns
-------
h_hat : ndarray, float, shape (n_variants,)
Notes
... | [
"def",
"h_hat",
"(",
"ac",
")",
":",
"# check inputs",
"ac",
"=",
"asarray_ndim",
"(",
"ac",
",",
"2",
")",
"assert",
"ac",
".",
"shape",
"[",
"1",
"]",
"==",
"2",
",",
"'only biallelic variants supported'",
"# compute allele number",
"an",
"=",
"ac",
".",... | Unbiased estimator for h, where 2*h is the heterozygosity
of the population.
Parameters
----------
ac : array_like, int, shape (n_variants, 2)
Allele counts array for a single population.
Returns
-------
h_hat : ndarray, float, shape (n_variants,)
Notes
-----
Used in P... | [
"Unbiased",
"estimator",
"for",
"h",
"where",
"2",
"*",
"h",
"is",
"the",
"heterozygosity",
"of",
"the",
"population",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/admixture.py#L14-L43 |
cggh/scikit-allel | allel/stats/admixture.py | patterson_f2 | def patterson_f2(aca, acb):
"""Unbiased estimator for F2(A, B), the branch length between populations
A and B.
Parameters
----------
aca : array_like, int, shape (n_variants, 2)
Allele counts for population A.
acb : array_like, int, shape (n_variants, 2)
Allele counts for popula... | python | def patterson_f2(aca, acb):
"""Unbiased estimator for F2(A, B), the branch length between populations
A and B.
Parameters
----------
aca : array_like, int, shape (n_variants, 2)
Allele counts for population A.
acb : array_like, int, shape (n_variants, 2)
Allele counts for popula... | [
"def",
"patterson_f2",
"(",
"aca",
",",
"acb",
")",
":",
"# check inputs",
"aca",
"=",
"AlleleCountsArray",
"(",
"aca",
",",
"copy",
"=",
"False",
")",
"assert",
"aca",
".",
"shape",
"[",
"1",
"]",
"==",
"2",
",",
"'only biallelic variants supported'",
"ac... | Unbiased estimator for F2(A, B), the branch length between populations
A and B.
Parameters
----------
aca : array_like, int, shape (n_variants, 2)
Allele counts for population A.
acb : array_like, int, shape (n_variants, 2)
Allele counts for population B.
Returns
-------
... | [
"Unbiased",
"estimator",
"for",
"F2",
"(",
"A",
"B",
")",
"the",
"branch",
"length",
"between",
"populations",
"A",
"and",
"B",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/admixture.py#L46-L89 |
cggh/scikit-allel | allel/stats/admixture.py | patterson_f3 | def patterson_f3(acc, aca, acb):
"""Unbiased estimator for F3(C; A, B), the three-population test for
admixture in population C.
Parameters
----------
acc : array_like, int, shape (n_variants, 2)
Allele counts for the test population (C).
aca : array_like, int, shape (n_variants, 2)
... | python | def patterson_f3(acc, aca, acb):
"""Unbiased estimator for F3(C; A, B), the three-population test for
admixture in population C.
Parameters
----------
acc : array_like, int, shape (n_variants, 2)
Allele counts for the test population (C).
aca : array_like, int, shape (n_variants, 2)
... | [
"def",
"patterson_f3",
"(",
"acc",
",",
"aca",
",",
"acb",
")",
":",
"# check inputs",
"aca",
"=",
"AlleleCountsArray",
"(",
"aca",
",",
"copy",
"=",
"False",
")",
"assert",
"aca",
".",
"shape",
"[",
"1",
"]",
"==",
"2",
",",
"'only biallelic variants su... | Unbiased estimator for F3(C; A, B), the three-population test for
admixture in population C.
Parameters
----------
acc : array_like, int, shape (n_variants, 2)
Allele counts for the test population (C).
aca : array_like, int, shape (n_variants, 2)
Allele counts for the first source ... | [
"Unbiased",
"estimator",
"for",
"F3",
"(",
"C",
";",
"A",
"B",
")",
"the",
"three",
"-",
"population",
"test",
"for",
"admixture",
"in",
"population",
"C",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/admixture.py#L93-L147 |
cggh/scikit-allel | allel/stats/admixture.py | patterson_d | def patterson_d(aca, acb, acc, acd):
"""Unbiased estimator for D(A, B; C, D), the normalised four-population
test for admixture between (A or B) and (C or D), also known as the
"ABBA BABA" test.
Parameters
----------
aca : array_like, int, shape (n_variants, 2),
Allele counts for popula... | python | def patterson_d(aca, acb, acc, acd):
"""Unbiased estimator for D(A, B; C, D), the normalised four-population
test for admixture between (A or B) and (C or D), also known as the
"ABBA BABA" test.
Parameters
----------
aca : array_like, int, shape (n_variants, 2),
Allele counts for popula... | [
"def",
"patterson_d",
"(",
"aca",
",",
"acb",
",",
"acc",
",",
"acd",
")",
":",
"# check inputs",
"aca",
"=",
"AlleleCountsArray",
"(",
"aca",
",",
"copy",
"=",
"False",
")",
"assert",
"aca",
".",
"shape",
"[",
"1",
"]",
"==",
"2",
",",
"'only bialle... | Unbiased estimator for D(A, B; C, D), the normalised four-population
test for admixture between (A or B) and (C or D), also known as the
"ABBA BABA" test.
Parameters
----------
aca : array_like, int, shape (n_variants, 2),
Allele counts for population A.
acb : array_like, int, shape (n_... | [
"Unbiased",
"estimator",
"for",
"D",
"(",
"A",
"B",
";",
"C",
"D",
")",
"the",
"normalised",
"four",
"-",
"population",
"test",
"for",
"admixture",
"between",
"(",
"A",
"or",
"B",
")",
"and",
"(",
"C",
"or",
"D",
")",
"also",
"known",
"as",
"the",
... | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/admixture.py#L150-L202 |
cggh/scikit-allel | allel/stats/admixture.py | moving_patterson_f3 | def moving_patterson_f3(acc, aca, acb, size, start=0, stop=None, step=None,
normed=True):
"""Estimate F3(C; A, B) in moving windows.
Parameters
----------
acc : array_like, int, shape (n_variants, 2)
Allele counts for the test population (C).
aca : array_like, int, s... | python | def moving_patterson_f3(acc, aca, acb, size, start=0, stop=None, step=None,
normed=True):
"""Estimate F3(C; A, B) in moving windows.
Parameters
----------
acc : array_like, int, shape (n_variants, 2)
Allele counts for the test population (C).
aca : array_like, int, s... | [
"def",
"moving_patterson_f3",
"(",
"acc",
",",
"aca",
",",
"acb",
",",
"size",
",",
"start",
"=",
"0",
",",
"stop",
"=",
"None",
",",
"step",
"=",
"None",
",",
"normed",
"=",
"True",
")",
":",
"# calculate per-variant values",
"T",
",",
"B",
"=",
"pa... | Estimate F3(C; A, B) in moving windows.
Parameters
----------
acc : array_like, int, shape (n_variants, 2)
Allele counts for the test population (C).
aca : array_like, int, shape (n_variants, 2)
Allele counts for the first source population (A).
acb : array_like, int, shape (n_varia... | [
"Estimate",
"F3",
"(",
"C",
";",
"A",
"B",
")",
"in",
"moving",
"windows",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/admixture.py#L206-L252 |
cggh/scikit-allel | allel/stats/admixture.py | moving_patterson_d | def moving_patterson_d(aca, acb, acc, acd, size, start=0, stop=None,
step=None):
"""Estimate D(A, B; C, D) in moving windows.
Parameters
----------
aca : array_like, int, shape (n_variants, 2),
Allele counts for population A.
acb : array_like, int, shape (n_variants, ... | python | def moving_patterson_d(aca, acb, acc, acd, size, start=0, stop=None,
step=None):
"""Estimate D(A, B; C, D) in moving windows.
Parameters
----------
aca : array_like, int, shape (n_variants, 2),
Allele counts for population A.
acb : array_like, int, shape (n_variants, ... | [
"def",
"moving_patterson_d",
"(",
"aca",
",",
"acb",
",",
"acc",
",",
"acd",
",",
"size",
",",
"start",
"=",
"0",
",",
"stop",
"=",
"None",
",",
"step",
"=",
"None",
")",
":",
"# calculate per-variant values",
"num",
",",
"den",
"=",
"patterson_d",
"("... | Estimate D(A, B; C, D) in moving windows.
Parameters
----------
aca : array_like, int, shape (n_variants, 2),
Allele counts for population A.
acb : array_like, int, shape (n_variants, 2)
Allele counts for population B.
acc : array_like, int, shape (n_variants, 2)
Allele coun... | [
"Estimate",
"D",
"(",
"A",
"B",
";",
"C",
"D",
")",
"in",
"moving",
"windows",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/admixture.py#L255-L302 |
cggh/scikit-allel | allel/stats/admixture.py | average_patterson_f3 | def average_patterson_f3(acc, aca, acb, blen, normed=True):
"""Estimate F3(C; A, B) and standard error using the block-jackknife.
Parameters
----------
acc : array_like, int, shape (n_variants, 2)
Allele counts for the test population (C).
aca : array_like, int, shape (n_variants, 2)
... | python | def average_patterson_f3(acc, aca, acb, blen, normed=True):
"""Estimate F3(C; A, B) and standard error using the block-jackknife.
Parameters
----------
acc : array_like, int, shape (n_variants, 2)
Allele counts for the test population (C).
aca : array_like, int, shape (n_variants, 2)
... | [
"def",
"average_patterson_f3",
"(",
"acc",
",",
"aca",
",",
"acb",
",",
"blen",
",",
"normed",
"=",
"True",
")",
":",
"# calculate per-variant values",
"T",
",",
"B",
"=",
"patterson_f3",
"(",
"acc",
",",
"aca",
",",
"acb",
")",
"# N.B., nans can occur if an... | Estimate F3(C; A, B) and standard error using the block-jackknife.
Parameters
----------
acc : array_like, int, shape (n_variants, 2)
Allele counts for the test population (C).
aca : array_like, int, shape (n_variants, 2)
Allele counts for the first source population (A).
acb : arra... | [
"Estimate",
"F3",
"(",
"C",
";",
"A",
"B",
")",
"and",
"standard",
"error",
"using",
"the",
"block",
"-",
"jackknife",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/admixture.py#L306-L373 |
cggh/scikit-allel | allel/stats/admixture.py | average_patterson_d | def average_patterson_d(aca, acb, acc, acd, blen):
"""Estimate D(A, B; C, D) and standard error using the block-jackknife.
Parameters
----------
aca : array_like, int, shape (n_variants, 2),
Allele counts for population A.
acb : array_like, int, shape (n_variants, 2)
Allele counts f... | python | def average_patterson_d(aca, acb, acc, acd, blen):
"""Estimate D(A, B; C, D) and standard error using the block-jackknife.
Parameters
----------
aca : array_like, int, shape (n_variants, 2),
Allele counts for population A.
acb : array_like, int, shape (n_variants, 2)
Allele counts f... | [
"def",
"average_patterson_d",
"(",
"aca",
",",
"acb",
",",
"acc",
",",
"acd",
",",
"blen",
")",
":",
"# calculate per-variant values",
"num",
",",
"den",
"=",
"patterson_d",
"(",
"aca",
",",
"acb",
",",
"acc",
",",
"acd",
")",
"# N.B., nans can occur if any ... | Estimate D(A, B; C, D) and standard error using the block-jackknife.
Parameters
----------
aca : array_like, int, shape (n_variants, 2),
Allele counts for population A.
acb : array_like, int, shape (n_variants, 2)
Allele counts for population B.
acc : array_like, int, shape (n_varia... | [
"Estimate",
"D",
"(",
"A",
"B",
";",
"C",
"D",
")",
"and",
"standard",
"error",
"using",
"the",
"block",
"-",
"jackknife",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/admixture.py#L376-L439 |
cggh/scikit-allel | allel/model/dask.py | get_chunks | def get_chunks(data, chunks=None):
"""Try to guess a reasonable chunk shape to use for block-wise
algorithms operating over `data`."""
if chunks is None:
if hasattr(data, 'chunklen') and hasattr(data, 'shape'):
# bcolz carray, chunk first dimension only
return (data.chunkle... | python | def get_chunks(data, chunks=None):
"""Try to guess a reasonable chunk shape to use for block-wise
algorithms operating over `data`."""
if chunks is None:
if hasattr(data, 'chunklen') and hasattr(data, 'shape'):
# bcolz carray, chunk first dimension only
return (data.chunkle... | [
"def",
"get_chunks",
"(",
"data",
",",
"chunks",
"=",
"None",
")",
":",
"if",
"chunks",
"is",
"None",
":",
"if",
"hasattr",
"(",
"data",
",",
"'chunklen'",
")",
"and",
"hasattr",
"(",
"data",
",",
"'shape'",
")",
":",
"# bcolz carray, chunk first dimension... | Try to guess a reasonable chunk shape to use for block-wise
algorithms operating over `data`. | [
"Try",
"to",
"guess",
"a",
"reasonable",
"chunk",
"shape",
"to",
"use",
"for",
"block",
"-",
"wise",
"algorithms",
"operating",
"over",
"data",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/model/dask.py#L47-L74 |
cggh/scikit-allel | allel/io/gff.py | iter_gff3 | def iter_gff3(path, attributes=None, region=None, score_fill=-1,
phase_fill=-1, attributes_fill='.', tabix='tabix'):
"""Iterate over records in a GFF3 file.
Parameters
----------
path : string
Path to input file.
attributes : list of strings, optional
List of columns t... | python | def iter_gff3(path, attributes=None, region=None, score_fill=-1,
phase_fill=-1, attributes_fill='.', tabix='tabix'):
"""Iterate over records in a GFF3 file.
Parameters
----------
path : string
Path to input file.
attributes : list of strings, optional
List of columns t... | [
"def",
"iter_gff3",
"(",
"path",
",",
"attributes",
"=",
"None",
",",
"region",
"=",
"None",
",",
"score_fill",
"=",
"-",
"1",
",",
"phase_fill",
"=",
"-",
"1",
",",
"attributes_fill",
"=",
"'.'",
",",
"tabix",
"=",
"'tabix'",
")",
":",
"# prepare fill... | Iterate over records in a GFF3 file.
Parameters
----------
path : string
Path to input file.
attributes : list of strings, optional
List of columns to extract from the "attributes" field.
region : string, optional
Genome region to extract. If given, file must be position
... | [
"Iterate",
"over",
"records",
"in",
"a",
"GFF3",
"file",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/io/gff.py#L31-L118 |
cggh/scikit-allel | allel/io/gff.py | gff3_to_recarray | def gff3_to_recarray(path, attributes=None, region=None, score_fill=-1,
phase_fill=-1, attributes_fill='.', tabix='tabix', dtype=None):
"""Load data from a GFF3 into a NumPy recarray.
Parameters
----------
path : string
Path to input file.
attributes : list of strings, ... | python | def gff3_to_recarray(path, attributes=None, region=None, score_fill=-1,
phase_fill=-1, attributes_fill='.', tabix='tabix', dtype=None):
"""Load data from a GFF3 into a NumPy recarray.
Parameters
----------
path : string
Path to input file.
attributes : list of strings, ... | [
"def",
"gff3_to_recarray",
"(",
"path",
",",
"attributes",
"=",
"None",
",",
"region",
"=",
"None",
",",
"score_fill",
"=",
"-",
"1",
",",
"phase_fill",
"=",
"-",
"1",
",",
"attributes_fill",
"=",
"'.'",
",",
"tabix",
"=",
"'tabix'",
",",
"dtype",
"=",... | Load data from a GFF3 into a NumPy recarray.
Parameters
----------
path : string
Path to input file.
attributes : list of strings, optional
List of columns to extract from the "attributes" field.
region : string, optional
Genome region to extract. If given, file must be posi... | [
"Load",
"data",
"from",
"a",
"GFF3",
"into",
"a",
"NumPy",
"recarray",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/io/gff.py#L124-L178 |
cggh/scikit-allel | allel/io/gff.py | gff3_to_dataframe | def gff3_to_dataframe(path, attributes=None, region=None, score_fill=-1,
phase_fill=-1, attributes_fill='.', tabix='tabix', **kwargs):
"""Load data from a GFF3 into a pandas DataFrame.
Parameters
----------
path : string
Path to input file.
attributes : list of strings... | python | def gff3_to_dataframe(path, attributes=None, region=None, score_fill=-1,
phase_fill=-1, attributes_fill='.', tabix='tabix', **kwargs):
"""Load data from a GFF3 into a pandas DataFrame.
Parameters
----------
path : string
Path to input file.
attributes : list of strings... | [
"def",
"gff3_to_dataframe",
"(",
"path",
",",
"attributes",
"=",
"None",
",",
"region",
"=",
"None",
",",
"score_fill",
"=",
"-",
"1",
",",
"phase_fill",
"=",
"-",
"1",
",",
"attributes_fill",
"=",
"'.'",
",",
"tabix",
"=",
"'tabix'",
",",
"*",
"*",
... | Load data from a GFF3 into a pandas DataFrame.
Parameters
----------
path : string
Path to input file.
attributes : list of strings, optional
List of columns to extract from the "attributes" field.
region : string, optional
Genome region to extract. If given, file must be po... | [
"Load",
"data",
"from",
"a",
"GFF3",
"into",
"a",
"pandas",
"DataFrame",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/io/gff.py#L181-L223 |
cggh/scikit-allel | allel/stats/selection.py | ehh_decay | def ehh_decay(h, truncate=False):
"""Compute the decay of extended haplotype homozygosity (EHH)
moving away from the first variant.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
truncate : bool, optional
If True, the return array wi... | python | def ehh_decay(h, truncate=False):
"""Compute the decay of extended haplotype homozygosity (EHH)
moving away from the first variant.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
truncate : bool, optional
If True, the return array wi... | [
"def",
"ehh_decay",
"(",
"h",
",",
"truncate",
"=",
"False",
")",
":",
"# check inputs",
"# N.B., ensure int8 so we can use cython optimisation",
"h",
"=",
"HaplotypeArray",
"(",
"np",
".",
"asarray",
"(",
"h",
")",
",",
"copy",
"=",
"False",
")",
"if",
"h",
... | Compute the decay of extended haplotype homozygosity (EHH)
moving away from the first variant.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
truncate : bool, optional
If True, the return array will exclude trailing zeros.
Returns
... | [
"Compute",
"the",
"decay",
"of",
"extended",
"haplotype",
"homozygosity",
"(",
"EHH",
")",
"moving",
"away",
"from",
"the",
"first",
"variant",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L20-L59 |
cggh/scikit-allel | allel/stats/selection.py | voight_painting | def voight_painting(h):
"""Paint haplotypes, assigning a unique integer to each shared haplotype
prefix.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
Returns
-------
painting : ndarray, int, shape (n_variants, n_haplotypes)
... | python | def voight_painting(h):
"""Paint haplotypes, assigning a unique integer to each shared haplotype
prefix.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
Returns
-------
painting : ndarray, int, shape (n_variants, n_haplotypes)
... | [
"def",
"voight_painting",
"(",
"h",
")",
":",
"# check inputs",
"# N.B., ensure int8 so we can use cython optimisation",
"h",
"=",
"HaplotypeArray",
"(",
"np",
".",
"asarray",
"(",
"h",
")",
",",
"copy",
"=",
"False",
")",
"if",
"h",
".",
"max",
"(",
")",
">... | Paint haplotypes, assigning a unique integer to each shared haplotype
prefix.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
Returns
-------
painting : ndarray, int, shape (n_variants, n_haplotypes)
Painting array.
indices :... | [
"Paint",
"haplotypes",
"assigning",
"a",
"unique",
"integer",
"to",
"each",
"shared",
"haplotype",
"prefix",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L62-L95 |
cggh/scikit-allel | allel/stats/selection.py | plot_voight_painting | def plot_voight_painting(painting, palette='colorblind', flank='right',
ax=None, height_factor=0.01):
"""Plot a painting of shared haplotype prefixes.
Parameters
----------
painting : array_like, int, shape (n_variants, n_haplotypes)
Painting array.
ax : axes, optio... | python | def plot_voight_painting(painting, palette='colorblind', flank='right',
ax=None, height_factor=0.01):
"""Plot a painting of shared haplotype prefixes.
Parameters
----------
painting : array_like, int, shape (n_variants, n_haplotypes)
Painting array.
ax : axes, optio... | [
"def",
"plot_voight_painting",
"(",
"painting",
",",
"palette",
"=",
"'colorblind'",
",",
"flank",
"=",
"'right'",
",",
"ax",
"=",
"None",
",",
"height_factor",
"=",
"0.01",
")",
":",
"import",
"seaborn",
"as",
"sns",
"from",
"matplotlib",
".",
"colors",
"... | Plot a painting of shared haplotype prefixes.
Parameters
----------
painting : array_like, int, shape (n_variants, n_haplotypes)
Painting array.
ax : axes, optional
The axes on which to draw. If not provided, a new figure will be
created.
palette : string, optional
A... | [
"Plot",
"a",
"painting",
"of",
"shared",
"haplotype",
"prefixes",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L98-L148 |
cggh/scikit-allel | allel/stats/selection.py | fig_voight_painting | def fig_voight_painting(h, index=None, palette='colorblind',
height_factor=0.01, fig=None):
"""Make a figure of shared haplotype prefixes for both left and right
flanks, centred on some variant of choice.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplot... | python | def fig_voight_painting(h, index=None, palette='colorblind',
height_factor=0.01, fig=None):
"""Make a figure of shared haplotype prefixes for both left and right
flanks, centred on some variant of choice.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplot... | [
"def",
"fig_voight_painting",
"(",
"h",
",",
"index",
"=",
"None",
",",
"palette",
"=",
"'colorblind'",
",",
"height_factor",
"=",
"0.01",
",",
"fig",
"=",
"None",
")",
":",
"import",
"matplotlib",
".",
"pyplot",
"as",
"plt",
"from",
"matplotlib",
".",
"... | Make a figure of shared haplotype prefixes for both left and right
flanks, centred on some variant of choice.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
index : int, optional
Index of the variant within the haplotype array to centre ... | [
"Make",
"a",
"figure",
"of",
"shared",
"haplotype",
"prefixes",
"for",
"both",
"left",
"and",
"right",
"flanks",
"centred",
"on",
"some",
"variant",
"of",
"choice",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L151-L251 |
cggh/scikit-allel | allel/stats/selection.py | compute_ihh_gaps | def compute_ihh_gaps(pos, map_pos, gap_scale, max_gap, is_accessible):
"""Compute spacing between variants for integrating haplotype
homozygosity.
Parameters
----------
pos : array_like, int, shape (n_variants,)
Variant positions (physical distance).
map_pos : array_like, float, shape (... | python | def compute_ihh_gaps(pos, map_pos, gap_scale, max_gap, is_accessible):
"""Compute spacing between variants for integrating haplotype
homozygosity.
Parameters
----------
pos : array_like, int, shape (n_variants,)
Variant positions (physical distance).
map_pos : array_like, float, shape (... | [
"def",
"compute_ihh_gaps",
"(",
"pos",
",",
"map_pos",
",",
"gap_scale",
",",
"max_gap",
",",
"is_accessible",
")",
":",
"# check inputs",
"if",
"map_pos",
"is",
"None",
":",
"# integrate over physical distance",
"map_pos",
"=",
"pos",
"else",
":",
"map_pos",
"=... | Compute spacing between variants for integrating haplotype
homozygosity.
Parameters
----------
pos : array_like, int, shape (n_variants,)
Variant positions (physical distance).
map_pos : array_like, float, shape (n_variants,)
Variant positions (genetic map distance).
gap_scale :... | [
"Compute",
"spacing",
"between",
"variants",
"for",
"integrating",
"haplotype",
"homozygosity",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L255-L322 |
cggh/scikit-allel | allel/stats/selection.py | ihs | def ihs(h, pos, map_pos=None, min_ehh=0.05, min_maf=0.05, include_edges=False,
gap_scale=20000, max_gap=200000, is_accessible=None, use_threads=True):
"""Compute the unstandardized integrated haplotype score (IHS) for each
variant, comparing integrated haplotype homozygosity between the
reference (0... | python | def ihs(h, pos, map_pos=None, min_ehh=0.05, min_maf=0.05, include_edges=False,
gap_scale=20000, max_gap=200000, is_accessible=None, use_threads=True):
"""Compute the unstandardized integrated haplotype score (IHS) for each
variant, comparing integrated haplotype homozygosity between the
reference (0... | [
"def",
"ihs",
"(",
"h",
",",
"pos",
",",
"map_pos",
"=",
"None",
",",
"min_ehh",
"=",
"0.05",
",",
"min_maf",
"=",
"0.05",
",",
"include_edges",
"=",
"False",
",",
"gap_scale",
"=",
"20000",
",",
"max_gap",
"=",
"200000",
",",
"is_accessible",
"=",
"... | Compute the unstandardized integrated haplotype score (IHS) for each
variant, comparing integrated haplotype homozygosity between the
reference (0) and alternate (1) alleles.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
pos : array_like, i... | [
"Compute",
"the",
"unstandardized",
"integrated",
"haplotype",
"score",
"(",
"IHS",
")",
"for",
"each",
"variant",
"comparing",
"integrated",
"haplotype",
"homozygosity",
"between",
"the",
"reference",
"(",
"0",
")",
"and",
"alternate",
"(",
"1",
")",
"alleles",... | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L325-L443 |
cggh/scikit-allel | allel/stats/selection.py | xpehh | def xpehh(h1, h2, pos, map_pos=None, min_ehh=0.05, include_edges=False,
gap_scale=20000, max_gap=200000, is_accessible=None,
use_threads=True):
"""Compute the unstandardized cross-population extended haplotype
homozygosity score (XPEHH) for each variant.
Parameters
----------
h1... | python | def xpehh(h1, h2, pos, map_pos=None, min_ehh=0.05, include_edges=False,
gap_scale=20000, max_gap=200000, is_accessible=None,
use_threads=True):
"""Compute the unstandardized cross-population extended haplotype
homozygosity score (XPEHH) for each variant.
Parameters
----------
h1... | [
"def",
"xpehh",
"(",
"h1",
",",
"h2",
",",
"pos",
",",
"map_pos",
"=",
"None",
",",
"min_ehh",
"=",
"0.05",
",",
"include_edges",
"=",
"False",
",",
"gap_scale",
"=",
"20000",
",",
"max_gap",
"=",
"200000",
",",
"is_accessible",
"=",
"None",
",",
"us... | Compute the unstandardized cross-population extended haplotype
homozygosity score (XPEHH) for each variant.
Parameters
----------
h1 : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array for the first population.
h2 : array_like, int, shape (n_variants, n_haplotypes)
H... | [
"Compute",
"the",
"unstandardized",
"cross",
"-",
"population",
"extended",
"haplotype",
"homozygosity",
"score",
"(",
"XPEHH",
")",
"for",
"each",
"variant",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L446-L571 |
cggh/scikit-allel | allel/stats/selection.py | nsl | def nsl(h, use_threads=True):
"""Compute the unstandardized number of segregating sites by length (nSl)
for each variant, comparing the reference and alternate alleles,
after Ferrer-Admetlla et al. (2014).
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplo... | python | def nsl(h, use_threads=True):
"""Compute the unstandardized number of segregating sites by length (nSl)
for each variant, comparing the reference and alternate alleles,
after Ferrer-Admetlla et al. (2014).
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplo... | [
"def",
"nsl",
"(",
"h",
",",
"use_threads",
"=",
"True",
")",
":",
"# check inputs",
"h",
"=",
"asarray_ndim",
"(",
"h",
",",
"2",
")",
"check_integer_dtype",
"(",
"h",
")",
"h",
"=",
"memoryview_safe",
"(",
"h",
")",
"# # check there are no invariant sites"... | Compute the unstandardized number of segregating sites by length (nSl)
for each variant, comparing the reference and alternate alleles,
after Ferrer-Admetlla et al. (2014).
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
use_threads : bool, o... | [
"Compute",
"the",
"unstandardized",
"number",
"of",
"segregating",
"sites",
"by",
"length",
"(",
"nSl",
")",
"for",
"each",
"variant",
"comparing",
"the",
"reference",
"and",
"alternate",
"alleles",
"after",
"Ferrer",
"-",
"Admetlla",
"et",
"al",
".",
"(",
"... | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L574-L658 |
cggh/scikit-allel | allel/stats/selection.py | xpnsl | def xpnsl(h1, h2, use_threads=True):
"""Cross-population version of the NSL statistic.
Parameters
----------
h1 : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array for the first population.
h2 : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array for th... | python | def xpnsl(h1, h2, use_threads=True):
"""Cross-population version of the NSL statistic.
Parameters
----------
h1 : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array for the first population.
h2 : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array for th... | [
"def",
"xpnsl",
"(",
"h1",
",",
"h2",
",",
"use_threads",
"=",
"True",
")",
":",
"# check inputs",
"h1",
"=",
"asarray_ndim",
"(",
"h1",
",",
"2",
")",
"check_integer_dtype",
"(",
"h1",
")",
"h2",
"=",
"asarray_ndim",
"(",
"h2",
",",
"2",
")",
"check... | Cross-population version of the NSL statistic.
Parameters
----------
h1 : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array for the first population.
h2 : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array for the second population.
use_threads : bool,... | [
"Cross",
"-",
"population",
"version",
"of",
"the",
"NSL",
"statistic",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L661-L736 |
cggh/scikit-allel | allel/stats/selection.py | haplotype_diversity | def haplotype_diversity(h):
"""Estimate haplotype diversity.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
Returns
-------
hd : float
Haplotype diversity.
"""
# check inputs
h = HaplotypeArray(h, copy=False)
... | python | def haplotype_diversity(h):
"""Estimate haplotype diversity.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
Returns
-------
hd : float
Haplotype diversity.
"""
# check inputs
h = HaplotypeArray(h, copy=False)
... | [
"def",
"haplotype_diversity",
"(",
"h",
")",
":",
"# check inputs",
"h",
"=",
"HaplotypeArray",
"(",
"h",
",",
"copy",
"=",
"False",
")",
"# number of haplotypes",
"n",
"=",
"h",
".",
"n_haplotypes",
"# compute haplotype frequencies",
"f",
"=",
"h",
".",
"dist... | Estimate haplotype diversity.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
Returns
-------
hd : float
Haplotype diversity. | [
"Estimate",
"haplotype",
"diversity",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L739-L766 |
cggh/scikit-allel | allel/stats/selection.py | moving_haplotype_diversity | def moving_haplotype_diversity(h, size, start=0, stop=None, step=None):
"""Estimate haplotype diversity in moving windows.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
size : int
The window size (number of variants).
start : int, o... | python | def moving_haplotype_diversity(h, size, start=0, stop=None, step=None):
"""Estimate haplotype diversity in moving windows.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
size : int
The window size (number of variants).
start : int, o... | [
"def",
"moving_haplotype_diversity",
"(",
"h",
",",
"size",
",",
"start",
"=",
"0",
",",
"stop",
"=",
"None",
",",
"step",
"=",
"None",
")",
":",
"hd",
"=",
"moving_statistic",
"(",
"values",
"=",
"h",
",",
"statistic",
"=",
"haplotype_diversity",
",",
... | Estimate haplotype diversity in moving windows.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
size : int
The window size (number of variants).
start : int, optional
The index at which to start.
stop : int, optional
T... | [
"Estimate",
"haplotype",
"diversity",
"in",
"moving",
"windows",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L769-L795 |
cggh/scikit-allel | allel/stats/selection.py | garud_h | def garud_h(h):
"""Compute the H1, H12, H123 and H2/H1 statistics for detecting signatures
of soft sweeps, as defined in Garud et al. (2015).
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
Returns
-------
h1 : float
H1 stati... | python | def garud_h(h):
"""Compute the H1, H12, H123 and H2/H1 statistics for detecting signatures
of soft sweeps, as defined in Garud et al. (2015).
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
Returns
-------
h1 : float
H1 stati... | [
"def",
"garud_h",
"(",
"h",
")",
":",
"# check inputs",
"h",
"=",
"HaplotypeArray",
"(",
"h",
",",
"copy",
"=",
"False",
")",
"# compute haplotype frequencies",
"f",
"=",
"h",
".",
"distinct_frequencies",
"(",
")",
"# compute H1",
"h1",
"=",
"np",
".",
"su... | Compute the H1, H12, H123 and H2/H1 statistics for detecting signatures
of soft sweeps, as defined in Garud et al. (2015).
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
Returns
-------
h1 : float
H1 statistic (sum of squares of... | [
"Compute",
"the",
"H1",
"H12",
"H123",
"and",
"H2",
"/",
"H1",
"statistics",
"for",
"detecting",
"signatures",
"of",
"soft",
"sweeps",
"as",
"defined",
"in",
"Garud",
"et",
"al",
".",
"(",
"2015",
")",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L798-L841 |
cggh/scikit-allel | allel/stats/selection.py | moving_garud_h | def moving_garud_h(h, size, start=0, stop=None, step=None):
"""Compute the H1, H12, H123 and H2/H1 statistics for detecting signatures
of soft sweeps, as defined in Garud et al. (2015), in moving windows,
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype ... | python | def moving_garud_h(h, size, start=0, stop=None, step=None):
"""Compute the H1, H12, H123 and H2/H1 statistics for detecting signatures
of soft sweeps, as defined in Garud et al. (2015), in moving windows,
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype ... | [
"def",
"moving_garud_h",
"(",
"h",
",",
"size",
",",
"start",
"=",
"0",
",",
"stop",
"=",
"None",
",",
"step",
"=",
"None",
")",
":",
"gh",
"=",
"moving_statistic",
"(",
"values",
"=",
"h",
",",
"statistic",
"=",
"garud_h",
",",
"size",
"=",
"size"... | Compute the H1, H12, H123 and H2/H1 statistics for detecting signatures
of soft sweeps, as defined in Garud et al. (2015), in moving windows,
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
size : int
The window size (number of variants).... | [
"Compute",
"the",
"H1",
"H12",
"H123",
"and",
"H2",
"/",
"H1",
"statistics",
"for",
"detecting",
"signatures",
"of",
"soft",
"sweeps",
"as",
"defined",
"in",
"Garud",
"et",
"al",
".",
"(",
"2015",
")",
"in",
"moving",
"windows"
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L844-L885 |
cggh/scikit-allel | allel/stats/selection.py | plot_haplotype_frequencies | def plot_haplotype_frequencies(h, palette='Paired', singleton_color='w',
ax=None):
"""Plot haplotype frequencies.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
palette : string, optional
A Seaborn palette ... | python | def plot_haplotype_frequencies(h, palette='Paired', singleton_color='w',
ax=None):
"""Plot haplotype frequencies.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
palette : string, optional
A Seaborn palette ... | [
"def",
"plot_haplotype_frequencies",
"(",
"h",
",",
"palette",
"=",
"'Paired'",
",",
"singleton_color",
"=",
"'w'",
",",
"ax",
"=",
"None",
")",
":",
"import",
"matplotlib",
".",
"pyplot",
"as",
"plt",
"import",
"seaborn",
"as",
"sns",
"# check inputs",
"h",... | Plot haplotype frequencies.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
palette : string, optional
A Seaborn palette name.
singleton_color : string, optional
Color to paint singleton haplotypes.
ax : axes, optional
... | [
"Plot",
"haplotype",
"frequencies",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L888-L945 |
cggh/scikit-allel | allel/stats/selection.py | moving_hfs_rank | def moving_hfs_rank(h, size, start=0, stop=None):
"""Helper function for plotting haplotype frequencies in moving windows.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
size : int
The window size (number of variants).
start : int, o... | python | def moving_hfs_rank(h, size, start=0, stop=None):
"""Helper function for plotting haplotype frequencies in moving windows.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
size : int
The window size (number of variants).
start : int, o... | [
"def",
"moving_hfs_rank",
"(",
"h",
",",
"size",
",",
"start",
"=",
"0",
",",
"stop",
"=",
"None",
")",
":",
"# determine windows",
"windows",
"=",
"np",
".",
"asarray",
"(",
"list",
"(",
"index_windows",
"(",
"h",
",",
"size",
"=",
"size",
",",
"sta... | Helper function for plotting haplotype frequencies in moving windows.
Parameters
----------
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
size : int
The window size (number of variants).
start : int, optional
The index at which to start.
stop : i... | [
"Helper",
"function",
"for",
"plotting",
"haplotype",
"frequencies",
"in",
"moving",
"windows",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L948-L996 |
cggh/scikit-allel | allel/stats/selection.py | plot_moving_haplotype_frequencies | def plot_moving_haplotype_frequencies(pos, h, size, start=0, stop=None, n=None,
palette='Paired', singleton_color='w',
ax=None):
"""Plot haplotype frequencies in moving windows over the genome.
Parameters
----------
pos : array... | python | def plot_moving_haplotype_frequencies(pos, h, size, start=0, stop=None, n=None,
palette='Paired', singleton_color='w',
ax=None):
"""Plot haplotype frequencies in moving windows over the genome.
Parameters
----------
pos : array... | [
"def",
"plot_moving_haplotype_frequencies",
"(",
"pos",
",",
"h",
",",
"size",
",",
"start",
"=",
"0",
",",
"stop",
"=",
"None",
",",
"n",
"=",
"None",
",",
"palette",
"=",
"'Paired'",
",",
"singleton_color",
"=",
"'w'",
",",
"ax",
"=",
"None",
")",
... | Plot haplotype frequencies in moving windows over the genome.
Parameters
----------
pos : array_like, int, shape (n_items,)
Variant positions, using 1-based coordinates, in ascending order.
h : array_like, int, shape (n_variants, n_haplotypes)
Haplotype array.
size : int
The... | [
"Plot",
"haplotype",
"frequencies",
"in",
"moving",
"windows",
"over",
"the",
"genome",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L999-L1070 |
cggh/scikit-allel | allel/stats/selection.py | moving_delta_tajima_d | def moving_delta_tajima_d(ac1, ac2, size, start=0, stop=None, step=None):
"""Compute the difference in Tajima's D between two populations in
moving windows.
Parameters
----------
ac1 : array_like, int, shape (n_variants, n_alleles)
Allele counts array for the first population.
ac2 : arr... | python | def moving_delta_tajima_d(ac1, ac2, size, start=0, stop=None, step=None):
"""Compute the difference in Tajima's D between two populations in
moving windows.
Parameters
----------
ac1 : array_like, int, shape (n_variants, n_alleles)
Allele counts array for the first population.
ac2 : arr... | [
"def",
"moving_delta_tajima_d",
"(",
"ac1",
",",
"ac2",
",",
"size",
",",
"start",
"=",
"0",
",",
"stop",
"=",
"None",
",",
"step",
"=",
"None",
")",
":",
"d1",
"=",
"moving_tajima_d",
"(",
"ac1",
",",
"size",
"=",
"size",
",",
"start",
"=",
"start... | Compute the difference in Tajima's D between two populations in
moving windows.
Parameters
----------
ac1 : array_like, int, shape (n_variants, n_alleles)
Allele counts array for the first population.
ac2 : array_like, int, shape (n_variants, n_alleles)
Allele counts array for the s... | [
"Compute",
"the",
"difference",
"in",
"Tajima",
"s",
"D",
"between",
"two",
"populations",
"in",
"moving",
"windows",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L1073-L1108 |
cggh/scikit-allel | allel/stats/selection.py | make_similar_sized_bins | def make_similar_sized_bins(x, n):
"""Utility function to create a set of bins over the range of values in `x`
such that each bin contains roughly the same number of values.
Parameters
----------
x : array_like
The values to be binned.
n : int
The number of bins to create.
... | python | def make_similar_sized_bins(x, n):
"""Utility function to create a set of bins over the range of values in `x`
such that each bin contains roughly the same number of values.
Parameters
----------
x : array_like
The values to be binned.
n : int
The number of bins to create.
... | [
"def",
"make_similar_sized_bins",
"(",
"x",
",",
"n",
")",
":",
"# copy and sort the array",
"y",
"=",
"np",
".",
"array",
"(",
"x",
")",
".",
"flatten",
"(",
")",
"y",
".",
"sort",
"(",
")",
"# setup bins",
"bins",
"=",
"[",
"y",
"[",
"0",
"]",
"]... | Utility function to create a set of bins over the range of values in `x`
such that each bin contains roughly the same number of values.
Parameters
----------
x : array_like
The values to be binned.
n : int
The number of bins to create.
Returns
-------
bins : ndarray
... | [
"Utility",
"function",
"to",
"create",
"a",
"set",
"of",
"bins",
"over",
"the",
"range",
"of",
"values",
"in",
"x",
"such",
"that",
"each",
"bin",
"contains",
"roughly",
"the",
"same",
"number",
"of",
"values",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L1111-L1157 |
cggh/scikit-allel | allel/stats/selection.py | standardize | def standardize(score):
"""Centre and scale to unit variance."""
score = asarray_ndim(score, 1)
return (score - np.nanmean(score)) / np.nanstd(score) | python | def standardize(score):
"""Centre and scale to unit variance."""
score = asarray_ndim(score, 1)
return (score - np.nanmean(score)) / np.nanstd(score) | [
"def",
"standardize",
"(",
"score",
")",
":",
"score",
"=",
"asarray_ndim",
"(",
"score",
",",
"1",
")",
"return",
"(",
"score",
"-",
"np",
".",
"nanmean",
"(",
"score",
")",
")",
"/",
"np",
".",
"nanstd",
"(",
"score",
")"
] | Centre and scale to unit variance. | [
"Centre",
"and",
"scale",
"to",
"unit",
"variance",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L1160-L1163 |
cggh/scikit-allel | allel/stats/selection.py | standardize_by_allele_count | def standardize_by_allele_count(score, aac, bins=None, n_bins=None,
diagnostics=True):
"""Standardize `score` within allele frequency bins.
Parameters
----------
score : array_like, float
The score to be standardized, e.g., IHS or NSL.
aac : array_like, int
... | python | def standardize_by_allele_count(score, aac, bins=None, n_bins=None,
diagnostics=True):
"""Standardize `score` within allele frequency bins.
Parameters
----------
score : array_like, float
The score to be standardized, e.g., IHS or NSL.
aac : array_like, int
... | [
"def",
"standardize_by_allele_count",
"(",
"score",
",",
"aac",
",",
"bins",
"=",
"None",
",",
"n_bins",
"=",
"None",
",",
"diagnostics",
"=",
"True",
")",
":",
"from",
"scipy",
".",
"stats",
"import",
"binned_statistic",
"# check inputs",
"score",
"=",
"asa... | Standardize `score` within allele frequency bins.
Parameters
----------
score : array_like, float
The score to be standardized, e.g., IHS or NSL.
aac : array_like, int
An array of alternate allele counts.
bins : array_like, int, optional
Allele count bins, overrides `n_bins`... | [
"Standardize",
"score",
"within",
"allele",
"frequency",
"bins",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L1166-L1260 |
cggh/scikit-allel | allel/stats/selection.py | pbs | def pbs(ac1, ac2, ac3, window_size, window_start=0, window_stop=None,
window_step=None, normed=True):
"""Compute the population branching statistic (PBS) which performs a comparison
of allele frequencies between three populations to detect genome regions that are
unusually differentiated in one popu... | python | def pbs(ac1, ac2, ac3, window_size, window_start=0, window_stop=None,
window_step=None, normed=True):
"""Compute the population branching statistic (PBS) which performs a comparison
of allele frequencies between three populations to detect genome regions that are
unusually differentiated in one popu... | [
"def",
"pbs",
"(",
"ac1",
",",
"ac2",
",",
"ac3",
",",
"window_size",
",",
"window_start",
"=",
"0",
",",
"window_stop",
"=",
"None",
",",
"window_step",
"=",
"None",
",",
"normed",
"=",
"True",
")",
":",
"# normalise and check inputs",
"ac1",
"=",
"Alle... | Compute the population branching statistic (PBS) which performs a comparison
of allele frequencies between three populations to detect genome regions that are
unusually differentiated in one population relative to the other two populations.
Parameters
----------
ac1 : array_like, int
Allele... | [
"Compute",
"the",
"population",
"branching",
"statistic",
"(",
"PBS",
")",
"which",
"performs",
"a",
"comparison",
"of",
"allele",
"frequencies",
"between",
"three",
"populations",
"to",
"detect",
"genome",
"regions",
"that",
"are",
"unusually",
"differentiated",
... | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/selection.py#L1263-L1339 |
cggh/scikit-allel | allel/stats/window.py | moving_statistic | def moving_statistic(values, statistic, size, start=0, stop=None, step=None, **kwargs):
"""Calculate a statistic in a moving window over `values`.
Parameters
----------
values : array_like
The data to summarise.
statistic : function
The statistic to compute within each window.
... | python | def moving_statistic(values, statistic, size, start=0, stop=None, step=None, **kwargs):
"""Calculate a statistic in a moving window over `values`.
Parameters
----------
values : array_like
The data to summarise.
statistic : function
The statistic to compute within each window.
... | [
"def",
"moving_statistic",
"(",
"values",
",",
"statistic",
",",
"size",
",",
"start",
"=",
"0",
",",
"stop",
"=",
"None",
",",
"step",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"windows",
"=",
"index_windows",
"(",
"values",
",",
"size",
",",
... | Calculate a statistic in a moving window over `values`.
Parameters
----------
values : array_like
The data to summarise.
statistic : function
The statistic to compute within each window.
size : int
The window size (number of values).
start : int, optional
The in... | [
"Calculate",
"a",
"statistic",
"in",
"a",
"moving",
"window",
"over",
"values",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/window.py#L12-L57 |
cggh/scikit-allel | allel/stats/window.py | index_windows | def index_windows(values, size, start, stop, step):
"""Convenience function to construct windows for the
:func:`moving_statistic` function.
"""
# determine step
if stop is None:
stop = len(values)
if step is None:
# non-overlapping
step = size
# iterate over window... | python | def index_windows(values, size, start, stop, step):
"""Convenience function to construct windows for the
:func:`moving_statistic` function.
"""
# determine step
if stop is None:
stop = len(values)
if step is None:
# non-overlapping
step = size
# iterate over window... | [
"def",
"index_windows",
"(",
"values",
",",
"size",
",",
"start",
",",
"stop",
",",
"step",
")",
":",
"# determine step",
"if",
"stop",
"is",
"None",
":",
"stop",
"=",
"len",
"(",
"values",
")",
"if",
"step",
"is",
"None",
":",
"# non-overlapping",
"st... | Convenience function to construct windows for the
:func:`moving_statistic` function. | [
"Convenience",
"function",
"to",
"construct",
"windows",
"for",
"the",
":",
"func",
":",
"moving_statistic",
"function",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/window.py#L75-L96 |
cggh/scikit-allel | allel/stats/window.py | position_windows | def position_windows(pos, size, start, stop, step):
"""Convenience function to construct windows for the
:func:`windowed_statistic` and :func:`windowed_count` functions.
"""
last = False
# determine start and stop positions
if start is None:
start = pos[0]
if stop is None:
... | python | def position_windows(pos, size, start, stop, step):
"""Convenience function to construct windows for the
:func:`windowed_statistic` and :func:`windowed_count` functions.
"""
last = False
# determine start and stop positions
if start is None:
start = pos[0]
if stop is None:
... | [
"def",
"position_windows",
"(",
"pos",
",",
"size",
",",
"start",
",",
"stop",
",",
"step",
")",
":",
"last",
"=",
"False",
"# determine start and stop positions",
"if",
"start",
"is",
"None",
":",
"start",
"=",
"pos",
"[",
"0",
"]",
"if",
"stop",
"is",
... | Convenience function to construct windows for the
:func:`windowed_statistic` and :func:`windowed_count` functions. | [
"Convenience",
"function",
"to",
"construct",
"windows",
"for",
"the",
":",
"func",
":",
"windowed_statistic",
"and",
":",
"func",
":",
"windowed_count",
"functions",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/window.py#L99-L132 |
cggh/scikit-allel | allel/stats/window.py | window_locations | def window_locations(pos, windows):
"""Locate indices in `pos` corresponding to the start and stop positions
of `windows`.
"""
start_locs = np.searchsorted(pos, windows[:, 0])
stop_locs = np.searchsorted(pos, windows[:, 1], side='right')
locs = np.column_stack((start_locs, stop_locs))
retur... | python | def window_locations(pos, windows):
"""Locate indices in `pos` corresponding to the start and stop positions
of `windows`.
"""
start_locs = np.searchsorted(pos, windows[:, 0])
stop_locs = np.searchsorted(pos, windows[:, 1], side='right')
locs = np.column_stack((start_locs, stop_locs))
retur... | [
"def",
"window_locations",
"(",
"pos",
",",
"windows",
")",
":",
"start_locs",
"=",
"np",
".",
"searchsorted",
"(",
"pos",
",",
"windows",
"[",
":",
",",
"0",
"]",
")",
"stop_locs",
"=",
"np",
".",
"searchsorted",
"(",
"pos",
",",
"windows",
"[",
":"... | Locate indices in `pos` corresponding to the start and stop positions
of `windows`. | [
"Locate",
"indices",
"in",
"pos",
"corresponding",
"to",
"the",
"start",
"and",
"stop",
"positions",
"of",
"windows",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/window.py#L135-L143 |
cggh/scikit-allel | allel/stats/window.py | windowed_count | def windowed_count(pos, size=None, start=None, stop=None, step=None,
windows=None):
"""Count the number of items in windows over a single chromosome/contig.
Parameters
----------
pos : array_like, int, shape (n_items,)
The item positions in ascending order, using 1-based coo... | python | def windowed_count(pos, size=None, start=None, stop=None, step=None,
windows=None):
"""Count the number of items in windows over a single chromosome/contig.
Parameters
----------
pos : array_like, int, shape (n_items,)
The item positions in ascending order, using 1-based coo... | [
"def",
"windowed_count",
"(",
"pos",
",",
"size",
"=",
"None",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
",",
"step",
"=",
"None",
",",
"windows",
"=",
"None",
")",
":",
"# assume sorted positions",
"if",
"not",
"isinstance",
"(",
"pos",
","... | Count the number of items in windows over a single chromosome/contig.
Parameters
----------
pos : array_like, int, shape (n_items,)
The item positions in ascending order, using 1-based coordinates..
size : int, optional
The window size (number of bases).
start : int, optional
... | [
"Count",
"the",
"number",
"of",
"items",
"in",
"windows",
"over",
"a",
"single",
"chromosome",
"/",
"contig",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/window.py#L146-L231 |
cggh/scikit-allel | allel/stats/window.py | windowed_statistic | def windowed_statistic(pos, values, statistic, size=None, start=None,
stop=None, step=None, windows=None, fill=np.nan):
"""Calculate a statistic from items in windows over a single
chromosome/contig.
Parameters
----------
pos : array_like, int, shape (n_items,)
The i... | python | def windowed_statistic(pos, values, statistic, size=None, start=None,
stop=None, step=None, windows=None, fill=np.nan):
"""Calculate a statistic from items in windows over a single
chromosome/contig.
Parameters
----------
pos : array_like, int, shape (n_items,)
The i... | [
"def",
"windowed_statistic",
"(",
"pos",
",",
"values",
",",
"statistic",
",",
"size",
"=",
"None",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
",",
"step",
"=",
"None",
",",
"windows",
"=",
"None",
",",
"fill",
"=",
"np",
".",
"nan",
")",... | Calculate a statistic from items in windows over a single
chromosome/contig.
Parameters
----------
pos : array_like, int, shape (n_items,)
The item positions in ascending order, using 1-based coordinates..
values : array_like, int, shape (n_items,)
The values to summarise. May also... | [
"Calculate",
"a",
"statistic",
"from",
"items",
"in",
"windows",
"over",
"a",
"single",
"chromosome",
"/",
"contig",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/window.py#L234-L376 |
cggh/scikit-allel | allel/stats/window.py | per_base | def per_base(x, windows, is_accessible=None, fill=np.nan):
"""Calculate the per-base value of a windowed statistic.
Parameters
----------
x : array_like, shape (n_windows,)
The statistic to average per-base.
windows : array_like, int, shape (n_windows, 2)
The windows used, as an ar... | python | def per_base(x, windows, is_accessible=None, fill=np.nan):
"""Calculate the per-base value of a windowed statistic.
Parameters
----------
x : array_like, shape (n_windows,)
The statistic to average per-base.
windows : array_like, int, shape (n_windows, 2)
The windows used, as an ar... | [
"def",
"per_base",
"(",
"x",
",",
"windows",
",",
"is_accessible",
"=",
"None",
",",
"fill",
"=",
"np",
".",
"nan",
")",
":",
"# calculate window sizes",
"if",
"is_accessible",
"is",
"None",
":",
"# N.B., window stops are included",
"n_bases",
"=",
"np",
".",
... | Calculate the per-base value of a windowed statistic.
Parameters
----------
x : array_like, shape (n_windows,)
The statistic to average per-base.
windows : array_like, int, shape (n_windows, 2)
The windows used, as an array of (window_start, window_stop)
positions using 1-based... | [
"Calculate",
"the",
"per",
"-",
"base",
"value",
"of",
"a",
"windowed",
"statistic",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/window.py#L379-L431 |
cggh/scikit-allel | allel/stats/window.py | equally_accessible_windows | def equally_accessible_windows(is_accessible, size, start=0, stop=None, step=None):
"""Create windows each containing the same number of accessible bases.
Parameters
----------
is_accessible : array_like, bool, shape (n_bases,)
Array defining accessible status of all bases on a contig/chromosom... | python | def equally_accessible_windows(is_accessible, size, start=0, stop=None, step=None):
"""Create windows each containing the same number of accessible bases.
Parameters
----------
is_accessible : array_like, bool, shape (n_bases,)
Array defining accessible status of all bases on a contig/chromosom... | [
"def",
"equally_accessible_windows",
"(",
"is_accessible",
",",
"size",
",",
"start",
"=",
"0",
",",
"stop",
"=",
"None",
",",
"step",
"=",
"None",
")",
":",
"pos_accessible",
",",
"=",
"np",
".",
"nonzero",
"(",
"is_accessible",
")",
"pos_accessible",
"+=... | Create windows each containing the same number of accessible bases.
Parameters
----------
is_accessible : array_like, bool, shape (n_bases,)
Array defining accessible status of all bases on a contig/chromosome.
size : int
Window size (number of accessible bases).
start : int, option... | [
"Create",
"windows",
"each",
"containing",
"the",
"same",
"number",
"of",
"accessible",
"bases",
"."
] | train | https://github.com/cggh/scikit-allel/blob/3c979a57a100240ba959dd13f98839349530f215/allel/stats/window.py#L434-L472 |
bartTC/django-attachments | attachments/templatetags/attachments_tags.py | attachment_form | def attachment_form(context, obj):
"""
Renders a "upload attachment" form.
The user must own ``attachments.add_attachment permission`` to add
attachments.
"""
if context['user'].has_perm('attachments.add_attachment'):
return {
'form': AttachmentForm(),
'form_url'... | python | def attachment_form(context, obj):
"""
Renders a "upload attachment" form.
The user must own ``attachments.add_attachment permission`` to add
attachments.
"""
if context['user'].has_perm('attachments.add_attachment'):
return {
'form': AttachmentForm(),
'form_url'... | [
"def",
"attachment_form",
"(",
"context",
",",
"obj",
")",
":",
"if",
"context",
"[",
"'user'",
"]",
".",
"has_perm",
"(",
"'attachments.add_attachment'",
")",
":",
"return",
"{",
"'form'",
":",
"AttachmentForm",
"(",
")",
",",
"'form_url'",
":",
"add_url_fo... | Renders a "upload attachment" form.
The user must own ``attachments.add_attachment permission`` to add
attachments. | [
"Renders",
"a",
"upload",
"attachment",
"form",
"."
] | train | https://github.com/bartTC/django-attachments/blob/012b7168f9342e07683a54ceab57696e0072962e/attachments/templatetags/attachments_tags.py#L12-L26 |
bartTC/django-attachments | attachments/templatetags/attachments_tags.py | attachment_delete_link | def attachment_delete_link(context, attachment):
"""
Renders a html link to the delete view of the given attachment. Returns
no content if the request-user has no permission to delete attachments.
The user must own either the ``attachments.delete_attachment`` permission
and is the creator of the at... | python | def attachment_delete_link(context, attachment):
"""
Renders a html link to the delete view of the given attachment. Returns
no content if the request-user has no permission to delete attachments.
The user must own either the ``attachments.delete_attachment`` permission
and is the creator of the at... | [
"def",
"attachment_delete_link",
"(",
"context",
",",
"attachment",
")",
":",
"if",
"context",
"[",
"'user'",
"]",
".",
"has_perm",
"(",
"'attachments.delete_foreign_attachments'",
")",
"or",
"(",
"context",
"[",
"'user'",
"]",
"==",
"attachment",
".",
"creator"... | Renders a html link to the delete view of the given attachment. Returns
no content if the request-user has no permission to delete attachments.
The user must own either the ``attachments.delete_attachment`` permission
and is the creator of the attachment, that he can delete it or he has
``attachments.d... | [
"Renders",
"a",
"html",
"link",
"to",
"the",
"delete",
"view",
"of",
"the",
"given",
"attachment",
".",
"Returns",
"no",
"content",
"if",
"the",
"request",
"-",
"user",
"has",
"no",
"permission",
"to",
"delete",
"attachments",
"."
] | train | https://github.com/bartTC/django-attachments/blob/012b7168f9342e07683a54ceab57696e0072962e/attachments/templatetags/attachments_tags.py#L30-L50 |
bartTC/django-attachments | attachments/models.py | attachment_upload | def attachment_upload(instance, filename):
"""Stores the attachment in a "per module/appname/primary key" folder"""
return 'attachments/{app}_{model}/{pk}/{filename}'.format(
app=instance.content_object._meta.app_label,
model=instance.content_object._meta.object_name.lower(),
pk=instance... | python | def attachment_upload(instance, filename):
"""Stores the attachment in a "per module/appname/primary key" folder"""
return 'attachments/{app}_{model}/{pk}/{filename}'.format(
app=instance.content_object._meta.app_label,
model=instance.content_object._meta.object_name.lower(),
pk=instance... | [
"def",
"attachment_upload",
"(",
"instance",
",",
"filename",
")",
":",
"return",
"'attachments/{app}_{model}/{pk}/{filename}'",
".",
"format",
"(",
"app",
"=",
"instance",
".",
"content_object",
".",
"_meta",
".",
"app_label",
",",
"model",
"=",
"instance",
".",
... | Stores the attachment in a "per module/appname/primary key" folder | [
"Stores",
"the",
"attachment",
"in",
"a",
"per",
"module",
"/",
"appname",
"/",
"primary",
"key",
"folder"
] | train | https://github.com/bartTC/django-attachments/blob/012b7168f9342e07683a54ceab57696e0072962e/attachments/models.py#L13-L20 |
csurfer/pyheat | pyheat/pyheat.py | PyHeat.show_heatmap | def show_heatmap(self, blocking=True, output_file=None, enable_scroll=False):
"""Method to actually display the heatmap created.
@param blocking: When set to False makes an unblocking plot show.
@param output_file: If not None the heatmap image is output to this
file. Suppor... | python | def show_heatmap(self, blocking=True, output_file=None, enable_scroll=False):
"""Method to actually display the heatmap created.
@param blocking: When set to False makes an unblocking plot show.
@param output_file: If not None the heatmap image is output to this
file. Suppor... | [
"def",
"show_heatmap",
"(",
"self",
",",
"blocking",
"=",
"True",
",",
"output_file",
"=",
"None",
",",
"enable_scroll",
"=",
"False",
")",
":",
"if",
"output_file",
"is",
"None",
":",
"if",
"enable_scroll",
":",
"# Add a new axes which will be used as scroll bar.... | Method to actually display the heatmap created.
@param blocking: When set to False makes an unblocking plot show.
@param output_file: If not None the heatmap image is output to this
file. Supported formats: (eps, pdf, pgf, png, ps, raw, rgba, svg,
svgz)
@para... | [
"Method",
"to",
"actually",
"display",
"the",
"heatmap",
"created",
"."
] | train | https://github.com/csurfer/pyheat/blob/cc0ee3721aea70a1da4918957500131aa7077afe/pyheat/pyheat.py#L53-L77 |
csurfer/pyheat | pyheat/pyheat.py | PyHeat.__profile_file | def __profile_file(self):
"""Method used to profile the given file line by line."""
self.line_profiler = pprofile.Profile()
self.line_profiler.runfile(
open(self.pyfile.path, "r"), {}, self.pyfile.path
) | python | def __profile_file(self):
"""Method used to profile the given file line by line."""
self.line_profiler = pprofile.Profile()
self.line_profiler.runfile(
open(self.pyfile.path, "r"), {}, self.pyfile.path
) | [
"def",
"__profile_file",
"(",
"self",
")",
":",
"self",
".",
"line_profiler",
"=",
"pprofile",
".",
"Profile",
"(",
")",
"self",
".",
"line_profiler",
".",
"runfile",
"(",
"open",
"(",
"self",
".",
"pyfile",
".",
"path",
",",
"\"r\"",
")",
",",
"{",
... | Method used to profile the given file line by line. | [
"Method",
"used",
"to",
"profile",
"the",
"given",
"file",
"line",
"by",
"line",
"."
] | train | https://github.com/csurfer/pyheat/blob/cc0ee3721aea70a1da4918957500131aa7077afe/pyheat/pyheat.py#L83-L88 |
csurfer/pyheat | pyheat/pyheat.py | PyHeat.__get_line_profile_data | def __get_line_profile_data(self):
"""Method to procure line profiles.
@return: Line profiles if the file has been profiles else empty
dictionary.
"""
if self.line_profiler is None:
return {}
# the [0] is because pprofile.Profile.file_dict stores the l... | python | def __get_line_profile_data(self):
"""Method to procure line profiles.
@return: Line profiles if the file has been profiles else empty
dictionary.
"""
if self.line_profiler is None:
return {}
# the [0] is because pprofile.Profile.file_dict stores the l... | [
"def",
"__get_line_profile_data",
"(",
"self",
")",
":",
"if",
"self",
".",
"line_profiler",
"is",
"None",
":",
"return",
"{",
"}",
"# the [0] is because pprofile.Profile.file_dict stores the line_dict",
"# in a list so that it can be modified in a thread-safe way",
"# see https:... | Method to procure line profiles.
@return: Line profiles if the file has been profiles else empty
dictionary. | [
"Method",
"to",
"procure",
"line",
"profiles",
"."
] | train | https://github.com/csurfer/pyheat/blob/cc0ee3721aea70a1da4918957500131aa7077afe/pyheat/pyheat.py#L90-L102 |
csurfer/pyheat | pyheat/pyheat.py | PyHeat.__fetch_heatmap_data_from_profile | def __fetch_heatmap_data_from_profile(self):
"""Method to create heatmap data from profile information."""
# Read lines from file.
with open(self.pyfile.path, "r") as file_to_read:
for line in file_to_read:
# Remove return char from the end of the line and add a
... | python | def __fetch_heatmap_data_from_profile(self):
"""Method to create heatmap data from profile information."""
# Read lines from file.
with open(self.pyfile.path, "r") as file_to_read:
for line in file_to_read:
# Remove return char from the end of the line and add a
... | [
"def",
"__fetch_heatmap_data_from_profile",
"(",
"self",
")",
":",
"# Read lines from file.",
"with",
"open",
"(",
"self",
".",
"pyfile",
".",
"path",
",",
"\"r\"",
")",
"as",
"file_to_read",
":",
"for",
"line",
"in",
"file_to_read",
":",
"# Remove return char fro... | Method to create heatmap data from profile information. | [
"Method",
"to",
"create",
"heatmap",
"data",
"from",
"profile",
"information",
"."
] | train | https://github.com/csurfer/pyheat/blob/cc0ee3721aea70a1da4918957500131aa7077afe/pyheat/pyheat.py#L104-L135 |
csurfer/pyheat | pyheat/pyheat.py | PyHeat.__create_heatmap_plot | def __create_heatmap_plot(self):
"""Method to actually create the heatmap from profile stats."""
# Define the heatmap plot.
height = len(self.pyfile.lines) / 3
width = max(map(lambda x: len(x), self.pyfile.lines)) / 8
self.fig, self.ax = plt.subplots(figsize=(width, height))
... | python | def __create_heatmap_plot(self):
"""Method to actually create the heatmap from profile stats."""
# Define the heatmap plot.
height = len(self.pyfile.lines) / 3
width = max(map(lambda x: len(x), self.pyfile.lines)) / 8
self.fig, self.ax = plt.subplots(figsize=(width, height))
... | [
"def",
"__create_heatmap_plot",
"(",
"self",
")",
":",
"# Define the heatmap plot.",
"height",
"=",
"len",
"(",
"self",
".",
"pyfile",
".",
"lines",
")",
"/",
"3",
"width",
"=",
"max",
"(",
"map",
"(",
"lambda",
"x",
":",
"len",
"(",
"x",
")",
",",
"... | Method to actually create the heatmap from profile stats. | [
"Method",
"to",
"actually",
"create",
"the",
"heatmap",
"from",
"profile",
"stats",
"."
] | train | https://github.com/csurfer/pyheat/blob/cc0ee3721aea70a1da4918957500131aa7077afe/pyheat/pyheat.py#L137-L189 |
csurfer/pyheat | pyheat/commandline.py | main | def main():
"""Starting point for the program execution."""
# Create command line parser.
parser = argparse.ArgumentParser()
# Adding command line arguments.
parser.add_argument("-o", "--out", help="Output file", default=None)
parser.add_argument(
"pyfile", help="Python file to be profil... | python | def main():
"""Starting point for the program execution."""
# Create command line parser.
parser = argparse.ArgumentParser()
# Adding command line arguments.
parser.add_argument("-o", "--out", help="Output file", default=None)
parser.add_argument(
"pyfile", help="Python file to be profil... | [
"def",
"main",
"(",
")",
":",
"# Create command line parser.",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"# Adding command line arguments.",
"parser",
".",
"add_argument",
"(",
"\"-o\"",
",",
"\"--out\"",
",",
"help",
"=",
"\"Output file\"",
",",
... | Starting point for the program execution. | [
"Starting",
"point",
"for",
"the",
"program",
"execution",
"."
] | train | https://github.com/csurfer/pyheat/blob/cc0ee3721aea70a1da4918957500131aa7077afe/pyheat/commandline.py#L31-L50 |
limist/py-moneyed | moneyed/classes.py | Money.round | def round(self, ndigits=0):
"""
Rounds the amount using the current ``Decimal`` rounding algorithm.
"""
if ndigits is None:
ndigits = 0
return self.__class__(
amount=self.amount.quantize(Decimal('1e' + str(-ndigits))),
currency=self.currency) | python | def round(self, ndigits=0):
"""
Rounds the amount using the current ``Decimal`` rounding algorithm.
"""
if ndigits is None:
ndigits = 0
return self.__class__(
amount=self.amount.quantize(Decimal('1e' + str(-ndigits))),
currency=self.currency) | [
"def",
"round",
"(",
"self",
",",
"ndigits",
"=",
"0",
")",
":",
"if",
"ndigits",
"is",
"None",
":",
"ndigits",
"=",
"0",
"return",
"self",
".",
"__class__",
"(",
"amount",
"=",
"self",
".",
"amount",
".",
"quantize",
"(",
"Decimal",
"(",
"'1e'",
"... | Rounds the amount using the current ``Decimal`` rounding algorithm. | [
"Rounds",
"the",
"amount",
"using",
"the",
"current",
"Decimal",
"rounding",
"algorithm",
"."
] | train | https://github.com/limist/py-moneyed/blob/1822e9f77edc6608b429e54c8831b873af9a4de6/moneyed/classes.py#L158-L166 |
klen/muffin | muffin/manage.py | run | def run():
"""CLI endpoint."""
sys.path.insert(0, os.getcwd())
logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler()])
parser = argparse.ArgumentParser(description="Manage Application", add_help=False)
parser.add_argument('app', metavar='app',
type=str, h... | python | def run():
"""CLI endpoint."""
sys.path.insert(0, os.getcwd())
logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler()])
parser = argparse.ArgumentParser(description="Manage Application", add_help=False)
parser.add_argument('app', metavar='app',
type=str, h... | [
"def",
"run",
"(",
")",
":",
"sys",
".",
"path",
".",
"insert",
"(",
"0",
",",
"os",
".",
"getcwd",
"(",
")",
")",
"logging",
".",
"basicConfig",
"(",
"level",
"=",
"logging",
".",
"INFO",
",",
"handlers",
"=",
"[",
"logging",
".",
"StreamHandler",... | CLI endpoint. | [
"CLI",
"endpoint",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/manage.py#L250-L278 |
klen/muffin | muffin/manage.py | Manager.command | def command(self, init=False):
"""Define CLI command."""
def wrapper(func):
header = '\n'.join([s for s in (func.__doc__ or '').split('\n')
if not s.strip().startswith(':')])
parser = self.parsers.add_parser(func.__name__, description=header)
... | python | def command(self, init=False):
"""Define CLI command."""
def wrapper(func):
header = '\n'.join([s for s in (func.__doc__ or '').split('\n')
if not s.strip().startswith(':')])
parser = self.parsers.add_parser(func.__name__, description=header)
... | [
"def",
"command",
"(",
"self",
",",
"init",
"=",
"False",
")",
":",
"def",
"wrapper",
"(",
"func",
")",
":",
"header",
"=",
"'\\n'",
".",
"join",
"(",
"[",
"s",
"for",
"s",
"in",
"(",
"func",
".",
"__doc__",
"or",
"''",
")",
".",
"split",
"(",
... | Define CLI command. | [
"Define",
"CLI",
"command",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/manage.py#L145-L202 |
klen/muffin | muffin/urls.py | routes_register | def routes_register(app, handler, *paths, methods=None, router=None, name=None):
"""Register routes."""
if router is None:
router = app.router
handler = to_coroutine(handler)
resources = []
for path in paths:
# Register any exception to app
if isinstance(path, type) and i... | python | def routes_register(app, handler, *paths, methods=None, router=None, name=None):
"""Register routes."""
if router is None:
router = app.router
handler = to_coroutine(handler)
resources = []
for path in paths:
# Register any exception to app
if isinstance(path, type) and i... | [
"def",
"routes_register",
"(",
"app",
",",
"handler",
",",
"*",
"paths",
",",
"methods",
"=",
"None",
",",
"router",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"if",
"router",
"is",
"None",
":",
"router",
"=",
"app",
".",
"router",
"handler",
... | Register routes. | [
"Register",
"routes",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L95-L132 |
klen/muffin | muffin/urls.py | parse | def parse(path):
"""Parse URL path and convert it to regexp if needed."""
parsed = re.sre_parse.parse(path)
for case, _ in parsed:
if case not in (re.sre_parse.LITERAL, re.sre_parse.ANY):
break
else:
return path
path = path.strip('^$')
def parse_(match):
[pa... | python | def parse(path):
"""Parse URL path and convert it to regexp if needed."""
parsed = re.sre_parse.parse(path)
for case, _ in parsed:
if case not in (re.sre_parse.LITERAL, re.sre_parse.ANY):
break
else:
return path
path = path.strip('^$')
def parse_(match):
[pa... | [
"def",
"parse",
"(",
"path",
")",
":",
"parsed",
"=",
"re",
".",
"sre_parse",
".",
"parse",
"(",
"path",
")",
"for",
"case",
",",
"_",
"in",
"parsed",
":",
"if",
"case",
"not",
"in",
"(",
"re",
".",
"sre_parse",
".",
"LITERAL",
",",
"re",
".",
... | Parse URL path and convert it to regexp if needed. | [
"Parse",
"URL",
"path",
"and",
"convert",
"it",
"to",
"regexp",
"if",
"needed",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L135-L152 |
klen/muffin | muffin/urls.py | RawReResource.url_for | def url_for(self, *subgroups, **groups):
"""Build URL."""
parsed = re.sre_parse.parse(self._pattern.pattern)
subgroups = {n:str(v) for n, v in enumerate(subgroups, 1)}
groups_ = dict(parsed.pattern.groupdict)
subgroups.update({
groups_[k0]: str(v0)
for k0,... | python | def url_for(self, *subgroups, **groups):
"""Build URL."""
parsed = re.sre_parse.parse(self._pattern.pattern)
subgroups = {n:str(v) for n, v in enumerate(subgroups, 1)}
groups_ = dict(parsed.pattern.groupdict)
subgroups.update({
groups_[k0]: str(v0)
for k0,... | [
"def",
"url_for",
"(",
"self",
",",
"*",
"subgroups",
",",
"*",
"*",
"groups",
")",
":",
"parsed",
"=",
"re",
".",
"sre_parse",
".",
"parse",
"(",
"self",
".",
"_pattern",
".",
"pattern",
")",
"subgroups",
"=",
"{",
"n",
":",
"str",
"(",
"v",
")"... | Build URL. | [
"Build",
"URL",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L38-L49 |
klen/muffin | muffin/urls.py | Traverser.state_not_literal | def state_not_literal(self, value):
"""Parse not literal."""
value = negate = chr(value)
while value == negate:
value = choice(self.literals)
yield value | python | def state_not_literal(self, value):
"""Parse not literal."""
value = negate = chr(value)
while value == negate:
value = choice(self.literals)
yield value | [
"def",
"state_not_literal",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"negate",
"=",
"chr",
"(",
"value",
")",
"while",
"value",
"==",
"negate",
":",
"value",
"=",
"choice",
"(",
"self",
".",
"literals",
")",
"yield",
"value"
] | Parse not literal. | [
"Parse",
"not",
"literal",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L185-L190 |
klen/muffin | muffin/urls.py | Traverser.state_max_repeat | def state_max_repeat(self, value):
"""Parse repeatable parts."""
min_, max_, value = value
value = [val for val in Traverser(value, self.groups)]
if not min_ and max_:
for val in value:
if isinstance(val, required):
min_ = 1
... | python | def state_max_repeat(self, value):
"""Parse repeatable parts."""
min_, max_, value = value
value = [val for val in Traverser(value, self.groups)]
if not min_ and max_:
for val in value:
if isinstance(val, required):
min_ = 1
... | [
"def",
"state_max_repeat",
"(",
"self",
",",
"value",
")",
":",
"min_",
",",
"max_",
",",
"value",
"=",
"value",
"value",
"=",
"[",
"val",
"for",
"val",
"in",
"Traverser",
"(",
"value",
",",
"self",
".",
"groups",
")",
"]",
"if",
"not",
"min_",
"an... | Parse repeatable parts. | [
"Parse",
"repeatable",
"parts",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L192-L203 |
klen/muffin | muffin/urls.py | Traverser.state_in | def state_in(self, value):
"""Parse ranges."""
value = [val for val in Traverser(value, self.groups)]
if not value or not value[0]:
for val in self.literals - set(value):
return (yield val)
yield value[0] | python | def state_in(self, value):
"""Parse ranges."""
value = [val for val in Traverser(value, self.groups)]
if not value or not value[0]:
for val in self.literals - set(value):
return (yield val)
yield value[0] | [
"def",
"state_in",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"[",
"val",
"for",
"val",
"in",
"Traverser",
"(",
"value",
",",
"self",
".",
"groups",
")",
"]",
"if",
"not",
"value",
"or",
"not",
"value",
"[",
"0",
"]",
":",
"for",
"val",
... | Parse ranges. | [
"Parse",
"ranges",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L207-L213 |
klen/muffin | muffin/urls.py | Traverser.state_category | def state_category(value):
"""Parse categories."""
if value == re.sre_parse.CATEGORY_DIGIT:
return (yield '0')
if value == re.sre_parse.CATEGORY_WORD:
return (yield 'x') | python | def state_category(value):
"""Parse categories."""
if value == re.sre_parse.CATEGORY_DIGIT:
return (yield '0')
if value == re.sre_parse.CATEGORY_WORD:
return (yield 'x') | [
"def",
"state_category",
"(",
"value",
")",
":",
"if",
"value",
"==",
"re",
".",
"sre_parse",
".",
"CATEGORY_DIGIT",
":",
"return",
"(",
"yield",
"'0'",
")",
"if",
"value",
"==",
"re",
".",
"sre_parse",
".",
"CATEGORY_WORD",
":",
"return",
"(",
"yield",
... | Parse categories. | [
"Parse",
"categories",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L218-L224 |
klen/muffin | muffin/urls.py | Traverser.state_subpattern | def state_subpattern(self, value):
"""Parse subpatterns."""
num, *_, parsed = value
if num in self.groups:
return (yield required(self.groups[num]))
yield from Traverser(parsed, groups=self.groups) | python | def state_subpattern(self, value):
"""Parse subpatterns."""
num, *_, parsed = value
if num in self.groups:
return (yield required(self.groups[num]))
yield from Traverser(parsed, groups=self.groups) | [
"def",
"state_subpattern",
"(",
"self",
",",
"value",
")",
":",
"num",
",",
"",
"*",
"_",
",",
"parsed",
"=",
"value",
"if",
"num",
"in",
"self",
".",
"groups",
":",
"return",
"(",
"yield",
"required",
"(",
"self",
".",
"groups",
"[",
"num",
"]",
... | Parse subpatterns. | [
"Parse",
"subpatterns",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L226-L232 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.