Cnv.get_attribute¶
-
Cnv.
get_attribute
(attribute, features=None, constraint=None)¶ Retrieve any attribute in the assay
Returns an np.array which could either be a row attribute, column attribute, layer or the passed attribute itself.
- Parameters
- attributestr / np.ndarray
The attribute to be searched for in the assay.
- featuresstr
In case the attribute is a layer or col, then the subset of features to select
- constraintstr
- One of the following is accepted.
- None
No contraint.
- ‘row’
The first dimension must be equal to the number of cells.
- ‘col’
The second dimension must be equal to the number of ids or the number of features given in the input.
- ‘row+col’
The dimension must be exactly (number of cells, number of ids). The layers have this shape.
- Returns
- pd.DataFrame
The array of the attribute with the given name found in the assay layer, row attributes, or col attributes in that order. If a constraint is provided, the array is reshaped appropriately if possible. In case constraint is provided then the columns and index are named based on the barcodes, ids, or a range depending on where the given attribute is found.
- Raises
- ValueError
When the attribute is not found or when the constraint is not satisfied.
- TypeError
When the attribute is neither a str not an np.ndarray
Notes
In case the constraint can reshape the array into the expected shape then no error will be raised. Eg. An assay with 100 barcodes and 10 ids has a shape (100, 10). When the attribute ‘barcode’ is fetched constrained by ‘col’ it will not raise an error, but rather return a 10x10 dataframe of barcodes.
>>> assay.shape (100, 10) >>> attr = assay.get_attribute('barcode', constrain='col') >>> attr.shape (10, 10)
Possible expected behavior >>> assay.shape (100, 11) >>> attr = assay.get_attribute(‘barcode’, constrain=’col’) ValueError - ‘The given attribute does not have the expected shape nor could be reshaped appropriately.’