SHARE
TWEET

Untitled

a guest Aug 19th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sparsematrix = io.mmread('my_gene_ontology_edit.obo.2014-01-01.hierarchy_annotations.mtx')
  2. go_hierarchy = sparsematrix.todok()
  3.  
  4. col_names = row_names = np.genfromtxt('my_gene_ontology_edit.obo.2014-01-01.hierarchy_annotations.mtx.rownames.tsv', dtype=str)
  5.  
  6. go_hierarchy.axes = col_names
  7.  
  8. #necessario rinomiare per fare combaciare con termini go
  9. human_129.columns = human_129.columns.str.replace(':', '_')
  10. human_152.columns = human_152.columns.str.replace(':', '_')
  11.  
  12. #determinare termini go comuni tra organismo e matrice gerarchica
  13. intersection = np.sort(np.intersect1d(go_hierarchy.axes, human_129.columns))
  14. human_129 = human_129.reindex(columns=intersection)
  15. human_152 = human_152.reindex(columns=intersection)
  16.  
  17. human_129.sort_index(axis=1, inplace=True)
  18. human_129.sort_index(inplace=True)
  19. human_152.sort_index(axis=1, inplace=True)
  20. human_152.sort_index(inplace=True)
  21.  
  22. #determinazione indici elementi usabili della matrice gerarchica
  23. import numpy_indexed as npi
  24. %time idx = npi.indices(go_hierarchy.axes, intersection)
  25.  
  26.  
  27. # seleziona le colonne: attenzione impiega 4-5 minuti con 4 core
  28. %time go__ = go_hierarchy[:,idx]
  29.  
  30. #seleziona le colonne
  31. %time go = go__[idx,:]
  32.  
  33. human_129 = csr_matrix(human_129)
  34. human_152 = csr_matrix(human_152)
  35.  
  36. human_129_tp = (human_129.dot(go) > 0).astype('int8')
  37. human_129_tp = human_129_tp = human_129
  38.  
  39. human_152_tp = (human_152.dot(go) > 0).astype('int8')
  40. human_152_tp = human_152_tp + human_152
  41.  
  42. human_129 = pd.DataFrame(human_129_tp.todense(), index=intersection_rows, columns=intersection)
  43. human_152 = pd.DataFrame(human_152_tp.todense(), index=intersection_rows, columns=intersection)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top