Answers.Body: <p>I was able to get to the normalized values using <code>logcounts</code> function in the following way:</p>
  
  <pre><code>mtx_norm_r = sceLib.logcounts(sce)
  mtx_norm = np.array(mtx_norm_r)
  </code></pre>
  
  <p>Since I used <code>log_exprs_offset=1</code> the field that I needed to use is <code>logcounts</code>, otherwise it should be <code>normcounts</code> which I found <a href="https://rdrr.io/bioc/scater/man/normalize.html" rel="nofollow noreferrer">here</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-13T07:31:50.953Z
Answers.Text: Maybe you know it but you can read the help page for each function using `?name_of_function` on the terminal (There is no need to consult an online help page that might not match your version of the package).
Answers.UserDisplayName: llrs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-13T19:12:57.167Z
Answers.Text: But I can not check it in `spyder`
Answers.UserDisplayName: Nikita Vlasenko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-13T19:48:01.723Z
Answers.Text: I don't know what is spyder but if it can run R is run you can.
Answers.UserDisplayName: llrs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-13T22:44:13.293Z
Answers.Text: It can not be done, or I do not know how anyway. It is `rpy2` python library that translates objects between `R` and `python` and the documentation is often not clear and detailed enough, in my view, probably because not that many people use it. Spyder is just IDE for `python` from `anaconda`
Answers.UserDisplayName: Nikita Vlasenko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-12T21:52:31.273Z
Answers.LastActivityDate: 2018-09-13T07:30:19.950Z
Answers.LastEditDate: 2018-09-13T07:30:19.950Z
Answers.UserDisplayName: Nikita Vlasenko
Body: <p>I am using <code>rpy2</code> to run normalization using <code>scran</code> package. After calling <code>computeSumFactors</code> I want to do the actual normalization calling <code>normalize()</code> function from <code>scater</code> package:</p>
  
  <pre><code>def normalize(counts):
  utils = importr('utils')
  utils.chooseCRANmirror(ind=1) 
  
  packnames = ('Matrix', 'limSolve')
  names_to_install = [x for x in packnames if not isinstalled(x)]
  if len(names_to_install) &gt; 0:
      utils.install_packages(StrVector(names_to_install))
  
  base = importr('base')
  base.source('http://www.bioconductor.org/biocLite.R')
  biocInstaller = importr('BiocInstaller')
  
  biocInstaller.biocLite('SingleCellExperiment', suppressUpdates=True)
  biocInstaller.biocLite('scran', suppressUpdates=True)
  biocInstaller.biocLite('scater', suppressUpdates=True)
  
  sceLib = importr("SingleCellExperiment")
  scranLib = importr("scran")
  scaterLib = importr("scater")
  named_list = robjects.r.list(counts=counts)
  sce = sceLib.SingleCellExperiment(named_list)
  
  try:
      clusters = scranLib.quickCluster(sce)
      sce = scaterLib.computeSumFactors(sce, cluster=clusters, positive=True)
  except rpy2.rinterface.RRuntimeError:
      print("fewer cells than the minimum cluster size, so no quickCluster is run")
      sce = scranLib.computeSumFactors(sce, positive=True)
  
  ----&gt; sce = scaterLib.normalize(sce, logExprsOffset=1)
  </code></pre>
  
  <p>Everything runs fine except the last line which gives the error:</p>
  
  <blockquote>
    <p>AttributeError: module 'scater' has no attribute 'normalize'</p>
  </blockquote>
  
  <p>This is strange since that is what I am supposed to do actually according to <a href="https://bioconductor.org/packages/3.7/bioc/vignettes/scran/inst/doc/scran.html" rel="nofollow noreferrer">docs</a>.</p>
  
  <p>I suspect that maybe I am loading a wrong <code>scran</code> version? I do not know though neither how to check the version number, nor how to install a specific one. Any suggestions would be greatly appreciated.</p>
  
  <p>I tried the following:</p>
  
  <pre><code>sce = scaterLib.normalizeSCE(sce, log_exprs_offset=1)
  </code></pre>
  
  <p>And it is working. I am afraid though that it is a wrong way to go.</p>
  
  <p>I tried to get the normalized matrix but it retrieved the initial raw counts one:</p>
  
  <pre><code>sce = scaterLib.normalizeSCE(sce, log_exprs_offset=1)
  mtx_norm_r = robjects.r.assay(sce)
  mtx_norm = np.array(mtx_norm_r)
  </code></pre>
  
  <p>So, something is definitely wrong here. Either I am retrieving the normalized matrix in the wrong way or the normalization was not run correctly. I tried the following method for retrieval but no luck:</p>
  
  <pre><code>mtx_norm_r = sceLib.normcounts(sce) 
  </code></pre>
  
  <blockquote>
    <p>RRuntimeError: Error in assay(object, i = exprs_values) : 
      'assay(, i="character", ...)' invalid subscript 'i'
    'normcounts' not in names(assays())</p>
  </blockquote>
  
  <p>I found a way to get the version numbers using <code>getNamespaceVersion()</code> function:</p>
  
  <pre><code>robjects.r.getNamespaceVersion('scater')
  </code></pre>
  
  <p>The versions are:</p>
  
  <pre><code>scater - 1.8.4
  scran - 1.8.4
  SingleCellExperiment - 1.2.0
  </code></pre>
  
  <p>They are the newest as I understand.</p>
  
