-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_liver_atlas.py
51 lines (32 loc) · 965 Bytes
/
read_liver_atlas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import scanpy as sc
import pandas as pd
import numpy as np
df=pd.read_csv('annot_mouseStStAll.csv')
data=df.to_numpy()
print(df.columns)
cluster=df['annot'].to_numpy()
umap=df[['UMAP_1', 'UMAP_2']].to_numpy()
cellid=df['cell'].to_numpy()
#cluster=df.to_numpy
df=pd.read_csv('barcodes.tsv',sep='\t',header=None)
barcode=df.to_numpy()
df=pd.read_csv('features.tsv',sep='\t',header=None)
genes=df.to_numpy()
d={}
for i in range(len(barcode)):
d[barcode[i,0]]=i
index=[]
for i in range(len(cellid)):
index.append(d[cellid[i]])
print(cellid[0:5],len(index))
newbarcode=barcode[index,0]
print(np.array_equal(newbarcode,cellid))
print(newbarcode.shape,umap.shape,cellid.shape,barcode.shape,genes.shape)
adata=sc.read_mtx('matrix.mtx', dtype='float32')
temp=adata.transpose()
temp.var_names=genes[:,0]
temp.obs_names=barcode[:,0]
newad=temp[index,:].copy()
newad.obs['cluster']=cluster
newad.obsm['X_umap']=umap
newad.write_h5ad('savedata.h5ad')