Git Product home page Git Product logo

Comments (1)

cbravo93 avatar cbravo93 commented on August 29, 2024

Hi @debbie28!

This is a great question! I will divide it in two parts:

  • 'I have a cisTopic analysis in R, can I still use it for SCENIC+?'

    Yes, you can! There is no need to repeat the topic modelling in Python :).
    
    For this, you will need to do the following in R first:
    
    ```
    # Export data to python
    library(arrow)
    path <- OUTDIR
    cisTopic_obj <- readRDS(PATH_TO_YOUR_CISTOPICOBJECT)
    modelMat <- modelMatSelection(cisTopic_obj, 'cell', 'Probability')
    modelMat <- as.data.frame(modelMat)
    write_feather(modelMat, sink=paste0(path, 'model_to_pycisTopic/cell_topic.feather'))
    modelMat <- modelMatSelection(cisTopic_obj, 'region', 'Probability', all.regions=TRUE)
    modelMat <- as.data.frame(modelMat)
    write_feather(modelMat, sink=paste0(path, 'model_to_pycisTopic/topic_region.feather'))
    # You can also save the count.matrix
    ct <- [email protected]
    ct <- as.data.frame(ct)
    write_feather(ct, sink=paste0(path, 'model_to_pycisTopic/count_matrix.feather'))
    ```
    
    And then in Python:
    
    ```
    import pycisTopic
    ## 1. Initialize cisTopic object
    from pycisTopic.cistopic_class import *
    # Load count matrix
    matrix_path=PATH_TO_FRAGMENTS_MATRIX
    fragment_matrix = pd.read_feather(matrix_path)
    cisTopic_obj = create_cistopic_object(fragment_matrix)
    # Also add the cell annotation, cell_data should be a pandas df with cells as rows (cell names as index) and variables as columns
    cisTopic_obj.add_cell_data(cell_data)
    # 2. Add model
    from pycisTopic.utils import *
    model = load_cisTopic_model(PATH_TO_THE_FOLDER_WHERE_YOU_SAVED_DATA_FROM_R)
    cistopic_obj.add_LDA_model(model)
    # 3. Get imputed accessibility matrix
    from pycisTopic.diff_features import *
    imputed_acc_obj = impute_accessibility(cistopic_obj, selected_cells=None, selected_regions=None, scale_factor=10**6)
    # 4. DARs
    normalized_imputed_acc_obj = normalize_scores(imputed_acc_obj, scale_factor=10**4)
    variable_regions = find_highly_variable_features(normalized_imputed_acc_obj,
                                               min_disp = 0.05,
                                               min_mean = 0.0125, 
                                               max_mean = 3,
                                               max_disp = np.inf,
                                               n_bins=20, 
                                               n_top_features=None,
                                               plot=True)
    markers_dict= find_diff_features(cistopic_obj, 
                          imputed_acc_obj,
                          variable='cell_type', # Here put the column of cell_data that you want to have DARs for
                          var_features=variable_regions,
                          contrasts=None,
                          adjpval_thr=0.05,
                          log2fc_thr=np.log2(1.5),
                          n_cpu=5) 
    # You can continue with pycistarget.
    ```
    
    Feel free to change the function if you do not want to work in feather format.
    
    ```
    def load_cisTopic_model(path_to_cisTopic_model_matrices):
        metrics = None
        coherence = None
        marg_topic = None
        topic_ass = None
        cell_topic = pd.read_feather(path_to_cisTopic_model_matrices + "cell_topic.feather")
        cell_topic.index = ["Topic" + str(x) for x in range(1, cell_topic.shape[0] + 1)]
        topic_region = pd.read_feather(
            path_to_cisTopic_model_matrices + "topic_region.feather"
        )
        topic_region.index = ["Topic" + str(x) for x in range(1, topic_region.shape[0] + 1)]
        topic_region = topic_region.T
        parameters = None
        model = cisTopicLDAModel(
            metrics, coherence, marg_topic, topic_ass, cell_topic, topic_region, parameters
        )
        return model
    ```
    
  • 'I have an analysis with another tool (e.g. Signac/ArchR), can I still use it for SCENIC+?'

Here you have two options:

  1. Start from the count matrix: If you have performed QC steps and generated you fragment count matrix with another tool, you can directly start with the creation of the cisTopic object. In this tutorial you have an example on how to do this.
  2. You want to skip the topic modelling altogether: I would not recommend this option because we have not tested it, but technically it is possible. You would need to get 1) a denoised fragment matrix and 2) region sets. The region sets will be used as input for cisTarget. The region sets could be Differentially Accessible Regions (DARs); however we do recommend to use topics as well as they can capture regions with accessibility patterns without the need of specifying contrasts. If only using DARs you will have to make sure to make the right contrats (for example, all cell types versus the rest; higher cell type groups versus rest, etc). For example, in the cortex data set the topics reveal a topic of regions shared across all neurons; this pattern would be lost if you only do contrasts per cell type and not higher groups. In conclusion, it is possible to plug it in code-wise; but we can't assure results will be as good as the workflow we propose.

I will add these responses in a FAQs tab in the readthedocs page as I find them very relevant, thanks for the heads up!

C

from scenicplus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.