Пример #1
0
def plot_down_sampling(rna_file,
                       adt_file,
                       out_file,
                       probs=[i / 10.0 for i in range(9, 0, -1)],
                       n_threads=1,
                       dpi=500,
                       figsize=None):
    data_gt = read_input(rna_file, mode='a')
    adt_gt = read_input(adt_file, mode='a')
    fracs, accuracy = down_sampling(data_gt,
                                    adt_gt,
                                    probs,
                                    n_threads=n_threads)
    plt.plot(fracs, accuracy, '.-')
    ax = plt.gca()
    ax.set_xlim(1.0, 0.0)
    ax.set_ylim(0.79, 1.01)
    vals = ax.get_yticks()
    ax.set_yticklabels(['{:.0%}'.format(v) for v in vals])
    ax.set_xlabel("Fraction of hashtag UMIs")
    ax.set_ylabel("Consistency")
    if figsize is not None:
        plt.gcf().set_size_inches(*figsize)
    plt.savefig(out_file, dpi=dpi)
    plt.close()
Пример #2
0
def make_interactive_plots(input_file, plot_type, output_file, **kwargs):
    adata = read_input(input_file, mode='r')
    basis = transform_basis(plot_type)
    if plot_type == 'diffmap' or plot_type == 'diffmap_pca':
        df = pd.DataFrame(adata.obsm['X_{}'.format(plot_type)][:, 0:3],
                          index=adata.obs.index,
                          columns=[basis + i for i in ['1', '2', '3']])
        if kwargs['isgene']:
            coln = adata.var.index.get_loc(kwargs['attr'])
            df.insert(0, 'Annotation', adata.X[:, coln].toarray().ravel())
        else:
            df.insert(0, 'Annotation', adata.obs[kwargs['attr']])
        if not kwargs['isreal']:
            iplot_library.scatter3d(df, output_file)
        else:
            iplot_library.scatter3d_real(df, output_file, kwargs['log10'])
    else:
        df = pd.DataFrame(adata.obsm['X_{}'.format(plot_type)],
                          index=adata.obs.index,
                          columns=[basis + i for i in ['1', '2']])
        if kwargs['isgene']:
            coln = adata.var.index.get_loc(kwargs['attr'])
            df.insert(0, 'Annotation', adata.X[:, coln].toarray().ravel())
        else:
            df.insert(0, 'Annotation', adata.obs[kwargs['attr']])
        if not kwargs['isreal']:
            iplot_library.scatter(df, output_file)
        else:
            iplot_library.scatter_real(df, output_file, kwargs['log10'])
    print(output_file + " is generated.")
    adata.file.close()
Пример #3
0
def run_annotate_cluster(input_file,
                         output_file,
                         threshold,
                         ignoreNA=False,
                         json_file="human"):
    start = time.time()
    if json_file == "human_immune":
        json_file = pkg_resources.resource_filename(
            'scCloud.annotate_cluster', 'human_immune_cell_markers.json')
    elif json_file == "mouse_immune":
        json_file = pkg_resources.resource_filename(
            'scCloud.annotate_cluster', 'mouse_immune_cell_markers.json')
    elif json_file == "mouse_brain":
        json_file = pkg_resources.resource_filename(
            'scCloud.annotate_cluster', 'mouse_brain_cell_markers.json')
    elif json_file == "human_brain":
        json_file = pkg_resources.resource_filename(
            'scCloud.annotate_cluster', 'human_brain_cell_markers.json')
    data = read_input(input_file, mode='r')
    with open(output_file, 'w') as fout:
        annotate_cluster.annotate_clusters(data, json_file, threshold, fout,
                                           ignoreNA)
    data.file.close()
    end = time.time()
    print("Time spent for annotating clusters is {:.2f}s.".format(end - start))
Пример #4
0
def annotate_anndata_object(input_file, annotation):
    data = read_input(input_file, mode='r+')
    anno_attr, anno_str = annotation.split(':')
    anno = anno_str.split(';')
    data.obs[anno_attr] = [
        anno[int(x) - 1] for x in data.obs[data.uns['de_labels']]
    ]
    data.write(input_file)
Пример #5
0
def show_attributes(input_file, show_attributes, show_gene_attributes, show_values_for_attributes):
	data = read_input(input_file, mode = 'r')
	if show_attributes:
		print("Available sample attributes in input dataset: {0}".format(', '.join(data.obs.columns.values)))
	if show_gene_attributes:
		print("Available gene attributes in input dataset: {0}".format(', '.join(data.var.columns.values)))
	if not show_values_for_attributes is None:
		for attr in show_values_for_attributes.split(','):
			print("Available values for attribute {0}: {1}.".format(attr, ', '.join(np.unique(data.obs[attr]))))
Пример #6
0
def make_static_plots(input_file, plot_type, output_file, dpi=500, **kwargs):
    adata = read_input(input_file, mode='r')
    assert plot_type in pop_list
    pop_set = pop_list[plot_type].copy()
    for key, value in kwargs.items():
        if value is None:
            pop_set.add(key)
    for key in pop_set:
        kwargs.pop(key)
    fig = getattr(plot_library, 'plot_' + plot_type)(adata, **kwargs)
    fig.savefig(output_file, dpi=dpi)
    print(output_file + " is generated.")
    adata.file.close()