Hello,
I'm trying to use scVelo to compute velocities for genes.
I'm using windows 11 to run the following python code on Visual Studio
import argparse
import scanpy as sc
import scvelo as scv
seed = 52
parser= argparse.ArgumentParser()
parser.add_argument('-k', type=int, help='Integer describing the size of the local neighborhood')
parser.add_argument('-pc', type=int, help='Integer describing the number of principal components')
parser.add_argument('-res', type=float, help='Float indicating the resolution of the Louvain community detection algorithm')
args = parser.parse_args()
print(args.k, args.pc, args.res)
CWD = os.getcwd()
DATA_FOLDER = os.path.join(CWD, "scRNA_adata")
DATA_PATH = os.path.join(DATA_FOLDER, '10xMouse_loom_preprocessed.h5ad')
adata = sc.read_h5ad(DATA_PATH)
scv.pp.moments(adata, n_neighbors=args.k, n_pcs=args.pc)
sc.pp.neighbors(adata, n_neighbors=args.k, n_pcs=args.pc, random_state = seed)
sc.tl.louvain(adata, resolution=args.res, random_state=seed)
sc.tl.umap(adata, random_state=seed)
# Recovers full splicing kinetics
scv.tl.recover_dynamics(adata, n_jobs=-1, backend='threading')
print("STWMPW")
scv.tl.velocity(adata, mode='dynamical')
scv.tl.velocity_graph(adata, n_jobs=-1)
title = f"Dynamical model K={args.k} PC={args.pc} resolution={args.res}"
path= f"dynamicalModel_{args.k}K{args.pc}PC{args.res}resolution.png"
scv.pl.velocity_embedding_stream(adata, basis='umap', color=['louvain', 'celltype'], title=title, save= path)
# Compute latent time (cell's internal clock)
title = f"Cell specific latent time K={args.k} PC={args.pc} resolution={args.res}"
path= f"latentTime_{args.k}K{args.pc}PC{args.res}resolution.png"
scv.tl.latent_time(adata)
scv.pl.scatter(adata, color='latent_time', color_map='gnuplot', size=40, save=path, title=title)
# Saving file
path = os.path.join(DATA_FOLDER, f"scVeloDynamical_{args.k}K{args.pc}PC{args.res}res.h5ad")
adata.write_h5ad(path)
This is the output I'm getting:
From the picture one can see that after recover_dynamics is called, a new thread is created and runs the same script from the beginning (it outputs the args parameters a second time, recomputes neighbors and moments and calls recover_dynamics - highlighted). Then, at the second call, I get the following error:
recovering dynamics (using 8/8 cores)
0%| | 0/1614 [00:00<?, ?gene/s]
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\aless\Desktop\scVEMO\10XMouse_scVelo_velocities.py", line 26, in <module>
scv.tl.recover_dynamics(adata, n_jobs=-1, backend='threading')
File "C:\Users\aless\Desktop\scVEMO\lib\site-packages\scvelo\tools\_em_model_core.py", line 553, in recover_dynamics
res = parallelize(
File "C:\Users\aless\Desktop\scVEMO\lib\site-packages\scvelo\core\_parallelize.py", line 121, in wrapper
queue = Manager().Queue()
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 57, in Manager
m.start()
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\managers.py", line 553, in start
self._process.start()
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
Traceback (most recent call last):
queue = Manager().Queue()
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 57, in Manager
m.start()
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\managers.py", line 557, in start
self._address = reader.recv()
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\connection.py", line 255, in recv
buf = self._recv_bytes()
File "C:\Users\aless\AppData\Local\Programs\Python\Python39\lib\multiprocessing\connection.py", line 310, in _recv_bytes
waitres = _winapi.WaitForMultipleObjects(
Hello, I'm trying to use scVelo to compute velocities for genes. I'm using windows 11 to run the following python code on Visual Studio
This is the output I'm getting: From the picture one can see that after recover_dynamics is called, a new thread is created and runs the same script from the beginning (it outputs the args parameters a second time, recomputes neighbors and moments and calls recover_dynamics - highlighted). Then, at the second call, I get the following error:
I'm using the following packages:
Any suggestion? I do not have the same issue when I run the same code on a jupyter notebook.