Skip to content

Commit

Permalink
change release to 0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyiran55 committed Jan 19, 2022
1 parent f800fc3 commit e37d479
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
31 changes: 29 additions & 2 deletions docs/source/Tutorials/FormatConversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/BGIResearch/stereopy/blob/dev/docs/source/_static/annh5ad2rds.R>`_.
Expand Down
6 changes: 6 additions & 0 deletions docs/source/release_note.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
9 changes: 3 additions & 6 deletions stereo/io/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
2 changes: 1 addition & 1 deletion stereo/preprocess/sc_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e37d479

Please sign in to comment.