Giter Site home page Giter Site logo

MAGIC on RNA + ATAC data about magic HOT 5 OPEN

yamajackr avatar yamajackr commented on August 17, 2024
MAGIC on RNA + ATAC data

from magic.

Comments (5)

scottgigante avatar scottgigante commented on August 17, 2024

@yamamotoryo this is a totally valid use case, yes. You can pass the distance matrix to a graphtools.Graph with precomputed='distance', and then pass this graph to MAGIC.fit(X, graph=graph).

from magic.

yamajackr avatar yamajackr commented on August 17, 2024

@scottgigante Thank you so much!
I will try it!

from magic.

yamajackr avatar yamajackr commented on August 17, 2024

Hi @scottgigante,
I tried that code. I used the affinity matrix and generated a graph.
Screenshot 2022-11-02 at 3 48 17 PM

I could make a magic operator using the graph. But transformation failed.

Screenshot 2022-11-02 at 3 53 16 PM

affi =  pd.read_csv('affinity_mat.tsv',header=0, sep='\t', index_col=0)
data = affi.to_numpy()
graph = graphtools.Graph(data, precomputed='affinity')
magic_op_g = magic.MAGIC()
magic_op_g = magic_op_g.fit(X=X,  graph=graph)
X_magic = magic_op_g.transform()

Error

magic_op_g = magic_op_g.fit(X=df, graph=graph)
Running MAGIC on 1729 cells and 21470 genes.
Using precomputed graph and diffusion operator...

X_magic = magic_op_g.transform()
Calculating imputation...
Calculated imputation in 0.26 seconds.
Traceback (most recent call last):

File "/var/folders/59/cxr2yt4926jc95n5w2mtz32r0000gn/T/ipykernel_34361/2648698257.py", line 1, in
X_magic = magic_op_g.transform()

File "/Users/jack/opt/anaconda3/envs/py310/lib/python3.10/site-packages/magic/magic.py", line 607, in transform
X_magic = utils.convert_to_same_format(

File "/Users/jack/opt/anaconda3/envs/py310/lib/python3.10/site-packages/magic/utils.py", line 167, in convert_to_same_format
data.columns = target_columns

File "/Users/jack/opt/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/generic.py", line 5588, in setattr
return object.setattr(self, name, value)

File "pandas/_libs/properties.pyx", line 70, in pandas._libs.properties.AxisProperty.set

File "/Users/jack/opt/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/generic.py", line 769, in _set_axis
self._mgr.set_axis(axis, labels)

File "/Users/jack/opt/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 214, in set_axis
self._validate_set_axis(axis, new_labels)

File "/Users/jack/opt/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/internals/base.py", line 69, in _validate_set_axis
raise ValueError(

ValueError: Length mismatch: Expected axis has 1729 elements, new values have 21470 elements

The default function without a graph worked.

magic_op = magic.MAGIC()
magic_op = magic_op.fit_transform(X=X)

Any help would be appreciated.

Thank you,
Ryosuke

from magic.

scottgigante avatar scottgigante commented on August 17, 2024

Looks like a bug, but you can work around it with magic_op_g = magic_op_g.fit(X=df.to_numpy(), graph=graph)

from magic.

yamajackr avatar yamajackr commented on August 17, 2024

Thanks, @scottgigante .
Your code worked, but the shape of obtained array was same as that of graph.
(Gene number was 21,000; cell number was 1,729; obtained array was 1,729 x 1.729)

Instead, I tried this.

magic_op_g = magic.MAGIC()
magic_op_g = magic_op_g.fit(X=df,  graph=graph)
diff_op_3 = np.linalg.matrix_power(magic_op_g.diff_op, 3) # t = 3
data_new = np.array(np.dot(diff_op_3, df)) 
df_new = pd.DataFrame(data=data_new, columns=df.columns.tolist())

I think it works.

from magic.

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.