Skip to content

Commit

Permalink
read function and fixes (#1034)
Browse files Browse the repository at this point in the history
fix req, modified datasets, added read_visium
  • Loading branch information
giovp committed Feb 11, 2020
1 parent 09b9856 commit 4bf1532
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 71 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,4 +1,4 @@
anndata>=0.6.22.post1
anndata>=0.7
# matplotlib 3.1 causes an error in 3d scatter plots. Once solved the dependency can be updated (https://github.com/matplotlib/matplotlib/issues/14298)
matplotlib==3.0.*
pandas>=0.21
Expand Down
2 changes: 1 addition & 1 deletion scanpy/__init__.py
Expand Up @@ -40,7 +40,7 @@

from anndata import AnnData
from anndata import read_h5ad, read_csv, read_excel, read_hdf, read_loom, read_mtx, read_text, read_umi_tools
from .readwrite import read, read_10x_h5, read_10x_mtx, write
from .readwrite import read, read_10x_h5, read_10x_mtx, write, read_visium
from .neighbors import Neighbors

set_figure_params = settings.set_figure_params
Expand Down
28 changes: 3 additions & 25 deletions scanpy/datasets/__init__.py
Expand Up @@ -12,7 +12,7 @@
from .. import logging as logg, _utils
from .._compat import Literal
from .._settings import settings
from ..readwrite import read, read_10x_h5
from ..readwrite import read, read_10x_h5, read_visium
from ._ebi_expression_atlas import ebi_expression_atlas


Expand Down Expand Up @@ -366,29 +366,7 @@ def visium_sge(
else:
_utils.check_presence_download(filename=files[f], backup_url=backup_urls[f])

# read h5 file
adata = read_10x_h5(files['counts'])
adata.var_names_make_unique()

# read images
# imread only accepts strings, not Path objects
adata.uns['images'] = dict(
hires=imread(str(files['hires_image'])),
lowres=imread(str(files['lowres_image'])),
)

# read json scalefactors
adata.uns['scalefactors'] = json.loads(files['scalefactors_json_file'].read_bytes())

# read coordinates
positions = pd.read_csv(
settings.datasetdir / 'spatial/tissue_positions_list.csv', header=None
)
positions.columns = ['index', '0', '1', '2', 'X2_coord', 'X1_coord']
positions.index = positions['index']

positions = positions.join(adata.obs, how='right')

adata.obsm['X_spatial'] = positions[['X1_coord', 'X2_coord',]].to_numpy()
adata = read_visium(files['counts'])

return adata

0 comments on commit 4bf1532

Please sign in to comment.