BiomedicalMachineLearning / stLearn

A novel machine learning pipeline to analyse spatial transcriptomics data
Other
199 stars 26 forks source link

tensorflow error #159

Closed februaryfang closed 2 years ago

februaryfang commented 2 years ago

hi, thanks for your work in stlearn, its a good toolkit for ST data. my analysis environments is like this : python-3.8, stlearn-0.4.6, tensorflow-2.8.0. my command lines :

import stlearn as st
data = st.Read10X(path="/stLearn/data/BCBA1/")
data.layers["raw_count"] = data.X
st.pp.filter_genes(data,min_cells=3)
st.pp.normalize_total(data)
st.pp.log1p(data)
data.raw = data
st.pp.scale(data)
st.em.run_pca(data,n_comps=50)
st.pp.tiling(data,out_path="tiling",crop_size = 40)
st.pp.extract_feature(data)
st.spatial.morphology.adjust(data,use_data="X_pca",radius=50,method="mean")
st.pp.neighbors(data,n_neighbors=25,use_rep='X_pca_morphology',random_state=0)
st.tl.clustering.louvain(data,random_state=0)
st.pl.cluster_plot(data, use_label="louvain", image_alpha=1, size=10, fname = "./pca_louvain.png", dpi = 300)

Here I have two problems. The 1, when I run 'st.pp.extract_feature(data)', I got the information as follows:

W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (b04.capitalbiotech.local): /proc/driver/nvidia/version does not exist
I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 

Is this a serious problem? I can still get results. Then I got the problem 2, the cluster result is different from the Documentation and Tutorials (https://stlearn.readthedocs.io/en/latest/) . Is this caused by different versions? or by the problem 1 error?

image

duypham2108 commented 2 years ago

I think the problem 1 is that you don't have CUDA lib or no GPU in your machine then you cannot use GPU option in tensorflow. It's ok, you can ignore it if this code st.spatial.morphology.adjust still run.

For the different result, I believe it's caused by different version because the downstream code still works.

februaryfang commented 2 years ago

How can I save my adata to object file after analysis ? like h5ad for scanpy. so I can re-load the object for other analysis. I tried with command line 'data.write("./data.h5ad")', it works. but I failed with 'data = sc.read("./data.h5ad")'.

duypham2108 commented 2 years ago

You should use .write_h5ad and .read_h5ad for it

februaryfang commented 2 years ago

hello , I use stlearn to analyze my spatial data. But I only have matrix data and spatial information. So I created the adata object according to the tutorials. When I choose to enter image path, my st.pl.cluster_plot result is abnormal. My command line and picture are as follows: adata = st.create_stlearn(count=matrix,patial=spatial,image_path=image_path,scale=json_data['tissue_hires_scalef']) Cluster

How should I adjust it?

duypham2108 commented 2 years ago

In visium data, the spatial data (adata.obsm["spatial"]) is the coordinate of raw image. The scale factor will be used to scale down the raw image to hires image or lowres image, and also for the spatial data to match them. So you should make sure scale parameter = the raw image resolution / scaled image resolution.

For example, raw image 4000x4000, hires image 2000x2000 -> the scale factor = 0.5