Exemplo n.º 1
0
#     if args.reference in adata.obs:
#         cluster_report(adata.obs[args.reference].cat.codes, adata.obs[args.cluster_method].astype(int))

    sc.settings.figdir = outdir
    sc.set_figure_params(dpi=80, figsize=(6, 6), fontsize=10)
    if args.embed == 'UMAP':
        sc.tl.umap(adata, min_dist=0.1)
        color = [
            c for c in ['celltype', args.cluster_method] if c in adata.obs
        ]
        sc.pl.umap(adata, color=color, save='.pdf', wspace=0.4, ncols=4)
    elif args.embed == 'tSNE':
        sc.tl.tsne(adata, use_rep='latent')
        color = [
            c for c in ['celltype', args.cluster_method] if c in adata.obs
        ]
        sc.pl.tsne(adata, color=color, save='.pdf', wspace=0.4, ncols=4)

    if args.impute:
        adata.obsm['impute'] = model.encodeBatch(testloader,
                                                 device=device,
                                                 out='x')
    if args.binary:
        adata.obsm['impute'] = model.encodeBatch(testloader,
                                                 device=device,
                                                 out='x')
        adata.obsm['binary'] = binarization(adata.obsm['impute'], adata.X)

    adata.write(outdir + 'adata.h5ad', compression='gzip')
Exemplo n.º 2
0
    pred = model.predict(testloader, device)
    pd.Series(pred, index=dataset.barcode).to_csv(os.path.join(
        outdir, 'cluster_assignments.txt'),
                                                  sep='\t',
                                                  header=False)

    # 3. imputed data
    if args.impute or args.binary:
        recon_x = model.encodeBatch(testloader,
                                    device,
                                    out='x',
                                    transforms=[normalizer.inverse_transform])
        if args.binary:
            import scipy
            print("Saving binary imputed data")
            recon_x = binarization(recon_x, dataset.data).T
            imputed_dir = outdir + '/binary_imputed/'
            os.makedirs(imputed_dir, exist_ok=True)
            scipy.io.mmwrite(imputed_dir + 'count.mtx', recon_x)
            pd.Series(dataset.peaks).to_csv(imputed_dir + 'peak.txt',
                                            sep='\t',
                                            index=False,
                                            header=None)
            pd.Series(dataset.barcode).to_csv(imputed_dir + 'barcode.txt',
                                              sep='\t',
                                              index=False,
                                              header=None)
        elif args.impute:
            print("Saving imputed data")
            recon_x = pd.DataFrame(recon_x.T,
                                   index=dataset.peaks,