Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in running RDR module #5

Closed
faridrashidi opened this issue Apr 24, 2023 · 10 comments
Closed

error in running RDR module #5

faridrashidi opened this issue Apr 24, 2023 · 10 comments
Labels
good first issue Good for newcomers

Comments

@faridrashidi
Copy link

Hi,

I'm trying to run XClone RDR module following scripts at here on a dataset but I get the following error:

File xclone_rdr_wrap.py:232, in run_RDR(RDR_adata, verbose, run_verbose, config_file)
    230 if trans_prob is None:
    231     trans_prob = np.array([[1-2*t, t, t],[t, 1-2*t, t],[t, t, 1-2*t]])
--> 232 RDR_adata = xclone.model.CNV_optimazation(RDR_adata, depth_key = depth_key, init_state_ratio = guide_cnv_ratio,
    233                 max_iter = max_iter,
    234                 min_iter = min_iter,
    235                 HMM_brk = HMM_brk,
    236                 start_prob = start_prob,
...
    443     if verbose:
    444         print(idx_kept)
--> 446 return res, res_log

UnboundLocalError: local variable 'res' referenced before assignment

Could you please help me what I should do to resolve this issue?

@Rongtingting
Copy link
Collaborator

Hi,
Thank you for using XClone. Maybe you can have a look at the tutorial TNBC1 dataset (10x) (details of params are shown in the tutorial).

And could you please show me the log of xconfig.display()?

@faridrashidi
Copy link
Author

faridrashidi commented Apr 24, 2023

Thank you for your help. I get the same error when running the TNBC1 example.
Here's the log of xconfig for the TNBC1 example:

RDR 
Configurations:
HMM_brk                        chr_arm
KNN_neighbors                  10
WMA_smooth_key                 chr_arm
WMA_window_size                40
_file_format_data              h5ad
_file_format_figs              pdf
_frameon                       True
_outdir                        .
_plot_suffix                   
_start                         1682306587.118832
_vector_friendly               True
cell_anno_key                  cluster.pred
dataset_name                   TNBC1_scRNA
dispersion_celltype            None
exclude_XY                     False
file_format_data               h5ad
file_format_figs               pdf
filter_ref_ave                 0.5
fit_GLM_libratio               False
gene_exp_group                 1
gene_exp_ref_log               True
guide_chr_anno_key             chr_arm
guide_cnv_ratio                None
guide_qt_lst                   [0.0001, 0.96, 0.99]
marker_group_anno_key          cluster.pred
max_iter                       2
min_iter                       1
module                         RDR
outdir                         .
plot_cell_anno_key             cluster
plot_suffix                    
rdr_plot_vmax                  0.7
rdr_plot_vmin                  -0.7
ref_celltype                   N
remove_guide_XY                False
remove_marker                  True
select_normal_chr_num          4
set_figtitle                   True
set_smartseq                   False
smart_transform                False
start_prob                     [0.1 0.8 0.1]
top_n_marker                   15
trans_prob                     [[9.99998e-01 1.00000e-06 1.00000e-06]
 [1.00000e-06 9.99998e-01 1.00000e-06]
 [1.00000e-06 1.00000e-06 9.99998e-01]]
trans_t                        1e-06
warninig_ignore                True
xclone_plot                    True

P.S. I use python v3.9.2 and XClone v0.3.4

@Rongtingting
Copy link
Collaborator

Hi, Could you have a try on python 3.7 and XClone v0.3.4?

@faridrashidi
Copy link
Author

faridrashidi commented Apr 24, 2023

Thank you, Rongting, for your assistance in resolving the issue. It seems XClone only works with Python 3.7. I tried running it with Python 3.8.10 and 3.9.2, but encountered the same issue. I appreciate your help in pointing me in the right direction.

I have two more questions before closing this issue:

  1. Can XClone detect tumor and normal cells without any prior information itself?
  2. It seem filter_ref_ave parameter is an important factor in determining the CNV which is set to 0.5 as default. Is there any way to adjust this variable accordingly to the data e.g. based on library size?

@Rongtingting
Copy link
Collaborator

Hi @faridrashidi, thank you for your feedback! XClone is stable in Python 3.7 (3.8 and 3.9 may cause some issues in xclone's requirement packages, we will test later).

  1. Actually, our BAF module can provide smoothened B allele frequency and also CNV states' probability, which can be used to do cell clustering and the cells with balanced BAF (around 0.5) are more likely to be normal cells. We have tested this strategy in our GX109-T1c sample and in the TNBC1 sample, it can accurately detect the normal cells. However, this function is not provided in v0.3.4 yet. (If you are interested in this part, can send you an example later.)
  2. Yes, the filter_ref_ave parameter is an important factor, but here it is just a parameter that helps to do gene filtering at the first step. if the average gene value in reference cells is too low, then the gene will be discarded. In 10x seq data, we set it to 0.5 as default to keep 3000~6000 genes for analysis.

@faridrashidi
Copy link
Author

Thank you very much!

@Rongtingting
Copy link
Collaborator

Hi, @faridrashidi, could you help to provide the scanpy version in your Python 3.8.10 and 3.9.2 env?

@faridrashidi
Copy link
Author

For 3.8.10 is v1.9.2
For 3.9.2 is v1.9.1

@faridrashidi
Copy link
Author

Hi, @Rongtingting, could you please send me the example for finding normal and tumor cells by XClone that you mentioned here?

@Rongtingting
Copy link
Collaborator

Hi @faridrashidi,

I am sorry for the late reply.
I have added functions for finding normal and tumor cells in XClone BAF module (latest version via github installation).
And XClone works well in Python 3.9 environment now.

Example

import xclone
import scanpy as sc

data_dir = "xxxxxx/BCH869_scRNA_trials/"
baf_final_file = data_dir + "data/BAF_merge_Xdata_KNN_HMM_post.h5ad"

adata = sc.read(baf_final_file)

## explore the clusters numbers by UMAP visualization
xclone.al.exploreClustering(adata, ref_anno_key = "spot_anno", Xlayer = "posterior_mtx", max_clusters = 5)


## explore the BAF clustering by specify 2 clusters
adata_anno = xclone.al.OnestopBAFClustering(adata, Xlayer = "posterior_mtx", 
                         n_clusters = 2, ref_anno_key = "spot_anno", clone_anno_key = "clone(2)", 
                         plot_title = "xxxx (XClone)",
                         file_save_path = "xxxx/analysis/", file_save_name =  "xxx_2clones", complex_plot = True)

## Similarly, explore the BAF clustering by specify 3 clusters
adata_anno = xclone.al.OnestopBAFClustering(adata, Xlayer = "posterior_mtx", 
                         n_clusters = 3, ref_anno_key = "spot_anno", clone_anno_key = "clone(3)", 
                         plot_title = "xxxx (XClone)",
                         file_save_path = "xxxx/analysis/", file_save_name =  "xxx_3clones", complex_plot = True)

Bests,
Rongting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants