theislab / single-cell-tutorial

Single cell current best practices tutorial case study for the paper:Luecken and Theis, "Current best practices in single-cell RNA-seq analysis: a tutorial"
1.38k stars 455 forks source link

computeSumFactors(data_mat, clusters=input_groups, min.mean=0.1) gives error #40

Closed ariberar closed 4 years ago

ariberar commented 4 years ago

I can run everything without problem until these lines:

%%R -i data_mat -i input_groups -o size_factors
size_factors = computeSumFactors(data_mat, clusters=input_groups, min.mean=0.1)

where I get this error:

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘assay’ for signature ‘"matrix", "character"’

Any idea whats going on here?

Im using the original code except for these lines that I commented: #adata.var['gene_id'] = adata.var['gene_id-1'] #adata.var.drop(columns = ['gene_id-1', 'gene_id-0'], inplace=True)

LuckyMD commented 4 years ago

Hi,

So it seems that within the object you have moved to R cannot be used with the assay() method. Do the versions of scran, SingleCellExperiment and R match with the tutorial?

ariberar commented 4 years ago

Hi, thanks for the answer :D!

These are my versions but I cant find wich versions of scran and SingleCellExperiment that are required for the tutorial:

R -> 4.0.0 scran -> 1.16.0 SingleCellExperiment -> 1.10.1

LuckyMD commented 4 years ago

So this has not been tested for the newest version of R at all. You can find the versions for the tutorial in the README that is in the same folder as the notebook.

ariberar commented 4 years ago

Hi again, thanks for the answers! Im a new linux and R user so Im trying to replicate your tutorial like it says in the README

Could you tell me which version of conda were you using for this tutorial? I used sc_tutorial_environment.yml to create my environment and I get R 4.0.0 (maybe if I install a previous version of conda I could get R 3.5) [conda version : 4.8.3; conda-build version : 3.18.11]

Im trying to downgrade R with this command while in the environment created for this tutorial: conda install r==3.5 and after 1 or few hours of "examining conflicts with..." I get a lot of messages for packages that are in conflict with R>=3.5

I also tried to create a new environment with r==3.5 and then install the R packages but Im getting "installation of package ‘nameOfPackage’ had non-zero exit status" when trying to install the packages used in latest_notebook

LuckyMD commented 4 years ago

Hi @ariberar, I guess we did not control the version of R in the environment.yaml. I think the exit status messages may have to do with other packages that you need to manually install. I have had issues like this quite commonly, where R doesn't control the dependencies well if you install via conda. The combination of conda and R is never pretty.

What should make things easier though, is a docker that @le-ander created. Could you link to your docker hub url here, @le-ander?

le-ander commented 4 years ago

Here you go! https://hub.docker.com/r/leanderd/single-cell-analysis

ariberar commented 4 years ago

Thank you so much for this tutorial and the answers!! I will try to use docker, I did not know of its existence

I have uninstalled anaconda and installed R 3.6.3 from r-project, rstudio, spyder, jupyter notebooks.

scran==1.14.6; SingleCellExperiment==1.8.0

I was able to install all the packages required by the tutorial (the latest versions) without problems and run the first sections of the code.

scanpy==1.5.0 anndata==0.7.3 umap==0.4.3 numpy==1.18.4 scipy==1.4.1 pandas==1.0.3 scikit-learn==0.23.1 statsmodels==0.11.1 python-igraph==0.8.2 louvain==0.7.0 leidenalg==0.8.0

To concatenate the anndata objects I had to add adata.var_names_make_unique() at the end of the first dataset load because there were genes with equal symbols for example:

mm10_Rp1 mm10_Rp1
mm10_ENSMUSG00000025900 mm10_ENSMUSG00000109048

With this new setup I was able to run computeSumFactors() but I got the following error "'ncol(x)' is not equal to 'length(clusters)'" so I changed data_mat = adata.X.T on the cell above because I think this function in R expects the count matrix to be genesXcells instead cellsXgenes like you said in the introduction. Then it worked.

LuckyMD commented 4 years ago

Hi @ariberar,

I'm glad things are working out for you! data_mat = adata.X.T should already be in the tutorial script already I believe.

ariberar commented 4 years ago

You are absolutely right. That line of code is on the tutorial script. I must have changed it before when I was trying to find out a fix to the function error in R. What do you think about adding adata.var_names_make_unique() at the end of the first data set load?

LuckyMD commented 4 years ago

In the example data in the notebook it's not needed i think... (and wasn't it automatically called anyway?). But yes, if needed it should be called ;).

Muedi commented 4 years ago

I just wanted to add, that the problem can be solved with removing the conda environment and reinstalling it with r-base+3.5 added to the yaml file.

jvivian-atreca commented 3 years ago

@le-ander — the container pushed 4 days ago (docker pull leanderd/single-cell-analysis:210114) runs into this issue as well since the version of R in the container is 4.0.3.

le-ander commented 3 years ago

@le-ander — the container pushed 4 days ago (docker pull leanderd/single-cell-analysis:210114) runs into this issue as well since the version of R in the container is 4.0.3.

yep, this is already fixed in a new version of the notebook. we are currently working on finalising it for publication here.

oligomyeggo commented 3 years ago

Hello! I'm running into the same computeSumFactors issue as described here after recently updating to R 4.0.3. I am wondering if the fix that @le-ander mentioned in the new version of the notebook is available?

LuckyMD commented 3 years ago

Hey! Please check #60 for a fix. Still working to get the latest version up to date I'm afraid.

oligomyeggo commented 3 years ago

Ah, perfect! That worked. Thanks so much, and sorry I missed seeing issue #60.