Tags: <r><python><scran><rpy2>
Title: AttributeError: module 'scater' has no attribute 'normalize'
ThreadText: # AttributeError: module 'scater' has no attribute 'normalize'
  
  (Asked by: username_0 on 2018-09-12)
  
  I am using `rpy2` to run normalization using `scran` package. After calling `computeSumFactors` I want to do the actual normalization calling `normalize()` function from `scater` package:
  
  ```
  def normalize(counts):
  utils = importr('utils')
  utils.chooseCRANmirror(ind=1) 
  
  packnames = ('Matrix', 'limSolve')
  names_to_install = [x for x in packnames if not isinstalled(x)]
  if len(names_to_install) > 0:
      utils.install_packages(StrVector(names_to_install))
  
  base = importr('base')
  base.source('http://www.bioconductor.org/biocLite.R')
  biocInstaller = importr('BiocInstaller')
  
  biocInstaller.biocLite('SingleCellExperiment', suppressUpdates=True)
  biocInstaller.biocLite('scran', suppressUpdates=True)
  biocInstaller.biocLite('scater', suppressUpdates=True)
  
  sceLib = importr("SingleCellExperiment")
  scranLib = importr("scran")
  scaterLib = importr("scater")
  named_list = robjects.r.list(counts=counts)
  sce = sceLib.SingleCellExperiment(named_list)
  
  try:
      clusters = scranLib.quickCluster(sce)
      sce = scaterLib.computeSumFactors(sce, cluster=clusters, positive=True)
  except rpy2.rinterface.RRuntimeError:
      print("fewer cells than the minimum cluster size, so no quickCluster is run")
      sce = scranLib.computeSumFactors(sce, positive=True)
  
  ----> sce = scaterLib.normalize(sce, logExprsOffset=1)
  
  ```
  
  Everything runs fine except the last line which gives the error:
  
  > AttributeError: module 'scater' has no attribute 'normalize'
  
  This is strange since that is what I am supposed to do actually according to [docs](https://bioconductor.org/packages/3.7/bioc/vignettes/scran/inst/doc/scran.html).
  
  I suspect that maybe I am loading a wrong `scran` version? I do not know though neither how to check the version number, nor how to install a specific one. Any suggestions would be greatly appreciated.
  
  I tried the following:
  
  ```
  sce = scaterLib.normalizeSCE(sce, log_exprs_offset=1)
  
  ```
  
  And it is working. I am afraid though that it is a wrong way to go.
  
  I tried to get the normalized matrix but it retrieved the initial raw counts one:
  
  ```
  sce = scaterLib.normalizeSCE(sce, log_exprs_offset=1)
  mtx_norm_r = robjects.r.assay(sce)
  mtx_norm = np.array(mtx_norm_r)
  
  ```
  
  So, something is definitely wrong here. Either I am retrieving the normalized matrix in the wrong way or the normalization was not run correctly. I tried the following method for retrieval but no luck:
  
  ```
  mtx_norm_r = sceLib.normcounts(sce) 
  
  ```
  
  > RRuntimeError: Error in assay(object, i = exprs\_values) :
  > 'assay(, i="character", ...)' invalid subscript 'i'
  > 'normcounts' not in names(assays())
  
  I found a way to get the version numbers using `getNamespaceVersion()` function:
  
  ```
  robjects.r.getNamespaceVersion('scater')
  
  ```
  
  The versions are:
  
  ```
  scater - 1.8.4
  scran - 1.8.4
  SingleCellExperiment - 1.2.0
  
  ```
  
  They are the newest as I understand.
  
  **Tags:** r, python, scran, rpy2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-09-12. Score: 1
  
  I was able to get to the normalized values using `logcounts` function in the following way:
  
  ```
  mtx_norm_r = sceLib.logcounts(sce)
  mtx_norm = np.array(mtx_norm_r)
  
  ```
  
  Since I used `log_exprs_offset=1` the field that I needed to use is `logcounts`, otherwise it should be `normcounts` which I found [here](https://rdrr.io/bioc/scater/man/normalize.html).
  
  > **Comments:**
  > **username_1**: Maybe you know it but you can read the help page for each function using `?name_of_function` on the terminal (There is no need to consult an online help page that might not match your version of the package).  
  > **username_0**: But I can not check it in `spyder`  
  > **username_1**: I don't know what is spyder but if it can run R is run you can.  
  > **username_0**: It can not be done, or I do not know how anyway. It is `rpy2` python library that translates objects between `R` and `python` and the documentation is often not clear and detailed enough, in my view, probably because not that many people use it. Spyder is just IDE for `python` from `anaconda`  
  
  ---
  
  