Compute utils
combine_coefficient_tables(coef_tables, coef_col='BETA')
¶
Combine a list of coefficient tables (output from a PRS model) into a single table that can be used for downstream tasks, such scoring and evaluation. Note that this implementation assumes that the coefficients tables were generated for the same set of variants, from a grid-search or similar procedure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coef_tables
|
A list of pandas dataframes containing variant information as well as inferred coefficients. |
required | |
coef_col
|
The name of the column containing the coefficients. |
'BETA'
|
Returns:
Type | Description |
---|---|
A single pandas dataframe with the combined coefficients. The new coefficient columns will be labelled as BETA_0, BETA_1, etc. |
Source code in viprs/utils/compute_utils.py
dict_concat(d, axis=0)
¶
Concatenate the values of a dictionary into a single vector
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
A dictionary where values are numeric scalars or vectors |
required | |
axis
|
Concatenate along given axis. |
0
|
Source code in viprs/utils/compute_utils.py
dict_dot(d1, d2)
¶
Perform dot product on the elements of d1 and d2
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d1
|
A dictionary where values are numeric scalars or vectors |
required | |
d2
|
A dictionary where values are numeric scalars or vectors |
required |
Source code in viprs/utils/compute_utils.py
dict_elementwise_dot(d1, d2)
¶
Apply element-wise product between the values of two dictionaries
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d1
|
A dictionary where values are numeric scalars or vectors |
required | |
d2
|
A dictionary where values are numeric scalars or vectors |
required |
Source code in viprs/utils/compute_utils.py
dict_elementwise_transform(d, transform)
¶
Apply a transformation to values of a dictionary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
A dictionary where values are numeric scalars or vectors |
required | |
transform
|
A function to apply to |
required |
Source code in viprs/utils/compute_utils.py
dict_max(d, axis=None)
¶
Estimate the maximum of the values of a dictionary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
A dictionary where values are numeric scalars or vectors |
required | |
axis
|
Perform aggregation along given axis. |
None
|
Source code in viprs/utils/compute_utils.py
dict_mean(d, axis=None)
¶
Estimate the mean of the values of a dictionary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
A dictionary where values are numeric scalars or vectors |
required | |
axis
|
Perform aggregation along given axis. |
None
|
Source code in viprs/utils/compute_utils.py
dict_repeat(value, shapes)
¶
Given a value, create a dictionary where the value is repeated according to the shapes parameter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shapes
|
A dictionary of shapes. Key is arbitrary, value is integer input to np.repeat |
required | |
value
|
The value to repeat |
required |
Source code in viprs/utils/compute_utils.py
dict_set(d, value)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
A dictionary where values are numeric vectors |
required | |
value
|
A value to set for all vectors |
required |
dict_sum(d, axis=None, transform=None)
¶
Estimate the sum of the values of a dictionary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
A dictionary where values are numeric scalars or vectors |
required | |
axis
|
Perform aggregation along given axis. |
None
|
|
transform
|
Transformation to apply before summing. |
None
|
Source code in viprs/utils/compute_utils.py
expand_column_names(c_name, shape, sep='_')
¶
Given a desired column name c_name
and a matrix shape
that we'd like to apply the column name to, return a list of
column names for every column in the matrix. The column names will be
in the form of c_name
followed by an index, separated by sep
.
For example, if the column name is BETA
, the
shape is (100, 3) and the separator is _
, we return a list with:
[BETA_0
, BETA_1
, BETA_2
]
If the matrix in question is a vector, we just return the column name without any indices appended to it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
c_name
|
A string object |
required | |
shape
|
The shape of a numpy matrix or vector |
required | |
sep
|
The separator |
'_'
|
Returns:
Type | Description |
---|---|
A list of column names |
Source code in viprs/utils/compute_utils.py
fits_in_memory(alloc_size, max_prop=0.9)
¶
Check whether there's enough memory resources to load an object with the given allocation size (in MB).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alloc_size
|
The allocation size |
required | |
max_prop
|
The maximum proportion of available memory allowed for the object |
0.9
|