Git Product home page Git Product logo

Comments (4)

gtca avatar gtca commented on August 28, 2024

This seems to have expected behaviour:

import numpy as np
from anndata import AnnData
from muon import prot as pt

adata = AnnData(np.arange(1000).reshape(-1, 10))
adata.raw = adata

pt.pp.clr(adata)
print(adata.X[:2,:2])
# [[0.         0.00276899]
#  [0.02767339 0.03004515]]
print(adata.raw.X[:2,:2])
# [[ 0.  1.]
#  [10. 11.]]

Any idea how your observation can be reproduced?

from muon.

GirayEryilmaz avatar GirayEryilmaz commented on August 28, 2024

Very interesting!
Here is my attempt:

import muon as mu
import anndata
import numpy as np

x = np.array([[10, 10],
              [10, 20]], dtype=float)
adata = anndata.AnnData(x)
adata.raw = adata

mu.prot.pp.clr(adata)
print(adata.X)
# [[0.64662716 0.50558292]
#  [0.64662716 0.83979984]]
print(adata.raw.X)
# [[0.64662716 0.50558292]
# [0.64662716 0.83979984]]
print(mu.__version__) # 0.1.5
print(anndata.__version__) # 0.9.2
print(sc.__version__) # 1.9.3

Also I noticed that giving inplace = False solves the problem for me:

x = np.array([[10, 10],
              [10, 20]], dtype=float)
adata = anndata.AnnData(x)
adata.raw = adata

adata = mu.prot.pp.clr(adata, inplace=False)
print(adata.X)
# [[0.64662716 0.50558292]
# [0.64662716 0.83979984]]
print(adata.raw.X)
# [[10. 10.]
# [10. 20.]]

Still I would like to understand what is going on and avoid an unnecessary copying operation. Any suggestions are welcome!

from muon.

GirayEryilmaz avatar GirayEryilmaz commented on August 28, 2024

I found the source of the problem.

x = np.array([[10, 20]], dtype=float)
adata = anndata.AnnData(x)

adata.raw = adata

print(adata.X is adata.raw.X) # Prints True

For me, apparently, adata.X IS adata.raw.X. That is why when clr normalizes X, raw.X is also normalized.
I don't know if this is the intended behavior of raw and I don't know why I am having this issue whilst @gtca is not.

@gtca would you mind sharing which version of Anndata you are using?

from muon.

gtca avatar gtca commented on August 28, 2024

Indeed, in anndata v0.8:

id(adata.raw.X) == id(adata.X)
# => False

whereas in anndata v0.9.2 as well as in anndata v.10:

id(adata.raw.X) == id(adata.X)
# => True

Probably a new issue in the anndata repo is a better place to track this then: scverse/anndata#1139!

from muon.

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.