예제 #1
0
    def survivalIntegral(self):
        """
        Calculate the survival integral.

        :return: float, float, StatusMessage -- survival integral, var(survival integral), status.
        """
        if self.isReplicateGroup():
            # here we average over the underlying replicates
            si=numpy.zeros([len(self.activeChildWellIndices())])

            allstatuses=StatusMessage()
            statuses=StatusMessage()
            i=0
            for clstc in self.activeChildWells():
                si[i], sivar, status = clstc.survivalIntegral()
                if status is not None:
                    allstatuses.addStatus(status)
                if status is not None and days is not None:
                    statuses.addStatus(status)
                i+=1

            idcs=numpy.isnan(si)
            if numpy.all(idcs):
                allstatuses.addStatus(self.initDiffStatus)
                return None, None, allstatuses

            simean, sivar = maskedArrayToMeanVar(si, ddof=1)

            statuses.addStatus(self.initDiffStatus)
            return simean, sivar, statuses

        days, viability, viabilityvar, initDiffStatus=self.viability()
        si=None
        if viability is not None and days is not None:
            si=numpy.trapz(viability,x=days)
        return si,None,None
예제 #2
0
    def viability(self):
        """
        Calculate the viability.

        :return: list(float), list(float), list(float), StatusMessage -- days, viability, var(viability), status.
        """
        if self.isReplicateGroup():
            # here we average over the underlying replicates
            viability=numpy.zeros([len(self.activeChildWellIndices()), self.days.shape[0]])

            allstatuses=StatusMessage()
            statuses=StatusMessage()
            i=0
            for clstc in self.activeChildWells():
                days, viability[i], viabilityvar, status = clstc.viability()
                if status is not None:
                    allstatuses.addStatus(status)
                if status is not None and days is not None:
                    statuses.addStatus(status)
                i+=1

            idcs=numpy.isnan(viability)
            if numpy.all(idcs):
                allstatuses.addStatus(self.initDiffStatus)
                return None, None, None, allstatuses

            viabilitymean, viabilityvar = maskedArrayToMeanVar(viability, idcs=idcs, ddof=1, axis=0)

            statuses.addStatus(self.initDiffStatus)
            return self.days, viabilitymean, viabilityvar, statuses

        viability=numpy.zeros([len(self._odReplicates)])
        viabilityvar=numpy.zeros([len(self._odReplicates)])
        mu_ef, mu_ef_var, od0_ef, od0_ef_var, maxt_ef, maxt_ef_var, lag_ef__0, lag_ef_var__0, method_ef, status = self._odReplicates[0].maxGrowthrate()
        if lag_ef__0 is None:
            return None, None, None, StatusMessage(
                key='viability:noInitialLag', severity=Severity.failed,
                longmsg='lag could not be extract for first timepoint')

        tcidx=-1
        for tc in self._odReplicates:
            tcidx+=1
            if tc is None:
                viability[tcidx]=None
                viabilityvar[tcidx]=None
                print('WARNING no Replicate defined for day '+str(self.days[tcidx])+' and sample/condition '+self._odReplicates[0].fullId())
                continue

            mu_ef, mu_ef_var, od0_ef, od0_ef_var, maxt_ef, maxt_ef_var, lag_ef, lag_ef_var, method_ef, status = tc.maxGrowthrate()
            doublingtime, doublingtimevar = Replicate.growthrateToDoublingTime(mu_ef,mu_ef_var)
            if lag_ef is not None and doublingtime is not None:
                deltaT=lag_ef-lag_ef__0
                # f(deltaT,doubling) = 2^(- deltaT/doubling )  [ == e^(-ln(2) deltaT/doubling) ]
                viability[tcidx]=math.pow(2,-deltaT/doublingtime)
            elif doublingtime is None:
                # if we could not extract a doubling time we assume that there was no growth at all
                viability[tcidx]=0.
                viabilityvar[tcidx]=0.
            else:
                viability[tcidx]=None
            if lag_ef_var__0 is not None and lag_ef_var is not None and doublingtimevar is not None:
                deltaTvar=lag_ef_var+lag_ef_var__0
                # df/ddeltaT  = - ln(2)/doubling  2^(- deltaT/doubling )
                # df/doubling = + ln(2) deltaT 1/doubling^2   2^(- deltaT/doubling )
                viabilityvar[tcidx]=( math.pow( math.log(2)/doublingtime * math.pow(2,-deltaT/doublingtime),2 ) * doublingtimevar
                                      + math.pow( math.log(2)*deltaT  * math.pow(doublingtime,-2) * math.pow(2,-deltaT/doublingtime),2 ) * deltaTvar)
            else:
                viabilityvar[tcidx]=None

        return self.days, viability, viabilityvar, self.initDiffStatus