示例#1
0
 def get_percentage_genes_covered_at_this_fraction(self, this):
     assert this <= 1 and this >= 0
     icol = self.coverage_column
     X = pylab.linspace(0, 1, 101)
     N = float(len(self.df))
     Y = np.array([sum(self.df[icol] > x) / N * 100 for x in X])
     return np.interp(this, X, Y)
示例#2
0
    def target_distribution(self, xprime):
        """The target distribution

        Compute histogram. Get X, Y.  Given xprime, interpolate to get yprime
        use e.g. np.interp

        """
        return np.interp(xprime, self.X[1:self.bins + 1], self.Y)
示例#3
0
文件: pacbio.py 项目: sequana/sequana
    def target_distribution(self, xprime):

        """The target distribution

        Compute histogram. Get X, Y.  Given xprime, interpolate to get yprime
        use e.g. np.interp

        """
        return np.interp(xprime, self.X[1:self.bins+1], self.Y)
示例#4
0
    def simulate(self, n=100000, burning=20000, step=None, x0=None):
        if step is None:
            self.step = (self.upper_bound - self.lower_bound) / 100.
            step = self.step

        if x0 is None:
            self.x0 = (self.upper_bound -
                       self.lower_bound) / 2 + self.lower_bound

        self.aprob = []

        # function target profile
        NS = self.Ytarget / sum(self.Ytarget)
        sdnorm = lambda x: np.interp(x, self.Xtarget, NS)

        x = self.x0

        vec = [x]  # starting seed

        # a gaussian jump centered on 0 is used as a random inovation
        # if the candidate is outside of the boundaries, we try another
        # candidate
        def jumper(x):
            #jump = uniform(-step, step)
            jump = gauss(0, step)
            xprime = x + jump
            while xprime < self.lower_bound or xprime > self.upper_bound:
                jump = gauss(0, step)
                xprime = x + jump
            return xprime

        for i in range(1, n * 2 + burning):
            xprime = jumper(x)

            aprob = min([1.,
                         sdnorm(xprime) / sdnorm(x)])  #acceptance probability
            u = uniform(0, 1)
            if u < aprob:
                x = xprime
                vec.append(x)
            self.aprob.append(aprob)

            if len(vec) == n + burning:
                break
        self.burning_vector = vec[0:burning]
        self.vec = vec[burning:]

        return vec[burning:]
示例#5
0
文件: mh.py 项目: sequana/sequana
    def simulate(self, n=100000, burning=20000, step=None, x0=None):
        if step is None:
            self.step = (self.upper_bound - self.lower_bound) / 100.
            step = self.step

        if x0 is None:
            self.x0 = (self.upper_bound - self.lower_bound) / 2 + self.lower_bound

        self.aprob = []

        # function target profile
        NS = self.Ytarget / sum(self.Ytarget)
        sdnorm = lambda x: np.interp(x, self.Xtarget, NS)

        x = self.x0

        vec = [x] # starting seed

        # a gaussian jump centered on 0 is used as a random inovation 
        # if the candidate is outside of the boundaries, we try another 
        # candidate
        def jumper(x):
            #jump = uniform(-step, step)
            jump = gauss(0, step)
            xprime = x + jump
            while xprime < self.lower_bound or xprime>self.upper_bound:
                jump = gauss(0, step)
                xprime = x + jump
            return xprime

        for i in range(1, n*2+burning):
            xprime = jumper(x)

            aprob = min([1., sdnorm(xprime)/sdnorm(x)]) #acceptance probability
            u = uniform(0, 1)
            if u < aprob:
                x = xprime
                vec.append(x)
            self.aprob.append(aprob)

            if len(vec) == n + burning:
                break
        self.burning_vector = vec[0:burning]
        self.vec = vec[burning:]

        return vec[burning:]