MaskGraphene
  • Installation
  • Data availability
  • Tutorial 1: Generate hard-links for consecutive ST slices
  • Tutorial 1b: Generate hard-links using PASTE
  • Tutorial 1c: Generate hard-links using SPACEL
  • Tutorial 2: Integrate DLPFC data with MaskGraphene
  • Tutorial 3: Integrate MHypo data with MaskGraphene
  • Tutorial 4: Integrate MB data with MaskGraphene
  • Tutorial 6: Integrate horizontal slices with MaskGraphene
MaskGraphene
  • Tutorial 1c: Generate hard-links using SPACEL
  • View page source

Tutorial 1c: Generate hard-links using SPACEL

[1]:
from SPACEL import Scube
import scanpy as sc
import numpy as np
import os
import pandas as pd
import seaborn as sns
import matplotlib
import pandas as pd
import anndata
from SPACEL import Splane
import time
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 from SPACEL import Scube
      2 import scanpy as sc
      3 import numpy as np

ModuleNotFoundError: No module named 'SPACEL'
[2]:
def load_DLPFC(root_dir='../benchmarking_data/DLPFC12', section_id='151507'):
    # 151507, ..., 151676 12 in total
    ad = sc.read_visium(path=os.path.join(root_dir, section_id), count_file=section_id+'_filtered_feature_bc_matrix.h5', load_images=True)
    ad.var_names_make_unique()

    gt_dir = os.path.join(root_dir, section_id, 'gt')
    gt_df = pd.read_csv(os.path.join(gt_dir, 'tissue_positions_list_GTs.txt'), sep=',', header=None, index_col=0)
    ad.obs['original_clusters'] = gt_df.loc[:, 6]
    keep_bcs = ad.obs.dropna().index
    ad = ad[keep_bcs].copy()
    ad.obs['original_clusters'] = ad.obs['original_clusters'].astype(int).astype(str)
    # print(ad.obs)
    return ad
[3]:
"""dlpfc 1"""
section_ids_list = [['151507', '151508']]
data_dir = '../../spatial_benchmarking/benchmarking_data/DLPFC12'
run_times = []
save_dir_gt = './SPACEL/align_coords'

for iter_ in range(1):
    for section_ids in section_ids_list:
        inputs = []

        i = 0
        # adata_list = []
        for section_id in section_ids:
            dataset = section_ids[0] + '_' + section_ids[1]

            adata = load_DLPFC(root_dir=data_dir, section_id=section_id)
            inputs.append(adata)

        start_time = time.time()
        if not os.path.exists(os.path.join(save_dir_gt, dataset)):
            os.makedirs(os.path.join(save_dir_gt, dataset))
        save_path = os.path.join(save_dir_gt, dataset, 'aligned_coordinates.csv')

        Scube.align(inputs,
                    cluster_key='spatial_domain',
                    n_neighbors = 15,
                    n_threads=10,
                    p=2,
                    write_loc_path=save_path
                    )
        end_time = time.time()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[3], line 16
     13 for section_id in section_ids:
     14     dataset = section_ids[0] + '_' + section_ids[1]
---> 16     adata = load_DLPFC(root_dir=data_dir, section_id=section_id)
     17     inputs.append(adata)
     19 start_time = time.time()

Cell In[2], line 3, in load_DLPFC(root_dir, section_id)
      1 def load_DLPFC(root_dir='../benchmarking_data/DLPFC12', section_id='151507'):
      2     # 151507, ..., 151676 12 in total
----> 3     ad = sc.read_visium(path=os.path.join(root_dir, section_id), count_file=section_id+'_filtered_feature_bc_matrix.h5', load_images=True)
      4     ad.var_names_make_unique()
      6     gt_dir = os.path.join(root_dir, section_id, 'gt')

NameError: name 'sc' is not defined
Previous Next

© Copyright 2024, Yunfei Hu.

Built with Sphinx using a theme provided by Read the Docs.