stereo.core.ms_data.MSData¶
- class stereo.core.ms_data.MSData(_data_list=<factory>, _merged_data=None, _names=<factory>, _obs=None, _var=None, _var_type='intersect', _relationship='other', _relationship_info=<factory>, _name_dict=<factory>, _data_dict=<factory>, _MSDataStruct__idx_generator=-1, _scopes_data=<factory>)[source]¶
MSDatais a composite structure of severalStereoExpDataorganized by some relationship.- Parameters:
data_list (List[StereoExpData]
stereo_exp_dataarray) – An array ofstereo_exp_dataorganized by some relationship defined by_relationshipand_relationship_infomerged_data (
stereo_exp_dataobject) – Anstereo_exp_datamerged withdata_listused batches integrate.names (List[str]
stereo_exp_dataarray’s names) – An array of `stereo_exp_data`s’ unique names.obs (pandas.DataFrame = None) –
pandas.DataFramedescribes all the cells or bins observed, indexes mean cell names or bin names, columns mean some math statistic or types produced by bio-information algorithm.var (pd.DataFrame = None) –
pandas.DataFramedescribes genes, similar to_obs._var_type (str = 'intersect') – Which claims that
_varis intersected by lots ofgenesfrom different samples.relationship (str = 'other') – Relationship about samples in
_data_list._relationship_info (object) – Relationship extra info.
tl (object) –
MSDataalgorithms collections, include all tools methods inherited fromstereo_exp_dataand multi-samplesmethods. Methods from
stereo_exp_datawill organized with mutilthreads while running.
plt (object) –
MSDataplot methods collections, same astl.
Examples
Constructing MSData from two `stereo_exp_data`s.
>>> from stereo.io.reader import read_gef >>> from stereo.core.ms_data import MSData >>> data1 = read_gef("../demo_data/SS200000135TL_D1/SS200000135TL_D1.gef") >>> data2 = read_gef("../demo_data/SS200000135TL_D1/SS200000135TL_D1.tissue.gef") >>> ms_data = MSData(_data_list=[data1, data2], _names=['raw', 'tissue'], _relationship='other', _var_type='intersect') # noqa >>> ms_data
ms_data: {‘raw’: (9004, 25523), ‘tissue’: (9111, 20816)} num_slice: 2 names: [‘raw’, ‘tissue’] obs: [‘test_obs_1’] var: [‘test_var_1’] relationship: other var_type: intersect to 20760 tl.result: defaultdict(<class ‘list’>, {})
Constructing MSData one by one using add method.
>>> from stereo.core.ms_data import MSData >>> from stereo.io.reader import read_gef >>> ms_data = MSData() >>> ms_data += read_gef("../demo_data/SS200000135TL_D1/SS200000135TL_D1.gef") >>> ms_data += read_gef("../demo_data/SS200000135TL_D1/SS200000135TL_D1.tissue.gef") >>> ms_data ms_data: {'0': (9004, 25523), '1': (9111, 20816)} num_slice: 2 names: ['0', '1'] obs: ['test_obs_1'] var: ['test_var_1'] relationship: other var_type: intersect to 20760 tl.result: defaultdict(<class 'list'>, {})
Slice features like python list.
>>> from stereo.core.ms_data import MSData >>> from stereo.io.reader import read_gef >>> ms_data = MSData() >>> ms_data += read_gef("../demo_data/SS200000135TL_D1/SS200000135TL_D1.gef") >>> ms_data += read_gef("../demo_data/SS200000135TL_D1/SS200000135TL_D1.tissue.gef") >>> ms_data += read_gef("../demo_data/SS200000135TL_D1/SS200000135TL_D1.gef") >>> ms_data += read_gef("../demo_data/SS200000135TL_D1/SS200000135TL_D1.tissue.gef") >>> ms_data += read_gef("../demo_data/SS200000135TL_D1/SS200000135TL_D1.gef") >>> ms_data += read_gef("../demo_data/SS200000135TL_D1/SS200000135TL_D1.tissue.gef") >>> ms_data[3:] _MSDataView(_names=['3', '4', '5'], _data_list=[StereoExpData object with n_cells X n_genes = 9111 X 20816 bin_type: bins bin_size: 100 offset_x = 0 offset_y = 2 cells: ['cell_name'] genes: ['gene_name'], ...)
Slice features like DataFrame.
>>> ms_data[('1', '4'):] _MSDataView(_names=['1', '4'], _data_list=[StereoExpData object with n_cells X n_genes = 9111 X 20816 bin_type: bins bin_size: 100 offset_x = 0 offset_y = 2 cells: ['cell_name'] genes: ['gene_name'], ...)
- __init__(_data_list=<factory>, _merged_data=None, _names=<factory>, _obs=None, _var=None, _var_type='intersect', _relationship='other', _relationship_info=<factory>, _name_dict=<factory>, _data_dict=<factory>, _MSDataStruct__idx_generator=-1, _scopes_data=<factory>)¶
Methods
__init__([_data_list, _merged_data, _names, ...])add_data([data, names])- rtype:
object
del_data(name)generate_scope_key([scope])get_data_list(key_idx_list)integrate([scope, remove_existed])Integrate some single-samples specified by
scopeto a merged one.remove_scopes_data(scope)rename(mapper)- rtype:
object
reset_name([start_idx, default_key])- rtype:
object
reset_position([mode])split_after_batching_integrate()to_integrate(scope, res_key, _from[, type, ...])Integrate an obs column or a var column from some single-samples spcified by
_fromto the merged sample.to_isolated(scope, res_key, to[, type, ...])Copy a result from mss group specfied by scope to some single-samples specfied by
to.to_msdata(data[, batch_key, relationship, ...])var_percent()Attributes
data_listmerged_datamssnamesnum_sliceobspltrelationshiprelationship_infoscopes_datashapetlvarvar_type