Package: genevector
InstallationInstall using pippip install genevectoror install from Githubpython3 -m venv gvenv
source gvenv/bin/activate
python3 pip install -r requirements.txt
python3 setup.py installTutorials (see "example" directory)PBMC workflow: Identification of interferon stimulated metagene and cell type annotation.TICA workflow: Cell type assignment.SPECTRUM workflow: Vector arithmetic for site specific metagenes.FITNESS workflow: Identifying increasing metagenes in time series.GeneVector WorkflowLoading scanpy dataset into GeneVector.GeneVector makes use of Scanpy anndata objects and requires that the raw count data be loaded into .X matrix. It is highly recommended to subset genes using theseurat_v3flavor in Scanpy. Thedevice="cuda"flag should be omitted if there is no GPU available. All downstream analysis requires a GeneVectorDataset object.from genevector.data import GeneVectorDataset
from genevector.model import GeneVectorTrainer
from genevector.embedding import GeneEmbedding, CellEmbedding

import scanpy as sc

dataset = GeneVectorDataset(adata, device="cuda")Training GeneVectorAfter loading the expression, creating a GeneVector object will compute the mutual information between genes (can take up to 15 min for a dataset of 250k cells). This object is only required if you wish to train a model. Model training times vary depending on datasize. The 10k PBMC dataset can be trained in less than five minutes.emb_dimensionsets the size of the learned gene vectors. Smaller values decrease training time, but values smaller than 50 may not provide optimal results.cmps = GeneVector(dataset,
                  output_file="genes.vec",
                  emb_dimension=100,
                  threshold=1e-6,
                  device="cuda")
cmps.train(1000, threshold=1e-6) # run for 1000 iterations or loss delta below 1e-6.To understand model convergence, a loss plot by epoch can be generated.cmps.plot()Loading Gene EmbeddingAfter training, two vector files are produced (for input and output weights). It is recommended to take the average of both weightsvector="average"). The GeneEmbedding class has several important analysis and visualization methods listed below.gembed = GeneEmbedding("genes.vec", dataset, vector="average")1. Computing gene similaritiesA pandas dataframe can be generated usingcompute_similaritiesthat includes the most similar genes and their cosine similarities for a given gene query. A barplot figure with a specified number of the most similar genes can be generated usingplots_similarities.df = gembed.compute_similarities("CD8A")
gembed.plot_similarities("CD8A",n_genes=10)2. Generating Metagenesget_adataproduces and AnnData object that houses the gene embedding. This allows the use of Scanpy and AnnData visualization functions. The resolution parameter is passed directly tosc.tl.leidento cluster the co-expression graph.get_metagenesreturns a dictionary that stores each metagene as a list associated with an id. For a given id, the metagene can be visualized on a UMAP embedding using theplot_metagenefunction.gdata = embed.get_adata(resolution=40)
metagenes = embed.get_metagenes(gdata)
embed.plot_metagene(gdata, mg=isg_metagene)Loading the Cell EmbeddingUsing the GeneEmbedding object and the GeneVectorDataset object, a CellEmbedding object can be instantiated and used to produce a Scanpy AnnData object withget_adata. This method stores cell embedding underX_genevectorin layers and generates a UMAP embedding using Scanpy. Scanpy functionality can be used to visualize UMAPS (sc.pl.umap).cembed = CellEmbedding(dataset, embed)
adata = cembed.get_adata()The cell embedding can be batch corrected usingcembed.batch_correct. The user is required to select a valid column present in theobsdataframe and specify a reference label. This is a very fast operation.cembed.batch_correct(column="sample",reference="control")
adata = cembed.get_adata()Scoring Cells by MetageneTo score expression for each metagene against all cells, we can call the GeneEmbedding functionscore_metageneswith the cell-based AnnData object. To plot a heatmap of all metagenes over a set of cell labels, use theplot_metagenes_scoresfunction. Metagenes are scored with the Scanpysc.tl.score_genesfunction.embed.score_metagenes(adata, metagenes)
embed.plot_metagenes_scores(adata,mgs,"cell_type")Performing Cell Type AssignmentUsing a dictionary of cell type annotations to marker genes, each cell can be classified using the CellEmbedding functionphenotype_probability. This function returns a new annotated AnnData object, where the resulting classification can be found in.obs["genevector"](the user can also supply a column name usingcolumn=). A separate column in the obs dataframe is created to hold the pseudo-probabilities for each cell type. These probabilties can be shown on a UMAP using standard the Scanpy functionsc.pl.umap.markers = dict()
markers["T Cell"] = ["CD3D","CD3G","CD3E","TRAC","IL32","CD2"]
markers["B/Plasma"] = ["CD79A","CD79B","MZB1","CD19","BANK1"]
markers["Myeloid"] = ["LYZ","CST3","AIF1","CD68","C1QA","C1QB","C1QC"]

annotated_adata = cembed.phenotype_probability(adata,markers)

prob_cols = [x for x in annotated_adata.obs.columns.tolist() if "Pseudo-probability" in x]
sc.pl.umap(annotated_adata,color=prob_cols+["genevector"],size=25)All additional analyses described in the manuscript, including comparisons to LDVAE and CellAssign, can be found in Jupyter notebooks in the examples directory. Results were computed for v0.0.1.