multired icon indicating copy to clipboard operation
multired copied to clipboard

Dump JSD matrix to a tsv file

Open lljotall opened this issue 8 years ago • 1 comments

Hello KatolaZ,

First, I would like to say that it is very nice of you to share your code with the community.

I wrote a function to dump the JSD matrix to a .tsv file, that can be easily exported to other platforms, such as R or MATLAB. It can be extended to dump the JSD_aprox matrix as well. If you think it could be useful for others, feel free to add it to your project!

def dump_JSD_tsv(self, output_filename = 'JSD.tsv', force_compute=False):
  if self.JSD == None:
      if force_compute:
          self.compute_JSD_matrix()
      else:
          print "Error!!! call to dump_JSD_tsv but JSD matrix has not been computed!!!"
          sys.exit(1)

  f = open(output_filename, "w")
  # column names
  f.write('\t')
  for i in range(len(self.layers)):
    f.write(str(i)+'\t')
  f.write('\n')

  for i in range(len(self.layers)):
    f.write(str(i)+'\t') # rowname
    for j in range(len(self.layers)):
      f.write(str(self.JSD[i][j])+'\t')
    f.write('\n')

I also suggest replacing self.len in lines 320 and 321 for len(self.layers)

Have a good one!

lljotall avatar Aug 11 '17 10:08 lljotall

Hi @lljotall sorry but I was on vacation, with scarce internet access. Will have a look at your code in the next days and incorporate it. Thanks!

KatolaZ avatar Aug 31 '17 14:08 KatolaZ