STREAM icon indicating copy to clipboard operation
STREAM copied to clipboard

AttributeError: 'SpectralEmbedding' object has no attribute 'transform'

Open jipeifeng opened this issue 4 years ago • 6 comments

Hi: Sorry for bother you again. When mapping the new data set to the reference, error happened.

Command lines:

  1. Generating reference stream.select_variable_genes(wt) stream.dimension_reduction(wt, n_jobs=4) stream.seed_elastic_principal_graph(wt) stream.elastic_principal_graph(wt,incr_n_nodes=10, epg_alpha=0.03, epg_trimmingradius=0.1) stream.optimize_branching(wt) stream.prune_elastic_principal_graph(wt) stream.shift_branching(wt) stream.extend_elastic_principal_graph(wt)

This works well.

  1. Mapping step ko = sc.read_h5ad('ko.h5ad') stream.set_workdir(ko, './stream') stream.remove_mt_genes(ko) ko.obs.rename(columns={'type':'label'}, inplace=True) stream.add_cell_colors(ko) sc.pp.subsample(ko, n_obs=10000) stream.map_new_data(wt, ko, method='se') Error:

AttributeError Traceback (most recent call last) in ----> 1 stream.map_new_data(wt, ko, method='se')

/miniconda3/envs/stream/lib/python3.7/site-packages/stream/core.py in map_new_data(adata, adata_new, feature, method, use_radius) 4830 if(method == 'se'): 4831 trans = adata.uns['trans_se'] -> 4832 adata_new.obsm['X_se_mapping'] = trans.transform(input_data) 4833 adata_new.obsm['X_dr'] = adata_new.obsm['X_se_mapping'].copy() 4834 if(method == 'mlle'):

AttributeError: 'SpectralEmbedding' object has no attribute 'transform'

Thanks for you help!

Best,

Peifeng

jipeifeng avatar Dec 05 '19 08:12 jipeifeng

I believe that the issue should be caused by a bug. I have looked into the code in core.py and found that the 'SpectralEmbedding' only have 'fit' and 'fit_transform' function. But, which function should I choose? PS: I have chose fit_transform to run, it works.

jipeifeng avatar Dec 05 '19 09:12 jipeifeng

Thanks for the important feedback! I will try to fix it in the next update.

huidongchen avatar Dec 05 '19 16:12 huidongchen

Hi Peifeng,

I was looking into the issue and just realized that the spectral embedding method se currently doesn't have the method transform supported in scikit-learn yet. Unless we write the projection function ourselves (this may take a long time), currently in STREAM, to map new data, you might have to use other available methods (e.g. mlle or umap. but you need to use the same method during the dimension reduction step)

huidongchen avatar Dec 06 '19 01:12 huidongchen

I believe that the issue should be caused by a bug. I have looked into the code in core.py and found that the 'SpectralEmbedding' only have 'fit' and 'fit_transform' function. But, which function should I choose? PS: I have chose fit_transform to run, it works.

fit_transform will generate a new embedding space instead of projecting new points into the same embedding space used for the reference data. The result (generate a new embedding space for new points) might be similar to using transform (projecting new points to the same reference space) but like I said, it's not a mapping process any more. so you might need to be cautious about the final result.

huidongchen avatar Dec 06 '19 01:12 huidongchen

Ok, got it ! I'll use available methods. Thank for the reply.

jipeifeng avatar Dec 06 '19 02:12 jipeifeng

We found the "se" projection provides better trajectories than the "mlle", which is influenced by extream points when the data is small. Hope to see the "se" mapping strategy available soon.

ccshao avatar Dec 09 '19 13:12 ccshao