jianhuupenn / TESLA

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

No pixel_x key in AnnData object #8

Open jianggl2000 opened 9 months ago

jianggl2000 commented 9 months ago

Thanks for the great work! The tutorial gives an example on how to convert h5 to h5ad.

Read original 10x_h5 data and save it to h5ad

from scanpy import read_10x_h5 adata = read_10x_h5("../tutorial/data/151673/expression_matrix.h5") spatial=pd.read_csv("../tutorial/data/151673/positions.txt",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]

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("../tutorial/data/151673/sample_data.h5ad")

However, the data ['pixel_x', 'pixel_y', "array_x", "array_y"] are not created with read_10x_h5 by default. Should the following code be added or to replace x2-x5 above?

adata.obs["array_x"]=spatial[2]
adata.obs["array_y"]=spatial[3]
adata.obs["pixel_x"]=spatial[4]
adata.obs["pixel_y"]=spatial[5]

Also, I cannot find the pkl files in the results folder, nor in download data/results files, for 7.1 Read in cell type annotations.

with open('./results/B_annotation_c_d.pkl', 'rb') as f: c_d1 = pickle.load(f)

FileNotFoundError: [Errno 2] No such file or directory: './results/B_annotation_c_d.pkl' did I miss anything?

Perik-Zavodskii commented 2 months ago

I fixed the cell, it now works:

#Read original 10x_h5 data and save it to h5ad
from scanpy import read_10x_h5
adata = read_10x_h5("path/filtered_feature_bc_matrix.h5")
spatial=pd.read_csv("path/spatial/tissue_positions_list.csv",
                    sep=",",header=None,na_filter=False,index_col=0) 
adata.obs["Sample"]=spatial[1]
adata.obs["array_x"]=spatial[2]
adata.obs["array_y"]=spatial[3]
adata.obs["pixel_x"]=spatial[4]
adata.obs["pixel_y"]=spatial[5]
#Select captured samples
adata=adata[adata.obs["Sample"]==1]
adata.var_names=[i.upper() for i in list(adata.var_names)]
adata.var["genename"]=adata.var.index.astype("str")
adata.write_h5ad("Spatial.h5ad")
Perik-Zavodskii commented 2 months ago

Also if using cv2 (method 1), this line of code: spots=counts.obs.loc[:, ['pixel_x', 'pixel_y', "array_x", "array_y"]] must also be executed