感觉这个问题就很复杂哈,摸不清什么规律,只能判断前后的维度变化了
example 1
import scanpy as sc adata1 = sc.read('/Users/yxkang/Desktop/dataset/HER2/H5AD_file/ad_H1.h5ad')
print(adata1)adata2 = sc.read('/Users/yxkang/Desktop/dataset/HER2/H5AD_file/ad_G2.h5ad')
print(adata2)adata = sc.AnnData.concatenate(*[adata1,adata2])
print(adata)adata_list =[adata1,adata2]
print("before ....")
print(adata_list[0])
print(adata_list[1])
print(adata1)
print(adata2)for ad in adata_list:print(ad)ad = ad[:,adata.var_names[0:100]]print(ad)
print("After...")
print(adata_list[0])
print(adata_list[1])
print(adata1)
print(adata2)
example2
import scanpy as sc adata1 = sc.read('/Users/yxkang/Desktop/dataset/HER2/H5AD_file/ad_H1.h5ad')
print(adata1)adata2 = sc.read('/Users/yxkang/Desktop/dataset/HER2/H5AD_file/ad_G2.h5ad')
print(adata2)adata = sc.AnnData.concatenate(*[adata1,adata2])
print(adata)adata_list =[adata1,adata2]
print("before ....")
print(adata_list[0])
print(adata_list[1])
print(adata1)
print(adata2)for idx in range(len(adata_list)):print(adata_list[idx])adata_list[idx] = adata_list[idx][:,adata.var_names[0:100]]print(adata_list[idx])
print("After...")
print(adata_list[0])
print(adata_list[1])
print(adata1)
print(adata2)
example3
import scanpy as sc adata1 = sc.read('/Users/yxkang/Desktop/dataset/HER2/H5AD_file/ad_H1.h5ad')
print(adata1)adata2 = sc.read('/Users/yxkang/Desktop/dataset/HER2/H5AD_file/ad_G2.h5ad')
print(adata2)adata = sc.AnnData.concatenate(*[adata1,adata2])
print(adata)adata_list =[adata1,adata2]
print("before ....")
print(adata_list[0])
print(adata_list[1])
print(adata1)
print(adata2)for idx in range(len(adata_list)):ad = adata_list[idx]print(ad)ad = ad[:,adata.var_names[0:100]]print(ad)
print("After...")
print(adata_list[0])
print(adata_list[1])
print(adata1)
print(adata2)
可以看到,直接访问列表元素和中间过渡使用暂时变量,结果是有区别的,
而且为了彻底改变adata的值,不要view, 应该使用copy()
如下面
for idx in range(len(adata_list)):print(adata_list[idx])adata_list[idx] = adata_list[idx][:,adata_joint.var_names].copy()print(adata_list[idx])