Protein.ga
Protein.ga#
- Protein.ga(attribute: Union[str, numpy.ndarray], constraint: Optional[str] = None, features: Optional[Sequence] = None)#
Retrieve any attribute in the assay
Returns a pd.DataFrame which could either be a row attribute, column attribute, layer or the passed attribute itself.
- Parameters
- attribute
The attribute to be searched for in the assay.
- features:
In case the attribute is a layer or col, then the subset of features to select
- constraint
- One of the following is accepted.
- None
Contraint is auto-determined.
- ‘row’ / ‘r’
The first dimension must be equal to the number of cells.
- ‘col’ / ‘c’
The second dimension must be equal to the number of ids or the number of features given in the input.
- ‘row+col’ / ‘rc’
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, otherwise the best possible constraint for the given input is determined. The columns and index are named based on the barcodes, ids, or sequential integers depending on the constraint.
- 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.
>>> import missionbio.mosaic as ms >>> assay = ms.load_example_dataset("3 cell mix").dna[:100, :10] >>> assay.shape (100, 10) >>> attr = assay.get_attribute('barcode', constraint='col') >>> attr.shape (10, 10)
Possible expected behavior >>> assay = assay[:, :9] >>> assay.shape (100, 9) >>> attr = assay.get_attribute(‘barcode’, constraint=’col’) ValueError - ‘The given attribute does not have the expected shape nor could be reshaped appropriately.’