Advertisement
jhangyu

Normalize heatmap

May 24th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. # install clustergrammer
  2. pip3 install clustergrammer
  3.  
  4. # make network object and load file
  5. from clustergrammer import Network
  6. from pandas import DataFrame as df
  7. net = Network()
  8. net.load_file('/data/fastq/sex_determine_region.heatmap.txt')
  9.  
  10. # Z-score normalize the rows
  11. net.normalize(axis='row', norm_type='zscore', keep_orig=True)
  12.  
  13. # calculate clustering using default parameters
  14. net.cluster()
  15.  
  16. # save tsv to file for use by front end
  17. net.write_matrix_to_tsv('/data/fastq/nor.tsv')
  18.  
  19.  
  20. # procedure below and extra steps, use it as your will
  21.  
  22. # make network object and load DataFrame, df
  23. net = Network()
  24. net.load_df(df)
  25.  
  26. # filter for the top 100 columns based on their absolute value sum
  27. net.filter_N_top('col', 100, 'sum')
  28.  
  29. # cluster using default parameters
  30. net.cluster()
  31.  
  32. # save visualization JSON to file for use by front end
  33. net.write_json_to_file('viz', '/data/fastq/mult_view.json')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement