From e37d47933293697bed8ea112e293e80e79c6ba08 Mon Sep 17 00:00:00 2001 From: wuyiran55 Date: Wed, 19 Jan 2022 16:45:08 +0800 Subject: [PATCH] change release to 0.2.4 --- docs/source/Tutorials/FormatConversion.rst | 31 ++++++++++++++++++++-- docs/source/release_note.rst | 6 +++++ setup.py | 2 +- stereo/io/reader.py | 9 +++---- stereo/preprocess/sc_transform.py | 2 +- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/docs/source/Tutorials/FormatConversion.rst b/docs/source/Tutorials/FormatConversion.rst index 6a155367..64fd5864 100644 --- a/docs/source/Tutorials/FormatConversion.rst +++ b/docs/source/Tutorials/FormatConversion.rst @@ -8,15 +8,42 @@ The io module provides the function :mod:`stereo.io.stereo_to_anndata` to conver corresponding h5ad file(.h5ad). parameters -~~~~~~~~~~ +~~~~~~~~~~~~~~~ :param data: StereoExpData object -:param flavor: 'scanpy' or 'seurat'. If you want to converted the output_h5ad into the rds file, set flavor='seurat'. +:param flavor: 'scanpy' or 'seurat'. If you want to convert the output_h5ad into the rds file, set flavor='seurat'. :param sample_id: name of sample. This will be set as 'orig.ident' in adata.obs. :param reindex: whether to reindex the cell. The new index looks like "{sample_id}:{position_x}_{position_y}" format. :param output: Default is None. If None, it will not generate a h5ad file. :return: Anndata object +If you want to use sctransform to get the normalizetion result and convert the output_h5ad into the rds file, +you need to save raw data before you use sctransform. Otherwise, it may raise errors during conversion. +Example like this: + +.. code:: python + + import warnings + warnings.filterwarnings('ignore') + import stereo as st + + # read the gef file + mouse_data_path = './stereomics.h5' + data = st.io.read_gef(file_path=mouse_data_path, bin_size=50) + data.tl.cal_qc() + + # Must save raw data before sctransform. + data.tl.raw_checkpoint() + + # Be carefule with sctransform before the conversion. + data.tl.sctransform(res_key='sctransform', inplace=True) + + # You can use other functions as you want, like pca and so on. + data.tl.pca(use_highly_genes=False, n_pcs=30, res_key='pca') + + # conversion + adata = st.io.stereo_to_anndata(data,flavor='seurat',output='out.h5ad') + h5ad to rds file ---------------------------------- The output h5ad could be converted into rds file by `annh5ad2rds.R `_. diff --git a/docs/source/release_note.rst b/docs/source/release_note.rst index c246f217..5b0e443c 100644 --- a/docs/source/release_note.rst +++ b/docs/source/release_note.rst @@ -3,6 +3,12 @@ Release Notes .. role:: small +Version 0.2.4 +------------------ +0.2.4 :2022-01-19 +~~~~~~~~~~~~~~~~~~~~~ +1.Fix bug of tar package + Version 0.2.3 ----------- 0.2.3 :2022-01-17 diff --git a/setup.py b/setup.py index a8a01926..ff1532ae 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup( name='stereopy', - version='0.2.3', + version='0.2.4', setup_requires=['setuptools_scm', 'numpy', 'panel', 'pytest', 'quilt3', 'scipy', 'phenograph'], description='Spatial transcriptomic analysis in python.', long_description=Path('README.md').read_text('utf-8'), diff --git a/stereo/io/reader.py b/stereo/io/reader.py index 6c666167..4a8a190d 100644 --- a/stereo/io/reader.py +++ b/stereo/io/reader.py @@ -270,12 +270,9 @@ def stereo_to_anndata(data: StereoExpData, flavor='scanpy', sample_id="sample", elif key == 'sct': res_key = data.tl.key_record[key][-1] #adata.uns[res_key] = {} - if flavor == 'seurat' and len(data.tl.key_record['neighbors']) == 10: - continue - else: - logger.info(f"Adding data.tl.result['{res_key}'] in adata.uns['sct_'] .") - adata.uns['sct_counts'] = csr_matrix(data.tl.result[res_key][1]['filtered_corrected_counts']) - adata.uns['sct_data'] = csr_matrix(data.tl.result[res_key][1]['filtered_normalized_counts']) + logger.info(f"Adding data.tl.result['{res_key}'] in adata.uns['sct_'] .") + adata.uns['sct_counts'] = csr_matrix(data.tl.result[res_key][1]['filtered_corrected_counts']) + adata.uns['sct_data'] = csr_matrix(data.tl.result[res_key][1]['filtered_normalized_counts']) elif key in ['pca', 'umap', 'tsne']: # pca :we do not keep variance and PCs(for varm which will be into feature.finding in pca of seurat.) diff --git a/stereo/preprocess/sc_transform.py b/stereo/preprocess/sc_transform.py index b3d2c354..9b31263a 100644 --- a/stereo/preprocess/sc_transform.py +++ b/stereo/preprocess/sc_transform.py @@ -67,6 +67,6 @@ def sc_transform( data.exp_matrix = residuals.values gene_index = np.isin(data.gene_names, np.array(residuals.columns)) data.genes = data.genes.sub_set(gene_index) - vst_out['filtered_corrected_counts'] = corrected_counts.loc[:, gene_index] + vst_out['filtered_corrected_counts'] = corrected_counts.loc[:, residuals.columns] vst_out['filtered_normalized_counts'] = np.log1p(vst_out['filtered_corrected_counts']) return data, vst_out