def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--infiles", nargs="*", default=[])
    parser.add_argument("-k", "--key", default="length", type=str)
    parser.add_argument("-o", "--outfile", default="out", type=str)
    args = parser.parse_args()

    data = scc.SisterCellData(**vars(args))

    if not args.key in data.keylist_stripped:
        raise KeyError

    fig, axes = plt.subplots(figsize=(20, 10),
                             dpi=100,
                             ncols=2,
                             nrows=len(data),
                             sharey=True,
                             sharex=True)

    for dID, fn, x in data:
        dA = np.diff(x[args.key + 'A'])
        dB = np.diff(x[args.key + 'B'])
        axes[dID, 0].hist(dA, log=True, bins=50)
        axes[dID, 0].axvline(x=data.otsu(dA), c='red')
        axes[dID, 1].hist(dB, log=True, bins=50)
        axes[dID, 1].axvline(x=data.otsu(dB), c='red')

    fig.savefig(args.outfile + '.svg')
예제 #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--infiles", nargs="*", default=[])
    parser.add_argument("-o",
                        "--outfilesuffix",
                        default="discretized",
                        type=str)
    parser.add_argument("-D", "--DiscretizeKey", default="length", type=str)
    parser.add_argument("-H",
                        "--Histograms",
                        default=False,
                        action="store_true")
    parser.add_argument("-b", "--bins", default=100, type=int)
    parser.add_argument("-A",
                        "--AdditionalDataColumns",
                        type=str,
                        default=[],
                        nargs="*")
    args = parser.parse_args()

    data = scc.SisterCellData(**vars(args))

    if args.Histograms:
        histodata = dict()

    for dataID, fn, x in data:
        trajA, trajB = data.CellDivisionTrajectory(
            dataID,
            discretize_by=args.DiscretizeKey,
            additional_columns=args.AdditionalDataColumns)
        trajA.to_csv(os.path.splitext(os.path.basename(fn))[0] + '.' +
                     args.outfilesuffix + 'A',
                     sep=' ',
                     index_label='# generation')
        trajB.to_csv(os.path.splitext(os.path.basename(fn))[0] + '.' +
                     args.outfilesuffix + 'B',
                     sep=' ',
                     index_label='# generation')

        if args.Histograms:
            for k in trajA.keys():
                if not k in histodata.keys():
                    histodata[k] = trajA[k]
                else:
                    histodata[k] = np.concatenate([histodata[k], trajA[k]])
                histodata[k] = np.concatenate([histodata[k], trajB[k]])

    if args.Histograms:
        for k in histodata.keys():
            h, b = np.histogram(histodata[k], bins=args.bins)
            b = b[:-1] + 0.5 * np.diff(b)

            np.savetxt(k.replace(' ', '-') + '.histo', np.array([b, h]).T)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--infiles", default=[], nargs="*")
    parser.add_argument("-o", "--outfile", default="alltrajectories", type=str)
    parser.add_argument("-k", "--key", default="length", type=str)
    parser.add_argument("-H",
                        "--HistoTrajLength",
                        default=False,
                        action="store_true")
    parser.add_argument("-v", "--verbose", default=False, action="store_true")
    args = parser.parse_args()

    data = scc.SisterCellData(**vars(args))

    assert args.key in data.keylist_stripped, 'option -k "KEY" only allows values in [' + ', '.join(
        data.keylist_stripped) + ']'

    fig, axes = plt.subplots(nrows=len(data),
                             ncols=1,
                             figsize=(10, 100),
                             dpi=100,
                             frameon=False,
                             sharex=True,
                             sharey=True)

    maxtimes = list()

    for i, fn, d in data:
        maxtimes.append(np.max(d[u'timeA']))
        if args.verbose:
            print 'open file \033[91m{:s}\033[0m maxtime: {:5.2f}'.format(
                fn, np.max(d[u'timeA']))
        axes[i].plot(d[u'timeA'], d[args.key + 'A'])
        axes[i].plot(d[u'timeB'], d[args.key + 'B'])

    if args.verbose:
        print 'writing trajectories to \033[94m{:s}\033[0m'.format(
            args.outfile + '.svg')
    fig.savefig(args.outfile + '.svg')

    if args.HistoTrajLength:
        if args.verbose:
            print 'writing histogram to \033[94m{:s}\033[0m'.format(
                'maxtimehist.svg')
        fig2 = plt.figure()
        plt.hist(maxtimes, range=(0, 100), bins=51)
        fig2.savefig('maxtimehist.svg')
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--infiles", nargs="*", default=[])
    parser.add_argument("-k", "--DiscretizeKey", default="length", type=str)
    parser.add_argument("-o", "--outfileprefix", default="ACF", type=str)
    parser.add_argument("-m", "--minlength", default=10, type=int)
    parser.add_argument("-S",
                        "--averageSisters",
                        default=False,
                        action="store_true")
    parser.add_argument("-N",
                        "--Normalize",
                        default=False,
                        action="store_true")
    args = parser.parse_args()

    data = scc.SisterCellData(**vars(args))

    correlationfunctions = dict()

    for x in data:
        for y in data.CellDivisionTrajectory(x[0],
                                             discretize_by=args.DiscretizeKey):
            for k in y.keys():
                if k != 'time' and len(y[k]) > args.minlength:
                    k0 = k
                    if args.averageSisters:
                        k0 = k.rstrip('AB')
                    if not k0 in correlationfunctions.keys():
                        correlationfunctions[k0] = list()
                    correlationfunctions[k0].append(
                        autocorrelation(y[k], args.Normalize))

    for k in correlationfunctions.keys():
        maxL = np.max([len(a) for a in correlationfunctions[k]])
        cf_sum = np.zeros(maxL, dtype=np.float)
        cf_count = np.zeros(maxL, dtype=np.float)
        for acf in correlationfunctions[k]:
            if not np.any(np.isnan(acf)):
                cf_sum[:len(acf)] += acf
                cf_count[:len(acf)] += 1
        if cf_count[-1] == 0:
            maxL = np.argmin(cf_count > 0)
        np.savetxt(
            args.outfileprefix + "_" + k.replace(" ", "-"),
            np.array([np.arange(maxL), cf_sum[:maxL] / cf_count[:maxL]]).T)
