jianhuupenn / TESLA

Deciphering tumor ecosystems at super-resolution from spatial transcriptomics with TESLA
MIT License
38 stars 10 forks source link

function tesla.imputation() return adata.X full of NA #2

Closed FanZhang9 closed 1 year ago

FanZhang9 commented 1 year ago

I follow the tutorial.md `#Read original 10x_h5 data and save it to h5ad from scanpy import read_10x_h5 adata = read_10x_h5("/home/shpc_101112/singleCellData/CRCLM-ST/ST/ST-colon1/filtered_feature_bc_matrix.h5")

spatial=pd.read_csv("/home/shpc_101112/singleCellData/CRCLM-ST/ST/ST-colon1/tissue_positions_list.csv",sep=",",header=None,na_filter=False,index_col=0)

adata.obs["x1"]=spatial[1] adata.obs["x2"]=spatial[2] adata.obs["x3"]=spatial[3] adata.obs["x4"]=spatial[4] adata.obs["x5"]=spatial[5]

adata.obs["array_x"]=adata.obs["x2"] adata.obs["array_y"]=adata.obs["x3"] adata.obs["pixel_x"]=adata.obs["x4"] adata.obs["pixel_y"]=adata.obs["x5"]

Select captured samples

adata=adata[adata.obs["x1"]==1] adata.var_names=[i.upper() for i in list(adata.var_names)] adata.var["genename"]=adata.var.index.astype("str") adata.write_h5ad("/home/shpc_101112/singleCellData/CRCLM-ST/ST/sample_data.h5ad")`

/home/shpc_101112/.local/lib/python3.8/site-packages/anndata/_core/anndata.py:1830: UserWarning: Variable names are not unique. To make them unique, call.var_names_make_unique`.

utils.warn_names_duplicates("var")

/home/shpc_101112/.local/lib/python3.8/site-packages/anndata/_core/anndata.py:1830: UserWarning: Variable names are not unique. To make them unique, call .var_names_make_unique.

utils.warn_names_duplicates("var")`

adata.obs look like this adata.obs x1 x2 x3 x4 x5 array_x array_y pixel_x pixel_y
1 50 102 10343 12019 50 102 10343 12019
1 59 19 12009 3723 59 19 12009 3723
1 14 94 4077 11144 14 94 4077 11144
1 73 43 14421 6156 73 43 14421 6156
1 61 97 12266 11540 61 97 12266 11540
... ... ... ... ... ... ... ... ...
1 31 77 7060 9476 31 77 7060 9476
1 58 42 11807 6025 58 42 11807 6025
1 60 30 12170 4827 60 30 12170 4827
1 45 27 9559 4496 45 27 9559 4496
1 73 41 14423 5955 73 41 14423 5955

`##Gene expression enhancement

Set size of superpixel

res=20

Note, if the numer of superpixels is too large and take too long, you can increase the res to 100`

enhanced_exp_adata=tesla.imputation(img=img, raw=counts, cnt=cnt, genes=counts.var.index.tolist(), shape="None", res=res, s=1, k=2, num_nbs=10)`

home/shpc_101112/miniconda3/envs/scan/lib/python3.8/site-packages/TESLA/imputation.py:30: ImplicitModificationWarning: Trying to modify attribute.obs` of view, initializing view as actual. known_adata.obs["x"]=known_adata.obs["pixel_x"] /home/shpc_101112/.local/lib/python3.8/site-packages/numpy/core/fromnumeric.py:3432: RuntimeWarning: Mean of empty slice. return _methods._mean(a, axis=axis, dtype=dtype, /home/shpc_101112/.local/lib/python3.8/site-packages/numpy/core/_methods.py:190: RuntimeWarning: invalid value encountered in double_scalars ret = ret.dtype.type(ret / rcount)

Total number of sudo points: 7199 Calculating spot 0 Calculating spot 1000 Calculating spot 2000 Calculating spot 3000 Calculating spot 4000 Calculating spot 5000 Calculating spot 6000 Calculating spot 7000 --- 364.8504099845886 seconds ---

/home/shpc_101112/miniconda3/envs/scan/lib/python3.8/site-packages/TESLA/imputation.py:49: FutureWarning: X.dtype being converted to np.float32 from float64. In the next version of anndata (0.9) conversion will not be automatic. Pass dtype explicitly to avoid this warning. Pass AnnData(X, dtype=X.dtype, ...) to get the future behavour. sudo_adata=AnnData(np.zeros((sudo.shape[0], len(genes))))

Imputing spot 0 Imputing spot 1000 Imputing spot 2000 Imputing spot 3000 Imputing spot 4000 Imputing spot 5000 Imputing spot 6000 Imputing spot 7000 enhanced_exp_adata.X array([[nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], ..., [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan]], dtype=float32)`

jianhuupenn commented 1 year ago

Sorry for the late response. The nan value may result from unmatched coordinates and the histology image. Please check if the "pixel_x" and "pixel_y" match ethe image.