Skip to content

Adding a new projection method

David DeTomaso edited this page Mar 1, 2016 · 3 revisions

To add a new projection method, edit the Projections.py source file.

Step 1

Towards the bottom of the file, after the "# Add New Method Here" header, define a new method that applies the desired projection.

The function header must have the format:

def mynewmethodname(proj_data, proj_weights):

Input proj_data is a Num_Genes X Num_Samples numpy.ndarray Input proj_weights is a Num_Genes X Num_Samples numpy.ndarray

Your function should operate on the data and weights matrices to return an output that is a numpy.ndarray with shape (Num_Samples, 2)

Example: Adding the ZIFA1 projection method

from ZIFA import block_ZIFA, ZIFA
def apply_ZIFA(proj_data, proj_weights=None):
    Z, model_params = ZIFA.fitModel(proj_data.T, 2);
    return Z;
_proj_methods['ZIFA'] = apply_ZIFA;

Step 2

Register your new method so FastProject knows to call it when it next runs.

At the bottom of the file, add the method to the _proj_methods dictionary

_proj_methods['MyMethodName'] = mynewmethodname;

Additionally, you may want to add the method to the _proj_methods_pca dictionary. These methods are also run on data which has been pre-processed by PCA. This may or may not make sense for the dimensionality reduction method you are adding.

References

  1. Pierson, E., Yau, C.: ZIFA: Dimensionality reduction for zero-inflated single-cell gene expression analysis. Genome Biology 16(1), 241 (2015). doi:10.1186/s13059-015-0805-z