Changeset 1786:df95834ddac7 in orangebioinformatics for _bioinformatics/obiGeneSetSig.py
 Timestamp:
 05/21/13 15:01:58 (11 months ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

_bioinformatics/obiGeneSetSig.py
r1785 r1786 1 1 from __future__ import absolute_import 2 2 3 import random 3 4 import math 4 5 from collections import defaultdict … … 780 781 select = nth(sorted(scores, key=lambda x: x[1])[:self.top], 0) 781 782 782 print sorted(scores, key=lambda x: x[1])783 784 783 if len(select) < self.atleast: 785 784 select = nth(sorted(scores, key=lambda x: x[1])[:self.atleast], 0) … … 791 790 datas = Orange.data.Table(doms, datao) 792 791 793 return select, pca(datas) 792 if len(select) == 0: 793 return select, None 794 else: 795 return set(select), pca(datas) 794 796 795 797 def _use_par(self, arr, constructt): 796 798 select, constructt = constructt 797 select = set(select) 799 800 if len(select) == 0: 801 return 0. 798 802 799 803 arr = [ arr[i].value for i in range(len(arr.domain.attributes)) … … 807 811 808 812 return a 813 814 def _shuffleClass(data, rand): 815 """ Destructive! """ 816 locations = range(len(data)) 817 rand.shuffle(locations) 818 attribute = 1 819 l = [None]*len(data) 820 for i in range(len(data)): 821 l[locations[i]] = data[i][attribute] 822 for i in range(len(data)): 823 data[i][attribute] = l[i] 824 825 class SPCA_ttperm(SPCA): 826 """ Set threshold with a permutation test. """ 827 828 def __init__(self, **kwargs): 829 self.pval = kwargs.pop("pval", 0.01) #target pvalue 830 self.perm = kwargs.pop("perm", 100) #number of class permutation 831 self.sperm = kwargs.pop("sperm", 100) #sampled attributes per permutation 832 super(SPCA_ttperm, self).__init__(**kwargs) 833 834 def __call__(self, data, *args, **kwargs): 835 joined = [] 836 rand = random.Random(0) 837 nat = len(data.domain.attributes) 838 839 datap = Orange.data.Table(data.domain, data) 840 841 for p in range(self.perm): 842 _shuffleClass(datap, rand) 843 if self.sperm is not None: 844 ti = rand.sample(xrange(nat), self.sperm) 845 else: 846 ti = range(nat) 847 joined.extend([ obiExpression.MA_t_test()(i, datap) 848 for i in ti ]) 849 850 joined = map(abs, joined) 851 joined.sort(reverse=True) 852 853 t = joined[int(self.pval*len(joined))] 854 855 self.threshold = t 856 return super(SPCA_ttperm, self).__call__(data, *args, **kwargs) 857 809 858 810 859 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.