Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. gmm = pop['samples']['CONTROL']['gmm']
  2. C = pop['samples']['CONTROL']['C']
  3. M = pop['samples']['CONTROL']['M']
  4. types = PA.default_pbmc_types()
  5.  
  6. typeslist = list(types.keys()) # get list of types for consistency
  7. cols = range(gmm.n_components) # range of components
  8. finaltypes
  9. markers = np.concatenate([types[x] for x in types]) # get entire list of genes from dict
  10. markers = [x for x in markers if x in genes] # make sure to only keep valid genes
  11. genes_idx = [np.where(genes==x)[0][0] for x in markers] # get matching indices
  12.  
  13. M = M[genes_idx,:] # genes from initial M matrix
  14. M = sp.normalize(M, norm='max', axis=1) # scale rows by max
  15.  
  16. arr = [] # empty list to store mean vectors for each type
  17. for t in typeslist: # for each cell type t
  18. l = types[t] # get matching list of genes
  19. lidx = [markers.index(g) for g in l if g in markers] # retrieve gene indices from marker list (only valid genes in markers list)
  20. sub = M[lidx,:] # pick only genes for cell type t
  21. submean = np.array(sub.mean(axis=0)).flatten() # compute mean for each cell
  22. arr.append(submean) # store mean vector
  23. arr = np.vstack(arr) # stack mean vectors
  24. calls = np.argmax(arr,axis=0) # for each cell, get the index of max value = [] # to store top type for each component
  25.  
  26. for i in cols: # for each component i
  27. idx = np.where(prediction==i) # get indices of cells matching component i
  28. sub = calls[idx] # get the indices of max means for those cells
  29. unique, counts = np.unique(sub, return_counts=True) # count how many counts for each argmax
  30. finaltypes.append(typeslist[unique[np.argmax(counts)]]) # append name of most prominant cell type in component i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement