Comments (5)
@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.
@scottgigante Thank you so much!
I will try it!
from magic.
Hi @scottgigante,
I tried that code. I used the affinity matrix and generated a graph.
I could make a magic operator using the graph. But transformation failed.
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.
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.
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)
- Magic issue with mkl
- Suggestions for Unable to allocate 276. GiB for an array with shape (161877, 228942) and data type float64
- Magic + seurat workflow HOT 4
- Running UMAP after Magic - is it valid?
- NaN values when computing the kernel lead to inability to find t-optimal MATLAB.
- Error: package or namespace load failed for 'Rmagic': HOT 5
- Does it really run in parallel?
- problem running magic HOT 1
- Animate MAGIC error
- Rmagic was removed from the CRAN repository HOT 3
- magic() function error: Stuck on "Calculating PCA..." HOT 1
- ValueError: Length mismatch: Expected axis has 100 elements, new values have 10782 elements
- Name of the package confused with python-magic package
- can not put in more than 1 genes. HOT 5
- Getting 0.0 after imputation
- Option for Computing KNN with some genes, but returning whole graph
- Rmagic HOT 2
- Is it a good idea to run magic on sctransform processed data?
- Is it possible to pass a custom embedding?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magic.