[docs]defpositions(adata:AnnData,position_filepath:Path|str,scale_filepath:Path|str,quality:str="low",copy:bool=False,)->AnnData|None:"""\ Adding spatial information into the Anndata object Parameters ---------- adata Annotated data matrix. position_filepath Path to tissue_positions_list file. scale_filepath Path to scalefactors_json file. quality Choosing low or high resolution image. copy Return a copy instead of writing to adata. Returns ------- Depending on `copy`, returns or updates `adata` with the following fields. **imagecol** and **imagerow** : `adata.obs` field Spatial information of the tissue image. """adata=adata.copy()ifcopyelseadatatissue_positions=pd.read_csv(position_filepath,header=None)tissue_positions.columns=["barcode","tissue","row","col","imagerow","imagecol",]importjsonwithopen(scale_filepath)asjson_file:scale_factors=json.load(json_file)ifquality=="low":tissue_positions["imagerow"]=(tissue_positions["imagerow"]*scale_factors["tissue_lowres_scalef"])tissue_positions["imagecol"]=(tissue_positions["imagecol"]*scale_factors["tissue_lowres_scalef"])elifquality=="high":tissue_positions["imagerow"]=(tissue_positions["imagerow"]*scale_factors["tissue_hires_scalef"])tissue_positions["imagecol"]=(tissue_positions["imagecol"]*scale_factors["tissue_hires_scalef"])tmp=adata.obs.merge(tissue_positions.reset_index().set_index(["barcode"]),left_index=True,right_index=True,how="left",).reset_index()[["imagerow","imagecol"]]adata.obs["imagerow"]=tmp["imagerow"].valuesadata.obs["imagecol"]=tmp["imagecol"].valuesreturnadataifcopyelseNone