Row feature index
RowFeatureIndex
Maintains a mapping between a row and its features.
This is a ragged dataset, where the number and dimension of features can be different at every row.
Attributes:
Name | Type | Description |
---|---|---|
_cumulative_sum_index |
array
|
Pointer that deliniates which entries |
_feature_arr |
list[dict[str, ndarray]]
|
list of feature dictionaries for each dataset |
_num_genes_per_row |
list[int]
|
list that tracks the feature length (number of genes) for each dataset. |
_labels |
list[str]
|
list of labels |
_version |
The version of the dataset |
Source code in bionemo/scdl/index/row_feature_index.py
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 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
__init__()
Instantiates the index.
Source code in bionemo/scdl/index/row_feature_index.py
64 65 66 67 68 69 70 |
|
__len__()
The length is the number of rows or RowFeatureIndex length.
Source code in bionemo/scdl/index/row_feature_index.py
95 96 97 |
|
append_features(n_obs, features, num_genes, label=None)
Updates the index with the given features.
The dict is inserted into the feature array by adding a new span to the row lookup index. Additionally, we update the number of genes for the newly added row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_obs
|
int
|
The number of times that these feature occur in the |
required |
features
|
dict
|
Corresponding features. |
required |
num_genes
|
int
|
the length of the features for each feature key in features (i.e., number of genes) |
required |
label
|
str
|
Label for the features. |
None
|
Source code in bionemo/scdl/index/row_feature_index.py
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 |
|
column_dims()
Return the number of columns in all rows.
Returns:
Type | Description |
---|---|
list[int]
|
A list containing the lengths of the features in every row |
Source code in bionemo/scdl/index/row_feature_index.py
185 186 187 188 189 190 191 192 193 194 |
|
concat(other_row_index, fail_on_empty_index=True)
Concatenates the other FeatureIndex to this one.
Returns the new, updated index. Warning: modifies this index in-place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other_row_index
|
RowFeatureIndex
|
another RowFeatureIndex |
required |
fail_on_empty_index
|
bool
|
A boolean flag that sets whether to raise an |
True
|
Returns:
Type | Description |
---|---|
RowFeatureIndex
|
self, the RowIndexFeature after the concatenations. |
Source code in bionemo/scdl/index/row_feature_index.py
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 |
|
load(datapath)
staticmethod
Loads the data from datapath.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datapath
|
str
|
the path to load from |
required |
Returns: An instance of RowFeatureIndex
Source code in bionemo/scdl/index/row_feature_index.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
lookup(row, select_features=None)
Find the features at a given row.
It is assumed that the row is non-zero._cumulative_sum_index contains pointers to which rows correspond to given dictionaries. To obtain a specific row, we determine where it is located in _cumulative_sum_index and then look up that dictionary in _feature_arr Args: row (int): The row in the feature index. select_features (list[str]): a list of features to select Returns list[np.ndarray]: list of np arrays with the feature values in that row of the specified features str: optional label for the row Raises: IndexError: An error occured due to input row being negative or it exceeding the larger row of the rows in the index. It is also raised if there are no entries in the index yet.
Source code in bionemo/scdl/index/row_feature_index.py
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 |
|
number_of_rows()
The number of rows in the index"".
Returns:
Type | Description |
---|---|
int
|
An integer corresponding to the number or rows in the index |
Source code in bionemo/scdl/index/row_feature_index.py
214 215 216 217 218 219 220 |
|
number_of_values()
Get the total number of values in the array.
For each row, the number of genes is counted.
Returns:
Type | Description |
---|---|
list[int]
|
A list containing the lengths of the features in every block of rows |
Source code in bionemo/scdl/index/row_feature_index.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
number_vars_at_row(row)
Return number of variables in a given row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row
|
int
|
The row in the feature index. |
required |
Returns:
Type | Description |
---|---|
int
|
The length of the features at the row |
Source code in bionemo/scdl/index/row_feature_index.py
174 175 176 177 178 179 180 181 182 183 |
|
save(datapath)
Saves the RowFeatureIndex to a given path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datapath
|
str
|
path to save the index |
required |
Source code in bionemo/scdl/index/row_feature_index.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
version()
Returns a version number.
(following
Source code in bionemo/scdl/index/row_feature_index.py
88 89 90 91 92 93 |
|
are_dicts_equal(dict1, dict2)
Compare two dictionaries with string keys and numpy.ndarray values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dict1
|
dict[str, ndarray]
|
The first dictionary to compare. |
required |
dict2
|
dict[str, ndarray]
|
The second dictionary to compare. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the dictionaries have the same keys and all corresponding numpy arrays are equal; False otherwise. |
Source code in bionemo/scdl/index/row_feature_index.py
31 32 33 34 35 36 37 38 39 40 41 42 |
|