L2G Feature Matrix
gentropy.dataset.l2g_feature_matrix.L2GFeatureMatrix
¶
Dataset with features for Locus to Gene prediction.
Source code in src/gentropy/dataset/l2g_feature_matrix.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
__init__(_df: DataFrame, features_list: list[str] | None = None, with_gold_standard: bool = False, label_col: str = 'goldStandardSet') -> None
¶
Post-initialisation to set the features list. If not provided, all columns except the fixed ones are used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_df
|
DataFrame
|
Feature matrix dataset |
required |
features_list
|
list[str] | None
|
List of features to use. If None, all possible features are used. |
None
|
with_gold_standard
|
bool
|
Whether to include the gold standard set in the feature matrix. |
False
|
label_col
|
str
|
The target column when the feature matrix represents the gold standard |
'goldStandardSet'
|
Source code in src/gentropy/dataset/l2g_feature_matrix.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
append_null_features(features_list: list[str]) -> L2GFeatureMatrix
¶
Add features from the list that are not already in the dataframe as null columns filled with 0.0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features_list
|
list[str]
|
List of features to check and add if missing |
required |
Returns:
Name | Type | Description |
---|---|---|
L2GFeatureMatrix |
L2GFeatureMatrix
|
Updated feature matrix with additional features |
Source code in src/gentropy/dataset/l2g_feature_matrix.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
calculate_feature_missingness_rate() -> dict[str, float]
¶
Calculate the proportion of missing values in each feature.
Returns:
Type | Description |
---|---|
dict[str, float]
|
dict[str, float]: Dictionary of feature names and their missingness rate. |
Raises:
Type | Description |
---|---|
ValueError
|
If no features are found. |
Source code in src/gentropy/dataset/l2g_feature_matrix.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
fill_na(na_value: float = 0.0, subset: list[str] | None = None) -> L2GFeatureMatrix
¶
Fill missing values in a column with a given value.
For features that correspond to gene attributes, missing values are imputed using the mean of the column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
na_value
|
float
|
Value to replace missing values with. Defaults to 0.0. |
0.0
|
subset
|
list[str] | None
|
Subset of columns to consider. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
L2GFeatureMatrix |
L2GFeatureMatrix
|
L2G feature matrix dataset |
Source code in src/gentropy/dataset/l2g_feature_matrix.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
from_features_list(study_loci_to_annotate: StudyLocus | L2GGoldStandard, features_list: list[str], features_input_loader: L2GFeatureInputLoader) -> L2GFeatureMatrix
classmethod
¶
Generate features from the gentropy datasets by calling the feature factory that will instantiate the corresponding features.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
study_loci_to_annotate
|
StudyLocus | L2GGoldStandard
|
Study locus pairs to annotate |
required |
features_list
|
list[str]
|
List of feature names to be computed. |
required |
features_input_loader
|
L2GFeatureInputLoader
|
Object that contais features input. |
required |
Returns:
Name | Type | Description |
---|---|---|
L2GFeatureMatrix |
L2GFeatureMatrix
|
L2G feature matrix dataset |
Source code in src/gentropy/dataset/l2g_feature_matrix.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
generate_train_test_split(test_size: float, verbose: bool, label_encoder: dict[str, int], label_col: str) -> tuple[pd_dataframe, pd_dataframe]
¶
Generate train and test splits for the feature matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_size
|
float
|
Proportion of the test set |
required |
verbose
|
bool
|
Whether to print verbose output |
required |
label_encoder
|
dict[str, int]
|
Label encoder for the gold standard set |
required |
label_col
|
str
|
Column name for the gold standard set |
required |
Returns:
Type | Description |
---|---|
tuple[DataFrame, DataFrame]
|
tuple[pd_dataframe, pd_dataframe]: Train and test splits |
Source code in src/gentropy/dataset/l2g_feature_matrix.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
persist() -> Self
¶
Persist the feature matrix in memory.
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
Persisted Dataset |
Source code in src/gentropy/dataset/l2g_feature_matrix.py
201 202 203 204 205 206 207 208 |
|
select_features(features_list: list[str] | None) -> L2GFeatureMatrix
¶
Returns a new object with a subset of features from the original feature matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features_list
|
list[str] | None
|
List of features to select |
required |
Returns:
Name | Type | Description |
---|---|---|
L2GFeatureMatrix |
L2GFeatureMatrix
|
L2G feature matrix dataset |
Raises:
Type | Description |
---|---|
ValueError
|
If no features have been selected. |
Source code in src/gentropy/dataset/l2g_feature_matrix.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|