예제 #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--infiles", nargs="*", default=[])
    parser.add_argument("-o", "--outfilesuffix", default="dtd", type=str)
    parser.add_argument("-v", "--verbose", default=False, action="store_true")
    parser.add_argument("-O",
                        "--Get_OTSU_From_Both",
                        default=True,
                        action="store_false")
    args = parser.parse_args()

    data = ssc.SisterCellData(**vars(args))

    for i in range(len(data)):
        if args.verbose: print(data.filenames[i])
        dtd = data.DivisionTimeDifferences(i)
        outfilename = os.path.splitext(os.path.basename(
            data.filenames[i]))[0] + '.' + args.outfilesuffix
        np.savetxt(outfilename, np.array([np.arange(len(dtd)), dtd]).T)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--infiles", default=[], nargs="*")
    parser.add_argument("-K", "--DiscretizeKey", default='length', type=str)
    parser.add_argument("-N",
                        "--normalize",
                        default=False,
                        action="store_true")
    args = parser.parse_args()

    data = ssc.SisterCellData(**vars(args))

    histodata = np.array([], dtype=int)
    dt = data.timestep
    idt = 1. / dt
    histo = np.zeros(0, dtype=int)

    for dataID, fn, x in data:
        trajA, trajB = data.CellDivisionTrajectory(
            dataID, discretize_by=args.DiscretizeKey)

        for intdivtime in np.array(trajA['generationtime'] / dt, dtype=int):
            if intdivtime >= len(histo):
                histo = np.concatenate(
                    [histo,
                     np.zeros(intdivtime - len(histo) + 1, dtype=int)])
            histo[intdivtime] += 1

        for intdivtime in np.array(trajB['generationtime'] / dt, dtype=int):
            if intdivtime >= len(histo):
                histo = np.concatenate(
                    [histo,
                     np.zeros(intdivtime - len(histo) + 1, dtype=int)])
            histo[intdivtime] += 1

    if args.normalize:
        isum = 1. / np.sum(histo)
        for t, h in enumerate(histo):
            print('{:.3f} {:.6e}'.format(t * dt, isum * h))
    else:
        for t, h in enumerate(histo):
            print('{:.3f} {:4d}'.format(t * dt, h))
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--infiles", default=[], nargs="*")
    parser.add_argument("-n", "--TrajCount", default=10, type=int)
    parser.add_argument("-M", "--MinLength", default=None, type=int)
    parser.add_argument("-o", "--baseoutname", default="RandTraj", type=str)
    parser.add_argument("-F",
                        "--ForceLength",
                        default=False,
                        action="store_true")
    parser.add_argument("-S", "--SyncTime", default=False, action="store_true")
    parser.add_argument("-v", "--verbose", default=False, action="store_true")
    args = parser.parse_args()

    data = scc.SisterCellData(**vars(args))

    for i, rt in enumerate(
            data.RandomTrajectories(count=args.TrajCount,
                                    force_length=args.ForceLength,
                                    sync_time=args.SyncTime,
                                    min_length=args.MinLength)):
        fn = args.baseoutname + '{:03d}.xls'.format(i)
        if args.verbose: print("writing file '{}'".format(fn))
        rt.to_excel(fn, index=False)
