raphael-group / ConDoR

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code needs to be fixed at this line: solveConstrainedDollo.py line 303

seunghooh5 opened this issue · comments

Line causing problem:

solb = np.rint(np.reshape(model.getAttr('x', b).values(), (ncells, nmutations)))

Running ConDoR even with the sample data (overview_characteristic_matrix.csv, etc.) kept giving me the following value error:
ValueError: cannot reshape array of size 1 into shape (25,25)

The entire traceback message was as following:

Traceback (most recent call last):
  File "/home/user/condor_root_dir/src/condor.py", line 98, in <module>
    main(args)
  File "/home/user/condor_root_dir/src/condor.py", line 68, in main
    solver.solveSetInclusion()
  File "/home/user/condor_root_dir/src/solveConstrainedDollo.py", line 304, in solveSetInclusion
    solb = np.rint(np.reshape(model.getAttr('x', b).values(), (ncells, nmutations)))
  File "<__array_function__ internals>", line 200, in reshape
  File "/home/user/miniconda3/envs/ConDoR/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 298, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "/home/user/miniconda3/envs/ConDoR/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 54, in _wrapfunc
    return _wrapit(obj, method, *args, **kwds)
  File "/home/user/miniconda3/envs/ConDoR/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 43, in _wrapit
    result = getattr(asarray(obj), method)(*args, **kwds)
ValueError: cannot reshape array of size 1 into shape (25,25)

The reason for this was model.getAttr('x', b).values() returns a view object of the values in the dictionary, not a NumPy array.

So I fixed this (solb = np.rint(np.reshape(model.getAttr('x', b).values(), (ncells, nmutations)))) to:
solb = np.rint(np.reshape(np.array(list(model.getAttr('x', b).values())), (ncells, nmutations)))

and it worked.

Thanks! I had the same problem and this saved me much time debugging!