Ejemplo n.º 1
0
def reset_scvelo(gallery_conf, fname):
    import scvelo as scv

    scv.set_figure_params(style="scvelo",
                          color_map="viridis",
                          format="png",
                          ipython_format="png")
Ejemplo n.º 2
0
def configure_scvelo(args):
    scvelo.set_figure_params(style="scvelo",
                             dpi_save=args.dpi,
                             transparent=False)
    scvelo.settings.verbosity = 3
    scvelo.settings.plot_prefix = args.output
    scvelo.settings.figdir = ""
    scvelo.settings.autoshow = False
Ejemplo n.º 3
0
from tensorflow import keras
from tensorflow.keras import layers
from keras.layers import Input, Dense
from keras.models import Model
from keras.callbacks import EarlyStopping
from keras import regularizers

# As suggested in the tutorial by scanpy doc: Preprocessing and clustering 3k PBMCs
sc.settings.verbosity = 3
sc.logging.print_versions()
# To use scvelo's setting below
# sc.set_figure_params(dpi = 80, facecolor = 'white')

# The following settings are based on https://scvelo.readthedocs.io/VelocityBasics.html
scv.settings.presenter_view = True
scv.set_figure_params('scvelo')

# Want to make sure results can be reproducted
random_state = 17051256
# Used to mark some preprocess steps
regressout_uns_key_name = 'regressout_keys'
imputation_uns_key_name = 'imputation'
# 250 is a good number for pathway and network analysis. So far hard-code it.
n_rank_genes = 250

# Global level flags to control the use of the serve
# server = SimpleJSONRPCServer("localhost")
# isWaiting = True

# This dict is used for cache loaded AnnaData
cache = dict()
Ejemplo n.º 4
0
#import library
import scvelo as scv

#set parameters
scv.set_figure_params()
scv.settings.verbosity = 3  # show errors(0), warnings(1), info(2), hints(3)
scv.settings.presenter_view = True  # set max width size for presenter view
scv.settings.set_figure_params('scvelo')  # for beautified visualization

#load data
adata_merged = scv.read("/rsrch3/scratch/sarc_med_onco-rsch/dtruong4/LPS_scRNA/LPS_data_cell_velocyto.h5ad")

print('Running recover_dynamics')
scv.tl.recover_dynamics(adata_merged, n_jobs = 20)

print('Running velocity')
scv.tl.velocity(adata_merged, mode='dynamical')

print('Running velocity_graph')
scv.tl.velocity_graph(adata_merged, n_jobs = 20)

print('Writing data')
adata_merged.write("/rsrch3/scratch/sarc_med_onco-rsch/dtruong4/LPS_scRNA/LPS_data_cell_velocyto_calc_dynamic.h5ad")

print('Job done')
Ejemplo n.º 5
0
import numpy as np
import pandas as pd
import scanpy as sc
import scvelo as scv
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
from scipy import sparse

scv.set_figure_params(color_map='RdBu_r', frameon=True)
sc.settings.verbosity = 3
plt.rcParams["axes.grid"] = False

#load the data
DC_spliced = sparse.load_npz('./Data/DC_spliced.npz')
DC_unspliced = sparse.load_npz('./Data/DC_unspliced.npz')
DC_normed = pd.read_csv('./Data/DC_normed.txt', sep='\t', index_col=0)
DC_meta = pd.read_csv('./Data/DC_meta.txt', sep='\t', index_col=0)

sc_DC = sc.AnnData(DC_normed)
sc_DC.obs = DC_meta
sc_DC.layers['spliced'] = DC_spliced
sc_DC.layers['unspliced'] = DC_unspliced
scv.pp.filter_and_normalize(sc_DC,
                            min_cells=3,
                            min_cells_u=3,
                            min_shared_cells=3,
                            n_top_genes=None,
                            flavor='seurat',
                            log=True,
                            copy=False)