예제 #8
0
def main():
    parser = argparse.ArgumentParser()
    parser_io = parser.add_argument_group(
        description="==== I/O parameters ====")
    parser_io.add_argument("-i", "--infiles", default=[], nargs="*")
    parser_io.add_argument("-o",
                           "--OutFilePrefix",
                           default='corrmatrix',
                           type=str)
    parser_io.add_argument("-A", "--ACFFilePrefix", default=None, type=str)
    parser_io.add_argument("-v",
                           "--verbose",
                           default=False,
                           action="store_true")

    parser_alg = parser.add_argument_group(
        description="==== Algorithm parameters ====")
    parser_alg.add_argument("-k",
                            "--DiscretizeKey",
                            default='length',
                            type=str)
    parser_alg.add_argument("-m", "--MaxLag", default=10, type=int)
    parser_alg.add_argument("-S",
                            "--Symmetrize",
                            default=False,
                            action="store_true")
    parser_alg.add_argument("-N",
                            "--Normalize",
                            default=False,
                            action="store_true")
    args = parser.parse_args()

    data = ssc.SisterCellData(**vars(args))
    print(data)

    corrmatrix_sumAB = dict()
    corrmatrix_sumA = dict()
    corrmatrix_sumB = dict()
    corrmatrix_count = dict()

    if not args.ACFFilePrefix is None:
        acf_sumAA = dict()
        acf_sumA = dict()
        acf_countAA = dict()
        acf_countA = dict()

    for dataID in range(len(data)):
        if args.verbose:
            print('{:4d} \033[91m{:s}\033[0m'.format(dataID,
                                                     data.filenames[dataID]))

        cmAB, cmA, cmB, cmcount = data.lineagecorrelation(dataID,
                                                          maxlen=args.MaxLag)

        for key in cmAB.keys():
            if not key in corrmatrix_sumAB.keys():
                corrmatrix_sumAB[key] = cmAB[key]
                corrmatrix_sumA[key] = cmA[key]
                corrmatrix_sumB[key] = cmB[key]
                corrmatrix_count[key] = cmcount[key]
            else:
                corrmatrix_sumAB[key] += cmAB[key]
                corrmatrix_sumA[key] += cmA[key]
                corrmatrix_sumB[key] += cmB[key]
                corrmatrix_count[key] += cmcount[key]

        if not args.ACFFilePrefix is None:

            acfAA, acfcAA, acfA, acfcA = data.autocorrelation_restricted(
                dataID, maxlen=args.MaxLag)

            for key in acfAA.keys():
                if not key in acf_sumAA.keys():
                    acf_sumAA[corrkey] = np.zeros(args.MaxLag)
                    acf_countAA[corrkey] = np.zeros(args.MaxLag)
                    acf_sumA[corrkey] = 0
                    acf_countA[corrkey] = 0

                acf_sumAA[corrkey][:len(acfAA[corrkey])] += acfAA[corrkey]
                acf_countAA[corrkey][:len(acfAA[corrkey])] += acfcAA[corrkey]
                acf_sumA[corrkey] += acfA[corrkey]
                acf_countA[corrkey] += acfcA[corrkey]

    # compute correlation & output
    cm = dict()
    acf = dict()
    for corrkey in corrmatrix_sumAB.keys():
        cm[corrkey] = (corrmatrix_sumAB[corrkey] -
                       corrmatrix_sumA[corrkey] * corrmatrix_sumB[corrkey] /
                       corrmatrix_count[corrkey]) / corrmatrix_count[corrkey]

        fp = open(args.OutFilePrefix + '_' + corrkey, 'w')
        for i in range(np.shape(cm[corrkey])[0]):
            for j in range(np.shape(cm[corrkey])[1]):
                outvalue = cm[corrkey][i, j]
                if args.Symmetrize:
                    outvalue = 0.5 * (cm[corrkey][i, j] + cm[corrkey][j, i])
                if args.Normalize: outvalue /= cm[corrkey][0, 0]
                fp.write(
                    '{:3d} {:3d} {:14.6e}\n'.format(i + 1, j + 1, outvalue)
                )  # add 1, since first data point is first (!) generation of sisters
            fp.write('\n')
        fp.close()

        if not args.ACFFilePrefix is None:
            acf[corrkey] = acf_sumAA[corrkey] / acf_countAA[
                corrkey] - acf_sumA[corrkey] * acf_sumA[corrkey] / (
                    acf_countA[corrkey] * acf_countA[corrkey])
            if args.Normalize: acf[corrkey] = 1. / acf[corrkey][0]
            np.savetxt(
                args.ACFFilePrefix + '_' + corrkey,
                np.array([np.arange(len(acf[corrkey])), acf[corrkey]]).T)