comparison utils/__init__.py @ 0:8918de535391 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/rna_commander/tools/rna_tools/rna_commender commit 2fc7f3c08f30e2d81dc4ad19759dfe7ba9b0a3a1
author rnateam
date Tue, 31 May 2016 05:41:03 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8918de535391
1 """Util functions."""
2
3 import pandas as pd
4 import cPickle
5
6 __author__ = "Gianluca Corrado"
7 __copyright__ = "Copyright 2016, Gianluca Corrado"
8 __license__ = "MIT"
9 __maintainer__ = "Gianluca Corrado"
10 __email__ = "gianluca.corrado@unitn.it"
11 __status__ = "Production"
12
13
14 def feature_size(store_name):
15 """Number of features."""
16 store = pd.io.pytables.HDFStore(store_name)
17 a = store.features
18 store.close()
19 return a.shape[0]
20
21
22 def save_serendipity_dic(y, filename):
23 """Save the dictionary with the serendipity values."""
24 store = pd.io.pytables.HDFStore(y)
25 mat = store.matrix
26 store.close()
27 n = len(mat.columns)
28 ser = 1 - mat.sum(axis=1) / n
29
30 f = open(filename, "w")
31 cPickle.dump(ser.to_dict(), f, protocol=2)
32 f.close()
33
34
35 def get_serendipity_val(dic, key):
36 """Return the serendipity of a RNA."""
37 # The key was in the training set
38 try:
39 return dic[key]
40 # The key wasn't in the training set, then the serendipity is 1
41 except KeyError:
42 return 1.