Ejemplo n.º 6
0
def scvelo(data: Union[VelocytoData, str],
           cell_labels: Union[pd.Series, str] = None,
           num_components: int = 50,
           num_neighbors: int = 30,
           cluster_order=None,
           cluster_colors=None,
           cluster_labels=None,
           umap_scores: pd.DataFrame = None,
           umap_num_neighbors: int = 30,
           axis_labels=None,
           umap_seed: int = 0,
           title: str = None) -> None:
    """Modified scVelo workflow."""

    import scvelo as scv

    scv.settings.verbosity = 3  # show errors(0), warnings(1), info(2), hints(3)
    scv.settings.presenter_view = True  # set max width size for presenter view
    scv.set_figure_params('scvelo')  # for beautified visualization

    if isinstance(data, str):
        data = VelocytoData.load_npz(data)

    if isinstance(cell_labels, str):
        cell_labels = util.load_cell_labels(cell_labels)

    adata = data.to_anndata(cell_labels=cell_labels,
                            cluster_labels=cluster_labels,
                            cluster_order=cluster_order,
                            cluster_colors=cluster_colors,
                            umap_scores=umap_scores)

    try:
        clusters = adata.obs['clusters']
    except KeyError:
        clusters = None

    if 'X_umap' not in adata.obsm:
        # perform UMAP
        exp_matrix = ExpMatrix(adata.X.T,
                               genes=adata.var_names,
                               cells=adata.obs_names)
        _, umap_scores = umap_plot(exp_matrix,
                                   num_components,
                                   umap_num_neighbors,
                                   seed=umap_seed)
        adata.obsm['X_umap'] = umap_scores.values

    else:
        # use UMAP result stored in AnnData object
        if axis_labels is not None:
            columns = axis_labels
        else:
            columns = ['UMAP dim. 1', 'UMAP dim. 2']
        umap_scores = pd.DataFrame(adata.obsm['X_umap'],
                                   index=adata.obs_names,
                                   columns=columns)

    if clusters is not None:
        # plot UMAP with cell type labels
        cluster_order = clusters.cat.categories
        cluster_colors = adata.uns['plotly_cluster_colors']
        fig = plot_cells(umap_scores,
                         cell_labels=clusters,
                         cluster_order=cluster_order,
                         cluster_colors=cluster_colors,
                         labelsize=16,
                         showlabels=False,
                         title=title)
        color = None

    else:
        # plot UMAP without cell type labels
        fig = plot_cells(umap_scores, title=title)
        color = 'navy'

    fig.show()

    scv.pp.filter_genes(adata, min_shared_counts=20)
    scv.pp.normalize_per_cell(adata)
    anndata_ft_transform(adata)

    scv.pp.moments(adata, n_pcs=num_components, n_neighbors=num_neighbors)
    scv.tl.velocity(adata)
    scv.tl.velocity_graph(adata)

    # with raw=True (default), pl.proporitons uses raw counts
    # in adata.obs['initial_size_spliced'] and adata.obs['initial_size_unspliced']
    # that were stored there by the pp.filter_genes() function
    scv.pl.proportions(adata, figsize=(8, 4))

    scv.pl.velocity_embedding_grid(adata,
                                   basis='umap',
                                   dpi=200,
                                   size=10,
                                   arrow_size=5,
                                   arrow_length=1.0,
                                   arrow_color='black',
                                   fontsize=6,
                                   linewidth=0.1,
                                   legend_fontsize=6,
                                   figsize=[4.5, 4.5],
                                   legend_loc='right margin',
                                   title=title)

    scv.pl.velocity_embedding_stream(adata,
                                     basis='umap',
                                     dpi=200,
                                     size=10,
                                     fontsize=6,
                                     linewidth=1.0,
                                     legend_fontsize=6,
                                     figsize=[4.5, 4.5],
                                     color=color,
                                     title=title)

    return adata
Ejemplo n.º 7
0
import anndata
import scvelo as scv
import pandas as pd
import numpy as np
import matplotlib as plt
scv.logging.print_version()
scv.settings.verbosity = 3  # show errors(0), warnings(1), info(2), hints(3)
scv.settings.presenter_view = True  # set max width size for presenter view
scv.set_figure_params('scvelo')  # for beautified visualization

sample_one = anndata.read_loom("subset_final_possorted_bam_HF5H3.loom")
sample_obs = pd.read_csv("cellID_obs.csv")
umap_cord = pd.read_csv("cell_embeddings.csv")
cell_clusters = pd.read_csv("clusters.csv")
#umap = pd.read_csv("umap.csv")

my_list = []

for i in range(0, 1289):
    my_list.append(sample_one.obs.index.str.split(':')[i][1] + "-1")

sample_one.obs.index = my_list

sample_one.obs.index
#Let's cast our index as a data frame and change the column name

sample_one_index = pd.DataFrame(sample_one.obs.index)
sample_one_index = sample_one_index.rename(columns={0: 'Cell ID'})

umap = umap_cord.rename(columns={'Unnamed: 0': 'Cell ID'})