Giter VIP home page Giter VIP logo

Comments (4)

slowkow avatar slowkow commented on May 28, 2024

Have you tried replacing the original PCs with the harmonized PCs?

adjusted_pcs = pd.DataFrame(ho.Z_corr)
adata.obsm['X_pca'] = adjusted_pcs

You might also be able to add a new entry in the obsm slot:

adata.obsm['X_pca_harmonized'] = adjusted_pcs

I did not test these snippets, so I don't know if they will work or not.

from harmonypy.

321356766 avatar 321356766 commented on May 28, 2024

Thanks for your quick response!

In both cases I get a length error:

adjusted_pcs = pd.DataFrame(ho.Z_corr)
adata.obsm['X_pca'] = adjusted_pcs
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-93-d54e748e808d> in <module>
      1 adjusted_pcs = pd.DataFrame(ho.Z_corr)
----> 2 adata.obsm['X_pca'] = adjusted_pcs

~/anaconda3/lib/python3.7/site-packages/anndata/_core/aligned_mapping.py in __setitem__(self, key, value)
    148 
    149     def __setitem__(self, key: str, value: V):
--> 150         value = self._validate_value(value, key)
    151         self._data[key] = value
    152 

~/anaconda3/lib/python3.7/site-packages/anndata/_core/aligned_mapping.py in _validate_value(self, val, key)
    206             hasattr(val, "index")
    207             and isinstance(val.index, cabc.Collection)
--> 208             and not (val.index == self.dim_names).all()
    209         ):
    210             # Could probably also re-order index if it’s contained

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in cmp_method(self, other)
    103         if isinstance(other, (np.ndarray, Index, ABCSeries, ExtensionArray)):
    104             if other.ndim > 0 and len(self) != len(other):
--> 105                 raise ValueError("Lengths must match to compare")
    106 
    107         if is_object_dtype(self) and isinstance(other, ABCCategorical):

ValueError: Lengths must match to compare
---------------------------------------------------------------------------

Same thing also happens if I try to use

adata.obsm['X_pca'] = adjusted_pcs.values
ValueError: Value passed for key 'X_pca' is of incorrect shape. Values of obsm must match dimensions (0,) of parent. Value had shape (50, 29552) while it should have had (29552,).

Thanks for your time.

from harmonypy.

321356766 avatar 321356766 commented on May 28, 2024

I think a simple transpose fixed the issue:

adjusted_pcs = pd.DataFrame(ho.Z_corr).T
adata.obsm['X_pca']=adjusted_pcs.values

Thanks!

from harmonypy.

slowkow avatar slowkow commented on May 28, 2024

Thanks for sharing the results. Glad you got it working.

from harmonypy.

Related Issues (17)

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.