示例#1
0
import sys

# RPy hack, make it silent
import rpy_options
rpy_options.set_options(VERBOSE=False)
import rpy


class Test(object):

    methods = []

    def register(cls, callable, name, desc, type_=2):
        cls.methods.append((callable, name.strip(), desc.strip(), type_))

    register = classmethod(register)

    def __call__(self, method, *args, **kargs):
        for i in self.methods:
            if i[1] == method.strip():
                return i[0](*args, **kargs)
        raise KeyError, 'Unsupported statistic test method, %s' % method


def hyper(m1, n1, m2, n2, is_tail=False, **kargs):
    """ check significance based on R language
    """
    q, m, n, k = m1, m2, n2 - m2, n1
    if m < q: return 0
    if is_tail:
        if q == 0:
示例#2
0
文件: discover.py 项目: xmao/kobas
"""Find enriched pathways by frequency of terms and statistical
significance of terms."""

import os, string, csv
from sets import Set

# RPy hack, make it silent
import rpy_options

rpy_options.set_options(VERBOSE=False)
import rpy

from kobas import dbutils, exception


class Dist(dict):
    def __init__(self):
        dict.__init__(self)

    def add(self, class_, stuff):
        self[class_] = stuff

    def update(self, class_, iterable):
        for record in iterable:
            self.add(class_, record)

    def size(self):
        stuffs = Set()
        for rec in self.values():
            stuffs.update(rec)
        return len(stuffs)